:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-soft: #f7f9fa;
  --surface-strong: #24313a;
  --ink: #111820;
  --ink-soft: #34424d;
  --muted: #697986;
  --line: #d8e1e6;
  --line-strong: #b8c7d0;
  --blue: #176b87;
  --blue-soft: #e3f1f5;
  --green: #257451;
  --green-soft: #e3f3eb;
  --amber: #95621b;
  --amber-soft: #fff2dc;
  --red: #ad3e43;
  --red-soft: #fae6e7;
  --shadow: 0 18px 44px rgba(31, 43, 51, .09);
  --shadow-soft: 0 10px 24px rgba(31, 43, 51, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

h1, h2, h3, p, figure { margin-top: 0; }
h1 { margin-bottom: 2px; font-size: 20px; font-weight: 750; }
h2 { margin-bottom: 5px; font-size: 22px; font-weight: 760; }
h3 { margin-bottom: 4px; font-size: 15px; font-weight: 740; }
p, span, dt, dd, input, select, textarea, button { font-size: 14px; }
p, .brand p, .muted { color: var(--muted); }
button, input, select, textarea { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 12px 18px;
  background: rgba(238, 242, 244, .94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand p {
  max-width: 760px;
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs, .actions, .pager, .detail-actions, .schedule-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.tab, .button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.tab {
  background: transparent;
  color: var(--muted);
}

.tab.active {
  border-color: var(--blue);
  background: var(--surface);
  color: var(--blue);
  font-weight: 750;
  box-shadow: var(--shadow-soft);
}

.button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.button.subtle {
  background: var(--surface-soft);
}

.button.danger {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
}

.button:disabled {
  opacity: .52;
  cursor: wait;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 10px;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid rgba(23, 107, 135, .2);
  outline-offset: 1px;
}

.view { display: none; }
.view.active { display: block; }

.shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px;
}

#tab-cameras.active {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.source-rail {
  position: sticky;
  top: 64px;
  align-self: start;
  height: calc(100vh - 64px);
  overflow: auto;
  padding: 16px;
  background: #dde6ea;
  border-right: 1px solid var(--line-strong);
}

.rail-head, .rail-card-title, .page-title.split, .panel-title, .detail-head, .gallery-head, .settings-section-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.camera-rail-head {
  margin-bottom: 12px;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.pill, .badge, .source-state {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 4px 9px;
  font-weight: 760;
  font-size: 12px;
}

.pill, .badge.ok, .source-state.on {
  background: var(--green-soft);
  color: var(--green);
}

.pill.warn, .source-state.off {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.off {
  background: #e9eef1;
  color: var(--muted);
}

.source-nav {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.source-choice {
  width: 100%;
  min-height: 92px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px;
  background: rgba(255, 255, 255, .62);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.source-choice.active {
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.source-choice strong, .source-choice span {
  display: block;
  overflow-wrap: anywhere;
}

.source-choice strong {
  margin-top: 8px;
}

.source-choice > span:not(.source-state) {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.rail-card {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 13px;
  border: 1px solid rgba(184, 199, 208, .9);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
}

.field-label, .editor label, .settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 720;
}

.toggle-pill input, .switch-row input, .checks input {
  width: auto;
}

.schedule-readout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.schedule-readout div, .service-facts div {
  padding: 10px;
  border: 1px solid rgba(216, 225, 230, .86);
  border-radius: 7px;
  background: var(--surface-soft);
}

.schedule-readout span, dt {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.schedule-readout strong, dd {
  display: block;
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.service-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
}

.camera-stage {
  min-width: 0;
  padding: 20px;
}

.camera-command {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.camera-command h2 {
  margin-bottom: 4px;
  font-size: 24px;
}

.camera-command p {
  margin-bottom: 0;
}

.camera-tools {
  display: flex;
  justify-content: flex-end;
}

.camera-filter-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .68);
}

.camera-filter-chips, .camera-filter-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.camera-filter {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.camera-filter.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.camera-filter-tools span {
  color: var(--muted);
  font-size: 13px;
}

.camera-filter-tools select {
  width: auto;
  min-width: 150px;
}

.camera-grid {
  display: grid;
  gap: 18px;
}

.camera-wall-section, .camera-shelf {
  display: grid;
  gap: 12px;
}

.camera-wall-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
}

.camera-wall-heading h3 {
  margin-bottom: 0;
  font-size: 18px;
}

.camera-wall-heading > span {
  color: var(--muted);
  font-size: 13px;
}

.camera-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.camera-shelf-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(240px, 300px);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-color: var(--line-strong) transparent;
}

.camera-card, .gallery-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.camera-card {
  display: grid;
  grid-template-rows: auto 1fr;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.camera-card:hover {
  border-color: var(--blue);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.camera-thumb {
  position: relative;
  background: #cfd9de;
}

.camera-thumb img, .gallery-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.camera-status {
  position: absolute;
  right: 9px;
  bottom: 9px;
  max-width: calc(100% - 18px);
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 720;
  font-size: 12px;
}

.camera-status.fresh {
  background: rgba(227, 243, 235, .94);
  color: var(--green);
}

.camera-status.recent {
  background: rgba(227, 241, 245, .94);
  color: var(--blue);
}

.camera-status.stale {
  background: rgba(255, 242, 220, .96);
  color: var(--amber);
}

.camera-card-body, .gallery-card div {
  display: grid;
  gap: 8px;
  padding: 11px;
}

.camera-title-row {
  display: grid;
  gap: 4px;
}

.camera-card strong, .gallery-card strong, .camera-title-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-card span, .gallery-card span {
  color: var(--muted);
  font-size: 12px;
}

.camera-title-row span {
  width: fit-content;
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

.camera-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.camera-detail {
  margin-bottom: 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.detail-head h2, .detail-head p {
  margin-bottom: 0;
}

.detail-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 14px;
  margin-top: 12px;
}

.hero-frame {
  display: grid;
  place-items: center;
  min-height: 540px;
  margin-bottom: 0;
  border-radius: 8px;
  background: #111820;
  overflow: hidden;
}

.hero-frame img {
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
}

.detail-meta {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.detail-meta dl {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
}

.timeline-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.timeline {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--blue);
}

.timeline-readout {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.page-title {
  margin-bottom: 14px;
}

.page-title p { margin-bottom: 0; }

.panel, .toolbar, .settings-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 190px 150px 170px 120px;
  gap: 10px;
  padding: 12px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(420px, 1.1fr);
  gap: 16px;
}

.source-wizard {
  display: grid;
  grid-template-columns: minmax(230px, .7fr) minmax(360px, 1.3fr);
  gap: 14px;
  align-items: end;
  margin-bottom: 16px;
  padding: 14px;
}

.source-wizard h2, .source-wizard p {
  margin-bottom: 0;
}

.wizard-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.wizard-summary {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.wizard-summary strong {
  color: var(--blue);
}

.wizard-summary span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.source-choices {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.source-choice-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.source-choice-card.active {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.source-choice-card strong, .source-choice-card span {
  display: block;
  overflow-wrap: anywhere;
}

.source-choice-card span, .source span, .preview span {
  color: var(--muted);
  font-size: 12px;
}

.sources {
  display: grid;
  gap: 10px;
  align-content: start;
}

.source {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.source-line {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.source strong, .source span {
  display: block;
  overflow-wrap: anywhere;
}

.source-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.editor {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
}

.primary-checks {
  padding: 2px 0 4px;
}

.advanced-source {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.advanced-source summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 740;
}

.advanced-source[open] summary {
  margin-bottom: 10px;
}

.form-row, .scheduler-presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

textarea {
  resize: vertical;
}

.checks {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.checks label {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  color: var(--ink);
}

.settings-form {
  display: grid;
  gap: 14px;
  max-width: 1180px;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.settings-section-title {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.settings-section-title h3 {
  margin-bottom: 0;
  font-size: 16px;
}

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

.settings-grid.wide {
  grid-template-columns: repeat(2, minmax(240px, 1fr));
}

.settings-form .full-field {
  margin-top: 2px;
}

.switch-row {
  display: inline-flex !important;
  grid-template-columns: none;
  grid-auto-flow: column;
  align-items: center;
  width: fit-content;
  gap: 8px !important;
  color: var(--ink) !important;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stats article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.stats strong {
  display: block;
  font-size: 24px;
}

.stats span {
  color: var(--muted);
}

.maintenance-panel {
  padding: 14px;
}

.preview {
  display: grid;
  gap: 8px;
  max-height: 320px;
  margin-top: 12px;
  overflow: auto;
}

.preview article {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.preview strong, .preview span {
  display: block;
  overflow-wrap: anywhere;
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 36px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, .54);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(520px, calc(100vw - 36px));
  min-height: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .96);
  color: var(--ink-soft);
  box-shadow: var(--shadow);
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  #tab-cameras.active {
    grid-template-columns: 1fr;
  }

  .source-rail {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .source-nav {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  .detail-body, .two-column, .settings-grid, .settings-grid.wide {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .tabs, .actions, .rail-head, .rail-card-title, .page-title.split, .panel-title, .detail-head, .gallery-head, .settings-section-title, .timeline-readout, .camera-filter-bar, .camera-wall-heading {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar, .form-row, .stats, .timeline, .source-wizard, .wizard-row, .source-choice-card, .camera-command, .scheduler-presets {
    grid-template-columns: 1fr;
  }

  .camera-stage, .shell {
    padding: 14px;
  }

  .service-facts {
    grid-template-columns: 1fr;
  }

  .hero-frame {
    min-height: 320px;
  }

  .camera-shelf-row {
    grid-auto-columns: minmax(230px, 82vw);
  }
}
