/* MeshStation Cloud — same visual language as the Hub (pixel palette, square frames). */
@font-face { font-family: "Inter"; font-weight: 100 900; font-display: swap; src: url(/static/hub/fonts/inter-latin-wght-normal.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 100 900; font-display: swap; src: url(/static/hub/fonts/inter-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+1E00-1EFF, U+20A0-20C0; }
@font-face { font-family: "JetBrains Mono"; font-weight: 100 800; font-display: swap; src: url(/static/hub/fonts/jetbrains-mono-latin-wght-normal.woff2) format("woff2"); }
@font-face { font-family: "Pixelify Sans"; font-weight: 400 700; font-display: swap; src: url(/static/hub/fonts/pixelify-sans.woff2) format("woff2"); }

:root {
  color-scheme: dark;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --pixel: "Pixelify Sans", var(--mono);
  --bg: #151720; --bg-elev: #110e1a; --surface: #1b1b28; --surface-2: #242131; --surface-3: #302b40; --hover: #292538;
  --line: #343145; --line-2: #49445e; --frame-shadow: #332e48;
  --text: #f7eddf; --text-2: #c6bdd5; --text-3: #a69bb8;
  --accent: #f0bb79; --accent-ink: #251831; --accent-soft: #2e2137;
  --ok: #aed79f; --warn: #f2bd72; --err: #f19aa6; --info: #a0cfef; --violet: #c6b4ed; --teal: #91d3ca;
  --s0: #f0bb79; --s1: #a0cfef; --s2: #aed79f; --s3: #c6b4ed; --s4: #f19aa6; --s5: #91d3ca; --s6: #efa16c; --s7: #bfd782;
  --shadow: 3px 3px 0 var(--frame-shadow);
  --gut: 20px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f0e5; --bg-elev: #eee5d8; --surface: #fffaf2; --surface-2: #f5ecde; --surface-3: #e8ddcd; --hover: #f0e6d6;
  --line: #e0d4c4; --line-2: #cbbba6; --frame-shadow: #d8c9b4;
  --text: #291f30; --text-2: #574a5f; --text-3: #6f6277;
  --accent: #7b430b; --accent-ink: #fffaf2; --accent-soft: #f3e2cb;
  --ok: #326342; --warn: #854d06; --err: #a73849; --info: #1d5f8c; --violet: #5b3f97; --teal: #266964;
  --s0: #9a5a12; --s1: #1d5f8c; --s2: #326342; --s3: #5b3f97; --s4: #a73849; --s5: #266964; --s6: #b05a1a; --s7: #5c6e12;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f6f0e5; --bg-elev: #eee5d8; --surface: #fffaf2; --surface-2: #f5ecde; --surface-3: #e8ddcd; --hover: #f0e6d6;
    --line: #e0d4c4; --line-2: #cbbba6; --frame-shadow: #d8c9b4;
    --text: #291f30; --text-2: #574a5f; --text-3: #6f6277;
    --accent: #7b430b; --accent-ink: #fffaf2; --accent-soft: #f3e2cb;
    --ok: #326342; --warn: #854d06; --err: #a73849; --info: #1d5f8c; --violet: #5b3f97; --teal: #266964;
    --s0: #9a5a12; --s1: #1d5f8c; --s2: #326342; --s3: #5b3f97; --s4: #a73849; --s5: #266964; --s6: #b05a1a; --s7: #5c6e12;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 400 14.5px/1.5 var(--font); -webkit-font-smoothing: antialiased; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; line-height: 1.25; }
h2 { font-size: 1.25rem; } h3 { font-size: 1rem; }
h4 { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--text-2); } .faint { color: var(--text-3); } .small { font-size: .86rem; } .tiny { font-size: .76rem; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .err { color: var(--err); }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--surface); padding: 6px 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── shell */
.top { position: sticky; top: 0; z-index: 1100; display: flex; align-items: center; gap: 18px; padding: 10px var(--gut);
  background: var(--bg-elev); border-bottom: 2px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none !important; flex: none; }
.brand b { font-family: var(--pixel); font-size: 1.12rem; font-weight: 600; display: block; line-height: 1.1; }
.brand small { color: var(--text-3); font-size: .74rem; }
#nav { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 auto; scrollbar-width: none; }
#nav a { padding: 7px 11px; color: var(--text-2); white-space: nowrap; border: 2px solid transparent; text-decoration: none; font-weight: 550; font-size: .92rem; }
#nav a:hover { background: var(--hover); color: var(--text); }
#nav a.active { color: var(--accent-ink); background: var(--accent); }
#nav a .badge { margin-left: 6px; }
.top-right { display: flex; align-items: center; gap: 8px; flex: none; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--text-2); }
.live i { width: 9px; height: 9px; background: var(--text-3); display: inline-block; }
.live.on i { background: var(--ok); animation: blink 2.4s steps(2) infinite; }
.live.off i { background: var(--err); }
@keyframes blink { 50% { opacity: .35; } }
main { padding: 20px var(--gut) 60px; max-width: 1500px; margin: 0 auto; outline: none; }

/* ── components */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 14px; border: 2px solid var(--line-2);
  background: var(--surface-2); color: var(--text); font-weight: 600; cursor: pointer; box-shadow: var(--shadow); text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; }
