@font-face { font-family: Barlow; font-weight: 400; font-display: swap; src: url(/fonts/barlow/files/barlow-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: Barlow; font-weight: 500; font-display: swap; src: url(/fonts/barlow/files/barlow-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: Barlow; font-weight: 600; font-display: swap; src: url(/fonts/barlow/files/barlow-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Semi Condensed'; font-weight: 500; font-display: swap; src: url(/fonts/barlow-semi-condensed/files/barlow-semi-condensed-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'Barlow Semi Condensed'; font-weight: 600; font-display: swap; src: url(/fonts/barlow-semi-condensed/files/barlow-semi-condensed-latin-600-normal.woff2) format('woff2'); }

/* Instrument-panel palette: case grey, faceplate, signal yellow (trace 1), cyan (trace 2), LED green. */
:root {
  --bg: #DCDFD9;
  --panel: #EEF0EC;
  --panel-2: #E5E8E3;
  --ink: #1D2226;
  --ink-2: #525A5F;
  --ink-3: #7A8287;
  --line: #C5CAC3;
  --line-2: #B3B9B1;
  --sig: #E8A400;
  --sig-ink: #1D2226;
  --cyan: #0F8EA3;
  --led-on: #2FBF5B;
  --led-off: #9AA19C;
  --warn: #D98A00;
  --danger: #C8372D;
  --focus: #0F8EA3;
  --radius: 6px;
  --readout: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181A; --panel: #1E2225; --panel-2: #24292C; --ink: #E7EAE5; --ink-2: #A3ACA7; --ink-3: #78817C;
    --line: #2F3539; --line-2: #3B4246; --sig: #F2B705; --sig-ink: #15181A; --cyan: #3CC3D6; --led-off: #4C5450;
    --danger: #E5584D; --focus: #3CC3D6; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.5 Barlow, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'tnum' 1;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.boot { display: flex; gap: 10px; align-items: center; justify-content: center; min-height: 100vh; color: var(--ink-2); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail { position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 600; font-size: 18px; letter-spacing: -0.01em; text-decoration: none; }
.brand-mark { width: 26px; height: 18px; border-radius: 4px; background: #1D2226; box-shadow: 0 0 0 1px var(--line-2); position: relative; flex: none; }
.brand-mark::before { content: ''; position: absolute; left: 5px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--led-on); }
.brand-mark::after { content: ''; position: absolute; right: 4px; top: 5px; width: 6px; height: 3px; border-radius: 2px; background: var(--sig); box-shadow: 0 5px 0 var(--led-off); }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: var(--radius); text-decoration: none; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--panel-2); color: var(--ink); }
.nav a[aria-current='page'] { background: var(--panel); color: var(--ink); box-shadow: inset 3px 0 0 var(--sig); }
.nav .count { font-family: var(--readout); font-size: 13px; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; text-align: center; }
.rail-foot { margin-top: auto; padding: 10px; font-size: 13px; color: var(--ink-3); }
.rail-foot .conn { display: flex; }
.rail-foot strong { display: block; color: var(--ink-2); font-weight: 500; }
.link-btn { background: none; border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; cursor: pointer; }

.main { min-width: 0; padding: 28px 36px 64px; max-width: 1240px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.15; }
.page-head .sub { color: var(--ink-2); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-3); }

.mobile-bar, .tabbar { display: none; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  .mobile-bar { display: flex; position: sticky; top: 0; z-index: 5; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
  .mobile-bar .brand { padding: 0; }
  .tabbar { display: grid; grid-template-columns: repeat(var(--n, 4), 1fr); position: fixed; inset: auto 0 0 0; z-index: 5; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { padding: 10px 4px 12px; text-align: center; text-decoration: none; font-size: 13px; font-weight: 500; color: var(--ink-2); position: relative; }
  .tabbar a[aria-current='page'] { color: var(--ink); box-shadow: inset 0 3px 0 var(--sig); }
  .tabbar .count { position: absolute; top: 4px; margin-left: 2px; font-size: 11px; padding: 0 5px; border-radius: 8px; background: var(--danger); color: #fff; }
  .main { padding: 18px 16px 96px; }
  .page-head h1 { font-size: 24px; }
}

/* ---------- primitives ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--panel); color: var(--ink); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--sig); border-color: var(--sig); color: var(--sig-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { height: 30px; padding: 0 10px; font-size: 14px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-pad { padding: 18px 20px; }
.section { margin-top: 28px; }
.section > h2, .panel-title { margin: 0 0 12px; font-size: 17px; font-weight: 600; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 13px; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 14px; }
.hidden { display: none !important; }

.led { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--led-off); flex: none; box-shadow: inset 0 -1px 1px rgba(0,0,0,.25); }
.led.on { background: var(--led-on); box-shadow: 0 0 0 3px color-mix(in srgb, var(--led-on) 22%, transparent), 0 0 8px color-mix(in srgb, var(--led-on) 70%, transparent); }
.led.warn { background: var(--warn); }
.led.bad { background: var(--danger); box-shadow: 0 0 6px color-mix(in srgb, var(--danger) 60%, transparent); }

.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line-2); font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
button.tag { cursor: pointer; background: transparent; }
button.tag[aria-pressed='true'] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* forms */
.field { display: block; }
.field > span { display: block; font-weight: 500; font-size: 14px; margin-bottom: 5px; }
.field small { display: block; color: var(--ink-3); font-size: 13px; margin-top: 4px; }
.input, select.input, textarea.input { width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--bg); }
textarea.input { height: auto; min-height: 80px; padding: 9px 11px; resize: vertical; }
.input:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }
.error-text { color: var(--danger); font-size: 14px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--cyan); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { padding: 0 0 26px; font-size: 22px; }
.auth-card h1 { font-size: 24px; margin: 0 0 6px; font-weight: 600; }
.auth-card p { margin: 0 0 22px; color: var(--ink-2); }

/* ---------- device rack (the signature element) ---------- */
.fleet-line { font-size: 17px; color: var(--ink-2); }
.fleet-line b { font-family: var(--readout); font-weight: 600; color: var(--ink); font-size: 20px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 18px 0 12px; }
.toolbar .input { max-width: 280px; }

.rack { border: 1px solid var(--line); border-radius: var(--radius); background: var(--line); display: grid; gap: 1px; overflow: hidden; }
.module { display: grid; grid-template-columns: 22px minmax(170px, 1.1fr) minmax(0, 2.2fr) 120px; gap: 16px; align-items: center; padding: 14px 18px; background: var(--panel); text-decoration: none; position: relative; }
.module::after { content: ''; position: absolute; right: 8px; top: 50%; width: 3px; height: 22px; margin-top: -11px; border-radius: 2px; background: var(--line); }
.module:hover { background: var(--panel-2); }
.module:hover::after { background: var(--sig); }
.module.offline .readout b { color: var(--ink-3); }
.module-name { font-weight: 600; font-size: 16px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; }
.module-sub { font-size: 13px; color: var(--ink-3); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 3px; }
.readouts { display: flex; gap: 26px; overflow: hidden; }
.readout { min-width: 0; }
.readout b { display: block; font-family: var(--readout); font-weight: 600; font-size: 24px; line-height: 1.05; white-space: nowrap; }
.readout b small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.readout span { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.module-seen { font-size: 13px; color: var(--ink-2); text-align: right; padding-right: 10px; }
@media (max-width: 820px) {
  .module { grid-template-columns: 16px 1fr auto; gap: 6px 12px; padding: 14px 16px 14px 14px; }
  .module .readouts { grid-column: 2 / -1; gap: 20px; }
  .module-seen { grid-row: 1; grid-column: 3; text-align: right; }
  .readout b { font-size: 21px; }
}

.empty { padding: 44px 24px; text-align: center; }
.empty h2 { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.empty p { margin: 0 auto 18px; color: var(--ink-2); max-width: 46ch; }

/* ---------- device page ---------- */
.dev-head { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.dev-title { display: flex; gap: 12px; align-items: center; }
.dev-title .led { width: 14px; height: 14px; }
.dev-title h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.015em; }
.dev-facts { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); font-size: 14px; margin: 6px 0 0 26px; }
.back { display: inline-block; margin-bottom: 10px; color: var(--ink-2); font-size: 14px; text-decoration: none; }
.back:hover { color: var(--ink); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 22px 0 20px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 14px; font-weight: 500; color: var(--ink-2); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--sig); }

.dev-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 1000px) {
  .dev-grid { grid-template-columns: 1fr; }
  .dev-grid > .side { display: contents; }
  .dev-grid > .side > :first-child { order: -1; }
  .dev-grid > .side > * + * { margin-top: 0; }
}

.meters { display: flex; flex-wrap: wrap; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.meter { flex: 1 1 150px; background: var(--panel); padding: 14px 16px; }
.meter b { display: block; font-family: var(--readout); font-weight: 600; font-size: 30px; line-height: 1.1; }
.meter b small { font-size: 15px; color: var(--ink-2); font-weight: 500; margin-left: 2px; }
.meter span { font-size: 13px; color: var(--ink-2); }
.meter .when { display: block; font-size: 12px; color: var(--ink-3); }

.controls { display: grid; gap: 0; }
.control { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 13px 0; border-top: 1px solid var(--line); }
.control:first-child { border-top: 0; padding-top: 2px; }
.control label { font-weight: 500; }
.control .full { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; }
.control .val { font-family: var(--readout); font-weight: 600; min-width: 48px; text-align: right; }
.control.pending { opacity: .6; }
.control input[type=range] { flex: 1; accent-color: var(--sig); height: 28px; }
.control input[type=color] { width: 44px; height: 32px; padding: 0; border: 1px solid var(--line-2); border-radius: var(--radius); background: none; }

/* toggle switch */
.toggle { position: relative; width: 52px; height: 30px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle span { position: absolute; inset: 0; border-radius: 15px; background: var(--panel-2); border: 1px solid var(--line-2); transition: background .15s; pointer-events: none; }
.toggle span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--ink-3); transition: transform .15s, background .15s; }
.toggle input:checked + span { background: color-mix(in srgb, var(--led-on) 25%, var(--panel)); border-color: var(--led-on); }
.toggle input:checked + span::after { transform: translateX(22px); background: var(--led-on); }
.toggle input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* charts */
.range { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; }
.range button { border: 0; background: var(--panel); padding: 5px 11px; font-size: 14px; font-weight: 500; color: var(--ink-2); cursor: pointer; border-left: 1px solid var(--line-2); }
.range button:first-child { border-left: 0; }
.range button[aria-pressed='true'] { background: var(--ink); color: var(--bg); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.chart-card { padding: 14px 16px 10px; }
.chart-card header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.chart-card header b { font-weight: 600; }
.chart-card header span { font-family: var(--readout); font-weight: 600; font-size: 18px; }
.chart { position: relative; height: 150px; }
.chart canvas { width: 100%; height: 100%; display: block; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12.5px; padding: 4px 8px; border-radius: 4px; white-space: nowrap; transform: translate(-50%, -110%); }

/* lists / tables */
.list { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.list-row { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row .grow { min-width: 0; }
.list-row .title { font-weight: 500; }
.events .list-row { align-items: flex-start; padding: 10px 16px; }
.ev-time { flex: none; width: 92px; font-size: 13px; color: var(--ink-3); padding-top: 1px; }
.ev-type { flex: none; width: 74px; font-size: 13px; color: var(--ink-2); padding-top: 1px; }
.ev-msg { min-width: 0; overflow-wrap: anywhere; }
.lvl-warn .ev-msg { color: var(--warn); }
.lvl-error .ev-msg { color: var(--danger); }
@media (max-width: 600px) { .ev-type { display: none; } .ev-time { width: 70px; } }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: left; font-weight: 500; color: var(--ink-2); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
tr:first-child td { border-top: 0; }
td.num, th.num { text-align: right; font-family: var(--readout); }

.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; min-width: 90px; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: var(--cyan); transition: width .3s; }
.status { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; white-space: nowrap; }
.st-success { color: var(--led-on); }
.st-failed, .st-error, .st-timeout { color: var(--danger); }
.st-cancelled { color: var(--ink-3); }

.callout { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line-2); background: var(--panel-2); font-size: 14px; }
.callout.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--panel)); }
.callout.bad { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, var(--panel)); }

