:root {
  color-scheme: light;
  --bg: #f3f4f7;
  --surface: #ffffffcc;
  --surface-solid: #ffffff;
  --surface-muted: #f8f9fb;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e7e8ec;
  --line-soft: #f0f1f4;
  --accent: #5e5ce6;
  --accent-soft: #eeedff;
  --success: #2d9d78;
  --danger: #d74f4f;
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --shadow-sm: 0 8px 24px rgba(23, 23, 34, 0.05);
  --shadow-md: 0 16px 40px rgba(23, 23, 34, 0.08);
  --glass: blur(18px);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0e13;
  --surface: #191b24cc;
  --surface-solid: #161923;
  --surface-muted: #1f2330;
  --text: #f5f7ff;
  --muted: #9ea5bf;
  --line: #2a2f3d;
  --line-soft: #242938;
  --accent: #8c88ff;
  --accent-soft: #262343;
  --success: #53c89d;
  --danger: #ff7f7f;
  --shadow-sm: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 20px 50px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: "SF Pro Text", "SF Pro Display", Inter, "Segoe UI", Arial, sans-serif;
  background: radial-gradient(circle at top right, #ffffff 0%, var(--bg) 36%, var(--bg) 100%);
  color: var(--text);
  letter-spacing: -0.01em;
}

.layout { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; gap: 24px; padding: 20px; }
.sidebar {
  background: var(--surface);
  backdrop-filter: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  padding: 22px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.brand-wrap { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), #9ca0ff);
  box-shadow: inset 0 1px 0 #ffffff99;
}
.brand { font-size: 17px; font-weight: 680; margin: 0; }
.side-nav { display: grid; gap: 6px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--muted);
  border-radius: 12px; padding: 10px 12px;
  transition: all .22s ease;
}
.side-nav a::before {
  content: "";
  width: 7px; height: 7px; border-radius: 99px; background: var(--line);
  transition: all .22s ease;
}
.side-nav a:hover { background: var(--surface-muted); color: var(--text); transform: translateX(2px); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-nav a.active::before { background: var(--accent); transform: scale(1.1); }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; padding: 10px; }
.user-chip {
  background: var(--surface-muted); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: 10px 12px; display: grid; gap: 2px;
}

.content { padding: 10px 8px 24px 0; display: grid; gap: 18px; }
.topbar {
  background: var(--surface);
  backdrop-filter: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.page-title { font-size: clamp(24px, 2.8vw, 34px); line-height: 1.1; margin: 0 0 4px; letter-spacing: -0.022em; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.search-field input { min-width: 220px; }

h1, h2, h3 { margin: 0 0 12px; letter-spacing: -0.015em; }
h2 { font-size: 20px; }
h3 { font-size: 14px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.muted { color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.card, .panel {
  background: var(--surface);
  backdrop-filter: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card { transition: transform .25s ease, box-shadow .25s ease; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.card p { font-size: clamp(24px, 3vw, 32px); margin: 4px 0 0; font-weight: 620; }

.panel { overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.panel-headline { display: grid; gap: 2px; }

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}
label { color: var(--muted); font-size: 13px; display: grid; gap: 6px; }
input, select, button, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  font: inherit;
  color: var(--text);
  background: var(--surface-solid);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: color-mix(in oklab, var(--accent) 55%, var(--line));
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--accent) 18%, transparent);
}
textarea { min-height: 100px; resize: vertical; }

.btn {
  width: auto;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border-radius: 12px;
  font-weight: 560;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(150deg, var(--accent), #7d7af8);
  box-shadow: 0 8px 16px color-mix(in oklab, var(--accent) 28%, transparent);
}
.btn-ghost { background: var(--surface-muted); color: var(--text); border-color: var(--line); }
.btn-danger { background: color-mix(in oklab, var(--danger) 10%, var(--surface-solid)); color: var(--danger); border-color: color-mix(in oklab, var(--danger) 18%, var(--line)); }

.table-wrap { overflow: auto; border: 1px solid var(--line-soft); border-radius: 14px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 640px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-muted);
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 640; letter-spacing: .04em;
  text-transform: uppercase;
}
th, td { padding: 13px 14px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--line-soft); }
tbody tr { transition: background .2s ease; }
tbody tr:hover { background: color-mix(in oklab, var(--accent) 4%, var(--surface-solid)); }

.toast-stack {
  position: fixed; top: 24px; right: 24px; z-index: 1000;
  display: grid; gap: 8px; width: min(360px, 92vw);
}
.alert {
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-solid);
  box-shadow: var(--shadow-sm);
}
.alert-success { border-color: color-mix(in oklab, var(--success) 40%, var(--line)); color: var(--success); }
.alert-danger { border-color: color-mix(in oklab, var(--danger) 40%, var(--line)); color: var(--danger); }
.alert-warning { border-color: color-mix(in oklab, #ffbb55 45%, var(--line)); color: #bc7d2f; }

.danger { color: var(--danger); font-weight: 650; }
.success { color: var(--success); font-weight: 650; }
.warning { color: #bc7d2f; font-weight: 650; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.auth-card {
  width: min(440px, 95vw);
  padding: 28px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: var(--glass);
  box-shadow: var(--shadow-md);
}
.auth-card form { display: grid; gap: 10px; margin-top: 14px; }

.chart-grid { display: grid; grid-template-columns: 1.3fr .8fr; gap: 14px; }
.chart-bars { display: grid; gap: 10px; }
.bar-row { display: grid; gap: 5px; }
.bar-track { width: 100%; height: 9px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(120deg, var(--accent), #9d9bff); }
.quick-actions { display: grid; gap: 10px; }
.upload-dropzone {
  padding: 14px;
  border: 1px dashed color-mix(in oklab, var(--accent) 35%, var(--line));
  background: color-mix(in oklab, var(--accent-soft) 48%, var(--surface-solid));
  border-radius: 14px;
}
.upload-dropzone input { background: var(--surface-solid); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .content { padding: 0; }
}
@media (max-width: 860px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { width: 100%; }
  .search-field input { min-width: 0; width: 100%; }
  .chart-grid { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .btn, .toast-stack, .grid-form { display: none !important; }
  .layout { display: block; padding: 0; }
  .content { padding: 0; }
  .panel { border: 0; box-shadow: none; background: #fff; }
  .table-wrap { border: 0; overflow: visible; }
  table { min-width: 0; }
  body { background: #fff; color: #111; }
}
