/* Theme shared with SwarmDialer (cmd/gui/web/style.css there): the same
   dark and light token values, centered header with the logo and tab
   buttons below it, and the round theme toggle at the top right. Chart
   series are validated categorical palettes, each checked against its
   mode's chart surface (--panel-alt). */
:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-alt: #171b25;
  --border: #262c3d;
  --text: #e7e9f0;
  --muted: #8b93a7;
  --accent: #ffb454;
  --accent-hover: #ffc978;
  --accent-ink: #1a1305;
  --link: #5eb1ff;
  --ok: #3ddc97;
  --danger: #ff5470;
  --best-bg: rgba(61, 220, 151, 0.12);
  --disabled-bg: #3a3f4d;
  --console-bg: #05060a;
  --radius: 4px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef0f4;
  --panel: #ffffff;
  --panel-alt: #f1f3f6;
  --border: #d5dae3;
  --text: #151922;
  --muted: #586174;
  --accent: #b36b00;
  --accent-hover: #cc7a00;
  --accent-ink: #ffffff;
  --link: #1f6fd1;
  --ok: #13875a;
  --danger: #d42f4a;
  --best-bg: rgba(19, 135, 90, 0.12);
  --disabled-bg: #d5dae3;
  --console-bg: #f7f8fa;
  --series-1: #2a78d6;
  --series-2: #c94f1f;
  --series-3: #128a60;
  --series-4: #a86f00;
  --series-5: #c2457a;
  --series-6: #007a00;
  --series-7: #4a3aa7;
  --series-8: #d63c3b;
}
.icon-light { display: none; }
:root[data-theme="light"] .icon-light { display: inline; }
:root[data-theme="light"] .icon-dark { display: none; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--link); }
h1, h2, h3 { font-family: var(--mono); font-weight: 600; }
h1 { font-size: 22px; margin: 0 0 0.3rem; }
h2 { font-size: 16px; margin: 2rem 0 0.75rem; }
h3 { font-size: 14px; margin: 1.5rem 0 0.5rem; }
.sub { color: var(--muted); margin: 0 0 1rem; }
.muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 0.92em; }

/* ---- header: same placement as SwarmDialer ---- */
header {
  position: relative;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 14px; color: var(--text); text-decoration: none; }
.brand-icon { height: 52px; width: auto; }
header h1 { font-family: var(--mono); font-size: 34px; font-weight: 600; letter-spacing: 0.01em; margin: 0; color: var(--text); }
.theme-toggle {
  position: absolute; top: 14px; right: 18px;
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel-alt); color: var(--text);
  font-size: 17px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; align-items: center; }
nav.tabs a, nav.tabs button {
  font: inherit; font-size: 14px; border: 1px solid transparent; background: transparent;
  padding: 7px 16px; border-radius: var(--radius); cursor: pointer; color: var(--muted); text-decoration: none;
}
nav.tabs a:hover, nav.tabs button:hover { color: var(--text); }
nav.tabs a[aria-current="page"] { background: var(--panel-alt); border-color: var(--border); color: var(--accent); }
nav.tabs form { display: contents; }
nav.tabs button.logout { margin-left: 12px; opacity: 0.8; }

main { padding: 24px; max-width: 1500px; margin: 0 auto; }
footer { padding: 1rem 1.5rem 2rem; color: var(--muted); font-size: 12px; text-align: center; font-family: var(--mono); }

