/* Colours and components follow the dark theme of web-dashboard (shadcn-vue, zinc). */
:root {
  color-scheme: dark;
  --background: hsl(240 10% 3.9%);
  --foreground: hsl(0 0% 98%);
  --card: hsl(240 10% 3.9%);
  --primary: hsl(0 0% 98%);
  --primary-foreground: hsl(240 5.9% 10%);
  --secondary: hsl(240 3.7% 15.9%);
  --muted: hsl(240 3.7% 15.9%);
  --muted-foreground: hsl(240 5% 64.9%);
  --accent: hsl(240 3.7% 15.9%);
  --destructive: hsl(0 62.8% 30.6%);
  --border: hsl(240 3.7% 15.9%);
  --input: hsl(240 3.7% 15.9%);
  --ring: hsl(240 4.9% 83.9%);
  --radius: 0.5rem;
  --ok: #34d399;   /* emerald-400, as in dashboard tables */
  --bad: #f87171;  /* red-400 */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; border-width: 0; border-style: solid; border-color: var(--border); }
html, body { margin: 0; height: 100%; }
body {
  background: var(--background);
  color: var(--foreground);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; background: none; }
/* 16px inputs: iOS Safari does not zoom on focus */
input { font: inherit; font-size: 16px; }

:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring); }

.brand { font-weight: 700; letter-spacing: .04em; white-space: nowrap; font-size: 15px; }
.brand span { font-weight: 400; color: var(--muted-foreground); letter-spacing: 0; margin-left: 6px; }

/* ---- buttons (dashboard Button) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: calc(var(--radius) - 2px);
  font-size: 14px; font-weight: 500; white-space: nowrap; transition: background-color .15s, opacity .15s;
}
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: hsl(0 0% 98% / .9); }
.btn-outline { border: 1px solid var(--input); background: var(--background); }
.btn-outline:hover { background: var(--accent); }
.btn-ghost:hover { background: var(--accent); }
.btn-sm { height: 36px; padding: 0 12px; }
.btn-icon { width: 40px; padding: 0; }

/* ---- login (dashboard auth page) ---- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 320px; display: grid; gap: 24px; }
.login-head { display: grid; gap: 6px; text-align: center; }
.login-head h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.login-head p { margin: 0; color: var(--muted-foreground); font-size: 14px; }
.fields { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 500; }
.input {
  display: flex; width: 100%; height: 40px; padding: 8px 12px; border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px); background: var(--background); color: var(--foreground);
}
.input::placeholder { color: var(--muted-foreground); }
.error {
  margin: 0; padding: 10px 12px; font-size: 14px; color: var(--foreground);
  background: hsl(0 62.8% 30.6% / .35); border: 1px solid var(--destructive); border-radius: calc(var(--radius) - 2px);
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- header ---- */
/* the window never scrolls (iOS Safari header drift): only the grid scrolls in scroll mode */
.app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.top {
  position: sticky; top: 0; z-index: 5; background: hsl(240 10% 3.9% / .95);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user span { color: var(--muted-foreground); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

/* ---- tabs (dashboard TabsList / TabsTrigger) ---- */
.tabs {
  order: 3; width: 100%; display: inline-flex; align-items: center; height: 40px; padding: 4px;
  background: var(--muted); color: var(--muted-foreground); border-radius: calc(var(--radius) - 2px);
  overflow-x: auto; scrollbar-width: none;
}
.tabs:empty { display: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 1 0 auto; height: 32px; padding: 0 12px; border-radius: calc(var(--radius) - 4px);
  font-size: 14px; font-weight: 500; white-space: nowrap; transition: all .15s;
}
.tabs button[aria-selected=true] {
  background: var(--background); color: var(--foreground); box-shadow: 0 1px 2px rgb(0 0 0 / .3);
}
@media (min-width: 768px) {
  .tabs { order: 0; width: auto; }
  .tabs button { flex: none; }
}

/* ---- grid ----
   fill mode (default): app.js picks columns/rows for the actual number of cameras so the tiles
   cover the whole work area; scroll mode: too many cameras for the screen, plain scrolling grid. */
.grid {
  flex: 1 1 auto; min-height: 0; display: grid; gap: 8px; padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
@media (min-width: 768px) {
  .grid { gap: 12px; padding: 12px 16px 16px; }
}
.grid.fill { display: block; position: relative; overflow: hidden; }
/* placed by app.js: one height for all, width from the camera aspect */
.grid.fill .tile { position: absolute; aspect-ratio: auto; }
.grid.scroll {
  overflow-y: auto; -webkit-overflow-scrolling: touch; align-content: start;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 768px) {
  .grid.scroll { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}
.empty { color: var(--muted-foreground); text-align: center; padding: 48px 16px; }

/* tile = invisible grid cell; the frame inside it hugs the actual picture (dashboard Card look).
   Frame size = the largest box with the camera's aspect ratio that fits the cell (container units),
   the ratio comes from the stream itself (--ar, set in app.js), 3:2 until the video starts. */
.tile {
  position: relative; display: grid; place-items: center; padding: 0; min-width: 0; min-height: 0;
  aspect-ratio: 3 / 2; background: transparent; border: 0; container-type: size;
}
.tile:focus-visible { box-shadow: none; }
.frame {
  --ar: 1.5;
  position: relative; display: block; overflow: hidden;
  width: min(100cqw, calc(100cqh * var(--ar))); aspect-ratio: var(--ar);
  background: #000; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgb(0 0 0 / .3); transition: border-color .15s;
}
.tile:hover .frame { border-color: hsl(240 5% 26%); }
.tile:focus-visible .frame { box-shadow: 0 0 0 2px var(--background), 0 0 0 4px var(--ring); }
.frame video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
/* camera name with the connection dot: top right corner inside the frame */
.frame .label {
  position: absolute; top: 6px; right: 6px; max-width: calc(100% - 12px);
  display: flex; align-items: center; gap: 6px; padding: 3px 8px;
  background: rgb(0 0 0 / .6); border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.4;
}
.frame .label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-foreground); flex: none; }
.tile.live .dot { background: var(--ok); }
.tile.failed .dot { background: var(--bad); }
.status { font-size: 13px; color: var(--muted-foreground); }
.frame .status { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 8px; }
.tile.live .status { display: none; }
/* last snapshot until the live video plays, with its age as a small pill at the bottom left;
   the connection state is the dot next to the name */
.frame .snap { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.frame .age { display: none; }
.tile.has-snap .status { display: none; }
.tile.has-snap .age {
  position: absolute; left: 6px; bottom: 6px; display: block; max-width: calc(100% - 12px);
  padding: 3px 8px; border-radius: 999px; background: rgb(0 0 0 / .6);
  font-size: 12px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile.live .snap, .tile.live .age { display: none; }

/* ---- full screen (dashboard Sheet overlay) ---- */
.viewer { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; }
.viewer-bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--background); border-bottom: 1px solid var(--border);
}
.viewer-bar #viewer-title { font-weight: 600; }
.viewer-bar .btn { margin-left: auto; }
.viewer-stage { position: relative; flex: 1; min-height: 0; background: #000; }
.viewer-stage img, .viewer-stage video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: transparent;
}
.viewer-stage video { opacity: 0; transition: opacity .2s; }
.viewer-stage video.on { opacity: 1; }
.viewer-note {
  position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: 4px 12px; border-radius: 999px; background: rgb(0 0 0 / .65);
  font-size: 13px; color: var(--foreground); white-space: nowrap;
}
