:root {
  --bg: #111315;
  --band: #16181b;
  --surface: #262a30;
  --well: #1b1e22;
  --line: #5d6269;
  --hairline: #3a3f46;
  --text: #ffffff;
  --text-2: #c9ccd1;
  --text-3: #8b9097;
  --blue: #2aa9e6;
  --blue-fill: #3db2f0;
  --red: #f4533f;
  --amber: #f0a63a;
  --green: #3fc380;
  --radius: 10px;
  --col: 560px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  flex: none;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.screen {
  max-width: var(--col);
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(28px + var(--safe-bottom));
}

/* ---- Top bar ------------------------------------------------------------ */
.top {
  background: var(--surface);
  padding-top: var(--safe-top);
}

.topbar {
  display: grid;
  grid-template-columns: 50px 1fr 50px;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
}

.topbar.sticky-safe {
  padding-top: calc(10px + var(--safe-top));
}

.topbar h1,
.topbar .title {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--well);
  color: var(--blue);
  display: grid;
  place-items: center;
  position: relative;
}

.circle:active {
  filter: brightness(1.3);
}

/* ---- Modes ---------------------------------------------------------------- */
.modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 22px 28px 6px;
  align-items: start;
}

.mode {
  display: grid;
  justify-items: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 13px;
}

