/*
 * Console styles - the HDesk design system.
 *
 * Cream ground, white cards, AgeDash orange for actions and the active state,
 * teal for results. IBM Plex Sans / Condensed / Mono. A narrow icon rail
 * beside a collapsible section panel. Light by default; the rail toggles dark.
 *
 * Every token is defined on bare :root and only redefined for dark, so nothing
 * has its sole definition behind a media query.
 */

:root {
  --ground: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f5f1ea;
  --surface-3: #ece5db;

  --ink: #0d0c0b;
  --ink-2: #3b3633;
  --muted: #736c65;

  --line: #e9e3da;
  --line-2: #d9d1c5;

  --accent: #e07a5a;
  --accent-ink: #a2432a;
  --accent-wash: #fbe6dd;

  --brand-2: #1f6f5c;
  --brand-2-ink: #145244;
  --brand-2-wash: #dcece7;

  --ok: #1f6f5c;
  --ok-ink: #145244;
  --ok-wash: #dcece7;
  --warn: #9a6415;
  --warn-wash: #f8ecd6;
  --danger: #b3261e;
  --danger-wash: #f9e2e0;

  --bar-ok: #3f9d87;
  --bar-blocked: #d2953f;
  --bar-error: #d9564d;

  --shadow: 0 1px 2px rgba(13, 12, 11, 0.04), 0 10px 30px -20px rgba(13, 12, 11, 0.22);
  --shadow-lift: 0 2px 6px rgba(13, 12, 11, 0.06), 0 18px 44px -24px rgba(13, 12, 11, 0.3);

  --f-display: "IBM Plex Sans Condensed", "Helvetica Neue", Arial, sans-serif;
  --f-body: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;

  --r: 10px;
  --r-sm: 7px;
  --rail-icons: 60px;
  --rail-panel: 232px;

  color-scheme: light;
}

:root[data-theme="dark"] {
  --ground: #100f0e;
  --surface: #191715;
  --surface-2: #221f1d;
  --surface-3: #2b2724;
  --ink: #f6f2ec;
  --ink-2: #d6cec5;
  --muted: #9b938a;
  --line: #2c2825;
  --line-2: #3c3733;
  --accent: #e8886b;
  --accent-ink: #f2ab92;
  --accent-wash: #3a2620;
  --brand-2: #3f9d87;
  --brand-2-ink: #64b9a4;
  --brand-2-wash: #16302a;
  --ok: #3f9d87;
  --ok-ink: #64b9a4;
  --ok-wash: #16302a;
  --warn: #d2953f;
  --warn-wash: #33260f;
  --danger: #e9877f;
  --danger-wash: #3a1e1c;
  --bar-ok: #3f9d87;
  --bar-blocked: #d2953f;
  --bar-error: #e0746b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 10px 30px -20px rgba(0, 0, 0, 0.75);
  --shadow-lift: 0 2px 6px rgba(0, 0, 0, 0.5), 0 18px 44px -24px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--f-body);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); }
[hidden] { display: none !important; }

/* ══ Shell: icon rail · section panel · page ═══════════════════════════ */
.shell {
  display: grid;
  grid-template-columns: var(--rail-icons) var(--rail-panel) minmax(0, 1fr);
  min-height: 100vh;
}
.shell.collapsed { grid-template-columns: var(--rail-icons) minmax(0, 1fr); }

.railbar {
  position: sticky; top: 0; height: 100vh; z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 0;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
}
.railbar .mark {
  width: 30px; height: 30px; border-radius: 8px; margin-bottom: 12px;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  font-family: var(--f-display); font-weight: 700; font-size: 15px;
}
.railbtn {
  width: 40px; height: 38px; border: 0; border-radius: 9px; cursor: pointer;
  background: none; color: var(--muted);
  display: grid; place-items: center; flex: none;
  transition: background .13s, color .13s;
}
.railbtn:hover { background: var(--surface-3); color: var(--ink); }
.railbtn.on { background: var(--accent-wash); color: var(--accent-ink); }
.railbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.railbtn svg { width: 18px; height: 18px; }
.railbar .spacer { flex: 1; }

