:root {
  /* AquaVue brand palette, sampled from aquavueli.com:
     #1F2526 header dark · #212C2C deep slate · #1ECAFF cyan · #E7E7E7 light */
  --bg: #151b1c;
  --surface: #1f2526;
  --surface-2: #212c2c;
  --border: #2f393b;
  --text: #e7e7e7;
  --muted: #8c9a9c;
  --accent: #1ecaff;      /* AquaVue cyan */
  --accent-dim: #12657f;
  --on-accent: #04222c;   /* readable text on a cyan fill */
  --danger: #ff6b6b;
  --warn: #ffcf5c;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font-synthesis: none;
}

* { box-sizing: border-box; }

/* The `hidden` attribute relies on the UA rule `[hidden] { display: none }`,
   which ANY author `display` rule outranks regardless of specificity. Several
   toggled elements carry classes that set display (.modal, .login-wrap), so
   without this they'd never hide. Keep this above those rules. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
button { font-family: inherit; cursor: pointer; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
}
.login-card input:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }
/* Chrome repaints autofilled fields with its own pale background and ignores
   background-color; a large inset shadow is the only way to keep them dark. */
.login-card input:-webkit-autofill,
.login-card input:-webkit-autofill:hover,
.login-card input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  caret-color: var(--text);
}
.login-card button[type="submit"] {
  margin-top: 6px;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-weight: 600;
  font-size: 15px;
}
.login-card button[disabled] { opacity: 0.6; cursor: default; }
.fineprint { font-size: 11px; color: var(--muted); margin: 4px 0 0; }
.error {
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.4);
  color: #ffb3b3;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13px;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
/* The wordmark already carries the name, so it replaces the text lockup. */
.brand-logo { height: 24px; width: auto; display: block; }
.login-card .brand { justify-content: center; }
.login-card .brand-logo { height: 38px; }

/* AquaVue's site is topped by a thin cyan rule; it reads as the brand signature. */
.brandbar { height: 3px; background: var(--accent); }

/* ---- App shell ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.tabs { display: flex; gap: 4px; margin-left: 10px; }
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--accent); background: var(--surface-2); }
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }

/* Full-bleed: the camera wall should use the whole screen, not a centred column. */
main { padding: 18px; max-width: none; margin: 0; }
.view { animation: fade 0.15s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- Camera cards ---- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

/* ---- Preview tiles ---- */
.preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.preview canvas.preview-canvas,
.preview video.preview-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* The canvas holds the last still; the video only shows while this camera
   actually has the session, otherwise it would sit there black over the top. */
.preview video.preview-video { opacity: 0; }
.preview.active video.preview-video { opacity: 1; }
.preview canvas.preview-canvas { background: var(--surface-2); }
.preview canvas.preview-canvas.has-frame { background: #000; }
.preview-label {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}
.preview.active .preview-label { background: rgba(255, 60, 60, 0.85); }
.ghost.on { color: var(--accent); border-color: var(--accent-dim); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-name { font-weight: 600; font-size: 15px; }
.status-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
}
.status-pill.online { background: rgba(30, 202, 255, 0.15); color: var(--accent); }
.status-pill.offline { background: rgba(139, 147, 161, 0.15); color: var(--muted); }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { background: var(--surface-2); border-radius: 8px; padding: 9px 11px; }
.metric .label { font-size: 11px; color: var(--muted); }
.metric .value { font-size: 15px; font-weight: 600; margin-top: 2px; display: flex; align-items: center; gap: 6px; }

.battery-bar { height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 7px; }
.battery-fill { height: 100%; background: var(--accent); }
.battery-fill.low { background: var(--danger); }
.battery-fill.mid { background: var(--warn); }

.signal-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.signal-bars i { width: 3px; background: var(--muted); border-radius: 1px; }
.signal-bars i.on { background: var(--accent); }

.card-actions { display: flex; gap: 8px; margin-top: 2px; }
.primary {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 600;
  font-size: 13px;
  flex: 1;
}
.primary:disabled { opacity: 0.5; cursor: default; }
.chip { font-size: 11px; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.chip.warn { color: var(--warn); }
.chip.ok { color: var(--accent); }

/* ---- Controls ---- */
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-bottom: 20px; }
.controls label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.controls select, .controls input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
}

/* ---- Calendar ---- */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; max-width: 520px; }
.cal-cell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
}
.cal-cell.dow { background: transparent; border: none; color: var(--muted); font-weight: 600; font-size: 11px; }
.cal-cell.pad { background: transparent; border: none; }
.cal-cell.has-event { background: var(--accent-dim); color: #eaf9ff; border-color: var(--accent); cursor: pointer; font-weight: 600; }
.cal-cell.has-event:hover { background: var(--accent); color: var(--on-accent); }

/* ---- Clips ---- */
.clips { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.clip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.clip:hover { transform: translateY(-2px); border-color: var(--muted); }
.clip .thumb { aspect-ratio: 16/9; background: var(--surface-2) center/cover no-repeat; position: relative; }
.clip .thumb .play-icon {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 32px; color: rgba(255,255,255,0.85);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.clip .meta { padding: 9px 11px; font-size: 12px; }
.clip .meta .time { font-weight: 600; color: var(--text); }
.clip .meta .sub { color: var(--muted); margin-top: 2px; }

/* ---- Modals ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 720px; box-shadow: var(--shadow); overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-head .ghost { border: none; font-size: 22px; line-height: 1; padding: 2px 8px; }
.video-wrap { position: relative; background: #000; }
.video-wrap video { width: 100%; display: block; max-height: 70vh; }
.live-status {
  position: absolute; top: 12px; left: 12px;
  background: rgba(0,0,0,0.6); color: #fff; padding: 5px 10px; border-radius: 6px; font-size: 12px;
}
.modal-foot { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--border); }
.quality { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.quality select { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 8px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .tabs { margin-left: 0; }
  .topbar { flex-wrap: wrap; gap: 10px; }
  .account { width: 100%; }
}