.flash, .error, .once {
  background: var(--panel); border: 1px solid var(--border); border-left: 2px solid var(--ok);
  padding: 0.6rem 0.9rem; border-radius: var(--radius);
}
.error { border-left-color: var(--danger); }
.once { border-color: var(--accent); padding: 0.9rem 1rem; margin: 1rem 0; }
.once .secret { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0; }
.once .secret code {
  background: var(--console-bg); border: 1px solid var(--border); padding: 0.4rem 0.6rem; border-radius: var(--radius);
  font-size: 15px; user-select: all; word-break: break-all;
}

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.spread { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
  font: inherit; font-size: 14px; color: var(--text); background: var(--panel-alt); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* buttons: SwarmDialer's .btn (amber), .btn.secondary (outline) and danger */
button, .button {
  font: inherit; font-size: 14px; cursor: pointer; border-radius: var(--radius); padding: 8px 16px;
  border: 1px solid var(--border); background: transparent; color: var(--text); text-decoration: none; display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
button.primary:disabled { background: var(--disabled-bg); border-color: var(--disabled-bg); color: var(--muted); cursor: not-allowed; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
form.inline { display: inline; }

.filters { margin-bottom: 1rem; }
.filters input[type=search] { width: 16rem; }

/* tables: SwarmDialer's .mon-table look */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--panel-alt); }
tbody th { background: transparent; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-alt); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
td.test-name { min-width: 13rem; }
td.wide { min-width: 18rem; }
.card > h3:first-child { margin-top: 0; }
.hw { font-weight: 600; }
.hw-sub { color: var(--muted); font-size: 12px; }
table.kv { width: auto; }
table.kv th { font-weight: 400; background: transparent; }
table.kv tbody tr:hover td { background: none; }
.card table th { background: transparent; }
.env-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 14px; }
.env-grid > .card { min-width: 0; overflow-x: auto; }
.env-grid table th { white-space: normal; }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 3px; font-family: var(--mono);
  font-size: 12px; padding: 1px 7px; border-radius: 10px; background: var(--border); color: var(--text);
}
.chip.warn { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.chip.warn::before { content: "▼"; font-size: 9px; }
.chip.hw { background: color-mix(in srgb, var(--link) 16%, transparent); color: var(--link); font-family: var(--sans); }
.status { white-space: nowrap; }
.info-btn {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  width: 18px; height: 18px; padding: 0; margin-left: 6px; border-radius: 50%;
  font: italic 600 12px/1 Georgia, serif; border: 1px solid var(--link); color: var(--link); background: transparent;
}
.info-btn:hover, .info-btn[aria-expanded="true"] { background: var(--link); color: var(--panel); border-color: var(--link); }
.info-text {
  display: block; margin-top: 6px; padding: 6px 8px; max-width: 32rem; text-align: left; white-space: normal;
  font-size: 12px; font-weight: 400; line-height: 1.45; color: var(--text);
  background: var(--panel-alt); border: 1px solid var(--border); border-left: 2px solid var(--link); border-radius: var(--radius);
}
.info-text[hidden] { display: none; }
.chip.diag { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); font-family: var(--sans); }
.chip.legacy { background: color-mix(in srgb, var(--muted) 20%, transparent); color: var(--muted); font-family: var(--sans); }
.diag { margin: 10px 0 16px; display: flex; flex-direction: column; gap: 12px; }
.diag-summary {
  margin: 0; padding: 10px 12px; max-width: 72rem; line-height: 1.5;
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--link); border-radius: var(--radius);
}
.diag .card h3 { margin-top: 0; }
.diag .env-grid { align-items: start; grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr)); }
.diag table { margin-top: 6px; }
tr.near-limit th, tr.near-limit td { color: var(--danger); font-weight: 600; }
.warn-line { margin: 8px 0 0; color: var(--accent); }
.warn-line::before { content: "▲ "; }
.note-line { margin: 8px 0 0; color: var(--muted); }
.note-line::before { content: "ⓘ "; }
td.unreliable { color: var(--muted); text-decoration: line-through dotted; text-decoration-thickness: 1px; }
.ok-line { margin: 8px 0 0; color: var(--ok); }
.ok-line::before { content: "● "; }
details.timeline > summary { cursor: pointer; font-family: var(--mono); font-weight: 600; padding: 4px 0; }
details.timeline .table-wrap { margin-top: 6px; }
tr.ev-stop td, tr.ev-failures_started td { font-weight: 600; }
td .info-text { min-width: 20rem; }
td.stop-cell { white-space: nowrap; }
td.stop-cell .info-text { white-space: normal; }
.status + .info-btn { margin-left: 4px; }
.status.ok::before { content: "● "; color: var(--ok); }
.status.warn::before { content: "▲ "; color: var(--accent); }