.alert-row { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.alert-row:first-child { border-top: 0; }

pre.code { margin: 0; padding: 14px 16px; background: var(--ink); color: var(--bg); border-radius: var(--radius); overflow-x: auto; font: 13px/1.55 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
.secret { display: flex; gap: 8px; align-items: center; }
.secret code { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius); font: 13.5px ui-monospace, Menlo, Consolas, monospace; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; align-items: center; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--ink-2); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* modal */
dialog.modal { border: 1px solid var(--line-2); border-radius: 10px; padding: 0; background: var(--panel); color: var(--ink); width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
dialog.modal.wide { width: min(760px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgba(20, 24, 26, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.modal-body { padding: 16px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }
.close-x { width: 32px; height: 32px; border: 0; background: none; font-size: 22px; line-height: 1; color: var(--ink-2); cursor: pointer; border-radius: var(--radius); }
.close-x:hover { background: var(--panel-2); }
.pick-list { max-height: 280px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.pick-list label { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.pick-list label:first-child { border-top: 0; }

/* toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
@media (max-width: 820px) { #toasts { bottom: 76px; left: 16px; } }
.toast { padding: 11px 14px; border-radius: var(--radius); background: var(--ink); color: var(--bg); font-size: 14.5px; animation: toast-in .18s ease-out; }
.toast.bad { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
