/* SQC485I Mesh Configurator — Meshtastic-inspired clean UI */
:root {
  --bg: #14151a;
  --panel: #1d1f27;
  --panel-2: #23262f;
  --border: #2e3140;
  --text: #e7e9ee;
  --muted: #9aa0ad;
  --accent: #67ea94;      /* mesh green */
  --accent-d: #3fbf6e;
  --danger: #ff6b6b;
  --warn: #ffce5a;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

/* ── Top bar ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand b { font-size: 16px; }
.brand span { font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.spacer { flex: 1; }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border-radius: 999px; font-size: 13px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.on { color: var(--accent); border-color: var(--accent-d); }
.status-pill.on .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.status-pill.busy .dot { background: var(--warn); }

/* ── Layout ────────────────────────────────────────────────── */
/* --navw / --logw drive the side columns: full width vs 62px icon-rail. Keeping
   them variables lets every collapse combination reuse one grid rule. Neither
   side ever fully hides — collapsing just shrinks it to an icon strip. */
.wrap { --navw: 210px; --logw: 360px; display: grid;
  grid-template-columns: var(--navw) minmax(0, 1fr) var(--logw); min-height: calc(100vh - 57px); }
.wrap.nav-rail { --navw: 62px; }
.wrap.log-rail { --logw: 62px; }
/* round toggles that float on the seams between nav / main / activity.
   They live inside <main> (always present) so a button can never hide itself;
   a sticky 0-height wrapper keeps them pinned near the top while the page scrolls.
   main has 40px side padding, so -53px places a 26px button centred on the seam. */
.seamtoggles { position: sticky; top: 10px; height: 0; z-index: 30; pointer-events: none; }
.seambtn {
  pointer-events: auto; position: absolute; top: 4px;
  width: 26px; height: 26px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center; font-size: 15px; line-height: 1;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35); cursor: pointer;
}
.seambtn:hover { color: var(--accent); border-color: var(--accent-d); }
.seambtn.left  { left: -53px; }
.seambtn.right { right: -53px; }
nav.side {
  border-right: 1px solid var(--border); padding: 18px 10px; position: sticky;
  top: 57px; align-self: start; height: calc(100vh - 57px); overflow: auto;
  display: flex; flex-direction: column;
}

