:root {
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #222220;
  --line: #2e2e2b;
  --ink: #ecebe7;
  --ink-2: #b4b2ab;
  --muted: #8a8880;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --navy: #12305c;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
[hidden] { display: none !important; }
a { color: var(--accent); }
code, .mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h4 { font-size: 13px; margin: 20px 0 8px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: #ff8a8a; min-height: 1.4em; margin: 8px 0 0; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; letter-spacing: .08em; }
.brand b { color: var(--accent); font-weight: 700; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--navy); display: grid; place-items: center; font-weight: 700; letter-spacing: 0; }

/* Buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #4a4a45; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff9b9b; }
.btn.danger:hover { border-color: var(--critical); }
.btn.tiny { padding: 4px 10px; font-size: 12px; }
.btn.wide { width: 100%; }
input { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label { color: var(--ink-2); }
.inline { display: inline-flex; align-items: center; gap: 8px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { min-width: 260px; }

/* Sign-in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px;
  display: flex; flex-direction: column; gap: 10px; }
.login-card .brand { margin-bottom: 4px; }
.login-card p { margin: 0 0 8px; }

/* Layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--ink-2); text-decoration: none; padding: 8px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.side nav a:hover { background: var(--surface-2); color: var(--ink); }
.side nav a.active { background: var(--surface-2); color: var(--ink); box-shadow: inset 3px 0 0 var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.content { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }
.page-head { margin-bottom: 20px; }
.page-head p { margin: 0; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h3 { margin: 0; }
.card.note p { color: var(--ink-2); margin: 0 0 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid2 { margin-bottom: 16px; }

/* Status tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column;
  gap: 6px; text-decoration: none; color: inherit; }
a.tile:hover { border-color: #4a4a45; }
.tile-name { color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.tile-main { font-size: 18px; font-weight: 600; }
.tile-detail { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }

/* Status: always an icon and a word, never colour alone */
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.status::before { content: ""; width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; line-height: 16px;
  text-align: center; color: #0b0b0b; font-weight: 800; }
.status.good { color: #5fd35f; }
.status.good::before { content: "\2713"; background: var(--good); color: #fff; }
.status.warning { color: var(--warning); }
.status.warning::before { content: "!"; background: var(--warning); }
.status.critical { color: #ff8a8a; }
.status.critical::before { content: "\00D7"; background: var(--critical); color: #fff; font-size: 13px; }
.status.neutral { color: var(--muted); }
.status.neutral::before { content: "\2013"; background: #3a3a36; color: var(--ink-2); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* Key/value list */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Stats row */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.card .stat { background: var(--bg); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat-sub { color: var(--muted); font-size: 12px; }

/* Meter (credit used): the number beside it carries the value, the bar only shows it */
.meter { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.meter-track { flex: 1; height: 8px; border-radius: 4px; background: #2c2c29; position: relative; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--accent); }
.meter-fill.warning { background: var(--warning); }
.meter-fill.critical { background: var(--critical); }
.meter-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--surface); }
.meter-text { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }

/* Chart */
.chart-wrap { margin: 8px 0 12px; position: relative; }
.chart-wrap figcaption { color: var(--ink-2); font-size: 12.5px; margin-bottom: 8px; }
.chart { height: 200px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid { stroke: #2c2c29; stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { fill: #5a9df0; }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }
.tooltip { position: absolute; pointer-events: none; background: #0e0e0d; border: 1px solid #3a3a36; border-radius: 8px; padding: 8px 10px;
  font-size: 12.5px; white-space: nowrap; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); z-index: 5; }
.tooltip b { display: block; margin-bottom: 2px; }

details summary { cursor: pointer; color: var(--ink-2); margin: 4px 0 8px; }

/* New token, shown once */
.token-box { background: #0f1d33; border: 1px solid #24477a; border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.token-box p { margin: 0 0 8px; }
.token-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.token-row code { background: var(--bg); padding: 8px 10px; border-radius: 6px; flex: 1; min-width: 280px; overflow-wrap: anywhere; user-select: all; }
.key-row code { background: var(--bg); padding: 8px 10px; border-radius: 6px; display: block; overflow-wrap: anywhere; user-select: all; }

.toast { position: fixed; bottom: 20px; right: 20px; background: #0e0e0d; border: 1px solid #3a3a36; padding: 10px 14px; border-radius: 8px; z-index: 10; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin: 0; flex-direction: row; }
  .content { padding: 20px 16px; }
  .grid2 { grid-template-columns: 1fr; }
}

/* Forms (keys, credit rule) */
select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px 0; margin: 0; }
legend { color: var(--ink-2); padding: 0 6px; font-weight: 600; }
.form-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.grid2.flat { margin-bottom: 8px; }
.grid2.flat h4 { margin-top: 0; }
.key-state { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.page-head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }

/* Segmented control (chart measure) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 12.5px; background: transparent; color: var(--ink-2); border: 0; padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.chart.short { height: 150px; }

/* Sign-in with Google, the password kept under it for emergencies */
.btn.google { gap: 10px; text-decoration: none; padding: 10px 14px; }
.btn.google svg { background: #fff; border-radius: 50%; padding: 3px; width: 24px; height: 24px; }
.password-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.password-box summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.password-box form { display: grid; gap: 8px; margin-top: 10px; }
.side-foot .who { word-break: break-all; margin-bottom: 6px; }
