/* russozl traffic manager
   Tokens from the russozl design system: INK base, Slate, Paper text, Muted, one green for OK and
   one red for errors. No accent colour: emphasis is Paper, weight and size. Map categories and
   status colours come from the validated data-viz palette, see js/strings.js. */

:root {
  color-scheme: dark;
  --ink: #1f2430;
  --ink-deep: #191d27;
  --slate: #2e3a4d;
  --slate-2: #374559;
  --paper: #f4f1ea;
  --muted: #aab4c4;
  --dim: #7d8798;
  --line: rgba(244, 241, 234, 0.08);
  --line-2: rgba(244, 241, 234, 0.16);
  --ok: #1f7a44;
  --error: #c0392b;
  --critical: #d03b3b;
  --warning: #fab219;
  --player: #3987e5;
  --probe: #199e70;
  --persistent: #9085e9;

  --font-display: "Saira Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Saira", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px; --s5: 32px;
  --t-xs: 12px; --t-sm: 14px; --t-md: 17.5px; --t-lg: 22px; --t-xl: 27.5px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--paper); }
body { font: 400 var(--t-sm)/1.45 var(--font-body); -webkit-font-smoothing: antialiased; overflow: hidden; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  height: 100vh;
  grid-template-columns: 256px minmax(0, 1fr) 344px;
  grid-template-rows: 48px minmax(0, 1fr) 200px;
  grid-template-areas: "top top top" "left center right" "left bottom right";
}
.top { grid-area: top; display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s3); border-bottom: 1px solid var(--line); }
.left { grid-area: left; border-right: 1px solid var(--line); overflow-y: auto; }
.center { grid-area: center; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.right { grid-area: right; border-left: 1px solid var(--line); overflow-y: auto; }
.bottom { grid-area: bottom; border-top: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }

.brand { font: 800 var(--t-md)/1 var(--font-display); letter-spacing: 0.02em; white-space: nowrap; }
.brand span { font-weight: 600; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; font-size: var(--t-xs); margin-left: 6px; }
.brand.big { font-size: var(--t-xl); }
.brand.big span { font-size: var(--t-sm); }

.modes { display: flex; gap: 2px; margin-left: var(--s3); }
.modes button {
  background: none; border: 0; padding: 6px 12px; cursor: pointer; border-radius: 4px;
  font: 600 var(--t-xs)/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.modes button:hover { color: var(--paper); background: rgba(244, 241, 234, 0.04); }
.modes button.on { color: var(--paper); background: var(--slate); }

.server { margin-left: auto; display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.server-name { color: var(--muted); font-size: var(--t-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 380px; }
.badge {
  font: 700 11px/1 var(--font-mono); letter-spacing: 0.06em; padding: 5px 8px; border-radius: 3px;
  background: var(--slate); color: var(--paper); white-space: nowrap;
}
.badge.ok { background: var(--ok); }
.badge.bad { background: var(--error); }
.badge.warn { background: var(--warning); color: var(--ink); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 4px; width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; }
.icon-btn:hover { border-color: var(--line-2); }
.icon-btn svg { width: 16px; height: 16px; stroke: var(--muted); stroke-width: 1.5; fill: none; }

/* ------------------------------------------------------------------ panels */

.panel { padding: var(--s3); border-bottom: 1px solid var(--line); }
.panel:last-child { border-bottom: 0; }
.panel h2 {
  margin: 0 0 var(--s3); font: 700 var(--t-xs)/1 var(--font-body); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: var(--s2);
}
.panel h2 .spacer { flex: 1; }
.panel h3 { margin: var(--s3) 0 var(--s2); font: 600 var(--t-sm)/1.2 var(--font-body); color: var(--paper); }
.panel p { margin: 0 0 var(--s2); color: var(--muted); font-size: var(--t-xs); }

.kpi { padding: var(--s3) var(--s3) var(--s2); border-bottom: 1px solid var(--line); }
.kpi .label { font: 600 var(--t-xs)/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.kpi .value { font: 700 var(--t-xl)/1.1 var(--font-mono); margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: var(--t-sm); color: var(--muted); font-weight: 500; margin-left: 4px; }
.kpi .sub { font-size: var(--t-xs); color: var(--dim); margin-top: 2px; }
.kpi svg.spark { display: block; width: 100%; height: 34px; margin-top: 6px; overflow: visible; }
.kpi .status-row { display: flex; align-items: center; justify-content: space-between; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 36px; padding: 0 var(--s3); border-radius: 4px; cursor: pointer;
  border: 1px solid var(--line-2); background: transparent; color: var(--paper);
  font: 600 var(--t-xs)/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase;
}
.btn:hover { background: rgba(244, 241, 234, 0.05); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.block { width: 100%; }
.btn.primary { background: var(--paper); color: var(--ink); border-color: var(--paper); }
.btn.primary:hover { background: #fff; }
.btn.danger { background: var(--error); border-color: var(--error); color: #fff; }
.btn.danger:hover { background: #d0412f; }
.btn.small { height: 26px; padding: 0 10px; font-size: 11px; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--paper); }
.btn-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.btn-col { display: flex; flex-direction: column; gap: var(--s2); }

.field { display: block; margin-bottom: var(--s3); }
.field > span, .field-label { display: block; font-size: var(--t-xs); color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 4px; border: 1px solid var(--line-2);
  background: var(--ink-deep); color: var(--paper); outline: none;
}
textarea { height: auto; padding: 8px 10px; font-family: var(--font-mono); font-size: var(--t-xs); resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--muted); }
select { padding-right: 24px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--t-xs); cursor: pointer; white-space: nowrap; }
.check input { accent-color: var(--paper); }

.slider { margin-bottom: var(--s3); }
.slider .head { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--t-sm); margin-bottom: 6px; }
.slider .head .num { color: var(--paper); }
.slider input[type=range] { width: 100%; accent-color: var(--paper); }
.slider .scale { display: flex; justify-content: space-between; font: 500 11px/1 var(--font-mono); color: var(--dim); margin-top: 2px; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 8px 0; border-bottom: 1px solid var(--line); }
.toggle-row:last-child { border-bottom: 0; }
.toggle-row .t-label { font-size: var(--t-sm); }
.toggle-row .t-sub { font-size: var(--t-xs); color: var(--dim); }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--slate); cursor: pointer; transition: background 0.15s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.switch input:checked + span { background: var(--paper); }
.switch input:checked + span::after { transform: translateX(16px); background: var(--ink); }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 6px 12px; cursor: pointer; font: 700 11px/1 var(--font-mono); color: var(--muted); }
.seg button.on { background: var(--paper); color: var(--ink); }

/* ------------------------------------------------------------------ map */

.map-head { display: flex; align-items: center; gap: var(--s3); padding: 10px var(--s3); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.map-title { display: flex; align-items: baseline; gap: var(--s2); min-width: 0; }
.map-title h1 { margin: 0; font: 700 var(--t-md)/1.2 var(--font-display); letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-title span { font-size: var(--t-xs); white-space: nowrap; }
.map-tools { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }
.map-tools select { width: auto; height: 30px; font-size: var(--t-xs); }

.map-wrap { position: relative; flex: 1; min-height: 0; background: var(--ink-deep); overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#map.picking { cursor: crosshair; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap; pointer-events: none;
  font: 600 11px/1 var(--font-mono); padding: 4px 6px; border-radius: 3px; margin-top: -10px;
  background: rgba(25, 29, 39, 0.86); border: 1px solid var(--line-2); color: var(--paper);
}
.lbl.alert { border-color: var(--critical); color: #fff; background: rgba(160, 40, 40, 0.88); pointer-events: auto; cursor: pointer; }
.lbl.alert.warning { border-color: var(--warning); background: rgba(25, 29, 39, 0.9); color: var(--warning); }
.lbl.alert small { display: block; font-weight: 500; opacity: 0.85; margin-top: 2px; }
.lbl.place { background: none; border: 0; color: var(--dim); font-weight: 500; transform: translate(-50%, -50%); margin: 0; padding: 0; }
.lbl.sel { border-color: var(--paper); }
.lbl.probe { border-color: var(--probe); }
.lbl.player { border-color: var(--player); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 160px;
  background: rgba(25, 29, 39, 0.95); border: 1px solid var(--line-2); border-radius: 4px;
  padding: 8px 10px; font-size: var(--t-xs); line-height: 1.5;
}
.tooltip b { font-weight: 600; }
.legend {
  position: absolute; right: var(--s3); bottom: var(--s3); background: rgba(25, 29, 39, 0.9);
  border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; font-size: var(--t-xs); min-width: 170px;
}
.legend .row { display: flex; align-items: center; gap: 8px; margin: 3px 0; color: var(--muted); }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--ink-deep); }
.legend .sq { width: 14px; height: 4px; border-radius: 2px; flex: none; }
.legend .ramp { height: 6px; border-radius: 3px; margin: 6px 0 2px; }
.legend .ramp-scale { display: flex; justify-content: space-between; font: 500 11px/1 var(--font-mono); color: var(--dim); }
.legend .title { color: var(--paper); font-weight: 600; margin-bottom: 4px; }
.map-hint {
  position: absolute; left: 50%; top: var(--s3); transform: translateX(-50%); background: var(--paper); color: var(--ink);
  font-weight: 600; font-size: var(--t-xs); padding: 8px 12px; border-radius: 4px;
}
.map-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: var(--t-sm); }

/* ------------------------------------------------------------------ bottom list */

.tabs { display: flex; align-items: center; gap: 2px; padding: 6px var(--s3) 0; border-bottom: 1px solid var(--line); }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 10px 8px; cursor: pointer;
  font: 600 var(--t-xs)/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.tabs button.on { color: var(--paper); border-bottom-color: var(--paper); }
.tabs .count { font-family: var(--font-mono); margin-left: 4px; color: var(--dim); }
.tabs .count.hot { color: var(--critical); }
.tabs-spacer { flex: 1; }
.tabs .small input { height: 26px; width: 200px; font-size: var(--t-xs); }

.list { flex: 1; overflow-y: auto; font: 500 var(--t-xs)/1.4 var(--font-mono); }
.row-item { display: flex; align-items: center; gap: var(--s2); padding: 6px var(--s3); border-bottom: 1px solid var(--line); }
.row-item:hover { background: rgba(244, 241, 234, 0.03); }
.row-item .when { color: var(--dim); width: 64px; flex: none; }
.row-item .sev { width: 8px; height: 8px; border-radius: 2px; flex: none; background: var(--dim); }
.row-item .sev.critical { background: var(--critical); }
.row-item .sev.warning { background: var(--warning); }
.row-item .sev.ok { background: var(--ok); }
.row-item .msg { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .msg b { color: var(--paper); font-weight: 700; }
.row-item .msg .place { color: var(--muted); }
.row-item.ended { opacity: 0.55; }
.row-item .act { display: flex; gap: 6px; flex: none; }
.list .empty { padding: var(--s3); color: var(--dim); font-family: var(--font-body); }
.log-line { padding: 2px var(--s3); white-space: pre-wrap; word-break: break-word; color: var(--muted); }
.log-line.err { color: #ff8a80; }
.log-line.wrn { color: var(--warning); }
.log-line.ai { color: var(--paper); }

/* ------------------------------------------------------------------ hotspots, inspector, tables */

.spot { display: block; width: 100%; text-align: left; cursor: pointer; background: none; color: inherit;
  border: 1px solid var(--line); border-left: 3px solid var(--dim); border-radius: 4px; padding: 10px 12px; margin-bottom: var(--s2); }
.spot:hover { border-color: var(--line-2); }
.spot.critical { border-left-color: var(--critical); }
.spot.warning { border-left-color: var(--warning); }
.spot.ok { border-left-color: var(--ok); }
.spot .t { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.spot .t .num { color: var(--paper); }
.spot .s { font-size: var(--t-xs); color: var(--muted); margin-top: 2px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: var(--t-xs); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--paper); }
.kv dd.bad { color: #ff8a80; }
.kv dd.warn { color: var(--warning); }

.big-num { font: 700 var(--t-xl)/1 var(--font-mono); }
.inspector-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.inspector-head .model { font: 700 var(--t-md)/1.2 var(--font-display); }
.chip { display: inline-block; font: 600 11px/1 var(--font-mono); padding: 4px 6px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--muted); margin: 0 4px 4px 0; }
.chip.on { color: var(--paper); border-color: var(--paper); }
.chip.bad { color: #fff; background: var(--error); border-color: var(--error); }
.chip.warn { color: var(--ink); background: var(--warning); border-color: var(--warning); }

table.t { width: 100%; border-collapse: collapse; font-size: var(--t-xs); }
table.t th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 4px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
table.t td { padding: 6px 4px; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
table.t td.l { font-family: var(--font-body); }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: rgba(244, 241, 234, 0.03); }
.bar { height: 6px; background: var(--slate); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--paper); border-radius: 3px; }
.bars .bar-row { display: grid; grid-template-columns: 120px 1fr 52px; gap: 8px; align-items: center; font-size: var(--t-xs); margin: 6px 0; }
.bars .bar-row .n { text-align: right; font-family: var(--font-mono); }

/* params */
.param-search { position: sticky; top: 0; z-index: 2; background: var(--ink); padding: var(--s3); border-bottom: 1px solid var(--line); }
.param-group > h3 { margin: 0; padding: 12px var(--s3) 8px; font: 700 var(--t-xs)/1 var(--font-body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); cursor: pointer; display: flex; justify-content: space-between; }
.param { padding: 10px var(--s3); border-top: 1px solid var(--line); }
.param .p-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.param .p-name { font: 600 var(--t-xs)/1.3 var(--font-mono); color: var(--paper); word-break: break-all; }
.param .p-mode { font: 600 10px/1 var(--font-mono); letter-spacing: 0.04em; padding: 3px 5px; border-radius: 3px; border: 1px solid var(--line-2); color: var(--muted); flex: none; text-transform: uppercase; }
.param .p-mode.spawn { color: var(--warning); border-color: rgba(250, 178, 25, 0.5); }
.param .p-mode.restart { color: #ff8a80; border-color: rgba(208, 59, 59, 0.6); }
.param .p-desc { font-size: var(--t-xs); color: var(--dim); margin: 4px 0 6px; }
.param .p-ctl { display: flex; gap: 6px; align-items: center; }
.param .p-ctl input[type=text], .param .p-ctl input[type=number], .param .p-ctl select { height: 30px; font-family: var(--font-mono); font-size: var(--t-xs); }
.param .p-meta { font: 500 11px/1 var(--font-mono); color: var(--dim); margin-top: 6px; display: flex; gap: 10px; }
.param.changed .p-name::after { content: " · alterado"; color: var(--warning); font-weight: 500; }
.param.staged .p-name::after { content: " · ao reiniciar"; color: #ff8a80; font-weight: 500; }

/* drawer, toasts, login */
.drawer {
  position: fixed; top: 48px; right: 0; bottom: 0; width: 420px; max-width: 100vw; background: var(--ink);
  border-left: 1px solid var(--line-2); z-index: 20; overflow-y: auto; box-shadow: -12px 0 32px rgba(0, 0, 0, 0.35);
}
.toasts { position: fixed; left: 50%; bottom: var(--s4); transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; gap: var(--s2); align-items: center; }
.toast { background: var(--paper); color: var(--ink); padding: 10px 14px; border-radius: 4px; font-weight: 600; font-size: var(--t-xs); max-width: 560px; }
.toast.err { background: var(--error); color: #fff; }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--ink); }
.login-box { width: 360px; max-width: calc(100vw - 32px); }
.login-box .brand { margin-bottom: var(--s4); }
.login-error { color: #ff8a80; font-size: var(--t-xs); min-height: 1em; }

pre.yaml { background: var(--ink-deep); border: 1px solid var(--line); border-radius: 4px; padding: 10px; font: 500 11px/1.5 var(--font-mono); white-space: pre-wrap; max-height: 320px; overflow: auto; margin: 0 0 var(--s2); }

/* ------------------------------------------------------------------ narrow screens */

@media (max-width: 1280px) {
  .app { grid-template-columns: 216px minmax(0, 1fr) 312px; }
  .modes button { padding: 6px 8px; }
  .server-name { max-width: 200px; }
}
@media (max-width: 980px) {
  body { overflow: auto; }
  .app { height: auto; grid-template-columns: 1fr; grid-template-rows: auto 70vh auto auto auto;
    grid-template-areas: "top" "center" "right" "bottom" "left"; }
  .top { flex-wrap: wrap; padding: 8px var(--s3); gap: var(--s2); }
  .modes { order: 3; width: 100%; overflow-x: auto; margin-left: 0; }
  .right, .left { border: 0; border-top: 1px solid var(--line); }
  .bottom { height: 260px; }
  .map-tools { margin-left: 0; flex-wrap: wrap; }
}

.sub-note { font-size: var(--t-xs); color: var(--dim); margin: -8px 0 var(--s3); }
.slider .head > span:first-child { flex: 1; }
.slider .head .num { white-space: nowrap; margin-left: 8px; }
