/* Base styling and responsive layout */
:root {
  color-scheme: dark light;
  color: #111;
  background: #f4f7fb;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  font-size: 16px;
  --surface: #ffffff;
  --surface-alt: #f0f4fb;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #d1d5db;
  --primary: #2563eb;
  --primary-contrast: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
}

@media (prefers-color-scheme: dark) {
  :root {
    background: #0b1120;
    color: #e5e7eb;
    --surface: #111827;
    --surface-alt: #1f2937;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary: #60a5fa;
    --primary-contrast: #0f172a;
    --danger: #f87171;
    --success: #34d399;
  }
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at top left, rgba(96, 165, 250, 0.12), transparent 32%),
    linear-gradient(180deg, var(--surface) 0%, var(--surface-alt) 100%);
  color: var(--text);
}

.body.theme-light {
  color-scheme: light;
}

body.theme-dark {
  color-scheme: dark;
  background: #050816;
}

body.theme-dark,
body.theme-dark .panel,
body.theme-dark .auth-card,
body.theme-dark input,
body.theme-dark select,
body.theme-dark textarea,
body.theme-dark .btn-secondary {
  color: var(--text);
}

body.theme-dark {
  --surface: #0f172a;
  --surface-alt: #111827;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #60a5fa;
  --primary-contrast: #0f172a;
  --danger: #f87171;
  --success: #34d399;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

.topbar-brand a,
.topbar-nav a,
.topbar-actions a,
.topbar-actions button {
  color: var(--text);
}

.topbar-brand a {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  text-decoration: none;
  font-size: 1.1rem;
}

.topbar-logo {
  width: 1.7rem;
  height: 1.7rem;
  display: inline-block;
  object-fit: contain;
}

.topbar-title {
  display: grid;
  gap: 0.2rem;
  text-align: center;
  flex: 1;
}

.topbar-kicker {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.topbar-title strong {
  font-size: 1.1rem;
}

.topbar-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-nav a {
  text-decoration: none;
  color: var(--text-muted);
  padding: 0.45rem 0.6rem;
  border-radius: 0.75rem;
  transition: background 150ms ease, color 150ms ease;
}

.topbar-nav a:hover,
.topbar-nav a.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--text);
}

.topbar-nav a.active {
  border: 1px solid rgba(37, 99, 235, 0.22);
}

.topbar-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.app-shell {
  width: min(1400px, calc(100% - 2rem));
  margin: 1.5rem auto;
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.left-rail {
  position: sticky;
  top: 6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.08);
  transition: width 0.2s ease, padding 0.2s ease;
}

.left-rail__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.left-rail__title,
.rail-section__label {
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
}

.sidebar-toggle {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  width: 2.1rem;
  height: 2.1rem;
  cursor: pointer;
}

.rail-section {
  display: grid;
  gap: 0.7rem;
  margin-top: 1.1rem;
}

.rail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.rail-item a,
.rail-placeholder,
.tree-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: var(--surface-alt);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.rail-item a:hover,
.rail-placeholder:hover,
.tree-item:hover {
  border-color: rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
}

.tree-list {
  display: grid;
  gap: 0.75rem;
}

.tree-branch {
  display: grid;
  gap: 0.45rem;
}

.tree-branch__label {
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  margin: 0.15rem 0.1rem;
}

.tree-item {
  justify-content: flex-start;
  width: 100%;
}

.tree-item--nested {
  margin-left: 0.45rem;
}

.tree-item.is-active {
  border-color: rgba(37, 99, 235, 0.45);
  background: rgba(37, 99, 235, 0.08);
}

.tree-node {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-status {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.rail-status--active {
  background: var(--success);
}

.rail-status--idle {
  background: var(--text-muted);
}

.rail-label,
.rail-meta {
  display: inline-block;
}

.rail-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
}

.rail-placeholder {
  opacity: 0.8;
  cursor: pointer;
}

.content-panel {
  min-width: 0;
}

.left-rail.collapsed {
  padding: 1rem 0.7rem;
}

.left-rail.collapsed .left-rail__title,
.left-rail.collapsed .rail-section__label,
.left-rail.collapsed .rail-label,
.left-rail.collapsed .rail-meta {
  display: none;
}

.left-rail.collapsed .rail-item a,
.left-rail.collapsed .rail-placeholder {
  justify-content: center;
}

.left-rail.collapsed .rail-status {
  margin: 0;
}

@media (max-width: 900px) {
  .topbar,
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-nav {
    width: 100%;
    justify-content: flex-start;
  }

  .channel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .left-rail {
    position: static;
  }
}

img {
  max-width: 100%;
  display: block;
}

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

.page-shell,
.page-grid,
.form-page {
  width: min(1200px, calc(100% - 2rem));
  margin: 1.5rem auto;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.toolbar-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.panel,
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.08);
}

