/* ============================================================
   HOME SENTINEL - Camera Monitoring PWA
   Dark cinematic surveillance aesthetic
   ============================================================ */

:root {
  --bg-deep: #0a0e1a;
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #253348;
  --border: #334155;
  --border-light: #475569;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.25);
  --success: #22c55e;
  --success-glow: rgba(34, 197, 94, 0.2);
  --night: #8b5cf6;
  --night-glow: rgba(139, 92, 246, 0.2);
  --warning: #f59e0b;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --nav-height: 72px;
}

/* ---- RESET & BASE ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-primary);
  -webkit-user-select: none;
  user-select: none;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* ---- STATUS BAR ---- */
#status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--bg-deep);
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  flex-shrink: 0;
  z-index: 20;
  min-height: 48px;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.status-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-glow);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--danger);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#camera-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.status-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  font-family: var(--font-mono);
}

.status-badge.night {
  background: var(--night-glow);
  color: var(--night);
}

.status-badge.alarm {
  background: var(--danger-glow);
  color: var(--danger);
  animation: badge-flash 1s ease-in-out infinite;
}

@keyframes badge-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ---- SCREEN CONTAINER ---- */
#screen-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
}

.screen.active {
  opacity: 1;
  visibility: visible;
}

/* ---- SCREEN HEADER ---- */
.screen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg-deep);
  z-index: 10;
}

.screen-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.refresh-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all 0.2s;
}

.refresh-btn:active {
  background: var(--bg-card);
  color: var(--accent);
  transform: rotate(180deg);
}

/* ============================================================
   LIVE SCREEN
   ============================================================ */

.live-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.live-video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  flex-shrink: 0;
}

.live-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(135deg, #0a0e1a 0%, #111827 100%);
  z-index: 2;
}

.live-placeholder span {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.live-placeholder svg {
  animation: cam-breathe 3s ease-in-out infinite;
}

@keyframes cam-breathe {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.05); }
}

#live-stream {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.live-overlay-top {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 3;
  pointer-events: none;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
  backdrop-filter: blur(8px);
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: live-blink 1.2s ease-in-out infinite;
}

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

/* Live Controls */
.live-controls {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 6px;
  padding: 20px 16px;
  flex-shrink: 0;
}

.live-btn {
  flex: 1;
  max-width: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all 0.15s ease;
  min-height: 72px;
}

.live-btn span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.live-btn:active {
  background: var(--bg-card-hover);
  transform: scale(0.95);
}

.live-btn.audio-btn {
  background: var(--bg-card);
  border-color: var(--success);
  color: var(--success);
}

.live-btn.audio-btn.active {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.live-btn.talk-btn {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
}

.live-btn.talk-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow), 0 0 40px var(--accent-glow);
  animation: talk-pulse 0.8s ease-in-out infinite;
}

@keyframes talk-pulse {
  0%, 100% { box-shadow: 0 0 20px var(--accent-glow); }
  50% { box-shadow: 0 0 30px var(--accent-glow), 0 0 60px rgba(59, 130, 246, 0.15); }
}

.live-btn.alarm-btn.active {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  box-shadow: 0 0 20px var(--danger-glow);
  animation: alarm-pulse 0.6s ease-in-out infinite;
}

@keyframes alarm-pulse {
  0%, 100% { box-shadow: 0 0 15px var(--danger-glow); }
  50% { box-shadow: 0 0 30px var(--danger-glow), 0 0 50px rgba(239, 68, 68, 0.15); }
}

/* Fullscreen mode */
.live-video-container:fullscreen,
.live-video-container:-webkit-full-screen {
  background: #000;
}

.live-video-container:fullscreen #live-stream,
.live-video-container:-webkit-full-screen #live-stream {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ============================================================
   EVENTS SCREEN
   ============================================================ */

.events-list {
  padding: 0 16px;
}

.date-group-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 16px 0 8px;
  font-family: var(--font-mono);
  border-bottom: 1px solid rgba(51, 65, 85, 0.3);
  margin-bottom: 8px;
}

.event-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  overflow: hidden;
}

.event-card:active {
  background: var(--bg-card-hover);
  transform: scale(0.985);
}

.event-thumb {
  width: 80px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  object-fit: cover;
  flex-shrink: 0;
}

