:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8f9fb;
  --text: #171a1f;
  --muted: #747b86;
  --line: #e4e7ec;
  --blue: #526bc4;
  --blue-soft: #eef1ff;
  --green: #22a56f;
  --green-soft: #e9f8f1;
  --amber: #f2a928;
  --red: #db4961;
  --red-soft: #fff0f3;
  --shadow: 0 10px 34px rgba(27, 37, 55, .08);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 14px/1.5 Inter, "Microsoft YaHei", system-ui, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
[hidden], .hidden { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.muted, .empty { color: var(--muted); }
.empty { padding: 42px 20px; text-align: center; }

.camera-header {
  height: 78px;
  padding: max(10px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255,255,255,.95);
  border-bottom: 1px solid #f0f1f3;
  backdrop-filter: blur(16px);
}
.camera-title { text-align: center; min-width: 0; }
.camera-title strong, .camera-title small { display: block; }
.camera-title strong { font-size: 20px; letter-spacing: .02em; }
.camera-title small { color: var(--muted); font-size: 10px; margin-top: 1px; }
.header-actions { display: flex; justify-content: flex-end; gap: 8px; }
.icon-button {
  width: 42px;
  height: 42px;
  padding: 9px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}
.icon-button:hover, .icon-button:focus-visible { background: #f0f2f5; outline: none; }
.icon-button svg, .action-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.camera-tabs {
  height: 60px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  position: sticky;
  top: 78px;
  z-index: 29;
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid var(--line);
}
.camera-tab {
  position: relative;
  border: 0;
  background: transparent;
  color: #6f747d;
  font-size: 16px;
  font-weight: 600;
}
.camera-tab::after { content: ""; position: absolute; left: 31%; right: 31%; bottom: 0; height: 4px; border-radius: 4px 4px 0 0; background: transparent; }
.camera-tab.active { color: var(--text); }
.camera-tab.active::after { background: var(--blue); }

.camera-shell { width: min(940px, 100%); margin: 0 auto; padding: 24px 20px max(72px, env(safe-area-inset-bottom)); }
.view-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.live-heading, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.live-heading h1, .section-heading h1 { margin: 0; font-size: 23px; }
.live-heading p, .section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.online { color: var(--green); background: var(--green-soft); }
.status.offline { color: var(--red); background: var(--red-soft); }

.video-stage { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; border-radius: 14px; }
.video-stage video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; color: #c8ccd2; background: radial-gradient(circle, #1c2229, #050607); text-align: center; pointer-events: none; }
.live-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 18px 0 0; }
.live-action { display: grid; justify-items: center; gap: 7px; padding: 8px 3px; border: 0; border-radius: 14px; background: transparent; color: #424750; font-size: 12px; }
.live-action:hover, .live-action:focus-visible { background: var(--surface-soft); outline: none; }
.live-action.active { color: var(--blue); }
.action-icon { width: 42px; height: 42px; display: grid; place-items: center; padding: 9px; border: 1px solid var(--line); border-radius: 50%; background: #fff; }
.live-action.active .action-icon { color: #fff; border-color: var(--blue); background: var(--blue); }
.action-feedback { min-height: 20px; margin: 5px 0 0; color: var(--blue); text-align: center; font-size: 12px; }
.privacy-strip { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 14px; background: var(--surface-soft); border-radius: 14px; }
.privacy-strip strong, .privacy-strip small { display: block; }
.privacy-strip small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.privacy-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px var(--green-soft); }

input { min-height: 42px; padding: 9px 12px; color: var(--text); background: #fff; border: 1px solid var(--line); border-radius: 11px; }
.primary, .secondary, .danger, .danger-outline { min-height: 42px; padding: 9px 16px; border-radius: 11px; font-weight: 700; }
.primary { border: 1px solid var(--blue); background: var(--blue); color: #fff; }
.secondary { border: 1px solid var(--line); background: #fff; color: var(--text); }
.danger { border: 1px solid var(--red); background: var(--red); color: #fff; }
.danger-outline { border: 1px solid #f1b4be; background: var(--red-soft); color: #bf324a; }
.date-tools { display: flex; gap: 8px; }

.recording-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.timeline-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-button { min-height: 36px; padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--muted); }
.filter-button.active { color: var(--blue); border-color: var(--blue); background: var(--blue-soft); }
.timeline-legend { display: flex; flex-wrap: wrap; gap: 12px 20px; margin: 10px 0; color: var(--muted); font-size: 12px; }
.timeline-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-marker { display: inline-grid; place-items: center; font-style: normal; }
.legend-marker.cat { width: 20px; height: 20px; border-radius: 50%; background: #ffd56c; color: #503400; font-size: 9px; font-weight: 800; box-shadow: 0 0 0 4px #fff6dd; }
.legend-marker.motion { width: 8px; height: 15px; border-radius: 99px; background: #9ba4ae; }
.recording-list-summary { display: flex; justify-content: space-between; gap: 12px; min-height: 24px; padding: 5px 0 10px; color: var(--muted); font-size: 12px; }
.cleanup-feedback.success { color: var(--green); }
.cleanup-feedback.error { color: var(--red); }

.timeline { display: grid; gap: 12px; }
.timeline-block { width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: #fff; transition: border-color .15s, box-shadow .15s; content-visibility: auto; contain-intrinsic-size: 220px; }
.timeline-block.is-selected { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.timeline-block.has-cat-events { border-color: #efc867; }
.timeline-row-header { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; align-items: center; gap: 16px; padding: 16px 17px 9px; }
.timeline-summary { min-width: 0; padding: 0; border: 0; background: transparent; color: var(--text); text-align: left; }
.timeline-range { display: block; font-size: 16px; font-weight: 750; }
.timeline-summary small { display: block; color: var(--muted); margin-top: 3px; }
.timeline-event-counts, .timeline-row-actions { display: flex; gap: 7px; }
.event-count { display: inline-flex !important; justify-content: center; min-width: 70px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-soft); color: #8a919a; font-size: 11px; font-weight: 700; }
.event-count.cat.active { color: #9b6700; border-color: #edc65e; background: #fff8e5; }
.event-count.motion.active { color: #58636d; border-color: #c7cdd3; background: #f3f5f7; }
.timeline-row-actions button { min-width: 72px; min-height: 36px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); font-size: 12px; font-weight: 700; }
.timeline-row-actions .row-play { color: #fff; border-color: var(--blue); background: var(--blue); }
.timeline-event-track { position: relative; height: 34px; margin: 0 22px 10px; }
.timeline-event-track::before { content: ""; position: absolute; left: 0; right: 0; top: 16px; height: 3px; border-radius: 10px; background: #e3e6ea; }
.event-track-empty { position: absolute; left: 50%; top: 4px; transform: translateX(-50%); color: #a0a6ae; font-size: 10px; }
.event-marker { position: absolute; z-index: 2; left: var(--event-position); top: 16px; transform: translate(-50%,-50%); display: grid; place-items: center; padding: 0; border: 2px solid #fff; }
.event-marker.cat { width: 22px; height: 22px; border-radius: 50%; color: #503400; background: #ffd56c; font-size: 9px; font-weight: 900; box-shadow: 0 0 0 3px #fff3cf; }
.event-marker.motion { width: 9px; height: 17px; border-radius: 99px; background: #929ca7; }
.event-marker.other { width: 12px; height: 12px; border-radius: 50%; background: var(--blue); }
.event-marker.is-selected { box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--blue); }
.cat-event-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 9px; padding: 0 16px 14px; }
.event-thumbnail { display: grid; grid-template-columns: 88px minmax(0,1fr); align-items: center; gap: 10px; width: 100%; padding: 8px; border: 1px solid #ead79e; border-radius: 12px; background: #fffdf7; color: var(--text); text-align: left; }
.event-thumbnail.is-selected { border-color: var(--amber); box-shadow: 0 0 0 2px #fff0c5; }
.event-thumbnail-frame { width: 88px; height: 54px; display: grid; place-items: center; overflow: hidden; border-radius: 8px; background: #111; }
.event-thumbnail-frame img { width: 100%; height: 100%; object-fit: cover; }
.event-thumbnail-placeholder { display: grid !important; place-items: center; width: 100%; height: 100%; background: #ffe19a; color: #6b4900; font-weight: 800; }
.event-thumbnail-placeholder[hidden] { display: none !important; }
.event-thumbnail-copy { min-width: 0; }
.event-thumbnail-copy strong, .event-thumbnail-copy small { display: block; }
.event-thumbnail-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.event-thumbnail-copy small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.segment-details { padding: 10px 16px 14px; border-top: 1px solid var(--line); background: var(--surface-soft); }
.segment-detail-list { display: grid; gap: 7px; }
.segment-detail-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
.segment-detail-row strong, .segment-detail-row small { display: block; }
.segment-detail-row small { color: var(--muted); font-size: 10px; }
.segment-play { min-height: 34px; padding: 6px 10px; border: 1px solid var(--blue); border-radius: 9px; background: var(--blue); color: #fff; }

.event-list { display: grid; gap: 10px; }
.event { display: flex; gap: 13px; padding: 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); }
.event > span { width: 9px; height: 9px; flex: 0 0 auto; margin-top: 6px; border-radius: 50%; background: var(--blue); }
.event.warning > span { background: var(--amber); }
.event.critical > span, .event.error > span { background: var(--red); }
.event strong, .event small { display: block; }
.event small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.settings-card, .settings-list { border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.account-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 13px; padding: 17px; }
.account-card strong, .account-card small { display: block; }
.account-card small { color: var(--muted); font-size: 11px; }
.account-card form { margin: 0; }
.avatar { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px; color: #fff; background: linear-gradient(140deg, #637ce0, #4059b2); font-size: 20px; font-weight: 800; }
.settings-list { margin-top: 14px; overflow: hidden; }
.settings-list article { display: flex; align-items: center; gap: 13px; padding: 16px; }
.settings-list article + article { border-top: 1px solid var(--line); }
.settings-list small, .settings-list strong { display: block; }
.settings-list small { color: var(--muted); font-size: 11px; }
.settings-list strong { margin-top: 2px; }
.setting-icon { width: 40px; height: 40px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 13px; color: var(--blue); background: var(--blue-soft); font-weight: 800; }

body.modal-open { overflow: hidden; }
dialog { color: var(--text); }
.playback-dialog, .cleanup-dialog { width: min(920px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: 0 28px 100px rgba(0,0,0,.3); overflow: auto; }
.cleanup-dialog { width: min(560px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(16,20,28,.68); backdrop-filter: blur(4px); }
.playback-dialog-content { display: grid; gap: 14px; padding: 18px; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.dialog-header small, .dialog-header strong { display: block; }
.dialog-header small { color: var(--muted); }
.dialog-header strong { font-size: 17px; }
.playback-video-stage { position: relative; aspect-ratio: 16/9; overflow: hidden; border-radius: 14px; background: #000; }
.playback-video-stage video { display: block; width: 100%; height: 100%; object-fit: contain; }
.playback-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 18px; color: #d3d6da; background: radial-gradient(circle, #20262d, #030405); pointer-events: none; }
.dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 11px; }
.dialog-footer p { margin: 0; }
.download { color: var(--blue); font-weight: 700; text-decoration: none; }
.cleanup-dialog-content { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 15px; padding: 22px; }
.cleanup-dialog h2 { margin: 3px 0 8px; }
.cleanup-warning-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--red); background: var(--red-soft); font-size: 22px; font-weight: 900; }
.cleanup-safety-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; margin: 14px 0; }
.cleanup-safety-grid > div { padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.cleanup-safety-grid small, .cleanup-safety-grid strong { display: block; }
.cleanup-safety-reasons { padding: 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); font-size: 11px; }
.irreversible-warning, .cleanup-dialog-error { padding: 11px; border-radius: 10px; color: #b72e46; background: var(--red-soft); font-size: 12px; }
.cleanup-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: #eef1f6; }
.login-card { width: min(430px,100%); padding: 38px; border: 1px solid var(--line); border-radius: 24px; background: #fff; box-shadow: var(--shadow); }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; color: #fff; background: linear-gradient(140deg,#637ce0,#4059b2); font-size: 26px; font-weight: 900; }
.login-card h1 { margin: 18px 0 0; }
.login-form { display: grid; gap: 15px; margin-top: 24px; }
.login-form label { display: grid; gap: 6px; color: var(--muted); }
.login-form button { min-height: 46px; border: 0; border-radius: 12px; color: #fff; background: var(--blue); font-weight: 800; }
.security-note { margin-top: 20px; color: var(--muted); text-align: center; font-size: 11px; }
.alert.error { margin-top: 16px; padding: 10px; border-radius: 10px; color: #b72e46; background: var(--red-soft); }
.device-login-card { text-align: center; }
.device-login-card .brand-mark { margin-inline: auto; }

@media (max-width: 680px) {
  .camera-header { height: 70px; grid-template-columns: 72px 1fr 84px; padding-inline: 10px; }
  .camera-title strong { font-size: 19px; }
  .camera-title small { display: none; }
  .icon-button { width: 38px; height: 38px; }
  .header-actions { gap: 3px; }
  .camera-tabs { top: 70px; height: 56px; }
  .camera-tab { font-size: 15px; }
  .camera-shell { padding: 0 0 max(44px, env(safe-area-inset-bottom)); }
  .view-panel { min-height: calc(100dvh - 126px); border: 0; border-radius: 0; box-shadow: none; padding: 20px 16px 32px; }
  .live-view { padding-top: 18px; }
  .live-heading { margin-bottom: 13px; }
  .live-heading h1 { font-size: 20px; }
  .live-heading p { max-width: 240px; }
  .video-stage { margin-inline: -16px; border-radius: 0; }
  .live-actions { margin-inline: -4px; }
  .action-icon { width: 46px; height: 46px; }
  .privacy-strip { margin-top: 18px; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading .date-tools { width: 100%; }
  .date-tools input { flex: 1; min-width: 0; }
  .recording-toolbar { align-items: stretch; flex-direction: column; }
  .timeline-filters { display: grid; grid-template-columns: repeat(4,1fr); }
  .filter-button { padding-inline: 6px; font-size: 11px; }
  .danger-outline { width: 100%; }
  .recording-list-summary { align-items: flex-start; flex-direction: column; }
  .timeline-row-header { grid-template-columns: 1fr; gap: 10px; padding: 14px; }
  .timeline-event-counts, .timeline-row-actions { width: 100%; }
  .timeline-event-counts > *, .timeline-row-actions > * { flex: 1; }
  .timeline-event-track { margin-inline: 20px; }
  .cat-event-cards { grid-template-columns: 1fr; padding-inline: 12px; }
  .segment-details { padding-inline: 12px; }
  .segment-detail-row { grid-template-columns: 1fr; }
  .segment-play { width: 100%; }
  .account-card { grid-template-columns: auto 1fr; }
  .account-card form { grid-column: 1 / -1; }
  .account-card button { width: 100%; }
  .playback-dialog { width: calc(100vw - 10px); max-height: calc(100dvh - 10px); border-radius: 15px; }
  .playback-dialog-content { padding: 11px; }
  .playback-video-stage { margin-inline: -3px; }
  .dialog-footer { align-items: stretch; flex-direction: column; }
  .cleanup-dialog-content { grid-template-columns: 1fr; padding: 19px; }
  .cleanup-safety-grid { grid-template-columns: 1fr; }
  .cleanup-dialog-actions { display: grid; grid-template-columns: 1fr; }
}
.camera-selector {
  max-width: 11rem;
  border: 0;
  background: transparent;
  color: #7a808c;
  font: inherit;
  font-size: .72rem;
  text-align: center;
  outline: none;
}
