:root {
  --bg: #0b0d10; --panel: #14181d; --panel2: #1b2027; --line: #262c35; --text: #e7ebf0; --muted: #8a94a3;
  --ok: #2fbf71; --warn: #e0a526; --bad: #e5484d; --info: #3b82f6; --accent: #7c5cff;
  --radius: 14px; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: #9db7ff; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer; min-height: 40px; }
button:hover { border-color: #3a4352; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { background: #3a1517; border-color: #6b2226; color: #ffb4b6; }
button.live { background: #b4232a; border-color: #d33; color: #fff; font-weight: 700; }
button:disabled { opacity: .45; cursor: not-allowed; }
input[type=text], input[type=password], input[type=number], select {
  background: #0f1216; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; min-height: 40px;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
label { display: block; color: var(--muted); font-size: 13px; margin: 10px 0 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; }
.hidden { display: none !important; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.ok::before { background: var(--ok); } .badge.ok { color: #b9f3d2; }
.badge.warn::before { background: var(--warn); } .badge.warn { color: #ffe3a3; }
.badge.bad::before { background: var(--bad); } .badge.bad { color: #ffc1c3; }
.badge.live { background: #b4232a; border-color: #d33; color: #fff; }
.badge.live::before { background: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- dashboard ---------- */
.app { max-width: 1100px; margin: 0 auto; padding: 14px 16px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.brand { font-size: 19px; font-weight: 750; letter-spacing: .2px; }
.brand span { color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.na { color: #5d6675; font-style: italic; }
.note { background: #12161b; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; color: var(--muted); font-size: 13px; margin-top: 10px; }
.warnbox { background: #2a2110; border: 1px solid #5a4613; color: #ffe3a3; border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-top: 10px; }
.errbox { background: #2a1214; border: 1px solid #5c2226; color: #ffc1c3; border-radius: 10px; padding: 8px 10px; font-size: 12.5px; margin-top: 8px; word-break: break-word; }
.dest { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.dest:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.dest-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dest-head h3 { margin: 0; font-size: 15px; }
details summary { cursor: pointer; color: #b8c2d0; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.events { max-height: 260px; overflow: auto; font-size: 12.5px; }
.events div { padding: 3px 0; border-bottom: 1px solid #1c2128; }
.events time { color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }
.preview { width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 10px; background: #000; margin-top: 10px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border: 1px solid #5c2226; border-radius: var(--radius); padding: 18px; max-width: 420px; width: 100%; }
.modal h3 { margin: 0 0 8px; color: #ffb4b6; }

/* ---------- login ---------- */
.center { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .brand { text-align: center; font-size: 24px; margin-bottom: 18px; }
.login button { width: 100%; margin-top: 14px; }
.err { color: #ffb4b6; min-height: 20px; font-size: 13.5px; margin-top: 10px; }

/* ---------- viewer ---------- */
body.viewer { overflow: hidden; background: #000; }
.stage { position: fixed; inset: 0; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
.stage canvas, .stage video { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { object-fit: contain; }
.stage.mode-360 video { opacity: 0; pointer-events: none; }
.stage.mode-flat canvas { display: none; }
.hud { position: absolute; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud.top { top: 0; padding-top: max(10px, env(safe-area-inset-top)); background: linear-gradient(#000a, #0000); }
.hud.bottom { bottom: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: linear-gradient(#0000, #000b); flex-wrap: wrap; justify-content: center; }
.hud button { background: #000a; border-color: #ffffff30; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); min-width: 44px; min-height: 44px; }
.hud button.on { background: var(--accent); border-color: var(--accent); }
.hud button.talking { background: #b4232a; border-color: #f55; }
.overlay-msg { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; color: #cfd6df; pointer-events: none; }
.stage.dim canvas, .stage.dim video { opacity: .18; filter: grayscale(1); transition: opacity .3s; }
.overlay-msg .big { font-size: 20px; font-weight: 650; }
.overlay-msg button { pointer-events: auto; }
.spinner { width: 34px; height: 34px; border: 3px solid #ffffff30; border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); background: #000c; padding: 6px 12px; border-radius: 999px; font-size: 13px; pointer-events: none; }
body.embed .hud.top .brand, body.embed #logout { display: none; }
@media (max-width: 520px) { .hud button { padding: 8px 10px; font-size: 14px; } .kv { font-size: 13.5px; } }

/* ---------- Phase 02: phone-first owner UI ---------- */
body.owner { font-size: 16px; }
.hero { margin-bottom: 14px; border-color: #343c48; }
.hero h2 { margin-top: 14px; }
.state-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.state-pill { font-size: 20px; font-weight: 800; letter-spacing: .5px; padding: 6px 14px; border-radius: 12px; background: var(--panel2); border: 2px solid var(--line); }
.state-pill.s-live { background: #b4232a; border-color: #ff6b6b; color: #fff; }
.state-pill.s-wait { background: #3a2c08; border-color: #e0a526; color: #ffe08a; }
.state-pill.s-ok { background: #0f3a24; border-color: #2fbf71; color: #c6ffe0; }
.state-pill.s-bad { background: #3a1517; border-color: #e5484d; color: #ffd0d2; }
.state-help { margin: 8px 0 4px; font-size: 15.5px; color: #dfe5ee; }
.health { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 6px 0; font-size: 14px; }
.health .lvl { font-weight: 800; padding: 3px 10px; border-radius: 8px; }
.lvl-GOOD { background: #0f3a24; color: #b9f3d2; } .lvl-FAIR { background: #3a2c08; color: #ffe08a; }
.lvl-POOR, .lvl-STALLED { background: #3a1517; color: #ffc1c3; } .lvl-NO_SIGNAL { background: var(--panel2); color: var(--muted); }
.toggles { display: grid; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--text); font-size: 16px; margin: 0; cursor: pointer; }
.toggle input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.toggle.small { font-size: 13.5px; padding: 8px 10px; margin-top: 10px; }
button.big { min-height: 54px; font-size: 17px; width: 100%; margin-top: 14px; }
.estop-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px max(10px, env(safe-area-inset-bottom)); background: linear-gradient(#0000, #000d 30%); z-index: 40; }
.estop { width: 100%; min-height: 60px; font-size: 19px; font-weight: 900; letter-spacing: .5px; background: #d1121b; border: 2px solid #ff8a8a; color: #fff; border-radius: 14px; }
.spacer { height: 90px; }
.dest-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14.5px; }
.dest-row:first-child { border-top: 0; }
.dest-row .q { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.framing { display: grid; grid-template-columns: minmax(160px, 260px) 1fr; gap: 14px; align-items: start; }
@media (max-width: 560px) { .framing { grid-template-columns: 1fr; } .frame-wrap { max-width: 260px; margin: 0 auto; } }
.frame-wrap { position: relative; aspect-ratio: 9 / 16; width: 100%; background: #000; border-radius: 12px; overflow: hidden; border: 2px solid #ffffffa0; touch-action: none; }
.frame-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.frame-label { position: absolute; left: 8px; top: 8px; font-size: 12px; background: #000a; padding: 2px 8px; border-radius: 999px; pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { min-height: 36px; padding: 6px 12px; border-radius: 999px; font-size: 14px; }
.chips button.sel { background: var(--accent); border-color: var(--accent); }
.table-wrap { overflow-x: auto; }
table.qm td, table.qm th { font-size: 12.5px; vertical-align: top; }
table.qm th[scope=row] { color: var(--muted); white-space: nowrap; }
.modal { max-height: 90vh; overflow: auto; }
.modal h3.arm { color: #c9bcff; }
.sum { font-size: 14px; } .sum li { margin: 4px 0; }
@media (max-width: 520px) { .app { padding: 10px 12px 40px; } .card { padding: 12px; } }

.calib { display: grid; gap: 6px; margin-bottom: 12px; }
