:root {
  --bg: #F2F3EF; --card: #FFFFFF; --ink: #14181F; --muted: #555D68; --line: #ECEDE8;
  --green: #12733F; --orange: #F28C00; --orange-ink: #1F1400; --orange-text: #B85F00; --red: #B42318; --sos: #8F1B13;
  --amber-bg: #FFF4E5; --amber-line: #F2C894; --amber-ink: #6B4210;
  --grey: #5C6670;
  font-family: Manrope, -apple-system, system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.screen { max-width: 520px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 20px) 20px calc(env(safe-area-inset-bottom) + 110px); display: flex; flex-direction: column; gap: 16px; }
.top { display: flex; justify-content: space-between; align-items: center; }
.top h1 { margin: 2px 0 0; font-size: 26px; font-weight: 800; }
.hello { font-size: 13px; font-weight: 600; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid #D5D8D2; background: var(--card); display: flex; align-items: center; justify-content: center; }

.banner { margin: 0; padding: 12px 14px; border-radius: 14px; font-size: 14px; line-height: 1.4; font-weight: 600; }
.banner.demo { background: #E6ECF5; color: #1F3A5F; }
.banner.offline { background: #E9EAEC; color: #2F3640; }

.status-card { border-radius: 24px; padding: 24px; color: #fff; display: flex; flex-direction: column; gap: 12px; transition: background .3s; }
.status-top { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; opacity: .9; }
.dot { width: 12px; height: 12px; border-radius: 6px; background: #fff; }
.status-label { font-size: 38px; font-weight: 800; line-height: 1.05; }
.status-sub { font-size: 14px; line-height: 1.4; opacity: .92; min-height: 1.4em; }
.s-disarm { background: var(--green); }
.s-stay { background: var(--orange); color: var(--orange-ink); }
.s-stay .dot { background: var(--orange-ink); }
.s-away { background: var(--red); }
.s-unknown { background: var(--grey); }
.s-alarm { background: var(--red); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { background: #B42318; } to { background: #7A130C; } }
.silence { margin-top: 4px; height: 52px; border-radius: 14px; border: none; background: #fff; color: var(--red); font-weight: 800; font-size: 17px; }

.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.mode { height: 96px; border-radius: 18px; border: 2px solid transparent; font-size: 15px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--card); transition: transform .1s; }
.mode:active { transform: scale(.97); }
.m-away { color: var(--red); border-color: var(--red); }
.m-stay { color: var(--orange-text); border-color: var(--orange); }
.m-disarm { color: var(--green); border-color: var(--green); }
.mode.current.m-away { background: var(--red); color: #fff; }
.mode.current.m-stay { background: var(--orange); color: var(--orange-ink); }
.mode.current.m-disarm { background: var(--green); color: #fff; }
.mode.busy { opacity: .6; }

.sos { position: relative; overflow: hidden; height: 64px; border-radius: 18px; border: none; background: var(--sos); color: #fff; display: flex; align-items: center; justify-content: center; gap: 12px; user-select: none; -webkit-user-select: none; touch-action: none; }
.sos-text { position: relative; font-size: 22px; font-weight: 800; letter-spacing: .08em; }
.sos-hint { position: relative; font-size: 13px; font-weight: 600; color: #FAD9D5; }
.sos-fill { position: absolute; inset: 0; width: 0; background: #E0352A; }
.sos.holding .sos-fill { width: 100%; transition: width 1s linear; }

.attention { text-align: left; background: var(--amber-bg); border: 1px solid var(--amber-line); border-radius: 18px; padding: 16px; display: flex; gap: 14px; align-items: center; color: var(--ink); }
.att-icon { width: 40px; height: 40px; border-radius: 20px; background: #B45309; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.attention.red .att-icon { background: var(--red); }
.att-text { display: flex; flex-direction: column; gap: 3px; flex: 1; font-size: 13px; color: var(--amber-ink); }
.att-text b { font-size: 15px; color: var(--ink); }

.card { background: var(--card); border-radius: 18px; padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.health-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.health-grid div { display: flex; flex-direction: column; gap: 4px; }
.health-grid span { font-size: 12px; color: var(--muted); }
.health-grid b { font-size: 14px; }
.ok-text { color: var(--green); } .warn-text { color: var(--red); }

.group-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--muted); margin: 8px 0 -4px; }
.group-title.att { color: var(--amber-ink); }
.list { background: var(--card); border-radius: 18px; overflow: hidden; }
.row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: none; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.row:last-child { border-bottom: none; }
.zdot { width: 12px; height: 12px; border-radius: 6px; flex-shrink: 0; background: var(--green); }
.zdot.orange { background: #D97706; } .zdot.red { background: var(--red); } .zdot.skip { background: #8A9099; }
.row-main { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.row-main b { font-size: 15px; }
.row-main span { font-size: 12px; color: var(--muted); }
.row-main span.orange { color: var(--amber-ink); } .row-main span.red { color: #9A1B12; }
.row-side { font-size: 12px; color: var(--muted); text-align: right; }
.batt { width: 44px; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 4px; margin-left: auto; }
.batt i { display: block; height: 100%; background: var(--green); }
.batt i.low { background: #D97706; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; margin: 0; }

.chips { display: flex; gap: 8px; }
.chip { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid #D5D8D2; background: var(--card); font-size: 13px; font-weight: 600; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.ev { display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: none; }
.ev time { font-size: 13px; font-weight: 700; color: var(--muted); width: 46px; flex-shrink: 0; }
.ev b.alert { color: #9A1B12; } .ev b.warn { color: var(--amber-ink); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 10px); background: linear-gradient(to top, var(--bg) 70%, rgba(242,243,239,0)); display: flex; justify-content: center; }
.tabbar { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; max-width: 480px; background: var(--card); border-radius: 22px; padding: 6px; box-shadow: 0 2px 12px rgba(20,24,31,.08); }
.tab { height: 48px; border: none; background: none; border-radius: 16px; font-size: 13px; font-weight: 600; position: relative; }
.tab.on { background: var(--ink); color: #fff; font-weight: 700; }
.tab-dot { position: absolute; top: 10px; right: 22%; width: 8px; height: 8px; border-radius: 4px; background: #D97706; }

.sheet { border: none; padding: 0; width: min(520px, 100%); max-width: 100%; margin: auto auto 0; border-radius: 22px 22px 0 0; background: var(--bg); color: var(--ink); max-height: 90vh; }
.sheet::backdrop { background: rgba(20,24,31,.45); }
#sheet-body { padding: 22px 20px calc(env(safe-area-inset-bottom) + 24px); display: flex; flex-direction: column; gap: 14px; }
.sheet h2 { margin: 0; font-size: 22px; font-weight: 800; }
.sheet p { margin: 0; font-size: 14px; line-height: 1.45; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
input, select { font: inherit; font-size: 16px; color: var(--ink); height: 48px; border-radius: 12px; border: 1px solid #CDD1CA; padding: 0 12px; background: #fff; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 15px; font-weight: 600; color: var(--ink); flex-direction: row; }
.switch-row:last-child { border-bottom: none; }
.switch-row input { width: 24px; height: 24px; accent-color: var(--green); }
.primary, .secondary, .danger { height: 50px; border-radius: 14px; font-weight: 700; font-size: 16px; border: none; }
.primary { background: var(--ink); color: #fff; }
.secondary { background: var(--card); border: 1px solid #CDD1CA; }
.danger { background: var(--card); color: var(--red); border: 1px solid #E8C2BE; }
.row-btns { display: flex; gap: 10px; } .row-btns > * { flex: 1; }
.error { color: var(--red); font-size: 14px; min-height: 1.2em; margin: 0; font-weight: 600; }

button.banner { border: none; text-align: left; width: 100%; }
label.upload { flex-direction: row; align-items: center; justify-content: center; color: var(--ink); font-size: 16px; margin-top: 8px; position: relative; }
label.upload input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.intro { margin: 0; font-size: 14px; line-height: 1.45; color: var(--muted); }
#setup-form { display: flex; flex-direction: column; gap: 14px; }
.sheet .field-note { font-size: 12px; font-weight: 500; color: var(--muted); }
.login { justify-content: center; min-height: 100vh; }
.login-card { display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { margin: 0; font-size: 30px; font-weight: 800; }
.logo { width: 64px; height: 64px; border-radius: 16px; overflow: hidden; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; }
#login-form { display: flex; flex-direction: column; gap: 14px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 86px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; max-width: 90%; text-align: center; z-index: 10; }
.toast.bad { background: var(--red); }

.sheet .card h2 { font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 10px; }
.sheet .card .primary, .sheet .card .secondary { width: 100%; margin-top: 4px; }
.card .list .switch-row { padding: 12px 0; }
.sheet .card label + label, .sheet .card p + label { margin-top: 12px; }

/* cameras */
.cam-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cam-tile { border: none; padding: 0; background: var(--card); border-radius: 16px; overflow: hidden; text-align: left; display: flex; flex-direction: column; }
.cam-tile img, .cam-tile .cam-empty { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #2B3440; display: block; }
.cam-tile span { padding: 8px 12px 10px; font-size: 14px; font-weight: 700; }
.cam-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #11151B; border-radius: 14px; overflow: hidden; }
.cam-frame video, .cam-frame img { width: 100%; height: 100%; object-fit: contain; display: block; background: #11151B; }
.cam-frame .cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #D5D9DE; font-size: 14px; text-align: center; padding: 16px; }
.cam-frame .live-badge { position: absolute; left: 10px; top: 10px; background: rgba(180,35,24,.9); color: #fff; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 3px 8px; border-radius: 6px; }
.alert-cam { background: var(--red); color: #fff; border-radius: 22px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ac-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 16px; }
.ac-close { width: 40px; height: 40px; border-radius: 20px; border: none; background: rgba(255,255,255,.2); color: #fff; font-size: 24px; line-height: 1; }
.viewer { border: none; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; background: #0B0E12; color: #fff; }
.viewer[open] { display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: calc(env(safe-area-inset-top) + 12px) 12px calc(env(safe-area-inset-bottom) + 16px); }
.viewer::backdrop { background: #0B0E12; }
.viewer-top { display: flex; justify-content: space-between; align-items: center; font-size: 18px; }
.viewer-nav { display: flex; gap: 10px; } .viewer-nav > * { flex: 1; }
.ev-snap { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; margin-top: 6px; border: none; padding: 0; background: #2B3440; }
.ev-snap img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; display: block; }

.viewer .secondary { color: var(--ink); }

/* playback */
.viewer[open] { justify-content: flex-start; overflow-y: auto; gap: 12px; }
.viewer { --pb-fg: #E9ECEF; --pb-muted: #9AA3AD; --pb-panel: #161B22; --pb-line: #2A313A;
  --ev-alarm: #E5483B; --ev-person: #F28C00; --ev-vehicle: #3B82F6; --ev-motion: #8A9099; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--pb-panel); border-radius: 14px; padding: 4px; }
.seg-btn { height: 40px; border: none; border-radius: 10px; background: none; color: var(--pb-muted); font-weight: 700; font-size: 15px; }
.seg-btn.on { background: #fff; color: #14181F; }
.pb { display: flex; flex-direction: column; gap: 12px; color: var(--pb-fg); }
.pb-day { display: flex; align-items: center; justify-content: space-between; }
.pb-day b { font-size: 16px; }
.pb-icon { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--pb-line); background: var(--pb-panel); color: var(--pb-fg); font-size: 20px; line-height: 1; }
.pb-icon.sm { width: 36px; height: 36px; font-size: 18px; }
.pb-icon.lg { width: 56px; height: 56px; border-radius: 28px; font-size: 20px; }
.pb-time { display: flex; justify-content: space-between; align-items: baseline; font-variant-numeric: tabular-nums; }
.pb-time span:first-child { font-size: 28px; font-weight: 800; letter-spacing: .02em; }
.pb-time span:last-child { font-size: 13px; color: var(--pb-muted); font-weight: 600; }
.pb-tl-wrap { display: flex; flex-direction: column; gap: 6px; }
.pb-tl { width: 100%; height: 84px; background: var(--pb-panel); border-radius: 12px; touch-action: none; cursor: grab; display: block; }
.pb-zoom { display: flex; align-items: center; justify-content: flex-end; gap: 10px; font-size: 13px; color: var(--pb-muted); font-weight: 600; }
.pb-ctrl { display: flex; align-items: center; justify-content: center; gap: 22px; }
.pb-play { width: 72px; height: 72px; border-radius: 36px; border: none; background: #fff; color: #14181F; font-size: 26px; }
.pb-speeds { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.pb-speeds button { height: 40px; border-radius: 10px; border: 1px solid var(--pb-line); background: var(--pb-panel); color: var(--pb-fg); font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.pb-speeds button.on { background: #fff; color: #14181F; border-color: #fff; }
.pb-only { flex-direction: row; align-items: center; gap: 10px; color: var(--pb-fg); font-size: 14px; font-weight: 600; }
.pb-only input { width: 22px; height: 22px; accent-color: #fff; flex-shrink: 0; }
.pb-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--pb-muted); font-weight: 600; }
.pb-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.ev-alarm { background: var(--ev-alarm); } .ev-person { background: var(--ev-person); }
.ev-vehicle { background: var(--ev-vehicle); } .ev-motion { background: var(--ev-motion); }
.pb-events { display: flex; flex-direction: column; background: var(--pb-panel); border-radius: 14px; overflow: hidden; }
.pb-ev { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: none; border-bottom: 1px solid var(--pb-line); background: none; color: var(--pb-fg); text-align: left; }
.pb-ev:last-child { border-bottom: none; }
.pb-ev.now { background: #232A33; }
.pb-ev i { width: 10px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
.pb-ev time { font-weight: 800; font-variant-numeric: tabular-nums; width: 64px; flex-shrink: 0; }
.pb-ev span { font-size: 14px; }
.pb-empty { padding: 14px; color: var(--pb-muted); font-size: 14px; }
.cam-frame canvas.pb-canvas { width: 100%; height: 100%; display: block; }
.viewer[open] > * { flex-shrink: 0; }
.viewer .cam-frame.big { position: sticky; top: 0; z-index: 2; box-shadow: 0 8px 16px #0B0E12; }

/* camera wall: 1, 4 or 9 at once */
.wall-layout { margin-bottom: 12px; background: #E3E5E0; grid-template-columns: repeat(3, 1fr); }
.wall-layout .seg-btn { color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.wall-layout .seg-btn.on { background: var(--ink); color: #fff; }
.lay { width: 18px; height: 12px; display: inline-block; border-radius: 2px;
  background: currentColor; }
.lay.l1 { -webkit-mask: none; }
.lay.l4 { background: linear-gradient(90deg, transparent 47%, var(--seg-gap, #E3E5E0) 47% 53%, transparent 53%),
  linear-gradient(0deg, transparent 45%, var(--seg-gap, #E3E5E0) 45% 55%, transparent 55%), currentColor; }
.lay.l9 { background: linear-gradient(90deg, transparent 30%, var(--seg-gap, #E3E5E0) 30% 35%, transparent 35% 65%, var(--seg-gap, #E3E5E0) 65% 70%, transparent 70%),
  linear-gradient(0deg, transparent 29%, var(--seg-gap, #E3E5E0) 29% 37%, transparent 37% 63%, var(--seg-gap, #E3E5E0) 63% 71%, transparent 71%), currentColor; }
.wall-layout .seg-btn.on .lay { --seg-gap: var(--ink); }
.wall-box { position: relative; background: #000; border-radius: 14px; overflow: hidden; }
.cam-wall { display: grid; gap: 2px; background: #000; aspect-ratio: 16 / 9; width: 100%; }
.cam-wall[data-n="1"] { grid-template-columns: 1fr; }
.cam-wall[data-n="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cam-wall[data-n="9"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.wall-tile { border: none; padding: 0; margin: 0; background: #11151B; position: relative; overflow: hidden; min-height: 0; display: block; width: 100%; height: 100%; }
.wall-tile.empty { background: #07090C; }
.wall-pic { position: absolute; inset: 0; }
.wall-pic img, .wall-pic video { width: 100%; height: 100%; object-fit: fill; display: block; background: #11151B; }
.wall-pic .cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #9AA3AD; font-size: 11px; text-align: center; padding: 6px; }
.wall-arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 64px; border: none; border-radius: 12px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 30px; line-height: 1; opacity: 0; transition: opacity .3s; z-index: 2; }
.wall-arrow.left { left: 6px; } .wall-arrow.right { right: 6px; }
.wall-box.peek .wall-arrow { opacity: 1; }
.wall-pager { text-align: center; font-size: 14px; font-weight: 700; color: var(--muted); margin: 10px 0 0; min-height: 20px; }

/* phone turned sideways: cameras fill the screen, nothing else in the way */
@media (orientation: landscape) and (max-height: 600px) {
  body.on-cameras { background: #000; overflow: hidden; }
  body.on-cameras .tabs, body.on-cameras #cameras > :not(.wall-box) { display: none !important; }
  body.on-cameras #cameras { position: fixed; inset: 0; padding: 0; margin: 0; max-width: none; background: #000; z-index: 20;
    display: flex; align-items: center; justify-content: center; }
  body.on-cameras .wall-box { border-radius: 0; width: min(100vw, calc(100vh * 16 / 9)); }
  .viewer[open] { padding: 0; justify-content: center; align-items: center; overflow: hidden; background: #000; }
  .viewer[open] > :not(#viewer-frame):not(.viewer-top) { display: none !important; }
  .viewer .viewer-top { position: fixed; top: 8px; right: 8px; z-index: 3; animation: fade-low .4s 3s forwards; }
  .viewer .viewer-top b { display: none; }
  .viewer .cam-frame.big { position: static; border-radius: 0; box-shadow: none; width: min(100vw, calc(100vh * 16 / 9)); }
}
@keyframes fade-low { to { opacity: .25; } }

/* when home can't be reached */
.sim-card p { margin: 0 0 12px; font-size: 15px; line-height: 1.45; }
.sim-card .secondary { width: 100%; margin-top: 4px; }
.sim-112 { display: flex; align-items: center; justify-content: center; text-decoration: none; margin-top: 10px; color: var(--red) !important; font-weight: 700; }
