:root {
  --ink: #1c242c;
  --ink-soft: #5a6a76;
  --paper: #f3f1ec;
  --paper-card: #fffcf7;
  --paper-deep: #e4dfd6;
  --line: rgba(28, 36, 44, 0.1);
  --teal: #1f6f68;
  --teal-deep: #15554f;
  --teal-soft: rgba(31, 111, 104, 0.12);
  --motion: #c9852c;
  --people: #2f6fbd;
  --warn: #a13d2f;
  --ok: #2f8a4c;
  --shadow: 0 10px 30px rgba(28, 36, 44, 0.06);
  --radius: 16px;
  --font-display: "Syne", system-ui, sans-serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;
  --nav-width: 220px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#root {
  min-height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
a,
input {
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ——— Login ——— */

.login-stage {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: clamp(1.5rem, 4vw, 3rem);
  background:
    radial-gradient(1200px 700px at 12% 18%, rgba(31, 111, 104, 0.16), transparent 55%),
    radial-gradient(900px 600px at 88% 78%, rgba(45, 74, 98, 0.14), transparent 50%),
    linear-gradient(160deg, #f7f4ef 0%, #e8e4db 48%, #d9e0e4 100%);
}

.login-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(28, 36, 44, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(28, 36, 44, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 35%, transparent 78%);
  pointer-events: none;
}

.login-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(28, 36, 44, 0.1) 100%);
  pointer-events: none;
}

.login-frame {
  position: relative;
  z-index: 1;
  width: min(100%, 28rem);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.25rem;
  animation: rise-in 700ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.brand-hero {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.85rem;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3.2rem, 11vw, 4.8rem);
  letter-spacing: -0.04em;
  line-height: 0.92;
  color: var(--ink);
}

.brand-avatar {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: #f5f0e6;
  box-shadow: 0 8px 20px rgba(28, 36, 34, 0.12);
}

.brand-avatar-lg {
  width: 96px;
  height: 96px;
  animation: rise-in 700ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.tagline {
  margin: 0;
  max-width: 22rem;
  font-size: 1.125rem;
  line-height: 1.45;
  color: var(--ink-soft);
  animation: rise-in 800ms 80ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.cta-block {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.85rem;
  animation: rise-in 850ms 140ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.google-slot {
  min-height: 44px;
  min-width: 240px;
}

.google-slot iframe {
  border-radius: 4px !important;
}

.status-line {
  margin: 0;
  min-height: 1.4em;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.status-line[data-tone="error"] {
  color: var(--warn);
}

.status-line[data-tone="ok"] {
  color: var(--teal-deep);
}

.hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

/* ——— App shell ——— */

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
  background:
    radial-gradient(900px 500px at 100% 0%, rgba(31, 111, 104, 0.08), transparent 55%),
    linear-gradient(180deg, #f6f3ee 0%, #ebe7e0 100%);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.35rem 1rem 1.1rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.72);
  backdrop-filter: blur(10px);
}

.brand-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0 0.75rem;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: -0.03em;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  text-align: left;
  transition:
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.nav-item:hover:not(:disabled) {
  background: rgba(28, 36, 44, 0.04);
  color: var(--ink);
}

.nav-item.is-active {
  background: #ebe4d8;
  color: var(--ink);
  font-weight: 600;
}

.nav-item:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.nav-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: grid;
  place-items: center;
}

.nav-icon svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-footer {
  padding: 0.75rem 0.5rem 0.25rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.side-footer p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.status-chip,
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.status-chip.is-online,
.live-pill.is-online {
  color: var(--ok);
}

.live-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #b0b8bf;
  box-shadow: 0 0 0 3px rgba(176, 184, 191, 0.25);
}

.is-online .live-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(47, 138, 76, 0.18);
  animation: pulse-dot 2.4s ease-in-out infinite;
}

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.5rem 0.5rem;
}

.greeting-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.greeting-sub {
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
}

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--paper-deep);
  border: 1px solid var(--line);
}