.btn.sm { min-height: 30px; padding: 3px 10px; font-size: .86rem; }
.btn:disabled { opacity: .5; cursor: default; }
.card { background: var(--surface); border: 2px solid var(--line); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: 2fr 1fr; }
.span { grid-column: 1 / -1; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface); border: 2px solid var(--line); padding: 12px 14px; box-shadow: var(--shadow); }
.tile b { display: block; font-family: var(--pixel); font-size: 1.7rem; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { color: var(--text-3); font-size: .8rem; }
.tile.alert b { color: var(--err); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; font-size: .74rem; font-weight: 650; border: 1.5px solid currentColor; line-height: 1.6; white-space: nowrap; }
.tag.ok { color: var(--ok); } .tag.warn { color: var(--warn); } .tag.err { color: var(--err); } .tag.muted { color: var(--text-3); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; background: var(--err); color: var(--accent-ink); font-size: .72rem; font-weight: 700; text-align: center; line-height: 18px; }
.dot { width: 10px; height: 10px; display: inline-block; flex: none; background: var(--text-3); }
.dot.ok { background: var(--ok); } .dot.err { background: var(--err); } .dot.warn { background: var(--warn); }
.notice { padding: 10px 12px; border: 2px solid var(--line-2); background: var(--surface-2); }
.notice.warn { border-color: var(--warn); } .notice.err { border-color: var(--err); } .notice.ok { border-color: var(--ok); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: .9rem; }
dl.kv dt { color: var(--text-3); } dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; color: var(--text-3); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--hover); }
.table-wrap { overflow-x: auto; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; color: var(--text-2); }
.field input, .field select, .field textarea, input.inline, select.inline { min-height: 36px; padding: 6px 10px; background: var(--bg); border: 2px solid var(--line-2); color: var(--text); width: 100%; }
.field textarea { min-height: 80px; resize: vertical; }
.field .hint { font-size: .76rem; color: var(--text-3); }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { display: inline-flex; gap: 4px; align-items: center; padding: 0 6px; font-size: .74rem; background: var(--surface-2); border-left: 4px solid var(--c, var(--text-3)); white-space: nowrap; }
.empty { color: var(--text-3); padding: 24px; text-align: center; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 6px 0 14px; flex-wrap: wrap; }
.section-title p { color: var(--text-2); }

/* ── sites */
.sites { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); margin-bottom: 16px; }
.site { background: var(--surface); border: 2px solid var(--line); border-top: 5px solid var(--c); box-shadow: var(--shadow); padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.site:hover { background: var(--hover); }
.site.off { opacity: .72; }
.site h3 { display: flex; align-items: center; gap: 8px; }
.site .meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: .78rem; color: var(--text-3); }
.site .meta b { display: block; color: var(--text); font-size: .95rem; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 34px; display: block; }

