@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --bg:        #0d1117;
  --bg-2:      #161b22;
  --bg-card:   #1c2230;
  --border:    rgba(255,255,255,0.08);
  --accent:    #f0a500;
  --accent-15: rgba(240,165,0,0.12);
  --accent-30: rgba(240,165,0,0.28);
  --text:      #e6edf3;
  --text-2:    #8b949e;
  --red:       #ff4545;
  --red-15:    rgba(255,69,69,0.12);
  --radius:    10px;
  --nav-h:     52px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Prevent iOS double-tap zoom on interactive elements */
button, a, input, select { touch-action: manipulation; }

/* ─── Navigation ─────────────────────────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: var(--nav-h);
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  gap: 2px;
  padding-top: env(safe-area-inset-top, 0);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  font-weight: 700;
  margin-right: 12px;
  letter-spacing: -0.2px;
  min-height: 44px;
  padding: 0 4px;
  flex-shrink: 0;
}

.nav-brand svg { color: var(--accent); flex-shrink: 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  min-height: 44px;
  border-radius: 7px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}

.nav-link:hover  { background: rgba(255,255,255,0.06); color: var(--text); }
.nav-link.active { background: var(--accent-15); color: var(--accent); }

.nav-spacer { flex: 1; min-width: 4px; }

.nav-logout {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  min-height: 40px;
  border-radius: 7px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: 1px solid var(--border);
  font-family: inherit;
  transition: border-color 0.12s, color 0.12s;
  white-space: nowrap;
}

.nav-logout:hover { border-color: var(--red); color: var(--red); }

main { min-height: calc(100dvh - var(--nav-h)); }

/* ─── Live Page ──────────────────────────────────────────────────────────────── */
.live-page {
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.live-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 1400px;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  background: var(--red-15);
  border: 1px solid rgba(255,69,69,0.3);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  color: var(--red);
  letter-spacing: 1px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1.4s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

.live-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.live-controls { display: flex; gap: 6px; margin-left: auto; }

.control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.control-btn:hover { border-color: var(--accent-30); color: var(--accent); background: var(--accent-15); }

/* Camera frame */
.camera-frame {
  width: 100%;
  max-width: 1400px;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 0 0 1px rgba(240,165,0,0.06), 0 16px 48px rgba(0,0,0,0.6);
  position: relative;
  /* Maintain aspect ratio by letting browser determine height from stream */
}

.camera-feed {
  width: 100%;
  height: auto;
  display: block;
  max-height: 75dvh; /* Don't overflow screen */
  object-fit: contain;
}

/* Scanline texture */
.camera-scanline {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 3px,
    rgba(0,0,0,0.03) 3px, rgba(0,0,0,0.03) 4px
  );
  pointer-events: none;
}

/* Corner brackets */
.camera-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: var(--accent);
  border-style: solid;
  pointer-events: none;
  opacity: 0.5;
}
.camera-corner--tl { top: 8px;  left: 8px;  border-width: 2px 0 0 2px; border-radius: 3px 0 0 0; }
.camera-corner--tr { top: 8px;  right: 8px; border-width: 2px 2px 0 0; border-radius: 0 3px 0 0; }
.camera-corner--bl { bottom: 8px; left: 8px;  border-width: 0 0 2px 2px; border-radius: 0 0 0 3px; }
.camera-corner--br { bottom: 8px; right: 8px; border-width: 0 2px 2px 0; border-radius: 0 0 3px 0; }

.camera-overlay {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 10px;
  color: rgba(255,255,255,0.55);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* Footer stats */
.live-footer {
  display: flex;
  gap: 20px;
  width: 100%;
  max-width: 1400px;
  padding: 12px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.live-stat { display: flex; flex-direction: column; gap: 1px; }
.live-stat-label { font-size: 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 500; }
.live-stat-value { font-size: 13px; font-weight: 600; color: var(--text); }
.live-stat-value--online { color: #3fb950; }
.live-stat-value--offline { color: var(--red); }

/* ─── Archive Page ───────────────────────────────────────────────────────────── */
.archive-page { padding: 16px; }

.page-header { margin-bottom: 18px; }
.page-title  { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; margin-bottom: 2px; }
.page-subtitle { font-size: 12px; color: var(--text-2); }

/* Grid: 2 columns on mobile → 3 on tablet → 4 on wide */
.archive-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.archive-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(.4,0,.2,1), border-color 0.18s, box-shadow 0.18s;
  outline: none;
}

.archive-card:hover,
.archive-card:focus-visible {
  transform: translateY(-3px);
  border-color: var(--accent-30);
  box-shadow: 0 10px 28px rgba(0,0,0,0.35), 0 0 0 1px var(--accent-15);
}

.archive-thumb {
  position: relative;
  aspect-ratio: 4/3;
  background: #000;
  overflow: hidden;
}

.archive-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.archive-card:hover .archive-thumb img,
.archive-card:focus-visible .archive-thumb img { transform: scale(1.03); }

/* Skeleton while GIF loads */
.archive-thumb img:not([src*="api"]) {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-2) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.archive-thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.18s;
}

.archive-card:hover .archive-thumb-overlay,
.archive-card:focus-visible .archive-thumb-overlay { opacity: 1; }

.play-btn {
  width: 52px;
  height: 52px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(240,165,0,0.4);
  color: #000;
  transform: scale(0.8);
  transition: transform 0.18s cubic-bezier(.4,0,.2,1);
  padding-left: 3px; /* optical center for triangle */
}

.archive-card:hover .play-btn,
.archive-card:focus-visible .play-btn { transform: scale(1); }

.archive-duration-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 6px;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.6px;
}

