/* Codelyne Machine-Zone Presence Monitor
   Palette: light SaaS console, teal accent, state colours paired with a text label. */
/* Self-hosted (SIL OFL) so the UI works on isolated workshop networks */
@font-face { font-family: "Barlow"; font-weight: 400; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 500; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-semi-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 600; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-semi-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 700; font-style: normal; font-display: swap; src: url("/static/fonts/barlow-semi-condensed-latin-700-normal.woff2") format("woff2"); }
:root {
  --bg: #F4F7FB;
  --surface: #FFFFFF;
  --surface-2: #F6F8FB;
  --ink: #122033;
  --muted: #5E6E82;
  --rule: #E4EAF1;
  --accent: #0D9488;
  --accent-ink: #FFFFFF;
  --pos: #0F8A52;
  --pos-soft: #E7F7EF;
  --neg: #B45309;
  --neg-soft: #FFF6E5;
  --unk: #64748B;
  --unk-soft: #F1F4F8;
  --danger: #DC3B3B;
  --rail: #FFFFFF;
  --rail-ink: #3D4D61;
  --radius: 12px;
  --f-head: "Barlow Semi Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --f-body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--f-head); font-weight: 600; letter-spacing: .01em; margin: 0; line-height: 1.15; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-family: var(--f-head); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
body:has(.demo-banner) .shell { min-height: calc(100vh - 36px); }
.rail {
  background: var(--rail); color: var(--rail-ink); display: flex; flex-direction: column;
  padding: 22px 14px 16px; border-right: 1px solid var(--rule);
  box-shadow: 8px 0 24px rgba(18, 32, 51, .03);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 22px; font-family: var(--f-head); line-height: 1.1; }
.brand .mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); box-shadow: 0 0 0 4px rgba(13, 148, 136, .14); flex: none; }
.brand b { display: block; color: var(--ink); font-size: 1.15rem; font-weight: 600; }
.brand span { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.rail nav { display: grid; gap: 4px; }
.rail nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; text-decoration: none; color: var(--rail-ink);
  border-left: 3px solid transparent; border-radius: 10px; font-family: var(--f-body); font-weight: 500; font-size: .95rem;
}
.nav-ico { width: 18px; height: 18px; display: grid; place-items: center; color: var(--muted); flex: none; }
.nav-ico svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail nav a:hover { background: var(--surface-2); color: var(--ink); }
.rail nav a:hover .nav-ico { color: var(--ink); }
.rail nav a[aria-current="page"] { border-left-color: var(--accent); color: var(--accent); background: rgba(13, 148, 136, .1); font-weight: 600; }
.rail nav a[aria-current="page"] .nav-ico { color: var(--accent); }
.rail .who { margin-top: auto; padding: 16px 8px 0; border-top: 1px solid var(--rule); font-size: .9rem; }
.who-name { color: var(--ink); font-weight: 600; }
.who-role { color: var(--muted); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; margin-top: 2px; }
.rail .who button { margin-top: 12px; width: 100%; }
main { padding: 22px 26px 40px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.page-head .grow { flex: 1; }
.demo-banner {
  background: repeating-linear-gradient(-45deg, var(--accent) 0 14px, #25A89C 14px 28px); color: var(--accent-ink);
  padding: 6px 26px; font-weight: 600; font-family: var(--f-head);
}

/* ---------- controls ---------- */
button, .btn {
  font: inherit; font-family: var(--f-head); font-weight: 600; font-size: .98rem; cursor: pointer;
  border: 1px solid transparent; background: var(--accent); color: var(--accent-ink); padding: 8px 16px; border-radius: 8px;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button.secondary, a.btn.secondary { background: transparent; color: var(--ink); border-color: var(--rule); filter: none; }
button.secondary:hover, a.btn.secondary:hover { border-color: var(--accent); color: var(--accent); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); filter: none; }
button.danger:hover { background: rgba(240, 113, 103, .12); }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; font-family: var(--f-body); font-weight: 500; filter: none; }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.rail button { background: transparent; border-color: var(--rule); color: var(--rail-ink); font-size: .85rem; padding: 4px 10px; filter: none; }
.rail button:hover { border-color: var(--accent); color: var(--accent); }
label { display: grid; gap: 4px; font-size: .86rem; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface-2); border: 1px solid var(--rule); border-radius: 8px; padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(13, 148, 136, .2); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .92rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; align-items: end; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { background: var(--surface-2); color: var(--ink); border-color: var(--rule); font-size: .88rem; padding: 4px 10px; filter: none; }
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }

