:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --up-good: #006300;
  --down-bad: #b42b2b;
  --compare: #a8a69f;

  /* Grade scale: status-style, always shown with an icon + label */
  --g-underperforming: #d03b3b;
  --g-needs_improvement: #ec835a;
  --g-meets: #0ca30c;
  --g-exceeds: #3987e5;
  --g-outstanding: #184f95;
  --g-none: #c3c2b7;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --up-good: #0ca30c;
    --down-bad: #e66767;
    --compare: #6b6a65;
    --g-underperforming: #e05555;
    --g-needs_improvement: #ec835a;
    --g-meets: #0ca30c;
    --g-exceeds: #3987e5;
    --g-outstanding: #86b6ef;
    --g-none: #4a4a46;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --up-good: #0ca30c;
  --down-bad: #e66767;
  --compare: #6b6a65;
  --g-underperforming: #e05555;
  --g-needs_improvement: #ec835a;
  --g-meets: #0ca30c;
  --g-exceeds: #3987e5;
  --g-outstanding: #86b6ef;
  --g-none: #4a4a46;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body { font-size: 14px; line-height: 1.45; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ---- shell ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.brand .logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--ink-2); white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { color: var(--ink); background: var(--surface-2); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  position: relative; width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.badge {
  position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--g-underperforming); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 64px; }

/* ---- filters ---- */
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 20px;
}
.filters .spacer { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
select, input[type="date"], input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  min-width: 0;
}
input[type="number"] { width: 110px; }
select:focus, input:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.btn {
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }

/* ---- cards ---- */
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.section-head .sub { color: var(--muted); font-size: 13px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
.kpi-card { display: flex; flex-direction: column; gap: 10px; cursor: pointer; text-decoration: none; position: relative; }
.kpi-card:hover { border-color: var(--axis); }
.kpi-card .rail { position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; }
.kpi-card .label { color: var(--ink-2); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.kpi-card .value { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; }
.kpi-card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.kpi-card .target { color: var(--muted); font-size: 12px; }
.spark { width: 100%; height: 36px; display: block; }

.delta { font-size: 12px; font-weight: 600; white-space: nowrap; }
.delta.good { color: var(--up-good); }
.delta.bad { color: var(--down-bad); }
.delta.flat { color: var(--muted); }
.delta .vs { font-weight: 400; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 6px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  white-space: nowrap;
}
.pill .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: grid; place-items: center; }
.pill .dot svg { width: 8px; height: 8px; }

/* ---- detail ---- */
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.hero { font-size: 48px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.05; }
.hero-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.desc { color: var(--ink-2); max-width: 680px; margin-top: 4px; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 12px; }
.chart-box { position: relative; height: 320px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin: 4px 0 10px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .line { width: 16px; height: 0; border-top: 2px solid; }
.legend .line.dash { border-top-style: dashed; }
.forecast-list { display: grid; gap: 10px; }
.forecast-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.forecast-item:last-child { border-bottom: 0; }
.forecast-item .k { color: var(--ink-2); font-size: 13px; }
.forecast-item .v { font-size: 18px; font-weight: 600; }
.note { color: var(--muted); font-size: 12px; }
.callout {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-size: 13px;
  color: var(--ink-2); margin-bottom: 16px;
}

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.bar { height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 2px; }
.bar-cell { width: 30%; min-width: 120px; }
.muted { color: var(--muted); }
.unmapped { color: var(--muted); font-style: italic; }

/* ---- admin ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; padding: 8px 12px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.report { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; }
.report .stat { min-width: 90px; }
.report .stat b { display: block; font-size: 22px; }
.errors { color: var(--down-bad); font-size: 13px; margin: 0; padding-left: 18px; }
.status-ok { color: var(--up-good); font-weight: 600; }
.status-error { color: var(--down-bad); font-weight: 600; }
.status-skipped, .status-running { color: var(--muted); font-weight: 600; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login input { width: 100%; }
.error { color: var(--down-bad); font-size: 13px; min-height: 18px; }

/* ---- notifications ---- */
.notif { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--grid); }
.notif.unread .msg { font-weight: 600; }
.notif .when { color: var(--muted); font-size: 12px; }

#toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
.loading { opacity: .55; transition: opacity .15s; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

@media (max-width: 900px) {
  .two-col { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; gap: 8px; flex-wrap: wrap; }
  .nav { order: 3; width: 100%; flex-basis: 100%; }
  main { padding: 16px 16px 48px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .hero { font-size: 40px; }
  .chart-box { height: 260px; }
  .bar-cell { display: none; }
  .filters .field { flex: 1 1 140px; }
  .filters select, .filters input { width: 100%; }
}
