/* SMART AI Gateway dashboard. Plain CSS, no external fonts or CDNs (CSP: self only). */
:root {
  --page: #f9f9f7;
  --surface: #ffffff;
  --surface-2: #f4f4f1;
  --chart-surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e7e6e0;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #3b5bdb;
  --accent-ink: #ffffff;
  --accent-soft: #eef2ff;
  --good: #0ca30c;       /* status palette: fixed, never themed */
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;
  --critical-text: #b42323;
  --warning-text: #8a5a00;
  --neutral-mark: #b9b8b0;
  --shadow: 0 1px 2px rgba(11, 11, 11, .04);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0d; --surface: #161615; --surface-2: #1f1f1d; --chart-surface: #1a1a19;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --line: #2c2c2a; --grid: #2c2c2a; --axis: #383835;
    --accent: #6f8cff; --accent-ink: #0b0b0b; --accent-soft: #1c2340;
    --good-text: #0ca30c; --critical-text: #ff7b7b; --warning-text: #fab219; --neutral-mark: #5d5c57;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0d0d0d; --surface: #161615; --surface-2: #1f1f1d; --chart-surface: #1a1a19;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --line: #2c2c2a; --grid: #2c2c2a; --axis: #383835;
  --accent: #6f8cff; --accent-ink: #0b0b0b; --accent-soft: #1c2340;
  --good-text: #0ca30c; --critical-text: #ff7b7b; --warning-text: #fab219; --neutral-mark: #5d5c57;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.shell > * { min-width: 0; }
.side {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 20px; font-weight: 650; font-size: 15px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-2); margin-bottom: 2px; text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }
.side-foot form { margin-top: 8px; }
.main { padding: 28px 36px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 22px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 650; margin: 0 0 12px; }
.sub { color: var(--ink-2); margin: 4px 0 0; }

/* ---- cards & tiles ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ---- status pills (icon + label, never color alone) ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.good { color: var(--good-text); } .pill.good::before { background: var(--good); }
.pill.bad { color: var(--critical-text); } .pill.bad::before { background: var(--critical); }
.pill.warn { color: var(--warning-text); } .pill.warn::before { background: var(--warning); }
.pill.open { color: var(--warning-text); } .pill.open::before { background: var(--serious); }

/* ---- meters (quota) ---- */
.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter.hot > span { background: var(--serious); }
.meter.full > span { background: var(--critical); }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12.5px; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.empty { color: var(--muted); padding: 24px 12px; text-align: center; }

/* ---- forms ---- */
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 72px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input.otp { font-family: ui-monospace, Consolas, monospace; letter-spacing: .3em; font-size: 16px; max-width: 180px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--critical-text); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; }
.inline { display: inline; }
.row > select, .row > input { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: 6px 12px; color: var(--ink-2); border-right: 1px solid var(--line); text-decoration: none; }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---- notices ---- */
.notice { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid var(--line); background: var(--surface); }
.notice.ok { border-left: 4px solid var(--good); }
.notice.err { border-left: 4px solid var(--critical); }
.notice.warn { border-left: 4px solid var(--warning); }
.secret-box { display: flex; gap: 8px; align-items: center; margin: 10px 0 4px; }
.secret-box code { flex: 1; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; word-break: break-all; font-size: 14px; }

/* ---- chart ---- */
.chart { position: relative; background: var(--chart-surface); border-radius: 8px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--ink); fill-opacity: .04; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--ink-2); font-size: 13px; margin: 0 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.12); white-space: nowrap; z-index: 5;
}
.tip b { display: block; margin-bottom: 4px; }
.tip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 6px; }
.tip .n { float: right; margin-left: 16px; font-variant-numeric: tabular-nums; }

/* ---- auth pages ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { padding: 0 0 18px; }
#qr { background: #fff; padding: 12px; border-radius: 8px; display: inline-block; margin: 6px 0 10px; }

@media (max-width: 900px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 6px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 0 0; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; order: 3; flex-basis: 100%; }
  .nav a { padding: 6px 8px; }
  .page-head .row { width: 100%; }
  .nav a { margin: 0; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 20px 16px 48px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
}

/* ---- playground ---- */
.pg { display: grid; grid-template-columns: 300px minmax(0, 1fr) minmax(0, 420px); gap: 16px; align-items: start; }
.pg .card { margin: 0; }
.pg-hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.pg-msgs { min-height: 320px; max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 12px; }
.pg-b { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; max-width: 92%; overflow-wrap: anywhere; }
.pg-user { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.pg-assistant { align-self: flex-start; background: var(--surface-2); }
.pg-text { white-space: pre-wrap; }
.pg-pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin: 6px 0 0; max-height: 360px; overflow: auto; font-size: 12.5px; }
.pg-assistant .pg-pre { background: var(--surface); }
.pg-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.pg-compose { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.pg-thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.pg-thumb { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.pg-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pg-x { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; line-height: 20px; padding: 0; cursor: pointer; }
.pg-raw { border-top: 1px solid var(--line); padding-top: 12px; }
.pg-entry { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }
.pg-entry summary { cursor: pointer; }
.pg-sec { margin-top: 10px; }
.pg-timeline { margin: 6px 0 0; padding-left: 20px; font-size: 12.5px; }
.pg-timeline li { margin-bottom: 4px; }
#pg-tplinfo details { margin-top: 8px; }
@media (max-width: 1280px) { .pg { grid-template-columns: 280px minmax(0, 1fr); } .pg-inspect { grid-column: 1 / -1; } }
@media (max-width: 900px) { .pg { grid-template-columns: minmax(0, 1fr); } }
