:root {
  --bg-color: #0f0f1a;
  --surface-color: #1a1a2e;
  --card-color: #16213e;
  --accent-primary: #00d2ff;
  --accent-secondary: #7b68ee;
  --alert-danger: #ff6b6b;
  --alert-success: #51cf66;
  --alert-warning: #fcc419;
  --text-primary: #e8e8e8;
  --text-secondary: #8892b0;
  
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Reset / Normalize */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-family);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Typography */
h1, h2, h3 {
  margin-bottom: 1rem;
}

/* Components */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  backdrop-filter: blur(4px);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #000;
}

.btn-danger {
  background-color: var(--alert-danger);
  color: #000;
}

.btn-icon {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  padding: 0;
}

.card {
  background-color: var(--card-color);
  border-radius: 1rem;
  padding: 1.5rem;
  border: 1px solid rgba(255,255,255,0.05);
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 90%;
  max-width: 400px;
}

.toast {
  display: flex;
  align-items: center;
  padding: 1rem;
  border-radius: 0.5rem;
  background-color: var(--surface-color);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease forwards;
  color: var(--text-primary);
}

.toast-motion { border-left: 4px solid var(--accent-primary); }
.toast-sound { border-left: 4px solid var(--accent-secondary); }
.toast-success { border-left: 4px solid var(--alert-success); }
.toast-error { border-left: 4px solid var(--alert-danger); }
.toast-warning { border-left: 4px solid var(--alert-warning); }
.toast-info { border-left: 4px solid var(--accent-primary); }

.text-secondary { color: var(--text-secondary); }
.text-left { text-align: left; }
.p-2 { padding: 0.5rem; }
.rounded { border-radius: 0.5rem; }

/* Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  background-color: rgba(255,255,255,0.1);
}

.status-badge::before {
  content: '';
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  margin-right: 0.5rem;
}

.status-connected::before { background-color: var(--alert-success); }
.status-disconnected::before { background-color: var(--alert-danger); }
.status-relayed::before { background-color: var(--alert-warning); }

/* Pairing */
.pairing-code {
  font-size: 3rem;
  letter-spacing: 0.5rem;
  text-align: center;
  font-weight: bold;
  margin: 1rem 0;
  color: var(--accent-primary);
}

.pairing-input {
  width: 100%;
  font-size: 2.5rem;
  letter-spacing: 0.5rem;
  text-align: center;
  background: var(--surface-color);
  border: 2px solid var(--accent-secondary);
  color: var(--text-primary);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

.qr-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  padding: 1rem;
  border-radius: 0.5rem;
  margin: 1rem auto;
  max-width: fit-content;
}

/* Video & Controls */
.video-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  z-index: 1;
}

#overlay-controls {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.3s ease;
}

#overlay-controls > * {
  pointer-events: auto;
}

.overlay-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 0.75rem 1rem max(1.5rem, env(safe-area-inset-bottom)) 1rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.8) 30%, rgba(0,0,0,0.95));
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  z-index: 10;
  pointer-events: auto;
}

.overlay-top {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem 1rem;
  background: linear-gradient(rgba(0,0,0,0.9), transparent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  pointer-events: auto;
}

.control-btn-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.control-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-mic-talk {
  background: rgba(0, 210, 255, 0.18) !important;
  border: 2px solid var(--accent-primary) !important;
  width: 4rem !important;
  height: 4rem !important;
  font-size: 1.6rem !important;
  border-radius: 50% !important;
  box-shadow: 0 0 15px rgba(0, 210, 255, 0.35);
  transition: all 0.2s ease;
}

.btn-mic-talk:hover {
  background: rgba(0, 210, 255, 0.35) !important;
  transform: scale(1.05);
}

.btn-mic-talk.active {
  background: var(--accent-primary) !important;
  color: #0b0f19 !important;
  box-shadow: 0 0 25px rgba(0, 210, 255, 0.85) !important;
  transform: scale(1.08);
}

/* Settings */
.settings-panel {
  background-color: var(--surface-color);
  padding: 1.5rem;
  border-radius: 1rem;
  margin-top: 1rem;
}

.slider-control {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
}

.slider-control label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.slider-control input[type=range] {
  width: 100%;
}

.battery-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

/* Lullaby Menu */
.lullaby-menu {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-color);
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.lullaby-menu button {
  text-align: left;
  padding: 0.75rem;
  background: var(--surface-color);
  border: none;
  border-radius: 0.5rem;
  color: var(--text-primary);
  cursor: pointer;
}

.lullaby-menu button:hover {
  background: rgba(255,255,255,0.1);
}

/* Night Vision Modes */
.night-vision-boost {
  filter: brightness(2.2) contrast(1.6) saturate(0.5) !important;
}

.night-vision-ir {
  filter: brightness(2.0) contrast(1.8) grayscale(1) drop-shadow(0 0 8px rgba(0,255,100,0.3)) sepia(0.8) hue-rotate(80deg) !important;
}

/* Active Control Highlight */
.btn-icon.active {
  box-shadow: 0 0 12px var(--accent-primary);
}

/* Animations */
.recording-dot {
  width: 12px;
  height: 12px;
  background-color: var(--alert-danger);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(255, 107, 107, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 107, 107, 0); }
}

