/* Dashboard design: "premium calm". Shared components (sheets, keypad, settings,
   buttons, fields) live in styles.css; this file is the dashboard layout. */

:root {
  --bg: #0b0d11;
  --bg-2: #11141a;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.07);
  --surface-3: rgba(255, 255, 255, 0.11);
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #f3f5f8;
  --text-2: #a3acb9;
  --text-3: #6b7482;
  --ok: #3ddc97;
  --armed: #f5b13d;
  --alarm: #ff5a4e;
  --info: #6aa9ff;
  --radius: 26px;
  --radius-sm: 16px;
  --rail: 96px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

body {
  display: block;
  background: radial-gradient(120vmax 90vmax at 70% -20%, #161b24 0%, var(--bg) 55%);
  overflow: hidden;
}

/* Ambient light, softer than before */
.aura { opacity: 0.35; inset: -40vmax auto auto -30vmax; width: 100vmax; height: 100vmax; }

/* ------------------------------------------------------------ rail */
.rail {
  position: fixed; z-index: 5; top: 0; bottom: 0; left: 0; width: var(--rail);
  padding: calc(env(safe-area-inset-top) + 22px) 10px calc(env(safe-area-inset-bottom) + 22px);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
}
.rail-brand { height: 52px; display: grid; place-items: center; margin-bottom: 14px; }
.rail-brand .brand-mark { font-size: 30px; color: var(--accent); transition: color 0.6s; }
.rail-brand img.brand-mark { height: 40px; max-width: 70px; }
.rail-item {
  width: 76px; padding: 10px 0 9px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--text-3);
  transition: background 0.2s, color 0.2s;
}
.rail-item svg { font-size: 23px; }
.rail-item:hover { color: var(--text-2); }
.rail-item.is-on { background: var(--surface-2); color: var(--text); }
.rail-item.is-on svg { color: var(--accent); }
.rail-spacer { flex: 1; }
.rail-wall { padding: 12px 0; }
.rail .sos-btn { width: 52px; height: 52px; font-size: 12px; margin-top: 8px; }

/* ------------------------------------------------------------ app frame */
.app {
  position: relative; z-index: 1;
  height: 100vh; height: 100dvh;
  margin-left: var(--rail);
  padding: calc(env(safe-area-inset-top) + 18px) 34px 0 36px;
  display: flex; flex-direction: column;
}
.bar { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 14px; }
.greeting { font-size: 14px; color: var(--text-3); font-weight: 550; }
.bar h1 { margin: 2px 0 0; font-size: 30px; font-weight: 700; letter-spacing: -0.025em; }
.bar-right { display: flex; align-items: center; gap: 18px; }
.clock { text-align: right; }
.clock-time { font-size: 34px; font-weight: 250; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.clock-date { font-size: 12px; color: var(--text-3); margin-top: 5px; letter-spacing: 0.04em; }
.conn { padding: 7px 12px 7px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.banner { margin: 0 0 12px; }

.view { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: calc(env(safe-area-inset-bottom) + 28px); scrollbar-width: none; animation: view-in 0.35s var(--ease); }
.view::-webkit-scrollbar { display: none; }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } }
.view-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.card, .widget {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
}

/* ------------------------------------------------------------ home */
.view-home { display: grid; grid-template-columns: minmax(340px, 0.95fr) minmax(0, 1.1fr); gap: 28px; align-items: start; }
.home-hero {
  position: sticky; top: 0;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 18px 8px 8px;
}

/* The status ring: full when armed, empty when disarmed, pulsing in an alarm. */
.ring { position: relative; width: min(300px, 70vw); aspect-ratio: 1; }
.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.ring-arc {
  fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 603; stroke-dashoffset: 603;
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--accent) 55%, transparent));
  transition: stroke-dashoffset 1.1s var(--ease), stroke 0.6s;
}
.ring-core {
  position: absolute; inset: 15%; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 72%);
}
.ring-icon { font-size: 44px; color: var(--accent); transition: color 0.6s; }
.ring-label { font-size: 30px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.05; max-width: 90%; }
body[data-status="alarm"] .ring-arc { animation: ring-pulse 1.2s ease-in-out infinite; }
body[data-status="alarm"] .ring-label { color: var(--alarm); }
@keyframes ring-pulse { 50% { stroke-width: 16; opacity: 0.6; } }
body[data-status="armed"] .ring { animation: breathe-ring 4s ease-in-out infinite; }
@keyframes breathe-ring { 50% { transform: scale(1.015); } }
.status-sub { margin: 14px 0 0; font-size: 16px; color: var(--text-2); min-height: 22px; }