.mode-ring {
  width: 62px;
  height: 62px;
  margin: 6px;
  border-radius: 50%;
  background: var(--well);
  border: 1.5px solid var(--line);
  color: var(--text-2);
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.mode[aria-pressed='true'] {
  color: var(--text);
  font-weight: 600;
}

.mode[aria-pressed='true'] .mode-ring {
  transform: scale(1.19);
  border-color: transparent;
  color: #fff;
}

.mode[data-mode='disarmed'][aria-pressed='true'] .mode-ring {
  background: var(--blue);
}
.mode[data-mode='home'][aria-pressed='true'] .mode-ring {
  background: var(--amber);
}
.mode[data-mode='away'][aria-pressed='true'] .mode-ring {
  background: var(--red);
}

.mode.busy .mode-ring {
  opacity: 0.55;
}

.mode-caption {
  margin: 0;
  padding: 12px 0 18px;
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
}

.mode-caption b {
  color: var(--text);
  font-weight: 600;
}

/* ---- Dashboard ------------------------------------------------------------ */
.pad {
  padding: 16px 14px 0;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 13px 14px;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.tile svg {
  color: var(--blue);
  margin-bottom: auto;
}

.tile b {
  font-size: 13px;
  font-weight: 600;
  margin-top: 14px;
}

.tile small {
  font-size: 12px;
  color: var(--blue);
  margin-top: 2px;
  min-height: 15px;
}

.tile.center {
  align-items: center;
  text-align: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 8px;
}

.tile.center svg {
  margin: 0;
}

.tile.center b {
  margin: 0;
  line-height: 1.25;
}

.tile:active {
  filter: brightness(1.2);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 30px 14px 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.link {
  color: var(--blue);
  font-weight: 600;
  font-size: 13px;
}

.cams {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.cams.list {
  grid-template-columns: 1fr;
}

.cam {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  overflow: hidden;
  background: #1a1d21;
  cursor: pointer;
  display: block;
}

.cams.list .cam {
  aspect-ratio: 16 / 9;
}

.cam img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cam.asleep img {
  filter: grayscale(0.7) brightness(0.5);
}

.cam-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #3d4249;
}

.cam::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 46%;
  background: linear-gradient(rgba(0, 0, 0, 0.5), transparent);
  z-index: 1;
  pointer-events: none;
}

.cam-name {
  position: absolute;
  z-index: 2;
  top: 11px;
  left: 12px;
  right: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--blue);
  flex: none;
}

.dot.off {
  background: var(--text-3);
}

.dot.rec {
  background: var(--red);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.cam-more {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  width: 46px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #fff;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
}

.cam-age {
  position: absolute;
  z-index: 2;
  left: 12px;
  bottom: 12px;
  background: rgba(22, 24, 27, 0.86);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.cam-flag {
  position: absolute;
  z-index: 2;
  right: 10px;
  bottom: 12px;
  background: var(--red);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ---- Device page ---------------------------------------------------------- */
.hero {
  background: var(--surface);
  padding: 8px 28px 18px;
  border-bottom: 1px solid var(--hairline);
}

.hero-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 0 26px;
}

.device-art {
  color: var(--blue);
  display: grid;
  place-items: center;
}

.toggles {
  display: grid;
  gap: 26px;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  text-align: right;
  line-height: 1.3;
  max-width: 190px;
  margin-left: auto;
}

.switch {
  width: 68px;
  height: 32px;
  border-radius: 16px;
  background: #45494f;
  position: relative;
  flex: none;
  transition: background 0.15s ease;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 40px;
  height: 28px;
  border-radius: 14px;
  background: #8e9197;
  transition: transform 0.15s ease, background 0.15s ease;
}

.switch[aria-checked='true'] {
  background: var(--blue);
}

.switch[aria-checked='true']::after {
  transform: translateX(24px);
  background: #fff;
}

.switch.small {
  width: 52px;
  height: 30px;
}

.switch.small::after {
  width: 26px;
  height: 26px;
  border-radius: 13px;
}

.switch.small[aria-checked='true']::after {
  transform: translateX(22px);
}

.primary {
  width: 100%;
  height: 50px;
  border-radius: 8px;
  background: var(--blue-fill);
  color: #10202c;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

.primary:active {
  filter: brightness(0.9);
}

.primary[disabled] {
  opacity: 0.45;
}

.secondary {
  height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
}

.danger {
  color: var(--red);
}

.notice {
  margin: 14px 14px 0;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--amber);
  background: rgba(240, 166, 58, 0.08);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-2);
}

.notice b {
  color: var(--text);
}

.notice .link {
  display: inline-block;
  margin-top: 8px;
  font-size: 14px;
}

/* ---- Lists and settings rows --------------------------------------------- */
.band {
  background: var(--band);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  padding: 26px 18px 10px;
}

.rows {
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 18px;
  min-height: 58px;
  width: 100%;
  text-align: left;
}

.row + .row {
  border-top: 1px solid var(--hairline);
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-main b {
  display: block;
  font-size: 15.5px;
  font-weight: 600;
}

.row-main span {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-2);
}

.row-value {
  color: var(--text-2);
  font-size: 15px;
  text-align: right;
  overflow-wrap: anywhere;
}

.row svg.chev {
  color: var(--text-2);
}

.row select,
.field {
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 15px;
  min-width: 0;
}

.field {
  width: 100%;
  height: 46px;
}

.stack {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

.stack p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-2);
}

.stack code {
  display: block;
  padding: 10px 12px;
  background: var(--well);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
  color: var(--text);
  user-select: all;
}

.inline {
  display: flex;
  gap: 10px;
}

.inline .field {
  flex: 1;
}

.pair {
  display: grid;
  justify-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 20px;
  background: var(--well);
  color: var(--text-2);
  white-space: nowrap;
}

.pill.home {
  color: var(--green);
}

/* ---- History -------------------------------------------------------------- */
.chips {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  height: 34px;
  padding: 0 14px;
  border-radius: 17px;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.chip[aria-pressed='true'] {
  background: var(--blue);
  border-color: var(--blue);
  color: #0d1c27;
}

.day {
  margin: 0;
  padding: 22px 14px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.event {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: center;
  width: 100%;
  padding: 8px 14px;
  text-align: left;
}

.event:active {
  background: var(--band);
}

.event-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  background: #1a1d21;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: #3d4249;
}

.event-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.event-thumb em {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(22, 24, 27, 0.86);
  border-radius: 5px;
  padding: 2px 5px;
  font-size: 11px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.event-info b {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  font-weight: 600;
}

.event-info b svg {
  color: var(--blue);
}

.event-info span {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-2);
}

.event-info small {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--text-3);
}

.event.muted .event-info b,
.event.muted .event-info b svg {
  color: var(--text-3);
}

.empty {
  padding: 70px 30px;
  text-align: center;
  color: var(--text-2);
  font-size: 14.5px;
  line-height: 1.55;
}

.empty svg {
  margin: 0 auto 16px;
  color: #3d4249;
}

.empty b {
  display: block;
  color: var(--text);
  font-size: 17px;
  margin-bottom: 6px;
}

.more {
  display: block;
  margin: 18px auto 0;
}

/* ---- Player --------------------------------------------------------------- */
#overlay:empty {
  display: none;
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.player {
  position: absolute;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
}

/* the picture gets whatever height is left; placing the video absolutely keeps its natural size out of the layout */
.player .stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.player header,
.player footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--band);
}