/* ── map and live feed */
/* isolation: Leaflet's panes and controls (z-index 400-1000) stay inside the map, under the sticky header */
.map { height: 460px; border: 2px solid var(--line); background: var(--surface-2); position: relative; isolation: isolate; z-index: 0; }
.map.tall { height: calc(100vh - 230px); min-height: 420px; }
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); border-radius: 0; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 10px 12px; font-size: .86rem; }
.site-pin { width: 22px; height: 22px; border: 3px solid var(--bg); background: var(--c); box-shadow: 0 0 0 2px var(--c); }
.site-pin.off { opacity: .45; }
.ant-pin { width: 20px; height: 20px; border: 3px solid var(--bg); background: var(--c, var(--s0)); box-shadow: 0 0 0 2px var(--c, var(--s0)); display: inline-block; }
.ant-pin.p1 { transform: rotate(45deg) scale(.82); }
.ant-pin.off { opacity: .45; }
.ant-pin.mini { width: 11px; height: 11px; border-width: 2px; box-shadow: 0 0 0 1.5px var(--c, var(--s0)); vertical-align: -1px; }
.legend .ant-pin.mini { --c: var(--s0); } .legend .ant-pin.p1.mini { --c: var(--s1); }
.site.ant { border-top-style: solid; }
.node-pin { width: 9px; height: 9px; background: var(--info); border: 1.5px solid var(--bg); }
.node-pin.t3 { background: var(--violet); } .node-pin.t4 { background: var(--teal); } .node-pin.t1 { background: var(--text-3); }
.feed { max-height: 460px; overflow: auto; font-size: .82rem; }
.feed .ev { display: grid; grid-template-columns: 58px 74px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.feed .ev.fresh { animation: fresh 1.2s; }
@keyframes fresh { from { background: var(--accent-soft); } }
.ptype { font-family: var(--mono); font-size: .74rem; font-weight: 700; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .78rem; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }

/* ── charts */
.bars { display: flex; align-items: flex-end; gap: 2px; height: 90px; }
.bars i { flex: 1; background: var(--accent); min-height: 1px; opacity: .85; }
.bars i:hover { opacity: 1; }
.overlap { display: flex; height: 26px; border: 2px solid var(--line); }
.overlap span { display: flex; align-items: center; justify-content: center; font-size: .74rem; font-weight: 700; color: var(--accent-ink); min-width: 0; overflow: hidden; }
svg.chart { width: 100%; height: 160px; display: block; }
svg.chart text { fill: var(--text-3); font-size: 10px; font-family: var(--mono); }

/* ── coverage matrix */
.matrix td, .matrix th { text-align: center; padding: 4px 6px; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
.cell { display: inline-block; min-width: 46px; padding: 1px 4px; font-size: .74rem; font-weight: 650; }
.cell.d { background: color-mix(in srgb, var(--ok) 30%, transparent); }
.cell.r { background: color-mix(in srgb, var(--info) 20%, transparent); }

/* ── messages */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; padding-right: 4px; }
.msg { padding: 8px 10px; background: var(--surface-2); border-left: 4px solid var(--c, var(--line-2)); }
.msg .who { font-weight: 650; font-size: .86rem; } .msg .when { color: var(--text-3); font-size: .74rem; }
.msg.out { border-left-color: var(--accent); background: var(--accent-soft); }

/* ── overlays */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 3000; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 2px solid var(--line-2); box-shadow: var(--shadow); padding: 10px 14px; animation: fresh .4s; }
.toast.ok { border-color: var(--ok); } .toast.err { border-color: var(--err); }
dialog { background: var(--surface); color: var(--text); border: 2px solid var(--line-2); box-shadow: 6px 6px 0 var(--frame-shadow); padding: 0; max-width: min(640px, calc(100vw - 24px)); width: 100%; }
dialog::backdrop { background: rgba(13, 9, 19, .66); }
#modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; max-height: 85vh; overflow: auto; }
.drawer-head { display: flex; align-items: center; gap: 10px; }
pre.log { max-height: 50vh; overflow: auto; background: var(--bg); padding: 10px; font-size: .76rem; white-space: pre-wrap; border: 2px solid var(--line); }
.secret { font-family: var(--mono); background: var(--bg); padding: 8px 10px; border: 2px dashed var(--accent); overflow-wrap: anywhere; user-select: all; }

@media (max-width: 900px) {
  .grid.two { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; gap: 8px 12px; }
  #nav { order: 3; flex-basis: 100%; }
  .brand small { display: none; }
}
@media (max-width: 560px) {
  :root { --gut: 12px; }
  main { padding-top: 14px; }
  .map { height: 340px; }
  .feed .ev { grid-template-columns: 50px 1fr; }
  .feed .ev > :nth-child(3) { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
