:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f1f3f9;
  --line: #e3e6ef;
  --fg: #111827;
  --muted: #6b7280;
  --brand: #6d5dfc;
  --brand-2: #38bdf8;
  --brand-soft: #eeecff;
  --good: #059669;
  --warn: #b45309;
  --bad: #dc2626;
  --bar: #7c6ff7;
  --bar-2: #38bdf8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --panel: #121826; --panel-2: #192132; --line: #243047; --fg: #e5e7eb; --muted: #94a3b8;
    --brand: #8b7dff; --brand-2: #38bdf8; --brand-soft: #231f45; --good: #34d399; --warn: #fbbf24; --bad: #f87171;
    --bar: #8b7dff; --bar-2: #38bdf8; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --panel: #121826; --panel-2: #192132; --line: #243047; --fg: #e5e7eb; --muted: #94a3b8;
  --brand: #8b7dff; --brand-2: #38bdf8; --brand-soft: #231f45; --good: #34d399; --warn: #fbbf24; --bad: #f87171;
  --bar: #8b7dff; --bar-2: #38bdf8; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -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; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.only-dark { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .only-dark { display: block; } :root:not([data-theme="light"]) .only-light { display: none; } }

/* buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: linear-gradient(135deg, var(--brand), #5b8cff); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .6; cursor: default; }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
.linkish:hover { color: var(--fg); }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel-2); color: var(--fg); }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; }
input, select {
  font: inherit; color: var(--fg); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.error { color: var(--bad); margin: 12px 0 0; }

/* sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow);
}
.signin-card .wordmark { height: 40px; margin-bottom: 22px; }
.signin-card h1 { margin-bottom: 4px; }
.signin-card > p.muted { margin: 0 0 20px; }
.signin-foot { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 20px; font-size: 13px; }
.signin-foot .linkish { margin-left: auto; }

/* shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px;
}
.brand img { height: 34px; margin: 0 8px 20px; }
nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; color: var(--muted); font: inherit; font-weight: 550;
  padding: 8px 10px; border-radius: 9px; cursor: pointer;
}
nav button:hover { background: var(--panel-2); color: var(--fg); }
nav button[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
nav .ico { width: 18px; text-align: center; }
nav .count { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.who { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.who b { display: block; font-size: 13px; }

.main { min-width: 0; }
.banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 28px; font-size: 12.5px; color: var(--muted);
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.banner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex-shrink: 0; }
.banner .dot.stale { background: var(--warn); }
.banner a { margin-left: auto; font-weight: 550; }
.view { padding: 26px 28px 60px; max-width: 1180px; outline: none; }
.view-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.view-head p { margin: 4px 0 0; }
.view-head .actions { margin-left: auto; display: flex; gap: 8px; }

/* cards */
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head .right { margin-left: auto; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 550; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -18px -18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 18px; border-top: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--panel-2); border-top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty b { display: block; color: var(--fg); margin-bottom: 4px; }

/* charts */
.chart { width: 100%; height: 190px; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10.5px; }
.chart .bar { fill: var(--bar); }
.chart .bar:hover { fill: var(--brand-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.seg { display: inline-flex; background: var(--panel-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 7px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--fg); box-shadow: var(--shadow); }

/* list rows */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); min-width: 0; }
.row:first-child { border-top: 0; padding-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.search { max-width: 280px; padding: 8px 12px; }
.note { background: var(--brand-soft); color: var(--fg); border-radius: 12px; padding: 12px 14px; font-size: 13px; }
.note a { font-weight: 600; }
.code-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; overflow-x: auto; white-space: pre; }

/* drawer */
.drawer { position: fixed; inset: 0; background: rgba(8, 12, 20, .45); display: flex; justify-content: flex-end; z-index: 20; }
.drawer-panel { width: min(560px, 100%); height: 100%; background: var(--panel); display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.drawer-panel header { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-panel header h2 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; }
.msg { max-width: 85%; padding: 9px 12px; border-radius: 14px; margin: 0 0 10px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { margin-left: auto; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { background: var(--panel-2); border-bottom-left-radius: 4px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* phone */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; height: auto; min-width: 0; flex-direction: row; align-items: center; gap: 8px; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); z-index: 5; }
  .brand { flex-shrink: 0; }
  .brand img { height: 26px; margin: 0; }
  nav { flex-direction: row; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
  nav button { white-space: nowrap; padding: 7px 10px; width: auto; }
  nav .count { display: none; }
  .side-foot { margin: 0; border: 0; padding: 0; }
  .side-foot .who { display: none; }
  .banner { padding: 8px 16px; }
  .banner a { margin-left: 0; }
  .view { padding: 18px 16px 48px; }
  .table-wrap { margin: 0 -18px -18px; }
}