.ack-row { width: 100%; max-width: 440px; margin-top: 16px; }
.actions { width: 100%; max-width: 460px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 26px; }
.action {
  height: 76px; border-radius: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; font-weight: 650;
  background: var(--surface-2); border: 1px solid var(--line);
  transition: transform 0.15s var(--ease), background 0.2s;
}
.action svg { font-size: 24px; color: var(--armed); }
.action-off svg { color: var(--ok); }
.action:active { transform: scale(0.96); background: var(--surface-3); }

.home-widgets { display: flex; flex-direction: column; gap: 16px; padding-top: 6px; }
.widget { padding: 18px 18px 18px; }
.widget-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.widget-head h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; color: var(--text); }
.count { font-size: 13px; color: var(--text-3); }

.widget-camera { padding: 0; overflow: hidden; }
.widget-camera .camera { border: 0; border-radius: 0; width: 100%; }

.chips-row { display: flex; flex-wrap: wrap; gap: 8px; }
.scenario {
  height: 44px; padding: 0 16px 0 13px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--surface-2); border: 1px solid var(--line); font-size: 14.5px; font-weight: 600;
}
.scenario svg { font-size: 17px; color: var(--text-2); }
.scenario:active { background: var(--surface-3); }

/* Outputs as calm toggles */
.toggles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.toggle-tile {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 12px 14px; border-radius: 18px; text-align: left; min-height: 60px;
  background: var(--surface-2); border: 1px solid var(--line);
  transition: background 0.25s, border-color 0.25s;
}
.toggle-tile svg { font-size: 21px; color: var(--text-3); flex: none; transition: color 0.25s; }
.toggle-tile .t-name { font-size: 14px; font-weight: 600; line-height: 1.2; }
.toggle-tile .t-state { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.toggle-tile.is-on { background: color-mix(in srgb, #ffd27a 12%, transparent); border-color: color-mix(in srgb, #ffd27a 30%, transparent); }
.toggle-tile.is-on svg, .toggle-tile.is-on .t-state { color: #ffd27a; }

/* Areas: compact rows with a segmented control */
.areas { display: flex; flex-direction: column; gap: 10px; }
.area { display: flex; flex-direction: column; gap: 10px; padding: 0; background: none; border: 0; }
.area + .area { border-top: 1px solid var(--line); padding-top: 12px; }
.area-top { display: flex; align-items: center; justify-content: space-between; }
.area-name { font-size: 15px; font-weight: 600; }

.widget-system { display: flex; padding: 6px; }
.sys { flex: 1; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sys + .sys { border-left: 1px solid var(--line); }
.sys-label { font-size: 11px; color: var(--text-3); letter-spacing: 0.06em; text-transform: uppercase; }
.sys-value { font-size: 19px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------ segmented control */
.segmented { display: inline-flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.segmented button { height: 36px; padding: 0 14px; border-radius: 10px; display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.segmented button svg { font-size: 17px; }
.segmented button.is-on { background: var(--surface-3); color: var(--text); }

/* ------------------------------------------------------------ zones & cameras views */
.view-zones .zones { overflow: visible; mask-image: none; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; padding: 0; }
.zone { border-radius: 18px; min-height: 68px; }
.view-cameras .cameras { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.camera { border-radius: var(--radius); }

/* Floor plan */
.plan-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.plan-floors { display: flex; gap: 6px; flex-wrap: wrap; }
.plan {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  touch-action: none;
}
.plan img.plan-img { display: block; width: 100%; height: auto; opacity: 0.92; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.plan-empty { padding: 60px 20px; text-align: center; color: var(--text-3); }
.pin {
  --c: var(--ok);
  position: absolute; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 6px; border-radius: 999px;
  background: color-mix(in srgb, #000 55%, transparent); border: 1px solid color-mix(in srgb, var(--c) 55%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-size: 12px; font-weight: 600; color: #fff; white-space: nowrap;
}
.pin::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 10px var(--c); flex: none; }
.pin[data-s="open"] { --c: var(--armed); }
.pin[data-s="alert"] { --c: var(--alarm); animation: pin-pulse 1s ease-in-out infinite; }
.pin[data-s="bypassed"] { --c: var(--info); opacity: 0.75; }
@keyframes pin-pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--alarm) 30%, transparent); } }
.plan.is-editing .pin { cursor: grab; outline: 1px dashed var(--line-2); }
.plan-edit { margin-top: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.plan-tray { display: flex; flex-wrap: wrap; gap: 6px; }
.plan-tray .chip { cursor: grab; }

/* ------------------------------------------------------------ activity view */
.view-activity .activity-list { max-width: 820px; padding: 8px 22px 16px; margin: 0; max-height: none; overflow: visible; }

/* ------------------------------------------------------------ wall display */
.wall {
  position: fixed; inset: 0; z-index: 40;
  display: grid; grid-template-columns: 1fr minmax(0, 0.9fr); align-items: center; gap: 40px;
  padding: 6vh 6vw;
  background: radial-gradient(90vmax 70vmax at 20% 10%, color-mix(in srgb, var(--accent) 10%, #080a0e), #050608 70%);
  animation: fade 0.6s ease;
  cursor: none;
}
.wall-clock { font-size: clamp(90px, 15vw, 210px); font-weight: 200; letter-spacing: -0.05em; line-height: 0.9; font-variant-numeric: tabular-nums; }
.wall-date { font-size: clamp(18px, 2.2vw, 28px); color: var(--text-2); margin-top: 18px; }
.wall-status { display: inline-flex; align-items: center; gap: 12px; margin-top: 34px; padding: 12px 22px 12px 18px; border-radius: 999px; background: var(--surface-2); font-size: clamp(18px, 2vw, 26px); font-weight: 650; }
.wall-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 18px var(--accent); }
.wall-cam { position: relative; border-radius: 28px; overflow: hidden; aspect-ratio: 16 / 9; background: #000; }
.wall-cam img { width: 100%; height: 100%; object-fit: cover; display: block; }
.wall-cam span { position: absolute; left: 14px; bottom: 14px; padding: 6px 12px; border-radius: 999px; background: rgba(0,0,0,0.55); font-size: 14px; font-weight: 600; }
.wall-hint { position: absolute; bottom: 4vh; left: 0; right: 0; text-align: center; font-size: 13px; color: var(--text-3); }
.wall.is-night { filter: brightness(0.45); }
.wall.is-night .wall-cam { opacity: 0.6; }
body[data-status="alarm"] .wall { filter: none; }

/* ------------------------------------------------------------ countdown */
.countdown-box { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 20px; }
.countdown-ring { position: relative; width: min(260px, 64vw); aspect-ratio: 1; }
.countdown-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.countdown-ring .ring-arc { stroke: var(--cd, var(--armed)); stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear; }
.countdown-num { position: absolute; inset: 0; display: grid; place-items: center; font-size: 84px; font-weight: 250; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.countdown-title { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 8px; }
.countdown-sub { font-size: 15px; color: var(--text-2); max-width: 360px; }
.countdown-actions { display: flex; gap: 10px; margin-top: 14px; }
.countdown.is-entry { --cd: var(--alarm); }

/* ------------------------------------------------------------ portrait iPad / phones */
@media (max-width: 1000px) {
  .view-home { grid-template-columns: 1fr; }
  .home-hero { position: static; }
  .app { padding-left: 24px; padding-right: 24px; }
}
@media (max-width: 760px) {
  :root { --rail: 0px; }
  body { overflow: hidden; }
  .rail {
    top: auto; right: 0; width: auto; height: calc(68px + env(safe-area-inset-bottom));
    padding: 6px 8px env(safe-area-inset-bottom); flex-direction: row; justify-content: space-around;
    border-right: 0; border-top: 1px solid var(--line);
  }
  .rail-brand, .rail-spacer, .rail-wall { display: none; }
  .rail-item { width: auto; flex: 1; padding: 8px 0 6px; border-radius: 14px; font-size: 10.5px; }
  .rail-item svg { font-size: 21px; }
  .rail .sos-btn { width: 44px; height: 44px; margin: 6px 4px 0; flex: none; }
  .app { padding: calc(env(safe-area-inset-top) + 12px) 16px 0; height: calc(100dvh - 68px - env(safe-area-inset-bottom)); }
  .bar h1 { font-size: 24px; }
  .clock-date, .conn span:last-child { display: none; }
  .clock-time { font-size: 24px; }
  .ring { width: min(240px, 66vw); }
  .ring-label { font-size: 24px; }
  .actions { gap: 8px; }
  .action { height: 68px; font-size: 13px; }
  .view-cameras .cameras { grid-template-columns: 1fr; }
  .wall { grid-template-columns: 1fr; text-align: center; }
}

/* ------------------------------------------------------------ light mode (follows the device) */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0f4; --bg-2: #ffffff;
    --surface: rgba(255, 255, 255, 0.78); --surface-2: rgba(16, 24, 40, 0.05); --surface-3: rgba(16, 24, 40, 0.09);
    --line: rgba(16, 24, 40, 0.07); --line-2: rgba(16, 24, 40, 0.13);
    --text: #121722; --text-2: #4a5465; --text-3: #8a93a3;
    --ok: #12b07a; --armed: #e0901a; --alarm: #e5392d; --info: #2f7de1;
  }
  body { background: radial-gradient(120vmax 90vmax at 70% -20%, #ffffff 0%, var(--bg) 60%); color: var(--text); }
  .aura { opacity: 0.18; }
  .card, .widget { box-shadow: 0 1px 2px rgba(16,24,40,0.04), 0 8px 24px rgba(16,24,40,0.05); }
  .rail { background: color-mix(in srgb, #fff 75%, transparent); }
  .sheet, .settings { background: #fff; color: var(--text); }
  .overlay { background: rgba(240, 242, 246, 0.6); }
  .toast { background: #fff; color: var(--text); }
  .kp-grid button { background: var(--surface-2); color: var(--text); }
  .kp-ok, .btn.primary, .sheet-actions button.primary { background: var(--text); color: #fff; }
  .field input, .field select, .name-input, .login input { background: #fff; color: var(--text); border-color: var(--line-2); color-scheme: light; }
  .chip.is-on { background: var(--text); color: #fff; border-color: var(--text); }
  .pin { background: rgba(255,255,255,0.85); color: var(--text); }
  .toggle-tile.is-on { background: color-mix(in srgb, #f2b53a 16%, #fff); }
  .toggle-tile.is-on svg, .toggle-tile.is-on .t-state { color: #b77a00; }
  .login { background: radial-gradient(80vmax 80vmax at 20% 0%, color-mix(in srgb, var(--brand, #12b07a) 12%, transparent), transparent 60%), var(--bg); }
  .zone { background: var(--surface); }
  .wall { color: #f3f5f8; }
  .seg { background: var(--surface-2); border-color: var(--line); }
  .seg button { color: var(--text-2); }
  .seg button.is-on { background: #fff; box-shadow: 0 1px 3px rgba(16,24,40,0.12); }
}
.pin.is-picked { outline: 2px solid var(--info); outline-offset: 2px; }
.settings .item-icon { flex: none; }
.area { border-radius: 0; }
.countdown-ring .ring-arc { filter: none; } .countdown-ring { filter: drop-shadow(0 0 18px color-mix(in srgb, var(--cd, var(--armed)) 45%, transparent)); }

/* ------------------------------------------------------------ public demo */
.demo-pill {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  display: flex; align-items: center; gap: 10px; white-space: nowrap;
  padding: 8px 8px 8px 14px; border-radius: 999px;
  font-size: 13px; color: var(--text-2);
  background: color-mix(in srgb, var(--bg-2) 85%, transparent);
  border: 1px solid var(--line-2);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.demo-pill b { color: var(--text); letter-spacing: 0.08em; }
.demo-pill a { color: var(--text); text-decoration: none; padding: 5px 11px; border-radius: 999px; background: var(--surface-2); }
.demo-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent, var(--info)); }
/* Phones: above the tab bar */
@media (max-width: 760px) { .demo-pill { bottom: calc(env(safe-area-inset-bottom) + 84px); font-size: 12px; } }
