/* robot24 dashboard look.
   Colours are defined once as variables, so the dark theme only swaps them.
   Colour carries meaning: green = fine, amber = warning or stale,
   red = STOP or critical, grey = unavailable or locked. */
:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef2ef;
  --text: #17201b;
  --muted: #5b675f;
  --line: #d9e0db;
  --accent: #2f7d5b;
  --accent-text: #ffffff;
  --ok: #217a4b;
  --ok-bg: #e2f3e8;
  --warn: #8a5a00;
  --warn-bg: #fff1d1;
  --bad: #b3261e;
  --bad-bg: #fde4e1;
  --off: #5f6b64;
  --off-bg: #e8ecea;
  --stop: #c62828;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1613;
    --surface: #17211c;
    --surface-2: #1f2b25;
    --text: #e6ede8;
    --muted: #9fb0a6;
    --line: #2c3a33;
    --accent: #4fae84;
    --accent-text: #08130e;
    --ok: #6fd39f;
    --ok-bg: #173527;
    --warn: #f3c25a;
    --warn-bg: #3a2e12;
    --bad: #ff8a80;
    --bad-bg: #42201d;
    --off: #a9b6ae;
    --off-bg: #26312b;
    --stop: #e53935;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 6px; line-height: 1.2; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.lead { font-size: 17px; font-weight: 600; margin: 2px 0; }

button, .button-link {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 9px 14px; min-height: 40px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
input[type=text], input:not([type]), input[readonly] {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
}
.message { min-height: 1.4em; font-weight: 600; color: var(--warn); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); padding: 28px; border-radius: var(--radius);
  width: 100%; max-width: 380px; display: grid; gap: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.login-card label { display: grid; gap: 4px; font-weight: 600; }

/* Top bar: always visible, STOP is the one loud element */
.sticky { position: sticky; top: 0; z-index: 10; }
.topbar { display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.conn { flex: 1; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; min-width: 0; }
.conn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.conn.ok .dot { background: var(--ok); }
.conn.bad .dot { background: var(--bad); }
.conn.bad { color: var(--bad); font-weight: 600; }
button.stop { background: var(--stop); color: #fff; border: 0; font-size: 18px; letter-spacing: .04em;
  min-width: 112px; min-height: 48px; border-radius: 12px; box-shadow: 0 2px 0 rgba(0,0,0,.25); }
button.stop:active { transform: translateY(1px); }

.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--off-bg); color: var(--off); }
.badge.demo { background: var(--warn-bg); color: var(--warn); }
.badge.hardware { background: var(--ok-bg); color: var(--ok); }

.banner { padding: 10px 16px; font-weight: 600; border-bottom: 1px solid var(--line); }
.banner.demo { background: var(--warn-bg); color: var(--warn); }
.banner.offline, .banner.stopped { background: var(--bad-bg); color: var(--bad); }
.banner.hold { background: var(--off-bg); color: var(--text); font-weight: 500; }

/* Layout: cards flow into as many columns as fit */
.layout { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); grid-auto-flow: row dense;
  gap: 14px; padding: 16px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; min-width: 0; }
