/* Family website. Visual language follows the laptop Home tab (static/home.css):
   calm, large type, sparing status colour, the same chart fills. Phone first. */
:root {
  --h-bg: #ffffff;
  --h-surface: #ffffff;
  --h-ink: #111111;
  --h-muted: #5a5a5a;
  --h-line: #d4d4d4;
  --h-soft: #f4f4f2;
  --h-alert: #b3261e;
  --h-alert-bg: #fdecea;
  --h-ok: #1a6b3a;
  --h-ok-bg: #e8f4ec;
  --h-unknown: #6b6b6b;
  --h-c-with: #1a5e34;
  --h-c-without: #ef6a5a;
  --h-c-unknown: #a3a3a3;
  --h-c-track: #ececec;
  --h-c-motion: #3a3a3a;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --h-bg: #121212; --h-surface: #1b1b1b; --h-ink: #f2f2f2; --h-muted: #a8a8a8; --h-line: #343434;
    --h-soft: #222222; --h-alert: #ff8a80; --h-alert-bg: #3a1714; --h-ok: #7ddc98; --h-ok-bg: #14301e;
    --h-unknown: #9a9a9a; --h-c-with: #5cc97c; --h-c-without: #c8332e; --h-c-unknown: #6b6b6b;
    --h-c-track: #2a2a2a; --h-c-motion: #d0d0d0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --h-bg: #121212; --h-surface: #1b1b1b; --h-ink: #f2f2f2; --h-muted: #a8a8a8; --h-line: #343434;
  --h-soft: #222222; --h-alert: #ff8a80; --h-alert-bg: #3a1714; --h-ok: #7ddc98; --h-ok-bg: #14301e;
  --h-unknown: #9a9a9a; --h-c-with: #5cc97c; --h-c-without: #c8332e; --h-c-unknown: #6b6b6b;
  --h-c-track: #2a2a2a; --h-c-motion: #d0d0d0;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--h-bg);
  color: var(--h-ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 10; background: var(--h-ink); color: var(--h-bg); padding: 8px 12px; border-radius: 6px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--h-ink); outline-offset: 2px; }