/* ---------- panels & tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 8px 24px rgba(18, 32, 51, .05); }
.panel + .panel, .stack > * + * { margin-top: 14px; }
.panel h2, .panel h3 { margin-bottom: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--rule); }
td { padding: 9px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.selected td { background: rgba(13, 148, 136, .1); }
.table-wrap { overflow-x: auto; }
.notice { border-left: 4px solid var(--neg); background: var(--neg-soft); color: var(--ink); padding: 10px 12px; border-radius: 0 8px 8px 0; margin: 8px 0; }
.notice.info { border-left-color: var(--unk); background: var(--unk-soft); }
.notice.err { border-left-color: var(--danger); background: #FDECEC; color: var(--ink); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- state labels ---------- */
.state { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-family: var(--f-head); font-weight: 600; font-size: .9rem; }
.state::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--unk); }
.state.pos::before { background: var(--pos); }
.state.neg::before { background: var(--neg); }
.health { font-family: var(--f-head); font-weight: 600; padding: 2px 8px; border-radius: 999px; font-size: .85rem; background: var(--unk-soft); color: var(--ink); }
.health.online { background: var(--pos-soft); color: var(--pos); }
.health.offline, .health.stale, .health.frozen, .health.error { background: #FDECEC; color: var(--danger); }
.health.review { background: var(--neg-soft); color: var(--neg); }

/* ---------- live view ---------- */
.live-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px; align-items: start; }
.cam-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.cam-tabs button {
  background: var(--surface); color: var(--muted); border: 1px solid var(--rule); border-radius: 999px;
  font-size: .92rem; padding: 7px 14px; filter: none;
}
.cam-tabs button:hover { border-color: var(--accent); color: var(--ink); filter: none; }
.cam-tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: none; }
.viewer {
  position: relative; background: #E8EEF4; border-radius: 16px; overflow: hidden; line-height: 0;
  border: 1px solid var(--rule); box-shadow: 0 16px 40px rgba(18, 32, 51, .08); min-height: 220px;
}
.viewer img { width: 100%; height: auto; display: block; }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.cam-meta {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 12px; padding: 10px 14px;
  font-size: .88rem; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px;
}
.cam-meta .grow { flex: 1; }

.plates { display: grid; gap: 12px; }
.plate {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--rule); border-radius: 16px;
  overflow: hidden; min-height: 156px; box-shadow: 0 10px 28px rgba(18, 32, 51, .06);
}
.plate .band {
  background: var(--unk); color: #fff; display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px;
  padding: 14px 16px; font-family: var(--f-head); font-weight: 700; font-size: 1.45rem; letter-spacing: .06em; text-transform: uppercase;
}
.plate.pos { border-color: rgba(15, 138, 82, .35); }
.plate.neg { border-color: rgba(180, 83, 9, .35); }
.plate.pos .band { background: var(--pos); }
.plate.neg .band { background: var(--neg); }
.plate .band small { font-weight: 600; font-size: .75rem; letter-spacing: 0; text-transform: none; opacity: .8; margin-left: auto; text-align: right; }
.plate .body { padding: 14px 16px 16px; display: grid; gap: 4px; align-content: start; }
.plate .name { font-family: var(--f-head); font-size: 1.15rem; font-weight: 600; line-height: 1.1; color: var(--muted); }
.plate .elapsed { font-family: var(--f-head); font-size: 2.6rem; font-weight: 600; line-height: 1; letter-spacing: -.02em; }
.plate.pos .elapsed { color: var(--pos); }
.plate.neg .elapsed { color: var(--neg); }
.plate .why { font-size: .82rem; color: var(--muted); }
.plate .today { display: flex; gap: 12px; font-size: .82rem; margin-top: 6px; flex-wrap: wrap; }
.plate .today b { font-family: var(--f-head); font-weight: 600; }
.plate.selected { outline: 3px solid var(--accent); outline-offset: -1px; }
.mode-tag { font-size: .78rem; color: var(--muted); }

