/* Search API dashboard. Tokens first; everything below is written against roles.
   Chart colors were run through the dataviz palette validator for both modes. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);

  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-ink: #ffffff;
  --accent-wash: #e6f0fc;
  --track: #cde2fb;

  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --crit-ink: #b42828;
  --crit-wash: #fbeaea;
  --warn-wash: #fdf3dc;

  /* chart series: success / 4xx / 5xx */
  --s-ok: #2a78d6;
  --s-4xx: #eda100;
  --s-5xx: #e34948;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-ink: #ffffff;
    --accent-wash: #16263a;
    --track: #1b3352;
    --good-ink: #0ca30c;
    --crit-ink: #e66767;
    --crit-wash: #2e1918;
    --warn-wash: #2c2412;
    --s-ok: #3987e5;
    --s-4xx: #c98500;
    --s-5xx: #d03b3b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-ink: #ffffff;
  --accent-wash: #16263a;
  --track: #1b3352;
  --good-ink: #0ca30c;
  --crit-ink: #e66767;
  --crit-wash: #2e1918;
  --warn-wash: #2c2412;
  --s-ok: #3987e5;
  --s-4xx: #c98500;
  --s-5xx: #d03b3b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--ink-2); }
.faint { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
.boot { padding: 48px; color: var(--ink-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- shell */

.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 650; font-size: 15px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; left: 6px; top: 6px; width: 7px; height: 7px;
  border: 2px solid var(--accent-ink); border-radius: 50%;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--ink); }
.nav-icon { width: 16px; text-align: center; color: var(--muted); font-size: 13px; }
.nav a[aria-current="page"] .nav-icon { color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-foot .btn { justify-content: flex-start; }

.main { padding: 28px 32px 64px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.page-sub { margin: -14px 0 20px; color: var(--ink-2); }

@media (max-width: 860px) {
  /* minmax(0, …) and min-width: 0 so the one-line nav scrolls inside itself
     instead of stretching the whole page sideways */
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap;
    padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 4px 8px 4px 0; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; order: 3; min-width: 0; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; border: 0; padding: 0; }
  .main { padding: 20px 16px 48px; }
}

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #ffffff; }
.btn-danger:hover { filter: brightness(1.06); background: var(--crit); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-danger-text { color: var(--crit-ink); }

input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font: inherit; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input::placeholder { color: var(--muted); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button {
  height: 28px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent;
  color: var(--ink-2); font: inherit; font-weight: 500; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.filter-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.filter-row .check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }

/* ---------------------------------------------------------------- cards & layout */

.stack { display: flex; flex-direction: column; gap: 16px; transition: opacity 0.15s; }
.is-loading { opacity: 0.55; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px 0; }
.card-head .card-actions { margin-left: auto; display: flex; gap: 6px; }
.card-body { padding: 14px 16px 16px; }
.card-foot { padding: 0 16px 14px; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { padding: 14px 16px; }
.tile-label { color: var(--ink-2); font-size: 12.5px; font-weight: 500; }
.tile-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; }
.tile-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.banner-warn { background: var(--warn-wash); }
.banner-crit { background: var(--crit-wash); }
.banner-icon { font-weight: 700; }

.empty { padding: 36px 16px; text-align: center; color: var(--ink-2); }
.empty h3 { color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 12px; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.cell-main { min-width: 140px; }
td .sub { display: block; color: var(--muted); font-size: 12px; }
.trunc { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.table-scroll { max-height: 360px; overflow: auto; }

.inline-bar { display: inline-block; width: 72px; height: 6px; border-radius: 3px; background: var(--surface-2); vertical-align: middle; margin-left: 8px; overflow: hidden; }
.inline-bar-fill { display: block; height: 100%; border-radius: 3px; background: var(--accent); }

.meter { display: block; width: 120px; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 4px; }
.meter-fill { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter-fill.is-warn { background: var(--warn); }
.meter-fill.is-crit { background: var(--crit); }

/* status badges: icon + label in ink; color never carries meaning alone */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.badge-good .badge-dot { background: var(--good); }
.badge-warn .badge-dot { background: var(--warn); }
.badge-serious .badge-dot { background: var(--serious); }
.badge-crit .badge-dot { background: var(--crit); }
.badge-info .badge-dot { background: var(--accent); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); font-size: 11.5px; color: var(--ink-2); margin: 1px 2px 1px 0; }

/* ---------------------------------------------------------------- chart */

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; }
.sw-ok { background: var(--s-ok); }
.sw-4xx { background: var(--s-4xx); }
.sw-5xx { background: var(--s-5xx); }

.chart { position: relative; height: 240px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.c-grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.c-base { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.c-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-ok { fill: var(--s-ok); }
.c-4xx { fill: var(--s-4xx); }
.c-5xx { fill: var(--s-5xx); }
.c-col.is-active .c-seg { filter: brightness(1.12); }
.c-hit { fill: transparent; cursor: crosshair; }
.c-hover { fill: var(--ink); opacity: 0.04; }
.c-empty { fill: var(--muted); font-size: 13px; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 168px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 12.5px;
}
.tooltip[hidden] { display: none; }
.tt-title { color: var(--ink-2); margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 8px; }
.tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tt-key.k-ok { background: var(--s-ok); }
.tt-key.k-4xx { background: var(--s-4xx); }
.tt-key.k-5xx { background: var(--s-5xx); }
.tt-key.k-total { background: transparent; }
.tt-val { font-weight: 650; font-variant-numeric: tabular-nums; min-width: 34px; }
.tt-name { color: var(--ink-2); }
.tt-total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

/* ---------------------------------------------------------------- modal */

.modal-overlay {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.42);
  display: flex; align-items: flex-start; justify-content: center; padding: 64px 16px; overflow-y: auto;
}
.modal { width: 100%; max-width: 480px; background: var(--surface); border-radius: 14px; border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.modal-wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px 0; }
.modal-head h2 { font-size: 17px; }
.modal-head .btn { margin-left: auto; }
.modal-body { padding: 14px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 18px; flex-wrap: wrap; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.form-error { color: var(--crit-ink); font-size: 13px; }
.form-error:empty { display: none; }

.secret {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
}
.secret code { flex: 1; word-break: break-all; font-size: 13px; }
.codeblock {
  position: relative; margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2);
  border: 1px solid var(--border); font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-all;
}

.details { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px; }
.details dt { font-size: 12px; color: var(--ink-2); }
.details dd { margin: 0; font-weight: 500; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; margin-top: 4px; }
.action-list { display: flex; flex-direction: column; gap: 8px; }
.action-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.action-row .muted { flex: 1; font-size: 13px; }
.action-row strong { display: block; color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------- login */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 18px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login input { height: 40px; }
.login .btn { height: 40px; }

/* ---------------------------------------------------------------- playground results */

.results { display: flex; flex-direction: column; gap: 4px; }
.result { padding: 12px 0; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: 0; }
.result-title { font-size: 15px; font-weight: 600; }
.result-url { color: var(--good-ink); font-size: 12.5px; word-break: break-all; }
.result-snippet { color: var(--ink-2); margin-top: 2px; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- toasts */

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--ink); color: var(--page); box-shadow: var(--shadow); font-size: 13.5px; }
.toast-error { background: var(--crit); color: #ffffff; }

@media (prefers-reduced-motion: reduce) { .stack { transition: none; } }