a { color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--h-line);
  background: var(--h-bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.logo { width: 32px; height: 32px; border-radius: 8px; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-text strong { font-size: 17px; }
.home-name { font-size: 14px; color: var(--h-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-name:empty { display: none; }
.home-switch { order: 3; flex: 1 1 100%; }
.home-switch select { width: 100%; }

/* Tabs: a bottom tab bar on phones, inline in the header on wide screens. */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 6;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr; /* one column per visible tab (People is for owners and admins) */
  background: var(--h-bg);
  border-top: 1px solid var(--h-line);
  padding: 4px max(4px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; text-decoration: none; color: var(--h-muted); font-size: 12px; border-radius: 10px;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[hidden] { display: none; }
.tabs a[aria-current="page"] { color: var(--h-ink); font-weight: 700; }
.tabs a[aria-current="page"] svg { stroke-width: 2.4; }
body.signed-in { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }

/* Account menu */
.account { position: relative; flex: none; }
.account > summary { list-style: none; cursor: pointer; border-radius: 50%; }
.account > summary::-webkit-details-marker { display: none; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 50%;
  background: var(--h-ink); color: var(--h-bg); font-weight: 700;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: min(300px, calc(100vw - 32px));
  background: var(--h-surface); border: 1px solid var(--h-line); border-radius: 12px; padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18); z-index: 8;
}
.menu p { margin: 0; }
.menu-label { font-size: 13px; color: var(--h-muted); }
.menu-email { font-weight: 700; overflow-wrap: anywhere; }
.menu-role { font-size: 14px; color: var(--h-muted); margin-bottom: 10px !important; }
.menu-theme { display: block; font-size: 14px; color: var(--h-muted); margin-bottom: 12px; }
.menu-theme select, .menu button { display: block; width: 100%; margin-top: 4px; }

/* Banners */
.banner { margin: 0; padding: 10px 16px; font-size: 16px; font-weight: 600; background: var(--h-soft); border-bottom: 1px solid var(--h-line); }
.banner.tone-alert { background: var(--h-alert-bg); color: var(--h-alert); }

/* ---------- layout ---------- */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
  outline: none;
}
.app h1 { font-size: 28px; line-height: 1.2; margin: 0; outline: none; }
.app h2 { font-size: 20px; margin: 0 0 10px; }
.app h3 { font-size: 18px; margin: 20px 0 8px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; margin: 4px 0 14px; }
.app button, .app input, .app select, .app textarea, .menu select, .menu button, .home-switch select, .btn {
  font: inherit;
  font-size: 16px;
  background: var(--h-surface);
  color: var(--h-ink);
  border: 1px solid var(--h-line);
  border-radius: 8px;
  padding: 9px 14px;
  min-height: 44px;
  max-width: 100%;
}
.app button, .menu button, .btn { background: var(--h-soft); cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-weight: 600; }
.app button:hover:not(:disabled), .btn:hover { border-color: var(--h-ink); }
.app button:disabled { opacity: 0.55; cursor: default; }
.app .h-primary, .btn.h-primary { background: var(--h-ink); color: var(--h-bg); border-color: var(--h-ink); }
.h-big { font-size: 18px; padding: 12px 28px; }
.h-muted { color: var(--h-muted); font-size: 15px; }
.h-empty { color: var(--h-muted); margin: 8px 0; }
.h-card {
  background: var(--h-surface);
  border: 1px solid var(--h-line);
  border-radius: 14px;
  padding: 16px;
  margin: 0 0 18px;
  min-width: 0;
}
.h-note { font-size: 15px; color: var(--h-muted); border-top: 1px solid var(--h-line); padding-top: 14px; margin-top: 24px; }
.back { display: inline-block; text-decoration: none; color: var(--h-muted); padding: 8px 0; min-height: 44px; }

/* Sign-in */
.signin-card { max-width: 480px; margin: 24px auto; text-align: center; padding: 28px 20px; }
.signin-card h1 { margin-bottom: 10px; }
.signin-card .h-feedback { color: var(--h-alert); min-height: 1.5em; }

/* ---------- Now ---------- */
.h-overall {
  font-size: 19px; font-weight: 700; padding: 12px 16px; border-radius: 10px; margin: 0 0 10px;
  background: var(--h-soft); border-left: 6px solid var(--h-unknown);
}
.h-overall.tone-ok { border-left-color: var(--h-ok); }
.h-overall.tone-alert { border-left-color: var(--h-alert); background: var(--h-alert-bg); color: var(--h-alert); }
.conn { font-size: 15px; color: var(--h-muted); margin: 0 0 16px; display: flex; gap: 8px; align-items: baseline; }
.conn:empty { display: none; }
.conn::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--h-unknown); transform: translateY(1px); }
.conn.tone-ok::before { background: var(--h-ok); }
.conn.tone-alert::before { background: var(--h-alert); }
.conn.tone-alert { color: var(--h-alert); }
.h-cameras { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 14px; }
.h-cam {
  border: 1px solid var(--h-line); border-top: 6px solid var(--h-unknown); border-radius: 14px;
  overflow: hidden; background: var(--h-surface); min-width: 0;
}
.h-cam.tone-ok { border-top-color: var(--h-ok); }
.h-cam.tone-alert { border-top-color: var(--h-alert); }
.h-cam.tone-off { border-top-color: var(--h-line); }
.h-cam-body { padding: 12px 16px 14px; }
.h-cam.stale .h-status::after { content: " (last known)"; font-size: 15px; font-weight: 400; }
.h-cam-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.app .h-room { font-size: 18px; margin: 0; overflow-wrap: anywhere; }
.h-pill { font-size: 13px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--h-line); color: var(--h-muted); white-space: nowrap; }
.h-pill.on { color: var(--h-ink); border-color: var(--h-ink); }
.h-status { font-size: 22px; font-weight: 700; margin: 4px 0 2px; line-height: 1.25; }
.h-cam.tone-alert .h-status { color: var(--h-alert); }
.h-cam.tone-ok .h-status { color: var(--h-ok); }
.h-cam.tone-unknown .h-status, .h-cam.tone-off .h-status { color: var(--h-unknown); }
.h-meta { color: var(--h-muted); font-size: 15px; margin: 0 0 4px; }
.h-meta:empty { display: none; }
.h-evidence { font-size: 14px; color: var(--h-muted); margin: 0 0 6px; overflow-wrap: anywhere; }
.h-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.h-feedback { font-size: 15px; color: var(--h-muted); }
.h-feedback:empty { display: none; }
.h-feedback.tone-ok { color: var(--h-ok); }
.h-feedback.tone-alert { color: var(--h-alert); }