.channel-grid,
.rules-list,
.form-grid {
  display: grid;
  gap: 1rem;
}

.channel-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.empty-state {
  padding: 1.5rem;
  border-radius: 1rem;
  background: rgba(37, 99, 235, 0.08);
  color: var(--text);
}

.btn-primary,
.btn-secondary,
.btn-danger {
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1.2rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
  color: var(--primary-contrast);
  background: var(--primary);
}

.btn-secondary {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
}

.btn-danger {
  color: var(--primary-contrast);
  background: var(--danger);
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-danger:hover {
  transform: translateY(-1px);
}

.auth-card,
.panel {
  width: 100%;
}

.auth-form,
.rule-form {
  display: grid;
  gap: 1rem;
}

label {
  display: grid;
  gap: 0.5rem;
  color: var(--text);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface-alt);
  color: var(--text);
  padding: 0.85rem 1rem;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.channel-card {
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.channel-card__header,
.rule-card__title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.channel-card__body,
.rule-card__body {
  padding: 1rem;
}

.channel-card img {
  object-fit: cover;
  min-height: 140px;
  max-height: 140px;
  width: 100%;
}

.camera-preview {
  object-fit: cover;
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
}

.rule-card {
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: 1rem;
  background: var(--surface-alt);
}

.rule-card__actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--surface-alt);
}

.switch {
  position: relative;
  display: inline-flex;
  width: 3rem;
  height: 1.7rem;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.2s ease;
}

.slider::before {
  content: "";
  position: absolute;
  height: 1.25rem;
  width: 1.25rem;
  left: 0.25rem;
  top: 0.225rem;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch input:checked + .slider {
  background: var(--success);
}

.switch input:checked + .slider::before {
  transform: translateX(1.25rem);
}

.rule-status {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.rule-status--active {
  background: rgba(22, 163, 74, 0.12);
  color: var(--success);
}

.rule-status--disabled {
  background: rgba(220, 38, 38, 0.12);
  color: var(--danger);
}

.rule-card--disabled {
  opacity: 0.85;
  border-style: dashed;
}

.rules-section-title {
  margin: 0.5rem 0 0.25rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.82rem;
}

.rule-type {
  background: rgba(37, 99, 235, 0.12);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.flash-grid {
  display: grid;
  gap: 0.75rem;
}

.flash {
  border-radius: 0.85rem;
  padding: 0.9rem 1rem;
}

.flash-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #b91c1c;
}

.flash-success {
  background: rgba(34, 197, 94, 0.12);
  color: #166534;
}

.flash-warning {
  background: rgba(250, 204, 21, 0.15);
  color: #7c2d12;
}

.page-grid {
  display: grid;
  gap: 1.5rem;
}

.feature-overview,
.feature-preview {
  width: 100%;
}

.feature-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.feature-list li {
  position: relative;
  padding-left: 1.2rem;
  color: var(--text);
}

.feature-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}

.feature-sample {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1rem;
}

.feature-sample__card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
}

