/* Diffract Admin. Light and dark follow the OS setting. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #3f7272;
  --accent-ink: #ffffff;
  --accent-wash: rgba(91, 138, 138, 0.14);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b02a2a;
  --seq-rgb: 42, 120, 214;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #7fb0b0;
    --accent-ink: #0b0b0b;
    --accent-wash: rgba(127, 176, 176, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-text: #0ca30c;
    --critical-text: #e66767;
    --seq-rgb: 57, 135, 229;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.boot { padding: 48px; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ── Shell ─────────────────────────────────────────────────────────────── */

.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 2px;
  padding: 20px 12px; border-right: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: baseline; gap: 8px; padding: 0 10px 18px; }
.brand strong { font-size: 17px; letter-spacing: -0.3px; }
.brand span { color: var(--muted); font-size: 12px; }
.nav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; border-radius: 7px; color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--text); }
.nav .count {
  font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 9px;
  background: var(--critical); color: #fff; font-variant-numeric: tabular-nums;
}
.sidebar .spacer { flex: 1; }
.sidebar .foot { padding: 0 10px; font-size: 12px; color: var(--muted); display: grid; gap: 8px; }

.main { padding: 24px 28px 64px; max-width: 1280px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 21px; letter-spacing: -0.3px; margin-right: auto; }
.page-head .sub { flex-basis: 100%; color: var(--text-2); margin-top: -6px; }
.crumb { color: var(--muted); font-weight: 400; }

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0 8px 0 4px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar .spacer { display: none; }
  .sidebar .foot { margin-left: auto; }
  .sidebar .foot .ver { display: none; }
  .main { padding: 16px 16px 48px; }
}

/* ── Controls ──────────────────────────────────────────────────────────── */

button, select, input, textarea { font: inherit; color: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical-text); }
.btn.small { height: 26px; padding: 0 8px; font-size: 12.5px; }
.btn.link { border: 0; background: none; padding: 0; height: auto; color: var(--accent); }

input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); min-width: 0;
}
textarea { height: auto; padding: 8px 10px; width: 100%; resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.filters input[type="search"] { width: 260px; max-width: 100%; }
.filters .grow { margin-left: auto; }

.tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--surface); }
.tabs button { border: 0; background: none; height: 26px; padding: 0 10px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.tabs button[aria-pressed="true"] { background: var(--accent-wash); color: var(--text); }
.tabs .n { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 4px; }

/* ── Cards, tiles, grids ───────────────────────────────────────────────── */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card > h2 { font-size: 14px; font-weight: 600; }
.card > .hint { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card > h2 + .body, .card > .hint + .body { margin-top: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2 { padding: 14px 18px 0; }
.card.flush > .hint { padding: 0 18px; }

.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }

.tile .label { color: var(--text-2); font-size: 12.5px; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.5px; margin-top: 2px; }
.tile .foot { font-size: 12px; color: var(--muted); margin-top: 2px; min-height: 17px; }
.delta { font-weight: 600; }
.delta.good { color: var(--good-text); }
.delta.bad { color: var(--critical-text); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.notice { border: 1px solid var(--border); border-left: 3px solid var(--warning); border-radius: 8px; background: var(--surface); padding: 10px 14px; margin-bottom: 14px; }
.notice.error { border-left-color: var(--critical); }
.loading { opacity: 0.55; transition: opacity 0.15s; }

/* ── Badges ────────────────────────────────────────────────────────────── */

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.badge.good::before { background: var(--good); }
.badge.warn::before { background: var(--warning); }
.badge.bad::before { background: var(--critical); }
.badge.info::before { background: var(--series-1); }

/* ── Tables ────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }
td.wrap { max-width: 380px; overflow-wrap: anywhere; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--grid); color: var(--muted); font-size: 12.5px; }
.pager div { display: flex; gap: 6px; }

/* ── Charts ────────────────────────────────────────────────────────────── */

.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: 0.1; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .bar { fill: var(--series-1); }
.chart .band { fill: transparent; }
.chart .band.on { fill: var(--accent-wash); }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .end-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }

.tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 96px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14); padding: 6px 10px; font-size: 12px; white-space: nowrap;
}
.tip strong { display: block; font-size: 14px; }
.tip span { color: var(--text-2); }

.barlist { display: grid; grid-template-columns: max-content minmax(60px, 1fr) max-content; gap: 8px 12px; align-items: center; }
.barlist .name { color: var(--text-2); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist .track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.barlist .fill { height: 100%; border-radius: 4px; background: var(--series-1); min-width: 2px; }
.barlist .val { font-variant-numeric: tabular-nums; }
.barlist .val small { color: var(--muted); margin-left: 4px; }

.segbar { display: flex; gap: 2px; height: 28px; }
.segbar > div { border-radius: 4px; color: #fff; font-size: 12px; font-weight: 600; padding: 0 8px; display: flex; align-items: center; min-width: 3px; overflow: hidden; }
.seg-1 { background: var(--series-1); }
.seg-2 { background: var(--series-2); }
.seg-3 { background: var(--series-3); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; color: var(--text-2); font-size: 12.5px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.legend b { color: var(--text); font-weight: 600; margin-left: 4px; font-variant-numeric: tabular-nums; }

.heat td, .heat th { text-align: center; padding: 6px 8px; border-bottom: 0; font-variant-numeric: tabular-nums; }
.heat td:first-child, .heat th:first-child { text-align: left; }
.heat td.cell { border: 2px solid var(--surface); border-radius: 6px; min-width: 46px; }
.heat td.cell.dark { color: #fff; }

/* ── Detail bits ───────────────────────────────────────────────────────── */

pre.trace { margin: 0; padding: 14px 16px; background: var(--surface-2); border-radius: 8px; overflow-x: auto; font: 12px/1.55 var(--mono); white-space: pre; max-height: 420px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 2px 9px; border-radius: 6px; background: var(--surface-2); font-size: 12.5px; }

form.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; }
.field label, .field .lbl { font-weight: 500; }
.field .help { color: var(--muted); font-size: 12.5px; }
.field input:not([type="checkbox"]), .field select { width: 100%; max-width: 320px; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { margin-top: 3px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 22px; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { font-size: 16px; margin-bottom: 14px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; background: var(--text); color: var(--page); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); max-width: min(420px, calc(100vw - 40px)); }
.toast.error { background: var(--critical); color: #fff; }

/* ── Login ─────────────────────────────────────────────────────────────── */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(360px, 100%); padding: 26px; }
.login h1 { font-size: 20px; letter-spacing: -0.3px; }
.login p { color: var(--text-2); margin: 4px 0 18px; }
.login input { width: 100%; height: 38px; }
.login .btn { width: 100%; height: 38px; justify-content: center; margin-top: 12px; }
.login .err { color: var(--critical-text); margin-top: 10px; min-height: 20px; }
