:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --ink: #18211d;
  --muted: #5e6a64;
  --line: #e1dfd6;
  --brand: #0f4d3a;
  --brand-ink: #ffffff;
  --accent: #b8871b;
  --current: #0f6b4f;
  --previous: #a8aea9;
  --target: #b8871b;
  --up: #12784f;
  --down: #b3382c;
  --focus: #2f7cf6;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 4%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --surface: #171e1b;
    --surface-2: #1e2723;
    --ink: #e8ede9;
    --muted: #9aa8a1;
    --line: #2a3530;
    --brand: #13583f;
    --accent: #e3b341;
    --current: #3ccf94;
    --previous: #6b7570;
    --target: #e3b341;
    --up: #46d39a;
    --down: #f2786b;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171e1b; --surface-2: #1e2723; --ink: #e8ede9; --muted: #9aa8a1;
  --line: #2a3530; --brand: #13583f; --accent: #e3b341; --current: #3ccf94; --previous: #6b7570;
  --target: #e3b341; --up: #46d39a; --down: #f2786b; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px; background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 8px; box-shadow: 0 0 0 1px rgb(255 255 255 / 25%); }
.brand-name { font-weight: 700; font-size: 14px; }
.brand-sub { font-size: 12px; opacity: .8; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs a {
  padding: 8px 12px; border-radius: 8px; text-decoration: none; white-space: nowrap;
  color: rgb(255 255 255 / 80%); font-weight: 500;
}
.tabs a:hover { background: rgb(255 255 255 / 10%); color: #fff; }
.tabs a[aria-current="page"] { background: rgb(255 255 255 / 16%); color: #fff; }
.user { position: relative; }
.topbar .btn-ghost { color: #fff; border-color: rgb(255 255 255 / 30%); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 4px; display: grid;
}
.menu button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; font: inherit; color: inherit; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

/* Layout */
.view { max-width: 1180px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; }
.page-head p { margin: 4px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.stack { display: grid; gap: 16px; }
tr[aria-selected="true"] { background: color-mix(in srgb, var(--current) 10%, transparent); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.01em; }
.kpi .compare { margin-top: 4px; font-size: 13px; color: var(--muted); }
.delta { font-weight: 600; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--current); }

/* Controls */
.btn {
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 85%, #000); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--down); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button { font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select {
  font: inherit; font-size: 15px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
select { padding-right: 28px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.form-row > label { flex: 1 1 200px; }
.form-error { color: var(--down); margin: 0; font-size: 14px; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.notice.warn { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.notice.error { border-color: color-mix(in srgb, var(--down) 50%, var(--line)); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.good { color: var(--up); background: color-mix(in srgb, var(--up) 14%, transparent); }
.pill.bad { color: var(--down); background: color-mix(in srgb, var(--down) 14%, transparent); }
.pill.info { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }

/* Charts */
.chart { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.current { stroke: var(--current); }
.chart .line.previous { stroke: var(--previous); stroke-dasharray: 5 4; }
.chart .dot.current { fill: var(--current); }
.chart .dot.previous { fill: var(--previous); }
.chart .bar.current { fill: var(--current); }
.chart .bar.previous { fill: var(--previous); }
.chart .cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .hit { fill: transparent; }
.chart-tip {
  position: absolute; top: 0; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 13px; min-width: 160px;
}
.chart-tip-title { font-weight: 700; margin-bottom: 4px; }
.chart-tip-row { display: flex; align-items: center; gap: 6px; }
.chart-tip-row strong { margin-left: auto; padding-left: 10px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }
.swatch.current { background: var(--current); }
.swatch.previous { background: var(--previous); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; display: grid; gap: 20px; }
.login-card form { display: grid; gap: 14px; }
.login-card .brand-sub { color: var(--muted); opacity: 1; }
.brand-lg .brand-name { font-size: 17px; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog form { display: grid; gap: 14px; padding: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .user { margin-left: auto; }
  .view { padding: 16px; gap: 16px; }
  .kpi .value { font-size: 24px; }
  .grid-2 { grid-template-columns: 1fr; }
}