/* ── 3rd column: persistent activity log ───────────────────── */
aside.logpanel {
  border-left: 1px solid var(--border); position: sticky; top: 57px; align-self: start;
  height: calc(100vh - 57px); display: flex; flex-direction: column; background: var(--panel);
}
aside.logpanel .loghead {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
aside.logpanel .loghead b { font-size: 14px; }
aside.logpanel .loghead .spacer { flex: 1; }
aside.logpanel .loghead button { padding: 4px 10px; font-size: 12px; }
.logfeed { flex: 1; overflow: auto; padding: 8px 10px; font-size: 12.5px; }
.logitem {
  padding: 5px 8px; border-radius: 6px; margin-bottom: 3px; line-height: 1.35;
  border-left: 2px solid transparent; background: var(--panel-2);
  word-break: break-word; overflow-wrap: anywhere;
}
.logitem .lt { color: var(--muted); font-family: var(--mono); font-size: 11px; margin-right: 6px; }
.logitem.info { border-left-color: #4a90d9; }
.logitem.ok   { border-left-color: var(--accent); }
.logitem.warn { border-left-color: var(--warn); }
.logitem.err  { border-left-color: var(--danger); color: #ffd9d9; }
.logitem.rx   { border-left-color: #6f7787; font-family: var(--mono); font-size: 11.5px; }
.logfeed .empty { color: var(--muted); padding: 10px 8px; }
/* the ▦ icon shows only when the panel is collapsed to an icon strip */
aside.logpanel .loghead .logico { display: none; font-size: 17px; color: var(--muted); }
.wrap.log-rail aside.logpanel .loghead { justify-content: center; padding: 14px 0; }
.wrap.log-rail aside.logpanel .loghead .logico { display: block; }
.wrap.log-rail aside.logpanel .loghead b,
.wrap.log-rail aside.logpanel .loghead .spacer,
.wrap.log-rail aside.logpanel .loghead button,
.wrap.log-rail aside.logpanel .logfeed { display: none; }

@media (max-width: 1080px) {
  .wrap { grid-template-columns: 210px minmax(0, 1fr); }
  aside.logpanel { display: none; }   /* too narrow — log stays in toasts */
}
nav.side a {
  position: relative;
  display: flex; align-items: center; padding: 10px 12px; border-radius: 8px; color: var(--muted);
  text-decoration: none; font-size: 14px; margin-bottom: 3px;
}
nav.side a .ico { margin-right: 9px; width: 18px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 18px; }
/* inline Lucide SVG icons — inherit text colour, sized to the rail glyph box */
.ico svg { width: 18px; height: 18px; display: block; }
nav.side a .label { white-space: nowrap; overflow: hidden; }
nav.side a:hover { background: var(--panel-2); color: var(--text); }
nav.side a.active { background: var(--panel-2); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
nav.side a .navcount { margin-left: auto; font-size: 11px; color: var(--accent); }
nav.side .navspacer { flex: 1; min-height: 10px; }
nav.side .navnote { font-size: 11px; color: var(--muted); padding: 14px 12px 4px; }
/* expand/collapse-labels button at the foot of the rail */
.railtoggle {
  display: flex; align-items: center; width: 100%; margin-top: 4px; padding: 10px 12px;
  background: none; border: none; border-radius: 8px; color: var(--muted); font: inherit; cursor: pointer;
}
.railtoggle:hover { background: var(--panel-2); color: var(--text); border-color: transparent; }
.railtoggle .ico { margin-right: 9px; width: 18px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 18px; }

/* ── Icon-rail mode (Meshtastic-style): icons only, labels on hover ── */
.wrap.nav-rail nav.side { padding: 14px 8px; }
.wrap.nav-rail nav.side a,
.wrap.nav-rail nav.side .railtoggle { justify-content: center; padding: 11px 0; }
.wrap.nav-rail nav.side a .ico,
.wrap.nav-rail nav.side .railtoggle .ico { margin-right: 0; }
.wrap.nav-rail nav.side a .label,
.wrap.nav-rail nav.side .railtoggle .label,
.wrap.nav-rail nav.side .navnote { display: none; }
.wrap.nav-rail nav.side a.active {
  background: rgba(103, 234, 148, .15); color: var(--accent); box-shadow: none;
}
.wrap.nav-rail nav.side a .navcount {
  position: absolute; top: 3px; right: 7px; margin: 0;
  min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; line-height: 15px;
  text-align: center; background: var(--accent); color: #06210f; font-weight: 700;
}
/* hover tooltip — show the label as a floating chip next to the rail */
.wrap.nav-rail nav.side a:hover .label,
.wrap.nav-rail nav.side .railtoggle:hover .label {
  display: block; position: absolute; left: 100%; margin-left: 10px; z-index: 20;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 9px; font-size: 12px; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35); pointer-events: none;
}

/* nodes table */
table.nodes { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
table.nodes th, table.nodes td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.nodes th { color: var(--muted); font-weight: 500; font-size: 11px; }
table.nodes td.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
table.nodes tr.self td { background: var(--panel-2); }
table.nodes button.setdest { padding: 4px 10px; font-size: 12px; white-space: nowrap; }

/* tab pages: only the active one is shown */
.tabpage { display: none; }
.tabpage.active { display: block; }

main { padding: 26px 40px 80px; max-width: none; }
.devinfo { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.devinfo b { color: var(--text); }

/* ── Cards / sections ──────────────────────────────────────── */
section.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px; margin-bottom: 22px;
}
section.card h2 { margin: 0 0 4px; font-size: 17px; }
section.card .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.callout {
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 12px 14px; font-size: 13px; color: var(--muted); margin: 0 0 16px;
}
.callout b { color: var(--text); }
code {
  background: var(--bg); padding: 1px 5px; border-radius: 4px;
  font-family: var(--mono); font-size: 12px; color: var(--accent);
}
.row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }
.field.grow { flex: 1; min-width: 160px; }
.field.grow > input, .field.grow > select, .field.grow > textarea { width: 100%; }

input, select, textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; min-width: 90px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-d); }
input[type=number] { width: 100px; }
textarea { width: 100%; font-family: var(--mono); font-size: 12px; resize: vertical; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; margin-top: 4px; }
.toggle input { width: auto; min-width: 0; accent-color: var(--accent); transform: scale(1.2); }

/* template-JSON import */
details.jsonimport { margin: 4px 0 14px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; background: var(--panel-2); }
details.jsonimport summary { cursor: pointer; font-size: 13px; color: var(--text); }
details.jsonimport[open] summary { margin-bottom: 6px; }
.airpill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; margin-left: 6px; }
.airpill.fit { background: rgba(103,234,148,.15); color: var(--accent); }
.airpill.no { background: rgba(255,107,107,.15); color: var(--danger); }

/* USB↔RS485 bridge monitor */
.monhead { display: flex; align-items: center; gap: 10px; margin: 6px 0 6px; }
.monhead .spacer { flex: 1; }
.monhead button { padding: 4px 12px; font-size: 12px; }
.bridgemon {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; max-height: 320px; overflow: auto; font-family: var(--mono); font-size: 12.5px;
}
.bridgemon .empty { color: var(--muted); }
.bridgemon .mrow { padding: 5px 6px; border-radius: 6px; margin-bottom: 3px; line-height: 1.4; word-break: break-all; }
.bridgemon .mrow .mt { color: var(--muted); font-size: 11px; margin-right: 7px; }
.bridgemon .mrow .tag { font-weight: 700; margin-right: 7px; }
.bridgemon .mrow.tx { background: var(--panel-2); }
.bridgemon .mrow.tx .tag { color: var(--warn); }
.bridgemon .mrow.rx { background: rgba(103, 234, 148, .08); }
.bridgemon .mrow.rx .tag { color: var(--accent); }
.bridgemon .mrow.rxnone { background: rgba(255, 107, 107, .08); }
.bridgemon .mrow.rxnone .tag { color: var(--danger); }
.bridgemon .mrow .asc { color: var(--muted); margin-left: 8px; }

/* Test-the-read readout */
.testreadout { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin: 8px 0 0; }
.testreadout .trow { display: flex; justify-content: space-between; gap: 14px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.testreadout .trow:last-of-type { border-bottom: none; }
.testreadout .tnm { color: var(--muted); }
.testreadout .tvl { font: 600 15px var(--mono); color: var(--text); }
.testreadout .tvl.bad { color: var(--danger); font-weight: 400; font-size: 13px; }
.testreadout .traw { font: 11px var(--mono); color: var(--muted); margin-top: 8px; word-break: break-all; }

/* segmented role choice */
.choices { display: flex; gap: 12px; flex-wrap: wrap; }
.choice {
  flex: 1; min-width: 220px; cursor: pointer; border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; background: var(--panel-2);
}
.choice.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-d) inset; }
.choice b { display: block; }
.choice small { color: var(--muted); display: block; margin-top: 4px; }
.choice input { display: none; }
.choices.modes .choice { min-width: 280px; }
.modetools { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border); }
.modetools .note { margin-bottom: 8px; }
.modetools button { font-size: 13px; }
.choice .modemeta { margin-top: 8px; font-size: 11px; color: var(--accent-d); font-family: var(--mono); }
.choice.sel .modemeta { color: var(--accent); }