.selectbar { display: flex; align-items: center; gap: 0.8rem; margin: 0.75rem 0; flex-wrap: wrap; }
.selectbar #delete-btn { margin-left: auto; }
button.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
button.danger-fill:hover { background: color-mix(in srgb, var(--danger) 85%, #fff); border-color: var(--danger); color: #fff; }
button.danger-fill:disabled { background: var(--disabled-bg); border-color: var(--disabled-bg); color: var(--muted); }
.reports-table th.select-col, .reports-table td.select-col { width: 2.4rem; text-align: center; }
.reports-table input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin: 1rem 0; }
.pager-links { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.pager-links .button { padding: 5px 11px; min-width: 2.4rem; text-align: center; }
.pager-links .button.current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pager-links .button.disabled { opacity: 0.45; pointer-events: none; }
.pager-gap { color: var(--muted); padding: 0 4px; }

/* compare */
td.best { background: var(--best-bg); font-weight: 600; }
td.best::after { content: " ★"; color: var(--ok); font-weight: 400; font-size: 0.85em; }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.key.s1 { background: var(--series-1); } .key.s2 { background: var(--series-2); }
.key.s3 { background: var(--series-3); } .key.s4 { background: var(--series-4); }
.key.s5 { background: var(--series-5); } .key.s6 { background: var(--series-6); }
.key.s7 { background: var(--series-7); } .key.s8 { background: var(--series-8); }

/* charts: SwarmDialer's .mon-chart cards */
.test-block { margin-top: 2.5rem; }
.test-block > h2 { margin-top: 0; }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 14px; margin-top: 1rem; }
.chart { background: var(--panel-alt); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 10px 4px; min-width: 0; }
.chart h4 { margin: 0 0 4px 4px; font-family: var(--mono); font-size: 13px; font-weight: 600; }
.chart .unit { color: var(--muted); font-weight: 400; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 1rem 4px; }
.uplot { font-family: var(--sans); }
.uplot .u-legend { font-size: 12px; color: var(--muted); text-align: left; padding: 3px 4px; }
.uplot .u-legend .u-marker { width: 14px; height: 3px; border-radius: 2px; border: 0 !important; }
.uplot .u-legend .u-value { color: var(--text); font-family: var(--mono); font-weight: 600; }
.uplot .u-legend th { font-weight: 400; color: var(--muted); background: none; }
.uplot .u-legend td, .uplot .u-legend th { border: 0; padding: 1px 6px; }
.uplot .u-legend tr:hover td { background: none; }
.uplot .u-cursor-x { border-right: 1px solid var(--muted) !important; }
.uplot .u-cursor-y { display: none; }

.role-pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; }
.role-pill.admin { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.role-pill.user { background: var(--border); color: var(--muted); }

/* How-to pages */
ol.howto { display: flex; flex-direction: column; gap: 14px; padding-left: 1.4rem; max-width: 64rem; margin: 1rem 0 0; }
ol.howto > li::marker { font-family: var(--mono); font-weight: 600; color: var(--accent); }
ol.howto h2 { margin: 0 0 4px; font-size: 15px; }
ol.howto p { margin: 4px 0; }
ol.howto ul { margin: 4px 0; padding-left: 1.2rem; }
ol.howto ul li { margin: 3px 0; }
.howto-cmd { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.howto-cmd code {
  background: var(--console-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; font-size: 13px; user-select: all; word-break: break-all; flex: 1; min-width: 0;
}

/* HW Validation */
.hw-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.hw-filters { flex: 1; }
.hw-buttons { gap: 8px; align-items: center; }
.hw-search input { width: 20rem; max-width: 100%; }
.hw-form { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 12px; }
.hw-form h2 { margin: 0; }
.hw-form label.grow { flex: 1; min-width: 16rem; }
.hw-form textarea { width: 100%; resize: vertical; }
.hw-form .hw-form-details { max-width: 60rem; }
.hw-list { display: flex; flex-direction: column; gap: 12px; }
.hw-cat > summary {
  cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: 10px;
  padding: 8px 2px; font-family: var(--mono); font-weight: 600; font-size: 16px; user-select: none;
}
.hw-cat > summary::-webkit-details-marker { display: none; }
.hw-cat > summary::before { content: "▸"; color: var(--muted); font-size: 12px; transition: transform 0.15s ease; }
.hw-cat[open] > summary::before { transform: rotate(90deg); }
.hw-cat > summary:hover .hw-cat-name { color: var(--accent); }
.hw-cat-count { color: var(--muted); font-weight: 400; font-size: 13px; }
.hw-table td.hw-name { font-weight: 600; min-width: 16rem; }
.hw-table td.hw-comment { color: var(--muted); font-size: 12px; min-width: 16rem; max-width: 40rem; }
.hw-actions { text-align: right; }
.hw-actions button { padding: 4px 10px; font-size: 12px; }
.hw-actions form { margin-left: 4px; }
.hw-status { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; white-space: nowrap; }
.hw-status.supported { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.hw-status.unsupported { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.hw-status.unverified { background: var(--border); color: var(--muted); }
.hw-source { border-bottom: 1px dotted var(--muted); cursor: help; }
.hw-empty { padding: 10px 12px; margin: 0; }
@media (prefers-reduced-motion: reduce) { .hw-cat > summary::before { transition: none; } }

.login { max-width: 360px; margin: 60px auto 0; }
.login h2 { margin-top: 0; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }

@media (max-width: 640px) {
  main { padding: 16px; }
  header { padding: 12px 16px 10px; }
  header h1 { font-size: 26px; }
  .brand-icon { height: 40px; }
  nav.tabs a, nav.tabs button { padding: 6px 10px; }
  .charts { grid-template-columns: 1fr; }
  .filters input[type=search] { width: 100%; }
}

/* SwarmDialer tab: its icon before the name. */
nav.tabs a.tab-icon { display: inline-flex; align-items: center; gap: 6px; }
nav.tabs a.tab-icon img { height: 16px; width: auto; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; align-self: flex-end; padding-bottom: 6px; color: var(--text); }