.wide { grid-column: span 2; }
.full { grid-column: 1 / -1; }
.graphs { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.note-value { display: block; font-size: 20px; font-weight: 600; color: var(--muted); padding-top: 8px; }
@media (max-width: 660px) { .wide { grid-column: auto; } .topbar { flex-wrap: wrap; } .conn { order: 3; flex-basis: 100%; } }
.section-title { grid-column: 1 / -1; margin: 10px 0 0; font-size: 18px; }
.card-head, .subhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.subhead { margin-top: 14px; }
.control-card { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.control-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.control-card .message { flex-basis: 100%; margin: 0; }

/* Readings */
.big { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.unit { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.label { display: block; font-size: 13px; color: var(--muted); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.untrusted .big:not(.muted) { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 2px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--off-bg); color: var(--off); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }

/* Line sensors */
.cells { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin: 8px 0; }
.cell { border-radius: 8px; padding: 8px 0; text-align: center; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.cell.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.cells.clickable .cell { cursor: pointer; min-height: 40px; }
.position-bar { position: relative; height: 10px; border-radius: 5px; background: var(--surface-2); margin: 6px 0 2px; }
.position-bar::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--line); }
.marker { position: absolute; top: -4px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%;
  background: var(--accent); left: 50%; transition: left .2s; }
.marker.none { display: none; }
.scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* Warnings and events */
.warnings, .events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.warnings li { padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.warnings li.critical { background: var(--bad-bg); color: var(--bad); }
.warnings li.none { background: var(--ok-bg); color: var(--ok); }
.events { height: 320px; overflow: auto; }   /* fixed: new lines never push the page down */
.events li { display: grid; grid-template-columns: 74px 1fr; gap: 8px; font-size: 13px; padding: 4px 0;
  border-bottom: 1px solid var(--line); }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; }
.events .stop { color: var(--bad); font-weight: 700; }
.events .error { color: var(--bad); }
.events .warning { color: var(--warn); }

/* Graphs */
figure { margin: 8px 0 12px; }
figcaption { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
canvas { width: 100%; display: block; background: var(--surface-2); border-radius: 8px; }
.key { display: inline-block; width: 14px; height: 3px; vertical-align: middle; border-radius: 2px; }
.key.roll { background: #3b82c4; }
.key.pitch { background: #d07a12; }

/* Task panels */
.slider { display: grid; gap: 4px; font-weight: 600; margin: 6px 0; }
.slider input { width: 100%; accent-color: var(--accent); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
.pad button { min-height: 58px; font-size: 24px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.pad button.held { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.output { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; background: var(--surface-2);
  border-radius: 8px; padding: 8px 10px; min-height: 2.2em; white-space: pre-wrap; }
.row { display: flex; gap: 8px; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.led-row { display: grid; gap: 4px; margin: 8px 0 10px; font-size: 14px; font-weight: 600; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; }
.segmented button { min-height: 34px; padding: 5px 9px; font-size: 13px; }
.segmented button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.lamp { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--off-bg);
  border: 1px solid var(--line); margin-right: 6px; vertical-align: middle; }
.lamp.on { background: #f2b233; border-color: #f2b233; }
.oled { background: #000; color: #d8f3ff; font-family: ui-monospace, Consolas, monospace; font-size: 13px;
  line-height: 1.35; padding: 10px 12px; border-radius: 6px; aspect-ratio: 2 / 1; max-width: 320px; white-space: pre; overflow: hidden; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; font-weight: 600; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 10px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px 6px 0; }
.table td { padding: 6px 8px 6px 0; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }

/* Share */
.share-row { display: flex; gap: 8px; }
#qr { display: block; margin: 12px 0; background: #fff; border-radius: 8px; padding: 6px; max-width: 100%; }
.topbar .stop { margin-left: auto; }
.layout.untrusted { opacity: .55; }
.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.18); background: var(--surface); border: 1px solid var(--line);
  pointer-events: none; /* never blocks a button underneath (a held drive button must stay held) */ }
.toast.ok { color: var(--ok); }
.toast.warn { color: var(--warn); border-color: var(--warn); }

/* Programs */
.prog-grid { display: grid; grid-template-columns: 220px 1fr; gap: 14px; margin-top: 8px; }
@media (max-width: 760px) { .prog-grid { grid-template-columns: 1fr; } }
.prog-list ul { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 4px; }
.prog-list li button { width: 100%; text-align: left; font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px; padding: 7px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  justify-content: flex-start; display: block; }
@media (max-width: 760px) { .prog-list ul { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.prog-list li button.current { outline: 2px solid var(--accent); outline-offset: -2px; }
.prog-list li button.running::after { content: " \25CF"; color: var(--ok); }
.prog-list .empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.prog-editor { min-width: 0; display: grid; gap: 6px; }
.prog-bar { margin: 0; align-items: center; }
#prog-name { flex: 1 1 180px; min-width: 0; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
#prog-text, #files-text { width: 100%; min-height: 300px; resize: vertical; font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px; line-height: 1.5; tab-size: 4; padding: 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); }
#prog-text[readonly], #files-text:disabled { opacity: .85; }
.prog-out { margin: 0; height: 260px; overflow: auto; padding: 10px; border-radius: 8px; background: #0b100d; color: #d7e6dc;
  font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; line-height: 1.45; white-space: pre-wrap;
  word-break: break-word; }
.prog-input { margin-top: 6px; }
.prog-input input { flex: 1; min-width: 0; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.row.tight { margin: 0; gap: 4px; }
.prog-list li button .size { color: var(--muted); font-weight: 500; margin-left: 6px; }
.programs.dropping { outline: 3px dashed var(--accent); outline-offset: -6px; }
.files-bar { align-items: center; margin-top: 6px; gap: 6px; }
.files-bar .grow, .prog-bar .grow { flex: 1; }
.files-path { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; padding: 4px 8px;
  border-radius: 6px; background: var(--surface-2); overflow-wrap: anywhere; }
.files-grid { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 14px; margin-top: 8px; }
@media (max-width: 760px) { .files-grid { grid-template-columns: 1fr; } }
.files-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; max-height: 460px; overflow: auto;
  align-content: start; }
.files-list li button { width: 100%; text-align: left; display: flex; gap: 8px; align-items: baseline;
  font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; padding: 6px 8px; }
.files-list li button .fname { flex: 1; overflow-wrap: anywhere; }
.files-list li button .fmeta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.files-list li button.dir .fname::before { content: "\1F4C1  "; }
.files-list li button.current { outline: 2px solid var(--accent); outline-offset: -2px; }
.files-list .empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.files-editor { min-width: 0; display: grid; gap: 6px; align-content: start; }
.files-editor textarea { min-height: 360px; }
.files.dropping { outline: 3px dashed var(--accent); outline-offset: -6px; }
#update-last.bad { color: var(--bad); }