.event-thumb-placeholder {
  width: 80px;
  height: 60px;
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.event-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.event-time {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
}

.event-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.event-meta-item {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.event-badges {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.event-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  letter-spacing: 0.02em;
}

.event-badge.person {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent);
}

.event-badge.video {
  background: var(--success-glow);
  color: var(--success);
}

.event-badge.confidence {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

/* Event Detail */
.event-detail {
  position: absolute;
  inset: 0;
  background: var(--bg-deep);
  z-index: 30;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  animation: slide-in 0.25s ease;
}

@keyframes slide-in {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.event-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-deep);
  z-index: 5;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  padding: 8px 4px;
  min-width: 44px;
  min-height: 44px;
}

.event-detail-content {
  padding: 16px;
}

.detail-snapshots {
  margin-bottom: 20px;
}

.detail-snapshots h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
}

.snapshots-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.snapshots-scroll::-webkit-scrollbar {
  height: 3px;
}

.snapshots-scroll img {
  width: 240px;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  scroll-snap-align: start;
  background: var(--bg-card);
}

.detail-recordings {
  margin-bottom: 16px;
}

.detail-recordings h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
}

.detail-video {
  width: 100%;
  border-radius: var(--radius-md);
  background: #000;
  max-height: 300px;
}

.detail-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.detail-info-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.detail-info-item .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
  margin-bottom: 4px;
}

.detail-info-item .value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ============================================================
   RECORDINGS SCREEN
   ============================================================ */

.date-selector {
  display: flex;
  gap: 6px;
  padding: 0 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.date-selector::-webkit-scrollbar {
  display: none;
}

.date-btn {
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.date-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.date-btn:active {
  transform: scale(0.95);
}

.recordings-list {
  padding: 0 16px;
}

.recording-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.recording-item:active {
  background: var(--bg-card-hover);
  transform: scale(0.985);
}

.recording-play-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.recording-play-icon svg {
  margin-left: 2px;
}

.recording-info {
  flex: 1;
  min-width: 0;
}

.recording-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-mono);
  font-size: 13px;
}

.recording-size {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Recording Player */
.recording-player {
  position: absolute;
  inset: 0;
  background: var(--bg-deep);
  z-index: 30;
  overflow-y: auto;
  animation: slide-in 0.25s ease;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

.recording-player-content {
  padding: 16px;
}

#recording-video {
  width: 100%;
  border-radius: var(--radius-md);
  background: #000;
  max-height: 50vh;
}

/* ============================================================
   SETTINGS SCREEN
   ============================================================ */

.settings-content {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.settings-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.4);
}

.settings-card-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.settings-card-body {
  padding: 14px 16px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.status-row + .status-row {
  border-top: 1px solid rgba(51, 65, 85, 0.3);
  margin-top: 6px;
  padding-top: 10px;
}

.status-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.status-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.status-value.running {
  color: var(--success);
}

.status-value.stopped {
  color: var(--danger);
}

.status-value.active {
  color: var(--night);
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.settings-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  min-height: 44px;
  transition: all 0.15s;
}

.settings-btn.start {
  background: rgba(34, 197, 94, 0.12);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.settings-btn.start:active {
  background: rgba(34, 197, 94, 0.25);
  transform: scale(0.97);
}

.settings-btn.stop {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.settings-btn.stop:active {
  background: rgba(239, 68, 68, 0.25);
  transform: scale(0.97);
}

/* ============================================================
   BOTTOM NAVIGATION
   ============================================================ */

#bottom-nav {
  display: flex;
  align-items: stretch;
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  height: calc(var(--nav-height) + var(--safe-bottom));
  flex-shrink: 0;
  z-index: 50;
  position: relative;
}

#bottom-nav::before {
  content: '';
  position: absolute;
  top: -20px;
  left: 0;
  right: 0;
  height: 20px;
  background: linear-gradient(to top, var(--bg-deep), transparent);
  pointer-events: none;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  transition: color 0.2s;
  position: relative;
  min-height: 44px;
}

.nav-btn span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-btn.active::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 3px 3px;
}

.nav-btn:active {
  color: var(--accent);
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

.toast.success {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

/* ============================================================
   LOADING & EMPTY STATES
   ============================================================ */

.loading-state,
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  gap: 16px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================================
   DESKTOP ENHANCEMENTS
   ============================================================ */

@media (min-width: 640px) {
  #app {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (min-width: 1024px) {
  .live-controls {
    gap: 12px;
  }

  .live-btn {
    max-width: 120px;
  }

  .event-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
  }

  .recording-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
  }

  .nav-btn:hover {
    color: var(--text-secondary);
  }
}
