:root {
  --bg: #f4f5f7; --fg: #1b1f24; --muted: #5f6873; --card: #ffffff; --border: #dde1e6;
  --accent: #0b62d6; --accent-fg: #ffffff; --warn: #c77700; --bad: #c62828; --track: #e3e6ea; --cover: #9aa5b1;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --fg: #e6e8eb; --muted: #9aa3ad; --card: #1c2026; --border: #2c323a;
          --accent: #5ea2ff; --accent-fg: #0b1220; --warn: #f0a640; --bad: #ff6b6b; --track: #262b33; --cover: #5c6672; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
/* iOS draws buttons and inputs in its own style (ignoring the background) unless told not to */
button, select, input[type=search], input[type=time] { -webkit-appearance: none; appearance: none; }

#top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
       padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--card); border-bottom: 1px solid var(--border); }
#top .titles { flex: 1; min-width: 0; }
#top h1 { font-size: 17px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { background: none; border: 0; font-size: 26px; line-height: 1; width: 40px; height: 40px; border-radius: 8px; }
.icon:active { background: var(--track); }
#home { display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
#home[hidden] { display: none; }
/* the bell: a flat outline in the accent colour (like the blue buttons); grey and crossed out while snoozed */
#bell { display: inline-flex; align-items: center; justify-content: center; color: var(--accent); }
#bell.snoozed, #bell.off { color: var(--muted); }   /* grey: snoozed, or this phone gets no notifications */
main { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }

.status { color: var(--muted); padding: 16px 4px; }
.status.bad { color: var(--bad); }

/* cell list */
.cells { display: grid; gap: 8px; }
.cell { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--card); border: 1px solid var(--border);
        border-radius: 10px; text-align: left; width: 100%; }
.cell .label { min-width: 40px; padding: 4px 6px; border-radius: 6px; background: var(--track); font-weight: 600; text-align: center; }
.cell .name { flex: 1; min-width: 0; }
.cell .name small { display: block; color: var(--muted); }
.cell .live-btn { border: 1px solid var(--border); background: var(--bg); border-radius: 16px; padding: 4px 12px; }

/* camera tiles on the home screen */
.cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
/* Video tab picture sizes (Large / Medium / Small switch): medium is two per row on a phone, small three; both
   without the Events/Live buttons (a tap opens the camera) and with a one-line caption */
.sizes { display: flex; gap: 6px; justify-content: flex-end; margin: -4px 0 10px; }
.sizes .chip { padding: 4px 12px; font-size: 13px; }
.cams.size-medium { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.cams.size-small { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
.cams.size-medium .cam .actions, .cams.size-small .cam .actions { display: none; }
.cams.size-medium .cam .caption { padding: 5px 8px 7px; gap: 6px; }
.cams.size-medium .cam .caption .name { font-size: 13px; font-weight: 500; }
.cams.size-small .cam { border-radius: 8px; }
.cams.size-small .cam .pic { aspect-ratio: 4 / 3; }
.cams.size-small .cam .caption { padding: 3px 5px 4px; }
.cams.size-small .cam .caption .label { padding: 1px 4px; font-size: 12px; }
.cams.size-small .cam .caption .name { display: none; }
.cams.size-small .cam.card, .cams.size-medium .cam.card { min-height: 0; padding-bottom: 6px; }
.cam { background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; }
.cam .pic { position: relative; aspect-ratio: 16 / 9; background: #000; }
.cam .pic img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .2s; }
.cam .pic img.ok { opacity: 1; }
.cam .offline { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #aaa; font-size: 13px; }
.cam .offline[hidden] { display: none; }
.cam .caption { display: flex; align-items: center; gap: 8px; padding: 8px 10px 0; }
.cam .caption .label { padding: 2px 6px; border-radius: 6px; background: var(--track); font-weight: 600; font-size: 13px; }
.cam .caption .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.cam .actions { display: flex; gap: 8px; padding: 8px 10px 10px; }
.cam .actions button { flex: 1; padding: 7px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.cam .actions button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
h2.section { font-size: 14px; color: var(--muted); margin: 18px 2px 8px; font-weight: 600; }
.cam.card { display: flex; flex-direction: column; justify-content: center; min-height: 72px; padding-bottom: 10px; }
.cam .kind { padding: 2px 10px 0; color: var(--muted); font-size: 13px; }

/* edit home screen */
.edit-list { display: grid; gap: 6px; }
.edit-row { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 10px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.edit-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.edit-row .name small { display: block; color: var(--muted); }
.edit-row .label { padding: 1px 5px; border-radius: 5px; background: var(--track); font-weight: 600; font-size: 13px; }
.edit-row.is-section { background: var(--track); }
.section-title { flex: 1; min-width: 0; font: inherit; font-weight: 600; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--card); color: var(--fg); }
.icon.small { width: 34px; height: 34px; font-size: 16px; border: 1px solid var(--border); background: var(--bg); }
.edit-row input[type=checkbox] { width: 20px; height: 20px; margin: 0 8px 0 0; flex: none; }
input[type=time] { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--fg); }
.search { flex: 1; min-width: 180px; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--fg); }

/* tabs and chips */
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); }
.tab.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { padding: 5px 12px; border-radius: 16px; border: 1px solid var(--border); background: var(--card); font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* event grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.day { grid-column: 1 / -1; font-weight: 600; margin: 10px 2px 2px; }
.gap { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 12px; }
.tile { position: relative; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--card); }
.tile img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--track); }   /* most cameras are 16:9 */
/* much wider pictures (180-degree cameras): whole, with bars, instead of cut off at the sides */
.tile img.wide, .cam .pic img.wide { object-fit: contain; background: #000; }
.tile .meta { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px; font-size: 13px; }
.tile .tags { font-size: 13px; letter-spacing: 1px; }
.tile .zoom { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border: 0; border-radius: 15px;
              background: rgba(0,0,0,.55); color: #fff; font-size: 15px; }
.tile.selected { outline: 3px solid var(--warn); }
.more { display: block; width: 100%; margin: 14px 0 4px; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); }

/* players */
video { display: block; width: 100%; max-height: 70vh; background: #000; border-radius: 8px; }
.player-info { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 8px 2px; font-size: 14px; }
.player-info .now { font-weight: 600; font-variant-numeric: tabular-nums; }
.player-info .muted-note { color: var(--accent); font-weight: 600; }   /* iPhone started the video muted */
/* talk view: low-delay picture and a large hold-to-talk button (no text selection or callout on a long press) */
.talk-video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; }
.talk-btn { display: block; width: 100%; margin: 6px 0 10px; padding: 22px 12px; border-radius: 14px; border: 0; font-size: 19px; font-weight: 600;
  background: var(--accent); color: var(--accent-fg); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; }
.talk-btn.on { background: #d93025; color: #fff; }
.talk-btn:disabled { background: var(--track); color: var(--muted); }
.controls { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.controls button, .primary { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); }
.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
select { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--fg); }
canvas.timeline { display: block; width: 100%; height: 64px; margin-top: 10px; touch-action: manipulation; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* snapshot viewer */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.92); display: flex; flex-direction: column;
           align-items: center; justify-content: center; padding: env(safe-area-inset-top) 8px env(safe-area-inset-bottom); }
