:root {
  color-scheme: light dark;
  --bg: #f4f5fb;
  --panel: #ffffff;
  --surface: #f6f7fc;
  --text: #171a2c;
  --muted: #6b7090;
  --border: #e3e5f0;
  --border-strong: #cfd2e3;
  --accent: #5b4cf5;
  --accent-2: #c040e8;
  --accent-soft: #eeecff;
  --on-accent: #ffffff;
  --selected: #efedff;
  --hover: #f5f4ff;
  --track1: #4f6bff;
  --track2: #ff5f7e;
  --route: #ff9a1f;
  --ok: #3b82f6;
  --warn: #e08a00;
  --err: #e5364f;
  --warn-soft: #fff5e1;
  --err-soft: #ffe9ec;
  --grid: #eef0f7;
  --grid-strong: #d5d8e8;
  --shadow: 0 1px 2px rgb(23 26 44 / .04), 0 8px 24px -12px rgb(23 26 44 / .12);
  --radius: 16px;
  --radius-sm: 10px;
  --gutter: clamp(16px, 2vw, 36px);
  --header: 104px;
  --list-columns: 8px 52px 36px minmax(0, 1fr);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1020;
    --panel: #17182c;
    --surface: #1d1f36;
    --text: #eceefe;
    --muted: #9599bd;
    --border: #2a2c48;
    --border-strong: #3a3d60;
    --accent: #8f84ff;
    --accent-2: #e07bff;
    --accent-soft: #29265a;
    --on-accent: #ffffff;
    --selected: #262457;
    --hover: #1f2140;
    --track1: #7b93ff;
    --track2: #ff8aa2;
    --route: #ffb24d;
    --ok: #6ea8ff;
    --warn: #ffbf4d;
    --err: #ff6f84;
    --warn-soft: #3a2c12;
    --err-soft: #3d1a24;
    --grid: #202240;
    --grid-strong: #34375a;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 30px -14px rgb(0 0 0 / .6);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Inter", ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin-block-start: 0; }
h1, h2, h3 { letter-spacing: -.02em; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row, .toolbar, .presets, .legend { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

select, input, button {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  min-height: 34px;
  padding: 5px 11px;
  transition: border-color .15s, background-color .15s, box-shadow .15s, color .15s;
}
input[type="checkbox"], input[type="range"] { min-height: 0; padding: 0; accent-color: var(--accent); }
input[type="checkbox"] { width: 16px; height: 16px; }
input::placeholder { color: var(--muted); opacity: .8; }
input:hover, select:hover { border-color: var(--accent); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
button, select { cursor: pointer; }
button { font-weight: 600; }
button:hover { border-color: var(--accent); color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: wait; opacity: .6; }
a, .link { color: var(--accent); cursor: pointer; text-decoration: none; }
a:hover, .link:hover { text-decoration: underline; text-underline-offset: 3px; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}
.masthead {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 12px var(--gutter) 6px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 auto 0 0;
  font-size: 20px;
  line-height: 1.1;
}
.brand::before {
  content: "М";
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  box-shadow: 0 6px 16px -6px var(--accent);
}
#version {
  align-self: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
}
#version:empty { display: none; }
.masthead label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 500; }
.masthead select { font-size: 13px; min-height: 32px; max-width: 320px; background: var(--surface); }

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px var(--gutter) 10px;
}
.tabs button, .tabs .api-link {
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  min-height: 0;
  color: var(--muted);
  font-weight: 600;
}
.tabs button:hover { background: var(--hover); color: var(--text); }
.tabs button.active {
  background: var(--text);
  color: var(--panel);
}
.tabs .api-link { margin-left: auto; font-size: 13px; }
.tabs .api-link:hover { background: var(--accent-soft); text-decoration: none; }

main { padding: 20px var(--gutter) 32px; }
.tab { display: none; }
.tab.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
#tab-cards.active {
  display: grid;
  grid-template-columns: clamp(340px, 25vw, 430px) minmax(0, 1fr);
  align-items: start;
  gap: 20px;
}
.sidebar, .detail, .upload, .toolbar, .graph-wrap, .graph-info, .table-wrap {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sidebar {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: calc(var(--header) + 20px);
  max-height: calc(100vh - var(--header) - 40px);
  overflow: hidden;
}
.filters { padding: 16px; display: grid; gap: 10px; }
.list-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.list-heading h2 { font-size: 20px; margin: 0; }
.filters input { width: 100%; background: var(--surface); }
.filters .row { flex-wrap: nowrap; }
.filters select { flex: 1 1 auto; min-width: 0; font-size: 13px; }

.card-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.card-list li, .list-columns {
  display: grid;
  grid-template-columns: var(--list-columns);
  gap: 8px;
  align-items: center;
  padding: 7px 12px;
}
.list-columns {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-block: 1px solid var(--border);
  background: var(--surface);
}
.list-columns span:first-child { grid-column: 2; }
.card-list li { border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; transition: background-color .12s; }
.card-list li:hover, tr.clickable:hover { background: var(--hover); }
.card-list li.selected { background: var(--selected); box-shadow: inset 3px 0 0 var(--accent); }
.card-list li.selected > :nth-child(2) { color: var(--accent); font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.ok { background: var(--ok); }
.dot.warnings { background: var(--warn); }
.dot.error { background: var(--err); }

.detail { padding: 24px 28px; min-width: 0; }
.detail h2 { margin-bottom: 10px; font-size: clamp(26px, 2vw, 34px); line-height: 1.15; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}
.chip.derived { color: var(--accent); background: var(--accent-soft); border-color: transparent; font-weight: 600; }
.fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
  gap: 10px;
}
.fields > div {
  display: grid;
  align-content: start;
  gap: 3px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.fields .label { font-size: 12px; color: var(--muted); }
.fields .value { font-size: 16px; font-weight: 650; }
.table-wrap { overflow-x: auto; box-shadow: none; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 12px; }
td { border-top: 1px solid var(--border); }
th {
  background: var(--surface);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tbody tr { transition: background-color .12s; }
.detail td:first-child { font-weight: 600; }
.detail td:first-child .small { font-weight: 400; }
.detail > p { margin: 12px 0; }
.detail .table-wrap + p { margin-top: 14px; }
.issues { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 6px; }
.issues li { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--surface); }
.issues li.sev-error { background: var(--err-soft); }
.issues li.sev-warning { background: var(--warn-soft); }
.sev-error { color: var(--err); }
.sev-warning { color: var(--warn); }
.sev-info { color: var(--muted); }

.toolbar { padding: 12px 16px; gap: 10px 18px; }
.toolbar label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-weight: 500; }
.toolbar input:not([type]) { width: 82px; text-align: center; background: var(--surface); color: var(--text); }
#graph-route { width: 70px; }
.presets {
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.presets button { font-size: 12px; border: 0; border-radius: 999px; background: transparent; min-height: 28px; padding: 3px 12px; }
.presets button:hover { background: var(--panel); }
#station-show, #graph-draw, #upload-send, .detail > .row button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  border: 0;
  border-radius: 999px;
  padding-inline: 18px;
  box-shadow: 0 6px 16px -8px var(--accent);
}
#station-show:hover, #graph-draw:hover, #upload-send:hover, .detail > .row button:hover {
  color: var(--on-accent);
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.legend { gap: 6px 20px; margin: 14px 4px; font-size: 12px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 7px; }
.swatch { width: 22px; height: 0; border-top: 3px solid; border-radius: 2px; }
.swatch.t1 { border-color: var(--track1); }
.swatch.t2 { border-color: var(--track2); }
.swatch.dashed { border-top-style: dashed; border-color: var(--muted); }
.swatch.route { border-color: var(--route); border-top-width: 4px; }
.graph-wrap { position: relative; overflow: auto; max-height: calc(100vh - 320px); }
.graph-wrap > p { margin: 16px; }
.graph-wrap svg { display: block; }
.graph-wrap .grid { stroke: var(--grid); stroke-width: 1; }
.graph-wrap .grid.strong { stroke: var(--grid-strong); }
.graph-wrap .axis-text { fill: var(--muted); font-size: 11px; }
.graph-wrap .station-text { fill: var(--text); font-size: 12px; font-weight: 500; }
.graph-wrap .thread { fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.graph-wrap .thread.t1 { stroke: var(--track1); }
.graph-wrap .thread.t2 { stroke: var(--track2); }
.graph-wrap .thread.unknown { stroke-dasharray: 4 3; }
.graph-wrap .thread.dim { opacity: 0.15; }
.graph-wrap .thread.route { stroke: var(--route); stroke-width: 3.4; opacity: 1; }
.graph-wrap .thread.hover { stroke-width: 3.2; }
.graph-wrap .hit { fill: none; stroke: transparent; stroke-width: 9; cursor: pointer; }
.graph-wrap .label { font-size: 10px; fill: var(--text); }
.graph-wrap .label.dim { opacity: 0.25; }
.graph-wrap .link-line { stroke: var(--route); stroke-dasharray: 2 3; stroke-width: 1.6; fill: none; }

.graph-info { margin-top: 12px; padding: 12px 16px; }
.graph-info:empty { display: none; }
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text);
  color: var(--panel);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
  font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace;
  z-index: 20;
  white-space: pre;
  box-shadow: 0 12px 30px -10px rgb(0 0 0 / .4);
}
#station-table > .table-wrap { box-shadow: var(--shadow); }
.upload { padding: 22px 24px; margin-bottom: 20px; }
.upload h3, #report h3 { margin: 0 0 6px; font-size: 19px; }
.upload .row { margin-top: 12px; gap: 10px; }
.file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 600;
  transition: border-color .15s, background-color .15s;
}
.file:hover { border-color: var(--accent); background: var(--accent-soft); }
.file input { max-width: 250px; border: 0; background: transparent; padding: 0; min-height: 0; }
.file input::file-selector-button {
  font: inherit;
  font-weight: 600;
  margin-right: 8px;
  border: 0;
  border-radius: 8px;
  padding: 5px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
}
#report h3 { margin-top: 24px; }
#station-table > p { margin-block: 14px 10px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--panel); }
::-webkit-scrollbar-track { background: transparent; }