.feature-sample__card--main {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(96, 165, 250, 0.04));
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.metric-row small {
  display: block;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.metric-row strong {
  font-size: 1.8rem;
}

.sparkline {
  display: flex;
  align-items: end;
  gap: 0.4rem;
  height: 110px;
  margin-top: 1rem;
}

.sparkline span {
  flex: 1;
  display: block;
  border-radius: 999px 999px 0 0;
  background: linear-gradient(180deg, var(--primary), rgba(37, 99, 235, 0.28));
}

.sparkline span:nth-child(1) { height: 30%; }
.sparkline span:nth-child(2) { height: 45%; }
.sparkline span:nth-child(3) { height: 68%; }
.sparkline span:nth-child(4) { height: 52%; }
.sparkline span:nth-child(5) { height: 80%; }
.sparkline span:nth-child(6) { height: 96%; }

.camera-page {
  grid-template-columns: 1fr 1.4fr;
}

.camera-preview-panel {
  min-width: 300px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.timeline-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.5rem;
}

.timeline-main,
.timeline-filters {
  min-width: 0;
}

.timeline-main {
  position: relative;
}

.timeline-loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.timeline-loading[hidden] {
  display: none;
}

.timeline-loading__spinner {
  width: 1.15rem;
  height: 1.15rem;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: timeline-spin 0.8s linear infinite;
}

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

.timeline-filters {
  overflow: hidden;
}

.timeline-main__header,
.timeline-panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.timeline-main h2,
.timeline-panel-heading h2 {
  margin: 0.2rem 0 0;
}

.timeline-main__header p,
.filter-note {
  color: var(--text-muted);
}

.eyebrow {
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.timeline-count {
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.event-photo-wrap {
  position: relative;
  min-height: 340px;
  margin: 1.5rem 0 2rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: #0b1120;
}

.event-photo {
  width: 100%;
  height: 420px;
  object-fit: contain;
}

.event-photo-empty {
  position: absolute;
  inset: 50% auto auto 50%;
  color: #cbd5e1;
  transform: translate(-50%, -50%);
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.timeline-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.timeline-zoom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.timeline-zoom label {
  display: inline;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.timeline-zoom input[type="range"] {
  width: min(220px, 35%);
  padding: 0;
  accent-color: var(--primary);
}

.timeline-zoom output {
  min-width: 2.5rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.legend-swatch,
.legend-dot {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
}

.legend-swatch--detection { background: var(--primary); }
.legend-swatch--alert { background: #f59e0b; }
.legend-dot { background: #ef4444; }

.timeline-board {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  overflow-x: auto;
}

.timeline-row {
  display: grid;
  grid-template-columns: 135px var(--timeline-track-width, minmax(520px, 1fr));
  gap: 0.75rem;
  align-items: center;
}

.timeline-row__label {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 135px;
  background: var(--surface);
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-row__track {
  position: relative;
  width: var(--timeline-track-width, 520px);
  min-height: 3.4rem;
  padding-top: 1.1rem;
  border-bottom: 1px solid var(--border);
  background: repeating-linear-gradient(90deg, transparent 0, transparent calc(25% - 1px), var(--border) 25%);
}

.timeline-hours {
  position: absolute;
  inset: 0 0 auto;
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.65rem;
}

.timeline-swimlanes {
  display: grid;
  gap: 0.2rem;
}

.timeline-lane {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.timeline-lane__toggle {
  position: sticky;
  left: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.72rem;
  overflow: hidden;
  min-height: 1.8rem;
  width: 150px;
  background: var(--surface);
  padding: 0.35rem 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-lane__chevron {
  color: var(--primary);
  font-size: 1rem;
  transition: transform 0.15s ease;
}

.timeline-lane.is-collapsed .timeline-lane__chevron {
  transform: rotate(-90deg);
}

.timeline-lane.is-collapsed .timeline-lane__track {
  display: none;
}

.timeline-lane__track {
  position: relative;
  min-height: 2.35rem;
}

.timeline-lanes { position: relative; height: 2.35rem; }

.timeline-bar,
.timeline-alert {
  position: absolute;
  top: 0.55rem;
  height: 1rem;
  border: 0;
  cursor: pointer;
}

.timeline-bar {
  overflow: hidden;
  padding: 0 0.35rem;
  border-radius: 0.25rem;
  background: rgba(37, 99, 235, 0.75);
  color: var(--primary-contrast);
  font-size: 0.65rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-bar.is-selected {
  z-index: 2;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.28);
}

.timeline-alert {
  width: 0.8rem;
  height: 0.8rem;
  top: 0.65rem;
  margin-left: -0.4rem;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.16);
}

.timeline-alert--loitering {
  width: 1.1rem;
  height: 1.1rem;
  top: 0.5rem;
  margin-left: -0.55rem;
  border-radius: 0.25rem;
  background: #f59e0b;
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2);
}

.timeline-alert.is-selected {
  z-index: 2;
  box-shadow: 0 0 0 4px var(--primary), 0 0 0 7px rgba(96, 165, 250, 0.28);
}

.timeline-filters {
  align-self: start;
  position: sticky;
  top: 6rem;
}

.timeline-filters fieldset {
  margin: 1.5rem 0 0;
  padding: 0;
  border: 0;
}

.timeline-filters legend,
.date-filter label {
  margin-bottom: 0.5rem;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rule-filter {
  margin-top: 1.5rem;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rule-filter select {
  margin-top: 0.5rem;
  letter-spacing: normal;
  text-transform: none;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  overflow: hidden;
}

.segmented-control button {
  min-height: 2.4rem;
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
}

.segmented-control button:last-child { border-right: 0; }
.segmented-control button.is-active { background: var(--primary); color: var(--primary-contrast); }

.camera-checkboxes { display: grid; gap: 0.65rem; }

.camera-check {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-size: 0.85rem;
}

.camera-check input { width: auto; accent-color: var(--primary); }

.event-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 1.5rem;
  max-height: 300px;
  overflow-y: auto;
}

.event-list__item {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  width: 100%;
  min-width: 0;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.event-list__item.is-selected { border-color: var(--primary); }
.event-list__item strong,
.event-list__item small {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.event-list__item strong {
  color: var(--text);
  line-height: 1.35;
}

.event-list__item > span:last-child {
  min-width: 0;
  flex: 1;
}

.event-list__item small {
  margin-top: 0.2rem;
  color: var(--text-muted);
}
.event-list__type { font-size: 0.62rem; text-transform: uppercase; }
.event-list__type--alert { color: #f59e0b; }
.event-list__type--detection { color: var(--primary); }

@media (max-width: 900px) {
  .timeline-layout { grid-template-columns: 1fr; }
  .timeline-filters { position: static; }
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
}

legend {
  font-weight: 600;
}

.polygon-builder {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1rem;
}

.polygon-image-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
  background: var(--surface-alt);
}

.polygon-stage {
  display: grid;
  gap: 0.75rem;
}

.polygon-stage img {
  width: 100%;
  display: block;
  cursor: crosshair;
}

.polygon-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

.polygon-lines {
  fill: none;
  stroke: rgba(37, 99, 235, 0.95);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.polygon-fill {
  fill: rgba(37, 99, 235, 0.18);
  stroke: none;
}

.polygon-point {
  fill: rgba(37, 99, 235, 0.95);
  stroke: #fff;
  stroke-width: 2;
  cursor: pointer;
}

.polygon-point-label {
  font-size: 0.8rem;
  fill: #111827;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

.polygon-overlay text {
  cursor: default;
}

.polygon-help {
  position: fixed;
  top: 5rem;
  right: 1.5rem;
  left: auto;
  bottom: auto;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 1rem;
  font-size: 0.9rem;
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.16);
  z-index: 1050;
  max-width: 350px;
  margin: 0;
  backdrop-filter: blur(8px);
  animation: fadeOutPolygonHelp 6s forwards ease-in-out;
}

.polygon-help:hover {
  animation-play-state: paused;
  opacity: 1;
  visibility: visible;
}

@keyframes fadeOutPolygonHelp {
  0%, 75% {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
  }
  100% {
    opacity: 0;
    transform: translateY(-10px);
    visibility: hidden;
    pointer-events: none;
  }
}

body.theme-dark .polygon-help {
  background: rgba(15, 23, 42, 0.95);
  border-color: #334155;
  color: var(--text);
}

.polygon-help button {
  min-width: 2.2rem;
  min-height: 2.2rem;
  border: none;
  border-radius: 0.75rem;
  background: rgba(229, 231, 235, 0.95);
  color: #111827;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

body.theme-dark .polygon-help button {
  background: rgba(71, 85, 105, 0.95);
  color: #f8fafc;
}

.polygon-help button:hover {
  transform: translateY(-1px);
  background: rgba(37, 99, 235, 0.12);
}

.polygon-info {
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  background: var(--surface);
}

.polygon-info h3 {
  margin-top: 0;
}

.polygon-info ol {
  margin: 0;
  padding-left: 1.2rem;
}

.polygon-info button {
  margin-top: 1rem;
}

.form-warning {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 900px) {
  .toolbar,
  .page-grid,
  .form-page,
  .channel-grid,
  .form-grid,
  .polygon-builder {
    grid-template-columns: 1fr;
  }

  .camera-page {
    grid-template-columns: 1fr;
  }
}

.form-grid {
  grid-template-columns: 1fr;
}

.camera-page {
  grid-template-columns: 1fr;
}


@media (max-width: 640px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    justify-content: flex-start;
  }
}