/* ---------- report ---------- */
.report-head { align-items: flex-start; }
.export-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-export {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  padding: 10px 16px; box-shadow: 0 8px 18px rgba(13, 148, 136, .22);
}
.figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; border: none; border-radius: 0; background: transparent; }
.figure { padding: 14px 16px; background: #FFFFFF; border: 1px solid var(--rule); border-radius: 14px; box-shadow: 0 6px 16px rgba(18, 32, 51, .04); }
.figure .v { white-space: nowrap; font-family: var(--f-head); font-size: 1.7rem; font-weight: 600; line-height: 1.1; }
.figure .k { font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.figure.pos { border-color: rgba(15, 138, 82, .35); }
.figure.neg { border-color: rgba(180, 83, 9, .35); }
.figure.unk { border-color: #D5DDE6; }
.figure.pos .v { color: var(--pos); }
.figure.neg .v { color: var(--neg); }
.figure.unk .v { color: var(--unk); }
.formula { font-size: .83rem; color: var(--muted); margin-top: 12px; }
.timeline { margin: 8px 0 4px; }
.tl-bar { display: flex; height: 52px; border-radius: 12px; overflow: hidden; border: 1px solid var(--rule); background: var(--unk-soft); }
.tl-seg { height: 100%; border: none; padding: 0; border-radius: 0; min-width: 1px; cursor: pointer; background: var(--unk); filter: none; }
.tl-seg.pos { background: var(--pos); }
.tl-seg.neg { background: var(--neg); }
.tl-seg.unk { background: repeating-linear-gradient(45deg, #C5CED8 0 4px, #B7C2CE 4px 8px); }
.tl-seg:hover, .tl-seg.sel { box-shadow: inset 0 0 0 3px var(--accent); filter: none; }
.tl-ticks { position: relative; height: 22px; font-size: .78rem; color: var(--muted); }
.tl-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; top: 3px; }
.tl-ticks span::before { content: ""; position: absolute; left: 50%; top: -6px; height: 5px; border-left: 1px solid var(--muted); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .85rem; margin-top: 4px; }
.seg-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: .9rem; }
.seg-detail dt { color: var(--muted); font-size: .8rem; }
.seg-detail dd { margin: 0 0 6px; }
.evidence img, .evidence video { max-width: 100%; border-radius: 4px; border: 1px solid var(--rule); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }

/* ---------- zone editor ---------- */
.editor {
  position: relative; line-height: 0; background: #E8EEF4; border-radius: 16px; overflow: hidden; user-select: none;
  border: 1px solid var(--rule); box-shadow: 0 16px 40px rgba(18, 32, 51, .08);
}
.editor img { width: 100%; display: block; }
.editor canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.editor + p { margin: 10px 2px 0; }
.zone-list { padding: 0; margin: 10px 0 0; }
.zone-list li { list-style: none; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 12px; margin-bottom: 8px; background: var(--surface-2); cursor: pointer; }
.zone-list li.muted { cursor: default; }
.zone-list li[aria-selected="true"] { border-color: var(--accent); background: rgba(13, 148, 136, .1); box-shadow: inset 4px 0 0 var(--accent); }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 480px at 50% -10%, rgba(13, 148, 136, .16), transparent 55%), var(--bg);
}
.login form {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--rule); border-radius: 16px;
  padding: 32px 28px; display: grid; gap: 14px; box-shadow: 0 18px 50px rgba(18, 32, 51, .08);
}
.login h1 { font-size: 1.7rem; }
.login button { width: 100%; padding: 10px 16px; }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--surface); color: var(--ink); border: 1px solid var(--accent); padding: 12px 14px; border-radius: 10px; max-width: 420px; z-index: 50; box-shadow: 0 12px 32px rgba(18, 32, 51, .12); }
.toast.err { background: #FDECEC; color: var(--ink); border-color: var(--danger); }
dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--rule); border-radius: 16px; padding: 20px 22px; max-width: 560px; width: calc(100% - 32px); box-shadow: 0 24px 60px rgba(18, 32, 51, .16); }
dialog::backdrop { background: rgba(18, 32, 51, .4); }
.progress { height: 8px; background: var(--unk-soft); border-radius: 999px; overflow: hidden; min-width: 120px; margin-top: 6px; }
.progress div { height: 100%; background: var(--accent); }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.previews figure { margin: 0; cursor: pointer; background: var(--surface-2); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; }
.previews img { width: 100%; display: block; border: none; border-radius: 0; }
.previews figcaption { padding: 8px 10px 10px; color: var(--muted); }
.previews figure[aria-selected="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }

@media (max-width: 1100px) {
  .live-grid, .split { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .live-grid > section:last-child { order: -1; }
  .plate .band small { flex: 1 0 100%; margin-left: 0; text-align: left; }
  .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shell { grid-template-columns: 1fr; }
  body:has(.demo-banner) .shell { min-height: 0; }
  .rail { flex-direction: row; flex-wrap: wrap; padding: 10px; align-items: center; gap: 8px; border-right: none; border-bottom: 1px solid var(--rule); box-shadow: none; }
  .rail nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .rail nav a { border-left: none; padding: 8px 10px; }
  .rail nav a[aria-current="page"] { border-left-color: transparent; box-shadow: inset 0 -2px 0 var(--accent); }
  .rail .who { margin: 0 0 0 auto; border: none; padding: 0; }
  .rail .who button { width: auto; margin-top: 0; }
  .who-role { display: none; }
  .brand { padding: 0 6px; }
  main { padding: 16px; }
  .seg-detail { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