.archive-card-body {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.archive-card-date { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 1px; }
.archive-card-time { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.archive-card-size { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ─── Pagination ─────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pagination-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  text-decoration: none;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.pagination-btn:hover:not(.disabled) { border-color: var(--accent-30); color: var(--accent); background: var(--accent-15); }
.pagination-btn.disabled { opacity: 0.3; pointer-events: none; }
.pagination-info { font-size: 13px; color: var(--text-2); padding: 0 8px; font-variant-numeric: tabular-nums; }

/* ─── Video Modal ────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal {
  width: 100%;
  max-width: 960px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transform: scale(0.94) translateY(10px);
  transition: transform 0.22s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 24px 72px rgba(0,0,0,0.8);
}

.modal-backdrop.open .modal { transform: scale(1) translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 12px; font-weight: 600; color: var(--text-2); font-variant-numeric: tabular-nums; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  transition: border-color 0.12s, color 0.12s;
}

.modal-close:hover { border-color: var(--red); color: var(--red); }

.modal video {
  width: 100%;
  display: block;
  background: #000;
  max-height: 70dvh;
}

/* ─── Login Page ─────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  padding-top: calc(20px + env(safe-area-inset-top, 0));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 40% at 50% 0%, rgba(240,165,0,0.07) 0%, transparent 70%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
}

.login-logo { text-align: center; margin-bottom: 28px; }

.login-logo-icon {
  display: inline-flex;
  width: 58px;
  height: 58px;
  background: var(--accent-15);
  border: 1px solid var(--accent-30);
  border-radius: 14px;
  align-items: center;
  justify-content: center;
  margin-bottom: 13px;
  color: var(--accent);
}

.login-logo h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; margin-bottom: 3px; }
.login-logo p  { font-size: 12px; color: var(--text-2); }

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 7px;
}

.form-input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  /* 16px prevents iOS from zooming on focus */
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  -webkit-appearance: none;
}

.form-input:focus { border-color: var(--accent-30); box-shadow: 0 0 0 3px var(--accent-15); }
.form-input--error { border-color: rgba(255,69,69,0.5) !important; }
.form-input--error:focus { box-shadow: 0 0 0 3px var(--red-15) !important; }

.form-error { margin-top: 6px; font-size: 12px; color: var(--red); }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #000;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.12s, transform 0.1s;
  min-height: 48px;
  -webkit-appearance: none;
}

.btn-primary:hover  { opacity: 0.88; }
.btn-primary:active { transform: scale(0.99); }

/* ─── Error / Empty ──────────────────────────────────────────────────────────── */
.error-page {
  padding: 60px 24px;
  text-align: center;
}

.error-page h1 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.error-page p  { color: var(--text-2); margin-bottom: 20px; font-size: 14px; }
.error-page a  { color: var(--accent); text-decoration: none; font-weight: 500; }
.error-page a:hover { text-decoration: underline; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 24px;
  color: var(--text-2);
  gap: 12px;
}

.empty-state svg { opacity: 0.2; }
.empty-state p   { font-size: 14px; }

/* ─── Responsive: Tablet 640px+ ─────────────────────────────────────────────── */
@media (min-width: 640px) {
  .live-page    { padding: 24px 28px; gap: 18px; }
  .archive-page { padding: 24px 28px; }

  .live-title  { font-size: 18px; }
  .page-title  { font-size: 22px; }

  .archive-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; }

  .nav { padding: 0 24px; }

  .live-footer { gap: 28px; padding: 14px 20px; }

  .camera-feed { max-height: 80dvh; }
}

/* ─── Responsive: Desktop 1024px+ ───────────────────────────────────────────── */
@media (min-width: 1024px) {
  .live-page    { padding: 28px 32px; gap: 20px; }
  .archive-page { padding: 28px 32px; }

  .archive-grid { grid-template-columns: repeat(3, 1fr); gap: 20px; }

  .live-badge { font-size: 11px; }
  .live-title { font-size: 20px; }
  .page-title { font-size: 24px; }

  .camera-feed { max-height: none; }
}

@media (min-width: 1440px) {
  .archive-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ─── Mobile-only tweaks ─────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .nav-brand-text { display: none; }
  .nav-logout-text { display: none; }
  .nav-logout { padding: 0 10px; }

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

  .live-stat--hide-sm { display: none; }
}

/* Modal full-screen on small screens */
@media (max-width: 640px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 95dvh; }
  .modal video { max-height: 55dvh; }
}

/* Fullscreen camera frame */
.camera-frame:-webkit-full-screen { border-radius: 0; border: none; box-shadow: none; }
.camera-frame:fullscreen { border-radius: 0; border: none; box-shadow: none; }
.camera-frame:-webkit-full-screen .camera-feed,
.camera-frame:fullscreen .camera-feed { max-height: 100dvh; width: 100%; height: 100%; object-fit: contain; }