.rail {
  position: sticky; top: 0; height: 100vh; overflow: hidden auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 12px 18px;
  display: flex; flex-direction: column; gap: 2px;
}
.shell.collapsed .rail { display: none; }
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 10px; }
.rail-head h2 { margin: 0; font-family: var(--f-display); font-size: 17px; font-weight: 650; letter-spacing: -0.012em; }
.rail-toggle {
  width: 26px; height: 26px; flex: none; border: 0; border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.rail-toggle:hover { background: var(--surface-2); color: var(--ink); }
.rail-group { font-family: var(--f-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 14px 0 4px 8px; }
.rail a.nav {
  display: flex; align-items: center; justify-content: space-between; gap: 9px;
  padding: 7px 9px; border-radius: var(--r-sm); color: var(--ink-2);
  text-decoration: none; font-size: 14px; line-height: 1.3;
}
.rail a.nav:hover { background: var(--surface-2); color: var(--ink); }
.rail a.nav.active { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.rail a.nav .meta { font-family: var(--f-mono); font-size: 10.5px; color: var(--muted); }
.rail .spacer { flex: 1; }
.rail .who { font-size: 12px; color: var(--muted); padding: 10px 8px 0; border-top: 1px solid var(--line); margin-top: 10px; word-break: break-all; }

.main { padding: 28px 34px 90px; min-width: 0; }
.reopen {
  position: fixed; left: calc(var(--rail-icons) + 12px); top: 14px; z-index: 4;
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--muted);
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.reopen:hover { color: var(--ink); }

@media (max-width: 860px) {
  .shell, .shell.collapsed { grid-template-columns: var(--rail-icons) minmax(0, 1fr); }
  .rail { position: fixed; left: var(--rail-icons); top: 0; width: var(--rail-panel); box-shadow: var(--shadow-lift); z-index: 5; }
  .main { padding: 56px 16px 70px; }
  .reopen { left: calc(var(--rail-icons) + 10px); }
}

/* ══ Type ════════════════════════════════════════════════════════════ */
h1 { font-family: var(--f-display); font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-family: var(--f-display); font-size: 19px; font-weight: 650; margin: 30px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 22px; max-width: 72ch; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.mono { font-family: var(--f-mono); font-size: 12.5px; }
.muted { color: var(--muted); }

/* ══ Controls ════════════════════════════════════════════════════════ */
.btn {
  font: inherit; font-weight: 550; font-size: 14px; padding: 8px 15px;
  border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(224, 122, 90, .3); }
.btn.primary:hover:not(:disabled) { filter: brightness(0.95); background: var(--accent); }
.btn.secondary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.secondary:hover:not(:disabled) { filter: brightness(0.95); background: var(--brand-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
a.btn { text-decoration: none; }
a.btn:not(.primary):not(.secondary) { color: var(--ink); }
.btn.block { width: 100%; justify-content: center; }

input, select, textarea {
  font: inherit; font-size: 14px; width: 100%;
  padding: 9px 11px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
}
textarea { min-height: 96px; resize: vertical; font-family: var(--f-mono); font-size: 12.5px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[type="file"] { padding: 7px; }
label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 5px; color: var(--ink-2); }
.field { margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 2px; }
.choice {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font-weight: 450; font-size: 13.5px; color: var(--ink); margin: 0;
  padding: 7px 11px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface);
}
.choice:hover { background: var(--surface-2); }
.choice input { margin: 0; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-wash); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

/* Segmented control (date ranges, result tabs). */
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); padding: 2px; gap: 2px; }
.seg button {
  font: inherit; font-size: 13px; font-weight: 550; border: 0; background: none; color: var(--muted);
  padding: 5px 11px; border-radius: 5px; cursor: pointer;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--accent-wash); color: var(--accent-ink); }

/* ══ Surfaces ════════════════════════════════════════════════════════ */
.card { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 17px 19px; box-shadow: var(--shadow); margin-bottom: 16px; }
.cardhead { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cardhead h3 { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.cards .card { margin-bottom: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-family: var(--f-mono); font-size: 10px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.stat .v { font-family: var(--f-display); font-size: 25px; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.good .v { color: var(--ok); }
.stat.bad .v { color: var(--danger); }

.tablewrap { border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); overflow-x: auto; box-shadow: var(--shadow); margin-bottom: 16px; }
.card .tablewrap { box-shadow: none; margin-bottom: 0; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-family: var(--f-mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted);
  padding: 10px 13px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
td { padding: 10px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
table.kv { table-layout: fixed; }
table.kv td { word-break: break-word; padding: 9px 12px; }
table.kv td:first-child { width: 42%; font-size: 13px; }
table.kv td:first-child .mono { font-size: 10.5px; word-break: break-all; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .sub2 { display: block; font-size: 12px; color: var(--muted); }
td img.thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }

.empty { border: 1px dashed var(--line-2); border-radius: var(--r); padding: 30px; text-align: center; color: var(--muted); background: var(--surface); }
.toolbar { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin: 4px 0 16px; }

.note { border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: var(--r-sm); padding: 10px 14px; margin: 0 0 14px; background: var(--surface); font-size: 14px; }
.note.error { border-left-color: var(--danger); background: var(--danger-wash); color: var(--danger); }
.note.success { border-left-color: var(--ok); background: var(--ok-wash); color: var(--ok-ink); }
.note.warn { border-left-color: var(--warn); background: var(--warn-wash); color: var(--warn); }

.chip {
  display: inline-block; font-family: var(--f-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase; padding: 3px 8px;
  border-radius: 5px; background: var(--surface-3); color: var(--ink-2); white-space: nowrap;
}
.chip.ok { background: var(--ok-wash); color: var(--ok-ink); }
.chip.warn { background: var(--warn-wash); color: var(--warn); }
.chip.bad { background: var(--danger-wash); color: var(--danger); }
.chip.accent { background: var(--accent-wash); color: var(--accent-ink); }
.route-chip { font-family: var(--f-mono); font-size: 12px; padding: 4px 9px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); }

/* A thin success bar inside a table cell. */
.rate { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.rate .bar { width: 70px; height: 6px; border-radius: 3px; background: var(--danger-wash); overflow: hidden; }
.rate .bar i { display: block; height: 100%; background: var(--bar-ok); }

pre.code {
  margin: 0; padding: 13px 15px; border-radius: var(--r-sm); background: var(--surface-2);
  border: 1px solid var(--line); font-family: var(--f-mono); font-size: 12.3px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-all; max-height: 60vh; overflow: auto; color: var(--ink-2);
}

/* ══ Chart ═══════════════════════════════════════════════════════════ */
.chart { width: 100%; height: 190px; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { font-family: var(--f-mono); font-size: 10px; fill: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ══ Sign in ═════════════════════════════════════════════════════════ */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: var(--ground); }
.auth-box { width: min(400px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 700; font-size: 21px; margin: 0 0 16px 2px; }
.auth-brand i { width: 12px; height: 12px; border-radius: 3px; background: var(--accent); display: block; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 26px; box-shadow: var(--shadow-lift); }
.auth-card h1 { font-size: 24px; }
.otp-input { font-family: var(--f-mono); font-size: 26px; letter-spacing: 12px; text-align: center; padding: 12px; }
.linkbtn { border: 0; background: none; color: var(--accent-ink); cursor: pointer; font: inherit; font-size: 13.5px; padding: 0; text-decoration: underline; }
.linkbtn:disabled { color: var(--muted); text-decoration: none; cursor: default; }

/* ══ Modal ═══════════════════════════════════════════════════════════ */
.backdrop { position: fixed; inset: 0; background: rgba(13, 12, 11, 0.45); z-index: 40; display: grid; place-items: center; padding: 20px; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(720px, 100%); max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lift); }
.modal h2 { margin: 0 0 4px; font-size: 20px; }

.spin { display: inline-block; width: 13px; height: 13px; vertical-align: -2px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
