/* PAG app in the shadcn/ui (zinc) style of the mockup (Part 6), plain CSS. Light or dark follows the phone. */
:root {
  --page: #f4f4f5;
  --bg: #ffffff;
  --fg: #09090b;
  --muted: #f4f4f5;
  --muted-fg: #71717a;
  --border: #e4e4e7;
  --primary: #18181b;
  --primary-fg: #fafafa;
  --ring: #a1a1aa;
  --ok: #16a34a; --ok-soft: #dcfce7;
  --warn: #d97706; --warn-soft: #fef3c7;
  --bad: #dc2626; --bad-soft: #fee2e2;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #18181b; --bg: #09090b; --fg: #fafafa; --muted: #27272a; --muted-fg: #a1a1aa;
    --border: #27272a; --primary: #fafafa; --primary-fg: #18181b; --ring: #52525b;
    --ok: #4ade80; --ok-soft: #14532d; --warn: #fbbf24; --warn-soft: #451a03; --bad: #f87171; --bad-soft: #450a0a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
.muted { color: var(--muted-fg); }
.small { font-size: 13px; }
.boot { padding: 32px 16px; color: var(--muted-fg); text-align: center; }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 8px;
  font: 500 14px var(--font); border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  cursor: pointer; text-decoration: none; touch-action: manipulation;
}
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.lg { min-height: 48px; font-size: 16px; font-weight: 600; border-radius: 10px; width: 100%; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.field { display: grid; gap: 6px; font-size: 14px; font-weight: 500; }
.field input {
  height: 44px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font: 400 16px var(--font); width: 100%;
}
.field input::placeholder { color: var(--muted-fg); }
.stack { display: grid; gap: 14px; }
.ico { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.lg { width: 22px; height: 22px; }

.alert:empty { display: none; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; background: var(--muted); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

.card { border: 1px solid var(--border); border-radius: 12px; background: var(--bg); padding: 14px; display: grid; gap: 10px; }

/* Login, invite, setup */
.auth {
  min-height: 100%; display: grid; place-items: center; background: var(--page);
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.auth-card {
  width: 100%; max-width: 380px; display: grid; gap: 16px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 28px 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 12px 32px -12px rgba(0,0,0,.18);
}
.auth-card .logo { width: 56px; height: 56px; border-radius: 14px; }
.auth-card h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }

/* Logged in: top bar, content, tab bar */
.frame { min-height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.topbar {
  position: sticky; top: 0; z-index: 1; background: var(--bg);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; font-weight: 600; }
.topbar .titles { display: grid; min-width: 0; }
.topbar .sub { font-size: 13px; color: var(--muted-fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .grow { flex: 1; min-width: 0; }
.content { padding: 16px; display: grid; gap: 12px; align-content: start; width: 100%; max-width: 720px; margin: 0 auto; }
.hello { font-size: 18px; font-weight: 600; }
.tabbar {
  position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--border);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 6px 4px max(10px, env(safe-area-inset-bottom));
}
.tabbar a {
  display: grid; justify-items: center; gap: 2px; padding: 4px 0;
  font-size: 11px; color: var(--muted-fg); text-decoration: none;
}
.tabbar a.on { color: var(--fg); font-weight: 600; }

/* Building blocks of the screens (Part 6 mockup) */
:root { --info: #2563eb; --info-soft: #dbeafe; --cam1: #3f3f46; --cam2: #18181b; }
@media (prefers-color-scheme: dark) { :root { --info: #60a5fa; --info-soft: #172554; } }
.row { display: flex; align-items: center; gap: 10px; }
.row .grow, .grow { flex: 1; min-width: 0; }
.sep { height: 1px; background: var(--border); }
.strong { font-weight: 500; }
.center { text-align: center; }
.stack-sm { display: grid; gap: 8px; }
.tone-bad { color: var(--bad); display: inline-flex; }
.section { font-size: 13px; font-weight: 600; color: var(--muted-fg); margin-top: 4px; }
.card-t { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.card.soft { background: var(--muted); border-color: transparent; }
.ico.xl { width: 30px; height: 30px; }

.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 40px; padding: 0; }
.btn:disabled[aria-busy="true"] { opacity: .75; }
.btn.dimmed { opacity: .4; cursor: not-allowed; }
/* No live connection (Part 6): a bar on top, and the controls dimmed; app.js drops their presses */
.conn-bar { position: sticky; top: 0; z-index: 2; padding: max(8px, env(safe-area-inset-top)) 16px 8px; background: var(--bad-soft); color: var(--bad); font-size: 14px; text-align: center; }
.frame:has(> .conn-bar:not([hidden])) { grid-template-rows: auto auto 1fr auto; }
/* The bar takes the notch and stays on top; the title bar under it scrolls away */
.frame:has(> .conn-bar:not([hidden])) .topbar { position: static; padding-top: 12px; }
.frame.offline [data-control] { opacity: .4; cursor: not-allowed; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; border: 1px solid var(--border); color: var(--fg); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.avatars { display: flex; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--muted); border: 2px solid var(--bg);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}
.avatars .avatar + .avatar { margin-left: -8px; }
.avatar.away { opacity: .4; }

/* A light's on/off switch: a real button with role=switch */
.switch {
  width: 44px; height: 26px; border-radius: 999px; background: var(--border); position: relative; flex: none;
  border: 0; padding: 0; cursor: pointer; touch-action: manipulation;
}
.switch::after {
  content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: var(--bg);
  top: 2px; left: 2px; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .15s;
}
.switch.on { background: var(--primary); }
.switch.on::after { left: 20px; background: var(--primary-fg); }
.switch:disabled { opacity: .5; cursor: progress; }
.switch:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.light { display: grid; gap: 6px; }

/* A camera picture with its label */
.cam {
  position: relative; border-radius: 12px; overflow: hidden; aspect-ratio: 4/3; color: #fafafa;
  background: linear-gradient(160deg, var(--cam1), var(--cam2));
}
.cam .shot { display: block; width: 100%; height: 100%; object-fit: cover; }
.cam .shot.empty { display: grid; place-items: center; font-size: 13px; color: #a1a1aa; }
.cam .lbl {
  position: absolute; left: 10px; bottom: 8px; font-size: 12px; font-weight: 500; text-shadow: 0 1px 2px rgba(0,0,0,.7);
}

/* A screen with no tab bar, such as the doorbell */
.frame.bare { grid-template-rows: auto 1fr; }
.frame.bare .content { align-content: stretch; grid-template-rows: auto auto 1fr; }
.frame.bare .content > .grow-space { min-height: 8px; }

/* Screen 3: the step-up sheet over the screen */
.layer { position: fixed; inset: 0; z-index: 10; display: grid; align-items: end; }
.layer .dim { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet {
  position: relative; background: var(--bg); border-radius: 20px 20px 0 0; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 10px 16px max(22px, env(safe-area-inset-bottom)); display: grid; gap: 10px; justify-items: center; text-align: center;
}
.sheet h2 { font-size: 17px; font-weight: 600; }
.sheet .grab { width: 36px; height: 4px; border-radius: 4px; background: var(--border); }
.sheet .faceid { width: 60px; height: 60px; border-radius: 16px; border: 2px solid var(--fg); display: grid; place-items: center; }

/* Screen 6: the event feed (kind chips, camera picker, day picker, rows grouped by part of the day) */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  font: 500 13px var(--font); display: inline-flex; align-items: center; white-space: nowrap; flex: none;
  cursor: pointer; touch-action: manipulation;
}
.chip.on { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.chip:focus-visible, .ev-camera:focus-visible, .ev-person:focus-visible, .ev-day:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.ev-camera, .ev-person, .ev-day {
  height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font: 500 14px var(--font);
}
.ev-camera, .ev-person { width: 100%; }
.ev-day { max-width: 150px; }
.ev-feed { display: grid; gap: 14px; }
.ev-group { display: grid; gap: 2px; }
.daylbl { font-size: 11px; font-weight: 600; color: var(--muted-fg); text-transform: uppercase; letter-spacing: .06em; }
.ev-list { display: grid; }
.ev {
  display: flex; gap: 10px; align-items: center; padding: 8px 0; color: inherit; text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.ev-list .ev:last-child { border-bottom: 0; }
.ev .th {
  width: 72px; flex: none; aspect-ratio: 16/10; border-radius: 6px; overflow: hidden;
  background: linear-gradient(160deg, var(--cam1), var(--cam2));
}
.ev .th img { display: block; width: 100%; height: 100%; object-fit: cover; }
.ev .t1 { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev .t2 { font-size: 12px; color: var(--muted-fg); }
.ev-more { width: 100%; }

/* Screen 5: the camera grid and one camera full screen; screen 7: a clip with its timeline */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 10px; background: var(--muted); }
.seg-b {
  height: 32px; border: 0; border-radius: 7px; background: transparent; color: var(--muted-fg);
  font: 500 14px var(--font); cursor: pointer; touch-action: manipulation;
}
.seg-b.on { background: var(--bg); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg-b:focus-visible, .cam.tap:focus-visible, .tl-ev:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.cam.tap { cursor: pointer; }
.cam video.shot { background: #000; }
.cam .live-badge {
  position: absolute; left: 8px; top: 8px; z-index: 1; padding: 1px 6px; border-radius: 4px;
  background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .04em;
}
.cam .cam-status {
  position: absolute; inset: auto 8px 28px 8px; font-size: 12px; text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
.cam[data-state="stepup"] .cam-status, .cam[data-state="idle"] .cam-status { inset: 0; display: grid; place-items: center; text-shadow: none; }
.cam-full .cam { aspect-ratio: 16/9; }
.cam.clip { aspect-ratio: 16/9; background: #000; }
.cam.clip video.shot { object-fit: contain; }
.clip-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.clip-controls .btn[hidden] { display: none; }
.timeline { position: relative; height: 36px; border-radius: 8px; background: var(--muted); cursor: pointer; overflow: hidden; }
.timeline .tl-seg { position: absolute; top: 8px; bottom: 8px; border-radius: 3px; background: var(--ring); }
.timeline .tl-ev {
  position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; padding: 0; border-radius: 50%;
  border: 2px solid var(--bg); background: var(--warn); cursor: pointer;
}
.timeline .tl-ev.car { background: var(--info); }
.timeline .tl-ev.on { width: 16px; height: 16px; margin: -8px 0 0 -8px; background: var(--bad); }
.timeline .tl-now { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--fg); pointer-events: none; }
.timeline-ticks { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; }
.done-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.mono { font-family: var(--mono); }

/* Screens 11-13: the car's video. The More tab's link, one trip's player and bar, the map with its numbers and chart */
.more-link { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.btn.sm { min-height: 34px; padding: 0 10px; font-size: 13px; gap: 6px; }
.tone-warn { color: var(--warn); display: inline-flex; }
.trip-player .lbl { font-family: var(--mono); }
.trip-nav, .trip-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.trip-range { display: flex; flex-wrap: wrap; gap: 6px; }
.trip-bar { touch-action: none; user-select: none; -webkit-user-select: none; }
.trip-bar:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.timeline .tl-seg.ev { background: var(--warn); }
.timeline .tl-range { position: absolute; top: 0; bottom: 0; background: var(--info); opacity: .2; pointer-events: none; }
.timeline .tl-ev.trip-ev { background: var(--bad); }
.trip-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.trip-legend .dot-bad { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 5px; }

.trip-map {
  position: relative; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--muted);
  aspect-ratio: 16/10; min-height: 220px; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
}
.map-tiles { position: absolute; inset: 0; }
.map-tiles img { position: absolute; width: 256px; height: 256px; max-width: none; pointer-events: none; user-select: none; }
.map-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-svg .trk { fill: none; stroke: #2563eb; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.map-svg .trk.over { stroke: #dc2626; }
.map-svg .map-start { fill: #16a34a; stroke: #fff; stroke-width: 2; }
.map-svg .map-end { fill: #18181b; stroke: #fff; stroke-width: 2; }
.map-svg .map-ev { fill: #f59e0b; stroke: #fff; stroke-width: 2; }
.map-svg .map-now { fill: #fff; stroke: #2563eb; stroke-width: 3; }
.map-zoom { position: absolute; left: 8px; top: 8px; display: grid; gap: 4px; }
.map-zoom .btn { width: 34px; min-height: 34px; padding: 0; font-size: 18px; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.map-osm {
  position: absolute; left: 6px; bottom: 4px; font-size: 10px; color: #3f3f46; background: rgba(255,255,255,.85);
  padding: 0 4px; border-radius: 3px; text-decoration: none;
}
.map-pip {
  position: absolute; right: 8px; bottom: 8px; width: 38%; min-width: 128px; max-width: 280px; z-index: 1;
  border-radius: 8px; border: 2px solid var(--bg); overflow: hidden; cursor: default; touch-action: auto;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
/* Big: as large as the map allows, keeping 16/9, so the ⤢ toggle stays inside the map */
.map-pip.big { width: auto; height: calc(100% - 16px); aspect-ratio: 16/9; max-width: calc(100% - 16px); }
.map-pip.big .cam { width: 100%; height: 100%; aspect-ratio: auto; }
.map-pip .cam { border-radius: 0; }
.map-pip .lbl { font-size: 10px; left: 6px; bottom: 4px; }
.map-pip-size {
  position: absolute; right: 4px; top: 4px; z-index: 2; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 6px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 14px; cursor: pointer;
}
.trip-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); gap: 6px; text-align: center; }
.trip-stats .card { padding: 6px 2px; gap: 0; }
.trip-stats b { font-size: 15px; }
.trip-stats b.bad { color: var(--bad); }
.trip-speed { padding: 8px 10px; gap: 4px; }
.speed-svg { display: block; width: 100%; height: 56px; cursor: pointer; }
.speed-svg .spd { fill: none; stroke: var(--info); stroke-width: 2; vector-effect: non-scaling-stroke; }
.speed-svg .lim { stroke: var(--bad); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.speed-svg .over-band { fill: var(--bad); opacity: .12; }
.speed-svg .cur { stroke: var(--fg); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.trip-player .lbl { top: 8px; bottom: auto; }

/* Screens 8-10: scenarios, the rule editor (Khi, Nếu, Thì blocks), a device's Vì sao */
.field select {
  height: 44px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font: 400 16px var(--font); width: 100%;
}
fieldset.field { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.field legend { padding: 0; margin-bottom: 6px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 15px; font-weight: 400; }
.check input { width: 18px; height: 18px; padding: 0; accent-color: var(--primary); }
.blk { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg); }
.blk .k {
  padding: 8px 14px; background: var(--muted); font-size: 12px; font-weight: 600;
  color: var(--muted-fg); text-transform: uppercase; letter-spacing: .04em;
}
.blk .line + .line, .blk .line + .add { border-top: 1px solid var(--border); }
.blk .it, .blk .add {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 14px;
  border: 0; background: transparent; color: var(--fg); font: 400 15px var(--font); text-align: left; cursor: pointer;
}
.blk .add { color: var(--muted-fg); font-size: 14px; }
.blk .it:focus-visible, .blk .add:focus-visible, select:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.blk .it-edit { display: grid; gap: 10px; padding: 4px 14px 14px; }
.blk .it-edit .btn { justify-self: start; }
.why-line { display: grid; gap: 2px; }
.row.quick > .btn { flex: 1; }
