/* ==========================================================================
   Tapo C200 Direct Web Viewer - Modern Dark Glassmorphism Design System
   ========================================================================== */

:root {
  --bg-app: #07090e;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-card-hover: rgba(30, 41, 59, 0.85);
  --bg-glass: rgba(15, 23, 42, 0.6);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glass-bright: rgba(255, 255, 255, 0.16);

  --accent-primary: #06b6d4; /* Vibrant Cyan */
  --accent-primary-glow: rgba(6, 182, 212, 0.25);
  --accent-success: #10b981; /* Emerald Green */
  --accent-success-glow: rgba(16, 185, 129, 0.3);
  --accent-warning: #f59e0b; /* Amber */
  --accent-danger: #ef4444;  /* Rose Red */

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', var(--font-sans);
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background: radial-gradient(circle at 50% 0%, #131b2e 0%, var(--bg-app) 70%);
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-glass);
  z-index: 20;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.camera-icon-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(16, 185, 129, 0.2));
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: var(--radius-md);
  color: var(--accent-primary);
}

.camera-icon-badge svg {
  width: 22px;
  height: 22px;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-direct {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #fff;
  border-radius: var(--radius-full);
  box-shadow: 0 0 12px var(--accent-primary-glow);
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-success);
}

.status-chip.connecting {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.25);
  color: var(--accent-warning);
}

.status-chip.error {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--accent-danger);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: currentColor;
  border-radius: 50%;
  animation: pulse-glow 2s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.15);
    box-shadow: 0 0 8px 3px rgba(16, 185, 129, 0.3);
  }
}

.engine-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent-primary);
}

/* Viewport Section */
.viewport-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  position: relative;
}

.viewport-container {
  width: 100%;
  max-width: 1600px;
  height: 100%;
  max-height: calc((100vw - 32px) * 9 / 16);
  aspect-ratio: 16 / 9;
  position: relative;
  background: #020305;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--border-glass);
}

.stream-surface {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  background: #000;
}

.stream-surface.active {
  display: block;
}

/* Overlay / Spinner */
.viewport-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(2, 3, 5, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10;
  transition: opacity var(--transition-smooth), visibility var(--transition-smooth);
}

.viewport-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(6, 182, 212, 0.2);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

.overlay-text {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Live HUD */
.hud-overlay {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  background: rgba(10, 15, 29, 0.82);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass-bright);
  border-radius: var(--radius-md);
  padding: 6px 14px;
  gap: 12px;
  z-index: 5;
  font-family: var(--font-mono);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  transition: opacity var(--transition-smooth), transform var(--transition-smooth);
}

.hud-overlay.hidden {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.hud-item {
  display: flex;
  flex-direction: column;
}

.hud-label {
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.hud-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.hud-divider {
  width: 1px;
  height: 22px;
  background-color: var(--border-glass);
}

.latency-good { color: #10b981; }
.latency-fair { color: #f59e0b; }
.latency-poor { color: #ef4444; }

/* Toast Notifications */
.viewport-toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass-bright);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-smooth);
  z-index: 15;
}

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

/* Controls Panel */
.controls-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-glass);
  z-index: 20;
  gap: 20px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.btn-toggle-group {
  display: flex;
  background: rgba(0, 0, 0, 0.35);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
}

.btn-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn-toggle:hover {
  color: var(--text-main);
}

.btn-toggle.active {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.25), rgba(14, 165, 233, 0.35));
  color: #fff;
  border: 1px solid rgba(6, 182, 212, 0.4);
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.2);
}

.btn-icon {
  font-size: 0.6rem;
  color: var(--accent-primary);
}

.control-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-action:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-glass-bright);
  transform: translateY(-1px);
}

.btn-action:active {
  transform: translateY(0);
}

.btn-action svg {
  color: var(--accent-primary);
}

/* Responsive Handling */
@media (max-width: 900px) {
  .controls-panel {
    flex-wrap: wrap;
    justify-content: center;
  }
  .header-brand .brand-subtitle {
    display: none;
  }
  .hud-overlay {
    padding: 4px 8px;
    gap: 8px;
  }
}

#cameraSelect { color-scheme: dark; min-width: 110px; }