.overlay[hidden] { display: none; }
.viewer-bar { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; display: flex; align-items: center;
              justify-content: space-between; gap: 8px; padding: 8px 12px; color: #fff; }
.viewer-bar .icon { color: #fff; }
#viewer-img { max-width: 100%; max-height: 80vh; object-fit: contain; }
#viewer-play { margin-top: 12px; }

/* primary buttons inside a button row: '.controls button' is more specific than '.primary', so repeat the colours */
.controls button.primary, .cam .actions button.primary, .login button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
/* disabled buttons: plainly grey, not a faded accent colour */
button:disabled, button.primary:disabled, .cam .actions button.primary:disabled { background: var(--track); color: var(--muted); border-color: var(--border); cursor: default; opacity: 1; }
/* home screen categories (Video | Control): a tab strip joined to the header, not buttons */
.cattabs { display: flex; margin: -12px -12px 12px; padding: 0 12px; background: var(--card); border-bottom: 1px solid var(--border); }
.cattab { flex: 1; padding: 12px 8px 10px; border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none;
          color: var(--muted); font-weight: 600; letter-spacing: .3px; }
.cattab.on { color: var(--accent); border-bottom-color: var(--accent); }
.cattab:not(.on):active { color: var(--fg); }

/* camera events: go to a day */
.day-bar { align-items: center; margin-top: 0; }
.day-bar .hint { margin-top: 0; font-size: 13px; }
.day-pick { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--fg);
            color-scheme: light dark; min-height: 36px; min-width: 150px; }   /* native look kept: iOS collapses a restyled date field */

/* recent history: which cell, and how many events the tile stands for (like the viewer's number in the corner) */
.tile .who { position: absolute; top: 4px; left: 4px; max-width: calc(100% - 44px); padding: 1px 6px; border-radius: 6px;
             background: rgba(0,0,0,.6); color: #fff; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .count { position: absolute; left: 6px; bottom: 30px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 6px;
               background: #e0262c; color: #fff; font-weight: 700; font-size: 14px; line-height: 26px; text-align: center;
               box-shadow: 0 0 0 2px rgba(255,255,255,.85); }

/* control cells: state badge on the card, state box, command buttons, event list */
.cam.control .kind { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.state { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--track); color: var(--muted); }
.state.on { background: var(--bad); color: #fff; }
.state.busy { background: var(--warn); color: #000; }
.statebox { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 4px 0 8px; padding: 12px 14px; border-radius: 10px;
            border: 1px solid var(--border); background: var(--card); }
.statebox strong { font-size: 18px; }
.statebox span { color: var(--muted); }
.statebox.on { border-color: var(--bad); }
.statebox.on strong { color: var(--bad); }
.statebox.busy strong { color: var(--warn); }
/* two columns on a phone, more on wider screens; a button never grows past its column (long names wrap) */
.cmds { display: grid; grid-template-columns: 1fr 1fr; grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); gap: 10px; margin-top: 8px; }
.cmd { display: block; width: 100%; min-width: 0; min-height: 72px; margin: 0; padding: 12px 8px; border-radius: 12px; border: 2px solid var(--border);
       font-weight: 600; font-size: 16px; line-height: 1.25; white-space: normal; overflow-wrap: anywhere; }
.cmd:active { filter: brightness(.85); }
.cmd:disabled { opacity: .55; }
.alarm-list { display: grid; gap: 6px; margin-top: 10px; }
.alarm-row { display: flex; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); cursor: pointer; }
.alarm-row .when { min-width: 92px; font-variant-numeric: tabular-nums; font-weight: 600; }
.alarm-row .when small, .alarm-row .what small { display: block; color: var(--muted); font-weight: normal; }
.alarm-row .what { flex: 1; min-width: 0; }
.alarm-row .what .ack { color: var(--fg); }
.alarm-row.active { border-color: var(--bad); }
.alarm-row.selected { outline: 3px solid var(--accent); }

/* a status message that must be noticed (Notifications screen) */
.notice { margin: 8px 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--warn); background: var(--card); color: var(--fg); }
.notice.ok { border-color: var(--border); }
.notice a { color: var(--accent); word-break: break-all; }