.user-meta {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.user-meta strong {
  font-family: var(--font-display);
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.user-meta span {
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.ghost-btn,
.transport-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.8);
  color: var(--ink);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    transform 120ms ease;
}

.ghost-btn:hover,
.transport-btn:hover {
  background: #fff;
  border-color: rgba(28, 36, 44, 0.2);
}

.ghost-btn:active,
.transport-btn:active {
  transform: translateY(1px);
}

.ghost-btn:disabled,
.transport-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.transport-btn.is-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  min-width: 5.5rem;
  font-weight: 600;
}

.transport-btn.is-primary:hover {
  background: var(--teal-deep);
  border-color: var(--teal-deep);
}

.transport-btn.is-active {
  background: rgba(31, 111, 104, 0.14);
  border-color: var(--teal);
  color: var(--teal-deep);
  font-weight: 600;
}

.app-content {
  flex: 1;
  min-height: 0;
  padding: 0.75rem 1.35rem 1.35rem;
}

/* ——— Cameras page ——— */

.cameras-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1rem;
  min-height: calc(100dvh - 6.5rem);
  animation: rise-in 500ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.camera-list-panel,
.player-panel {
  background: var(--paper-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.camera-list-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-head {
  padding: 1.1rem 1.1rem 0.7rem;
}

.panel-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.panel-head p {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.camera-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0.7rem 0.9rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.camera-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.7rem 0.75rem;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.camera-row:hover {
  background: rgba(28, 36, 44, 0.03);
}

.camera-row.is-selected {
  background: var(--teal-soft);
  border-color: rgba(31, 111, 104, 0.22);
}

.camera-row input {
  accent-color: var(--teal);
}

.camera-row-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.camera-row-body strong {
  font-size: 0.95rem;
}

.camera-row-body span {
  color: var(--ink-soft);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-hint,
.camera-empty,
.loading-line {
  color: var(--ink-soft);
  padding: 1rem;
}

.player-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.9rem;
  min-width: 0;
}

.player-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.day-controls,
.transport {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.day-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
}

.day-picker input[type="date"] {
  border: 0;
  background: transparent;
  color: var(--ink);
}

.day-picker strong {
  font-family: var(--font-display);
  font-size: 0.92rem;
  text-transform: capitalize;
}

.banner-error {
  margin: 0;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  background: rgba(161, 61, 47, 0.08);
  color: var(--warn);
}

.camera-grid {
  display: grid;
  gap: 0.75rem;
  min-height: 280px;
}

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

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

.camera-grid.count-3,
.camera-grid.count-4 {
  grid-template-columns: 1fr 1fr;
}

.camera-grid.is-theatre {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.camera-grid.is-theatre .camera-tile.is-theatre-hero {
  grid-column: 1 / -1;
}

.camera-tile {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}

.camera-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 0.15rem;
}

.camera-tile-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.camera-tile-id {
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.camera-stage {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background:
    linear-gradient(160deg, #1a2229 0%, #0f1418 100%);
  border: 1px solid rgba(28, 36, 44, 0.18);
  container-type: size;
}

.camera-stage video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0d1216;
  transform-origin: center center;
}

.camera-stage[data-rotation="90"] video,
.camera-stage[data-rotation="270"] video {
  inset: auto;
  left: 50%;
  top: 50%;
  width: 100cqh;
  height: 100cqw;
  max-width: none;
  max-height: none;
}

.camera-stage[data-rotation="90"] video {
  transform: translate(-50%, -50%) rotate(90deg);
}

.camera-stage[data-rotation="180"] video {
  transform: rotate(180deg);
}

.camera-stage[data-rotation="270"] video {
  transform: translate(-50%, -50%) rotate(270deg);
}

.camera-stage video.is-standby {
  opacity: 0;
  pointer-events: none;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(8, 12, 16, 0.35);
  font-size: 0.95rem;
  padding: 1rem;
  text-align: center;
}

.camera-overlay.is-error {
  color: #ffb4a8;
}

.camera-chrome {
  position: absolute;
  left: 0.7rem;
  bottom: 0.7rem;
  right: 0.7rem;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 2;
}

.rec-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.camera-stage-actions {
  display: inline-flex;
  gap: 0.35rem;
  pointer-events: auto;
  margin-left: auto;
}

.stage-btn {
  width: 2.1rem;
  height: 2.1rem;
  border: 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.stage-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

.stage-btn:hover {
  background: rgba(0, 0, 0, 0.82);
}

.stage-btn:active {
  transform: scale(0.96);
}

.stage-btn.is-active {
  background: rgba(31, 111, 104, 0.92);
}

.camera-stage:fullscreen {
  aspect-ratio: auto;
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: 0;
  background: #000;
}

.camera-stage:fullscreen video {
  object-fit: contain;
}

.camera-stage:fullscreen .camera-chrome {
  padding: 0.25rem;
}

/* ——— Timeline ——— */

.timeline {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.35rem 0.15rem 0.15rem;
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

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

.timeline-hint {
  color: var(--ink-soft);
  font-size: 0.78rem;
  opacity: 0.85;
}

.timeline-zoom-out {
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
}

.timeline-clock {
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 2px;
  display: inline-block;
}

.swatch-seg {
  background: rgba(31, 111, 104, 0.45);
}

.swatch-motion {
  background: var(--motion);
}

.swatch-people {
  background: var(--people);
}

.timeline-track {
  position: relative;
  height: 84px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, #faf8f4 0%, #f0ebe3 100%);
  cursor: pointer;
  outline: none;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.timeline-track.is-selecting {
  cursor: col-resize;
}

.timeline-track:focus-visible {
  box-shadow: 0 0 0 3px rgba(31, 111, 104, 0.25);
}

.timeline-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(31, 111, 104, 0.18);
  border-left: 1px solid rgba(31, 111, 104, 0.55);
  border-right: 1px solid rgba(31, 111, 104, 0.55);
  pointer-events: none;
  z-index: 2;
}

.timeline-hours {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hour-mark {
  position: absolute;
  top: 0.35rem;
  transform: translateX(-50%);
  font-size: 0.68rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.hour-mark::before {
  content: "";
  position: absolute;
  top: 1.1rem;
  left: 50%;
  width: 1px;
  height: 58px;
  background: rgba(28, 36, 44, 0.08);
}

.timeline-lane {
  position: absolute;
  left: 0;
  right: 0;
  height: 16px;
}

.timeline-lane-segments {
  top: 28px;
}

.timeline-lane-activity {
  top: 50px;
}

.seg-block,
.activity-block {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 3px;
  /* Clicks/drags go to the track so mid-chunk scrubbing works. */
  pointer-events: none;
  min-width: 2px;
}

.seg-block {
  background: rgba(31, 111, 104, 0.38);
}

.seg-block.is-hq {
  background: rgba(31, 111, 104, 0.72);
}

.activity-block.is-motion {
  background: rgba(201, 133, 44, 0.85);
}

.activity-block.is-people {
  background: rgba(47, 111, 189, 0.85);
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  z-index: 2;
  pointer-events: none;
}

.playhead-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  background: var(--ink);
  transform: translateX(-50%);
}

.playhead-knob {
  position: absolute;
  top: 4px;
  left: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
  transform: translateX(-50%);
  box-shadow: 0 0 0 3px rgba(28, 36, 44, 0.12);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-dot {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(47, 138, 76, 0.35);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(47, 138, 76, 0);
  }
}

@media (max-width: 1100px) {
  .cameras-layout {
    grid-template-columns: 1fr;
  }

  .camera-list-panel {
    max-height: 220px;
  }

  .camera-grid.count-2,
  .camera-grid.count-3,
  .camera-grid.count-4 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    overflow-x: auto;
  }

  .brand-block {
    flex-direction: row;
    padding: 0;
  }

  .brand-name {
    display: none;
  }

  .nav-list {
    flex-direction: row;
    flex: 1;
  }

  .nav-item span:not(.nav-icon) {
    display: none;
  }

  .side-footer {
    border: 0;
    padding: 0;
  }

  .side-footer p {
    display: none;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .user-meta span {
    display: none;
  }
}

@media (max-width: 480px) {
  .login-frame {
    align-items: stretch;
  }

  .google-slot {
    width: 100%;
  }

  .day-picker strong {
    display: none;
  }
}