button.link { border: none; background: none; padding: 0; min-height: 0; color: var(--accent); font: inherit; font-weight: 600; }
button.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.notice {
  background: var(--warn-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.badge {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.status {
  display: inline-block;
  vertical-align: middle;
  font-size: 12px;
  font-weight: 600;
  margin-left: 10px;
  letter-spacing: 0;
  padding: 3px 10px;
  border-radius: 999px;
}
.status-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.status-warnings { color: var(--warn); background: var(--warn-soft); }
.status-error { color: var(--err); background: var(--err-soft); }
[aria-invalid="true"] { border-color: var(--err); box-shadow: 0 0 0 3px var(--err-soft); }
.field-error { color: var(--err); font-size: 12px; font-weight: 500; }

.logout { display: flex; align-items: center; gap: 8px; margin-left: 12px; }
.logout[hidden] { display: none; }
.logout button { min-height: 30px; padding: 3px 12px; border-radius: 999px; font-size: 13px; }
code { font: 12px/1.4 ui-monospace, "SF Mono", Menlo, monospace; }
code.secret {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px dashed var(--accent);
  user-select: all;
  word-break: break-all;
}
#key-name { flex: 1 1 320px; max-width: 460px; }
#key-create {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  border: 0;
  border-radius: 999px;
  padding-inline: 18px;
}
#key-new { margin-top: 16px; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--accent-soft); }
#key-new p { margin-bottom: 10px; }
tr.revoked td { color: var(--muted); text-decoration: line-through; }
tr.revoked td:last-child { text-decoration: none; }
button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
button.danger:hover { background: var(--err-soft); color: var(--err); border-color: var(--err); }

.login-body { min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 45%), var(--bg); }
.login { width: min(400px, 100% - 32px); }
.login-card {
  display: grid;
  gap: 14px;
  padding: 32px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.login-card .brand { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input { width: 100%; min-height: 40px; background: var(--surface); color: var(--text); }
.login-card button {
  min-height: 42px;
  margin-top: 4px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
}
.login-card button:hover { color: var(--on-accent); filter: brightness(1.08); }
.login-error { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--err-soft); color: var(--err); }
