:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #f8fbfa;
  --ink: #0e1b2a;
  --ink-2: #3d4b5c;
  --muted: #687789;
  --line: #e1e8ec;
  --brand: #007964;
  --brand-dark: #003f42;
  --brand-tint: #e7f5f2;
  --bar: #09947d;
  --grid: #edf1f3;
  --good: #10935d;  --good-bg: #e8f7ed;
  --warn: #9c6700;  --warn-bg: #fff3d6;
  --bad: #c42b1c;   --bad-bg: #ffe8e5;
  --info: #246bca;  --info-bg: #e8f0fb;
  --shadow: 0 1px 2px rgba(14, 27, 42, .05), 0 8px 24px rgba(14, 27, 42, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1615;
    --surface: #18201f;
    --surface-2: #1d2726;
    --ink: #eef3f2;
    --ink-2: #c3cfcd;
    --muted: #8fa09d;
    --line: #2a3634;
    --brand: #17a88c;
    --brand-dark: #0b5b4f;
    --brand-tint: #15322d;
    --bar: #13a78c;
    --grid: #26302f;
    --good: #4cc98a;  --good-bg: #173226;
    --warn: #e6b04a;  --warn-bg: #362a12;
    --bad: #ff7b6b;   --bad-bg: #3a1c19;
    --info: #7fb0f5;  --info-bg: #182a44;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* Buttons & inputs */
.btn {
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid transparent;
  padding: 9px 14px; cursor: pointer; background: var(--surface-2); color: var(--ink);
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.warn { background: var(--warn-bg); color: var(--warn); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
textarea { min-height: 84px; resize: vertical; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
.error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; margin: 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border-radius: 20px; padding: 32px 28px;
  box-shadow: var(--shadow); display: grid; gap: 14px; border: 1px solid var(--line);
}
.login-logo { width: 52px; height: 52px; }
.login-card h1 { font-size: 24px; font-weight: 800; }
.login-card p { margin: -6px 0 4px; }

/* Shell */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  min-width: 0;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 800; font-size: 17px; padding: 0 8px; }
.brand:hover { text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.brand small { font-weight: 600; color: var(--muted); font-size: 12px; margin-left: 2px; }
#nav { display: grid; gap: 2px; }
#nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 600;
}
#nav a:hover { background: var(--surface-2); text-decoration: none; }
#nav a.active { background: var(--brand-tint); color: var(--brand); }
.badge { background: var(--warn-bg); color: var(--warn); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 700; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 0 8px; }

.content { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 28px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.view { padding: 24px 28px 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; max-width: 1280px; }

/* Cards & tiles */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card h2 { font-size: 15px; font-weight: 700; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.tile { padding: 16px 18px; }
.tile .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 28px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.alert { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }

/* Pills */
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { color: var(--good); background: var(--good-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.info { color: var(--info); background: var(--info-bg); }
.pill.neutral { color: var(--muted); background: var(--surface-2); }

/* Tables */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar input { max-width: 280px; }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.tabs button { font: inherit; font-weight: 600; font-size: 13px; border: 0; background: transparent; color: var(--ink-2); padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }
.table-wrap { overflow-x: auto; margin: 0 -20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 20px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr { cursor: default; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td .sub { color: var(--muted); font-size: 12px; }
td.right, th.right { text-align: right; }
.empty { padding: 32px 0; text-align: center; color: var(--muted); }

/* Chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--bar); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { fill: var(--brand-dark); }
@media (prefers-color-scheme: dark) { .chart .bar.hover { fill: #5fd3b8; } }
.chart-tip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--surface);
  border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: var(--shadow);
}
.chart-tip strong { display: block; font-size: 14px; }
.link-btn { font: inherit; font-size: 12px; font-weight: 600; color: var(--brand); background: none; border: 0; cursor: pointer; padding: 0; }

/* Drawer */
.backdrop { position: fixed; inset: 0; background: rgba(10, 20, 25, .35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); z-index: 21;
  background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto;
  padding: 28px 28px 40px; box-shadow: -12px 0 40px rgba(0, 0, 0, .12);
}
.drawer-close { position: absolute; top: 14px; right: 16px; font-size: 26px; line-height: 1; border: 0; background: none; color: var(--muted); cursor: pointer; }
.drawer h2 { font-size: 20px; font-weight: 800; margin-right: 32px; }
.drawer section { margin-top: 22px; display: grid; gap: 10px; }
.drawer h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 12px 1fr; gap: 10px; }
.timeline li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-top: 6px; }
.timeline li:first-child::before { background: var(--brand); }
.notice { background: var(--warn-bg); color: var(--warn); padding: 12px 14px; border-radius: 10px; font-weight: 500; }
.notice.info { background: var(--info-bg); color: var(--info); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  box-shadow: var(--shadow);
}
.toast.bad { background: var(--bad); color: #fff; }

/* Phone & tablet */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 14px; }
  .tile .value { font-size: 22px; }
  .card-head .tabs { max-width: 100%; }
  .sidebar { position: static; height: auto; flex-direction: column; gap: 10px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  #nav { display: flex; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
  #nav a { white-space: nowrap; }
  .sidebar-foot { flex-direction: row; display: flex; align-items: center; justify-content: space-between; margin: 0; padding: 0; }
  .topbar { padding: 14px 16px; position: static; }
  .view { padding: 16px 16px 40px; }
  .table-wrap { margin: 0 -20px; }
  dl.kv { grid-template-columns: 1fr; gap: 2px; }
  dl.kv dd { margin-bottom: 8px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .toolbar input { max-width: none; }
}

.mt { margin-top: 12px; }
.section-title { font-size: 15px; margin-top: 8px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
