:root {
  --bg-main: #070a10;
  --bg-card: #0f1522;
  --bg-card-subtle: #162033;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: #3b82f6;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-blue: #2563eb;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --font-ui: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-ui);
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background-color: rgba(15, 21, 34, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  background: linear-gradient(135deg, #1d4ed8, #0ea5e9);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  box-shadow: 0 0 16px rgba(37, 99, 235, 0.4);
}

.brand-details h1 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #fff;
}

.brand-details .subtext {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.nav-center {
  display: flex;
  align-items: center;
  gap: 16px;
}

.system-status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-green);
  letter-spacing: 0.05em;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 12px var(--accent-green); }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.cctv-clock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #38bdf8;
  background: rgba(10, 15, 25, 0.8);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.2);
  letter-spacing: 0.06em;
}

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

.layout-controls {
  display: flex;
  background: rgba(10, 15, 25, 0.8);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  gap: 3px;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.btn-icon.active {
  color: #fff;
  background: var(--accent-blue);
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.5);
}

.btn-lbl {
  font-size: 10px;
  letter-spacing: 0.02em;
}

.btn-action {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-action:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.btn-action.primary {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.4);
}

.btn-action.primary:hover {
  background: #1d4ed8;
}

/* Channel Filter Bar */
.channel-filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  background: rgba(10, 15, 25, 0.9);
  border-bottom: 1px solid var(--border-color);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.filter-pill {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-pill:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.filter-pill.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: #3b82f6;
  color: #60a5fa;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

.stream-stats-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #34d399;
  background: rgba(16, 185, 129, 0.1);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

/* Viewport Grid Container */
.viewport-container {
  flex: 1;
  padding: 12px;
  gap: 12px;
  overflow-y: auto;
  display: grid;
}

/* Layout 4x4 (16 View) */
.viewport-container.layout-grid-4x4 {
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: minmax(180px, 1fr);
}

/* Layout 3x3 (9 View) */
.viewport-container.layout-grid-3x3 {
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(220px, 1fr);
}

/* Layout 2x2 (4 View) */
.viewport-container.layout-grid-2x2 {
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: minmax(280px, 1fr);
}

/* Layout Hero (1 Large + Small) */
.viewport-container.layout-hero {
  grid-template-columns: 2.5fr 1fr;
  grid-auto-rows: minmax(180px, 1fr);
}

.viewport-container.layout-hero .camera-card:first-child {
  grid-row: span 3;
}

/* Layout Single Focus (1x1) */
.viewport-container.layout-single {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.viewport-container.layout-single .camera-card:not(.active-single) {
  display: none;
}

/* Camera Card */
.camera-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.camera-card:hover {
  border-color: rgba(59, 130, 246, 0.4);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(10, 15, 25, 0.85);
  border-bottom: 1px solid var(--border-color);
}

.cam-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cam-badge {
  background: #162033;
  border: 1px solid #1e293b;
  color: #38bdf8;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
}

.cam-badge.tapo {
  color: #34d399;
  border-color: #059669;
}

.cam-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

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

.live-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-red);
  letter-spacing: 0.08em;
  font-family: var(--font-mono);
}

.live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-red);
  box-shadow: 0 0 5px var(--accent-red);
  animation: pulse-red 1.5s infinite;
}

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

/* Video Wrapper */
.video-wrapper {
  flex: 1;
  background: #000;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 120px;
}

.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Loading & Error */
.loading-spinner, .error-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(7, 10, 16, 0.85);
  backdrop-filter: blur(4px);
  z-index: 4;
  color: var(--text-muted);
  font-size: 11px;
}

.spinner-ring {
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.error-overlay.hidden, .loading-spinner.hidden {
  display: none;
}

.btn-retry {
  background: #1e293b;
  border: 1px solid #334155;
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
}

.btn-retry:hover {
  background: #334155;
}

/* Card Footer */
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: rgba(10, 15, 25, 0.85);
  border-top: 1px solid var(--border-color);
}

.stat-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cam-actions {
  display: flex;
  gap: 4px;
}

.action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.action-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* Fullscreen card */
.camera-card.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  border-radius: 0;
}

/* Tapo Card */
.tapo-card .placeholder-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  background: radial-gradient(circle at center, #162033 0%, #0f1522 100%);
  gap: 8px;
}

.btn-setup {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
  transition: 0.2s;
}

.btn-setup:hover {
  opacity: 0.9;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  width: 90%;
  max-width: 520px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8);
}

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

.modal-header h2 {
  font-size: 15px;
  color: #fff;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.modal-body {
  padding: 18px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
}

.steps-list {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.code-box {
  background: #070a10;
  border: 1px solid #1e293b;
  color: #38bdf8;
  font-family: var(--font-mono);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  margin-top: 4px;
  word-break: break-all;
}

.modal-note {
  font-size: 12px;
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Tapo Cloud Integration Styles */
.tapo-input {
  background: #070a10;
  border: 1px solid #1e293b;
  border-radius: 6px;
  padding: 9px 12px;
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.tapo-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.15);
}

.tapo-alert {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
}

.tapo-alert.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
}

.tapo-alert.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.filter-pill.tapo-pill {
  border-color: rgba(56, 189, 248, 0.3);
  color: #38bdf8;
}

.filter-pill.tapo-pill.active {
  background: rgba(56, 189, 248, 0.2);
  border-color: #38bdf8;
}

.tapo-device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #070a10;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  font-size: 12px;
}

.tapo-device-item:hover {
  border-color: rgba(56, 189, 248, 0.3);
}

.tapo-cam-card .tapo-cam-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
  background: radial-gradient(circle at center, #111a2e 0%, #080d1a 100%);
  gap: 8px;
  text-align: center;
}