.player header {
  padding-top: calc(10px + var(--safe-top));
}

.player footer {
  justify-content: space-between;
  padding-bottom: calc(12px + var(--safe-bottom));
}

.player .who {
  flex: 1;
  min-width: 0;
}

.player .who b {
  display: block;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player .who small {
  color: var(--text-2);
  font-size: 12.5px;
}

.scrub {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px;
  background: var(--band);
  min-width: 0;
}

.scrub .icon-btn {
  width: 38px;
  height: 38px;
}

.clip-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
  min-width: 32px;
  text-align: center;
}

/* a range input has a built-in minimum width; width: 0 with flex-grow lets it fit any screen */
.seek {
  flex: 1 1 0;
  width: 0;
  min-width: 30px;
  height: 32px;
  margin: 0 2px;
  accent-color: var(--blue);
  cursor: pointer;
}

.player video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.player header,
.player .scrub,
.player footer {
  flex: none;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--blue);
  background: var(--well);
  flex: none;
}

.icon-btn[disabled] {
  opacity: 0.3;
}

/* ---- Live view ------------------------------------------------------------ */
.live {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 10;
}

.live video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.live-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 14px 26px;
  background: linear-gradient(rgba(0, 0, 0, 0.7), transparent);
}

.live-top b {
  font-size: 17px;
  display: block;
}

.live-top small {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.live-badge {
  background: var(--red);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.8px;
  border-radius: 4px;
  padding: 2px 5px;
}

.live:not(.connected) .live-badge,
.live:not(.connected) #live-clock {
  display: none;
}

.live-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  padding: 30px;
  text-align: center;
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.5;
  pointer-events: none;
}

.live-status > * {
  pointer-events: auto;
}

.live-status:empty {
  display: none;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--blue);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.live-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 30px 14px calc(22px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

.live-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(38, 42, 48, 0.92);
  border: 1px solid var(--line);
  color: #fff;
  display: grid;
  place-items: center;
}

.live-btn.on {
  background: var(--blue);
  border-color: var(--blue);
  color: #0d1c27;
}

.live-btn.end {
  width: 64px;
  height: 64px;
  background: var(--red);
  border-color: var(--red);
}

.live-btn.rec.on {
  background: #fff;
  border-color: #fff;
  color: var(--red);
}

/* ---- Menu, status, toast --------------------------------------------------- */
.scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(300px, 82vw);
  background: var(--surface);
  padding: calc(18px + var(--safe-top)) 0 20px;
  border-right: 1px solid var(--hairline);
}

.drawer h3 {
  margin: 0;
  padding: 8px 22px 18px;
  font-size: 19px;
}

.drawer a {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 15px 22px;
  font-size: 16px;
  font-weight: 500;
}

.drawer a svg {
  color: var(--blue);
}

.drawer a:active {
  background: var(--well);
}

.status-screen {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: 30px;
  text-align: center;
  max-width: 440px;
  margin: 0 auto;
}

.status-screen h1 {
  margin: 0;
  font-size: 22px;
}

.status-screen p {
  margin: 0;
  color: var(--text-2);
  line-height: 1.55;
  font-size: 15px;
}

.status-screen code {
  display: block;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  color: var(--text);
}

.status-screen form {
  display: grid;
  gap: 12px;
  width: min(300px, 80vw);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  background: #f3f4f6;
  color: #14181d;
  font-size: 14px;
  font-weight: 500;
  padding: 11px 16px;
  border-radius: 10px;
  max-width: min(90vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 40;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 700px) {
  :root {
    --col: 760px;
  }
  .cams {
    grid-template-columns: repeat(3, 1fr);
  }
  .cams.list {
    grid-template-columns: repeat(2, 1fr);
  }
  .tile {
    min-height: 128px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