/* ---------- Live view ---------- */
.live-status { font-weight: 700; color: var(--h-unknown); }
.live-status.tone-ok { color: var(--h-ok); }
.live-status.tone-alert { color: var(--h-alert); }
.live-frame { position: relative; margin: 0 0 10px; aspect-ratio: 16 / 9; background: #111; border-radius: 14px; overflow: hidden; }
.live-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.live-off { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px; color: #c8c8c8; font-size: 16px; }
.paused .live-frame img { opacity: 0.55; }
.live-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.live-age { margin: 0; font-variant-numeric: tabular-nums; }
.live-age.stale { color: var(--h-alert); }

/* ---------- stats, episodes, events ---------- */
.h-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 8px 0 16px; }
.h-stat { background: var(--h-soft); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; min-width: 0; }
.h-stat-v { font-size: 24px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.h-stat-l { font-size: 14px; color: var(--h-muted); }
.h-stat.tone-alert .h-stat-v { color: var(--h-alert); }
.h-stat.tone-ok .h-stat-v { color: var(--h-ok); }
.h-episodes, .h-events { list-style: none; margin: 0; padding: 0; }
.h-episodes li { padding: 12px 0; border-top: 1px solid var(--h-line); }
.h-ep-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.h-ep-ev { font-size: 15px; color: var(--h-muted); overflow-wrap: anywhere; }
.h-tag { font-size: 13px; padding: 2px 9px; border-radius: 999px; background: var(--h-soft); color: var(--h-unknown); white-space: nowrap; }
.h-tag.tone-ok { background: var(--h-ok-bg); color: var(--h-ok); }
.h-tag.tone-alert { background: var(--h-alert-bg); color: var(--h-alert); }
.app .day-sep { font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--h-muted); margin: 18px 0 4px; }
.app .day-sep:first-child { margin-top: 0; }
.app .sub { font-size: 18px; margin-top: 20px; }
.h-events li { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 10px 0; border-top: 1px solid var(--h-line); }
.h-events strong { margin-right: 2px; }
.h-events time { font-size: 15px; color: var(--h-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.h-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 7px; background: var(--h-unknown); }
.h-events li.tone-alert .h-dot { background: var(--h-alert); }
.h-events li.tone-ok .h-dot { background: var(--h-ok); }

/* ---------- charts ---------- */
.h-chart { position: relative; }
.h-chart svg { display: block; max-width: 100%; height: auto; overflow: visible; }
.h-axis { font-size: 12px; fill: var(--h-muted); }
.h-grid-line { stroke: var(--h-line); stroke-width: 1; }
.h-baseline { stroke: var(--h-muted); stroke-width: 1; }
.h-hit { fill: transparent; }
.h-bar { outline: none; cursor: pointer; }
.h-bar:focus-visible .h-hit, .h-bar:hover .h-hit { fill: var(--h-soft); }
.h-seg-with { fill: var(--h-c-with); }
.h-seg-without { fill: var(--h-c-without); }
.h-seg-unknown { fill: var(--h-c-unknown); }
.h-zero { fill: var(--h-muted); }
.h-nodata { stroke: var(--h-line); stroke-dasharray: 3 3; }
.h-hatch { stroke: var(--h-line); stroke-width: 2; }
.h-track { fill: var(--h-c-track); }
.h-track.future { opacity: 0.45; }
.h-motion { fill: var(--h-c-motion); }
.h-alert-dot { fill: var(--h-alert); }
.h-chart-caption { margin: 8px 0 4px; }
.h-alert-key { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--h-alert); }
.h-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; color: var(--h-muted); margin-bottom: 10px; }
.h-legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; }
.sw-with { background: var(--h-c-with); }
.sw-without { background: var(--h-c-without); }
.sw-unknown { background: var(--h-c-unknown); }
.sw-nodata { border: 1px dashed var(--h-muted); background: repeating-linear-gradient(45deg, transparent 0 3px, var(--h-line) 3px 5px); }
.h-tip {
  position: absolute; z-index: 2; max-width: 260px; pointer-events: none;
  background: var(--h-ink); color: var(--h-bg); font-size: 14px; line-height: 1.35; padding: 7px 10px; border-radius: 6px;
}
.h-table { margin-top: 12px; }
.h-table summary { font-size: 15px; color: var(--h-muted); cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.table-scroll { overflow-x: auto; }
.app table { border-collapse: collapse; font-size: 15px; width: 100%; }
.app th, .app td { border: 1px solid var(--h-line); padding: 6px 8px; text-align: left; white-space: nowrap; }
.app thead th { background: var(--h-soft); }

/* ---------- settings ---------- */
.role-note { background: var(--h-soft); border-radius: 10px; padding: 10px 14px; margin: 0 0 16px; }
.cam-row { padding: 12px 0; border-top: 1px solid var(--h-line); }
.cam-row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cam-row p { margin: 2px 0 0; }
.cam-row .h-actions { margin-top: 8px; }
.cam-row:first-child { border-top: 0; }
.h-pill.role-owner, .h-pill.role-admin { color: var(--h-ink); border-color: var(--h-ink); }
.h-pill.tone-pending { color: var(--h-muted); border-style: dashed; }
.h-inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.h-inline label { flex: 1 1 220px; margin-bottom: 0; }
.h-inline label.h-narrow { flex: 0 1 140px; }
.h-roles { width: 100%; border-collapse: collapse; font-size: 15px; }
.h-roles th, .h-roles td { text-align: left; padding: 6px 8px 6px 0; border-top: 1px solid var(--h-line); vertical-align: top; }
.h-roles thead th { border-top: 0; color: var(--h-muted); font-weight: 600; }
.h-form fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.h-form fieldset:disabled { opacity: 0.8; }
.h-form label { display: block; margin-bottom: 14px; font-size: 16px; }
.h-form label > input:not([type="checkbox"]), .h-form label > select, .h-form label > textarea { display: block; width: 100%; margin-top: 4px; }
.h-form textarea { resize: vertical; }
.h-form label.h-check { display: flex; align-items: center; min-height: 44px; }
.app input[type="checkbox"] { min-height: 0; width: 22px; height: 22px; margin: 0 10px 0 0; flex: none; accent-color: var(--h-ink); padding: 0; }
.h-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.h-pair label { margin-bottom: 14px; }
.h-form input:invalid:not(:focus):not(:placeholder-shown) { border-color: var(--h-alert); }

/* ---------- wider screens ---------- */
@media (min-width: 560px) {
  .h-stats { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .h-card { padding: 20px; }
}
@media (min-width: 860px) {
  body.signed-in { padding-bottom: 0; }
  .topbar { flex-wrap: nowrap; gap: 20px; }
  .brand { flex: 0 1 auto; }
  .home-switch { order: 0; flex: 0 1 260px; }
  .tabs {
    position: static; display: flex; gap: 4px; border: 0; padding: 0; background: none; margin-left: auto;
  }
  .tabs a { flex-direction: row; gap: 8px; min-height: 44px; padding: 0 14px; font-size: 16px; }
  .tabs svg { width: 20px; height: 20px; }
  .tabs a[aria-current="page"] { background: var(--h-ink); color: var(--h-bg); }
  .tabs a:not([aria-current="page"]):hover { background: var(--h-soft); color: var(--h-ink); }
  .account { margin-left: 4px; }
  .app { padding-top: 24px; }
  .app h1 { font-size: 32px; }
  .h-status { font-size: 24px; }
  .h-stat-v { font-size: 28px; }
  #page-live { max-width: 900px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