@keyframes slideIn {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Utilities */
.hidden { display: none !important; }
.flex-center { display: flex; justify-content: center; align-items: center; }
.full-screen { width: 100vw; height: 100vh; overflow: hidden; position: relative; }

/* Main Layout Setup */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 1.5rem;
  width: 100%;
}

.text-center { text-align: center; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.flex-col { display: flex; flex-direction: column; gap: 1rem; }

/* Timeline & Sleep Journal Modal */
.timeline-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 150;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.timeline-drawer {
  background: var(--surface-color);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  max-height: 85dvh;
  border-radius: 1.5rem 1.5rem 0 0;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Centered Dialog Modal (Emergency Call, Alerts, Settings) */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(10px);
  z-index: 99999;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  overflow-y: auto;
  box-sizing: border-box;
}

.modal-dialog {
  background: var(--surface-color, #16213e);
  width: 100%;
  max-width: 480px;
  max-height: calc(100dvh - 3rem);
  border-radius: 1.25rem;
  border: 1px solid rgba(0, 210, 255, 0.35);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.85);
  animation: modalPopIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  box-sizing: border-box;
  margin: auto;
}

@keyframes modalPopIn {
  from { opacity: 0; transform: scale(0.92) translateY(15px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.timeline-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.timeline-summary-card {
  background: var(--card-color);
  padding: 0.75rem;
  border-radius: 0.75rem;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.timeline-summary-card .val {
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--accent-primary);
}

.timeline-summary-card .lbl {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.timeline-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 0.25rem;
  max-height: 50vh;
}

.timeline-item {
  background: var(--card-color);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-left: 4px solid var(--accent-primary);
}

.timeline-item.type-cry {
  border-left-color: var(--alert-danger);
}

.timeline-item.type-motion {
  border-left-color: var(--alert-warning);
}

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

.timeline-item-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.timeline-item-time {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.timeline-clip-player {
  width: 100%;
  max-height: 200px;
  border-radius: 0.5rem;
  background: black;
  margin-top: 0.5rem;
}

/* ═══════════════════════════════════════════════════════════════
   Pillar 5: LAN Discovery, Low-Power OLED & Room Security
   ═══════════════════════════════════════════════════════════════ */

/* LAN Auto-Discovery Card on Join Screen */
.discovered-rooms-card {
  background: rgba(0, 210, 255, 0.08);
  border: 1px solid rgba(0, 210, 255, 0.3);
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 1.25rem;
  animation: fadeIn 0.3s ease;
}

.discovered-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.75rem;
}

.discovered-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.discovered-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card-color);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 0.5rem;
  padding: 0.75rem 0.85rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.discovered-item:hover {
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.discovered-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.discovered-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.discovered-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-quick-connect {
  background: var(--accent-primary);
  color: #0b0f19;
  border: none;
  border-radius: 0.4rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-quick-connect:hover {
  background: #33dcff;
  transform: scale(1.03);
}

/* OLED Ultra Low-Power Screensaver on Camera Unit */
.oled-screensaver {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000000 !important;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #444444;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.oled-content {
  text-align: center;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.oled-icon {
  font-size: 3.5rem;
  filter: grayscale(1) opacity(0.3);
  animation: pulse 4s infinite ease-in-out;
}

.oled-content h3 {
  font-size: 1.1rem;
  color: #555555;
  font-weight: 500;
}

.oled-content p {
  font-size: 0.8rem;
  color: #333333;
  max-width: 260px;
}

.btn-wake {
  background: #111111;
  color: #666666;
  border: 1px solid #222222;
  border-radius: 2rem;
  padding: 0.5rem 1.5rem;
  font-size: 0.8rem;
  margin-top: 1rem;
  cursor: pointer;
}

.btn-wake:hover {
  background: #222222;
  color: #888888;
}

/* Audio-Only Low-Power Banner on Viewer */
.audio-only-banner {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 210, 255, 0.4);
  color: #00d2ff;
  border-radius: 2rem;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 20;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  animation: slideDown 0.3s ease;
}

.audio-only-pulse {
  width: 8px;
  height: 8px;
  background: #00d2ff;
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

.btn-control.active {
  background: var(--accent-primary) !important;
  color: #0b0f19 !important;
  box-shadow: 0 0 12px rgba(0, 210, 255, 0.6);
}

.btn-control.locked {
  border-color: var(--alert-danger) !important;
  color: var(--alert-danger) !important;
}