/* buttons */
button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 16px; font: inherit; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent-d); }
button.primary { background: var(--accent); color: #06210f; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-d); }
button.danger { color: var(--danger); border-color: #5a2b2b; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* poll table */
table.polls { width: 100%; border-collapse: collapse; margin: 6px 0 12px; font-size: 13px; }
table.polls th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 6px; font-size: 11px; }
table.polls td { padding: 3px 4px; }
table.polls input, table.polls select { min-width: 0; width: 100%; padding: 6px 7px; }
table.polls .w-name { min-width: 110px; }
table.polls .del { color: var(--danger); background: none; border: none; padding: 4px 8px; }

/* code/preview */
pre.code {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
  word-break: break-all; color: var(--accent); margin: 6px 0;
}
.note { font-size: 12px; color: var(--muted); }
@keyframes blobflash { from { background: rgba(103,234,148,.22); } to { background: var(--bg); } }
pre.code.flash { animation: blobflash .6s ease; }
.warnmsg { color: var(--warn); font-size: 13px; }
.errmsg { color: var(--danger); font-size: 13px; }

/* live monitor */
table.live { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 13px; }
table.live th, table.live td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border);
  vertical-align: top; word-break: break-all; overflow-wrap: anywhere;
}
table.live th { color: var(--muted); font-weight: 500; font-size: 11px; }
table.live th:nth-child(1), table.live td:nth-child(1) { width: 72px; }    /* Time */
table.live th:nth-child(2), table.live td:nth-child(2) { width: 84px; }    /* From */
table.live th:nth-child(3), table.live td:nth-child(3) { width: 34%; }     /* Bytes */
table.live .mono { font-family: var(--mono); font-size: 12px; }
.ok { color: var(--accent); }
.bad { color: var(--danger); }

.actionsbar {
  position: sticky; bottom: 0; display: flex; gap: 12px; align-items: center;
  background: linear-gradient(transparent, var(--bg) 40%); padding: 16px 0 4px; margin-top: 8px;
}
.toast {
  position: fixed; right: 20px; bottom: 20px; background: var(--panel-2);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 12px 16px; border-radius: 8px; font-size: 14px; max-width: 360px;
  opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-left-color: var(--danger); }

.unsupported { padding: 40px; text-align: center; color: var(--muted); }
.disabled-veil { opacity: .5; pointer-events: none; }
