/* ==========================================================================
   SKYGUARD Cockpit System Stylesheet
   Mobile-First, Responsive, Command-Center Aesthetic (Dark & Light Modes)
   ========================================================================== */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #273549;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #334155;
  --accent-cyan: #06b6d4;
  --accent-blue: #3b82f6;
  
  /* Status Colors */
  --status-online: #10b981;
  --status-online-bg: rgba(16, 185, 129, 0.15);
  --status-degraded: #f59e0b;
  --status-degraded-bg: rgba(245, 158, 11, 0.15);
  --status-not-verified: #38bdf8;
  --status-not-verified-bg: rgba(56, 189, 248, 0.15);
  --status-error: #ef4444;
  --status-error-bg: rgba(239, 68, 68, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --header-height: 64px;
  --bottom-nav-height: 68px;
}

[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: #cbd5e1;
  --accent-cyan: #0891b2;
  --accent-blue: #2563eb;
  --status-online-bg: #d1fae5;
  --status-degraded-bg: #fef3c7;
  --status-not-verified-bg: #e0f2fe;
  --status-error-bg: #fee2e2;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  padding-bottom: calc(var(--bottom-nav-height) + 16px);
}

/* Header & Navbar */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  backdrop-filter: blur(8px);
}

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

.radar-icon-container {
  position: relative;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.radar-core {
  width: 12px;
  height: 12px;
  background-color: var(--accent-cyan);
  border-radius: 50%;
}

.radar-ping {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 2px solid var(--accent-cyan);
  border-radius: 50%;
  animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
  opacity: 0.75;
}

@keyframes ping {
  75%, 100% {
    transform: scale(1.8);
    opacity: 0;
  }
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text-primary);
}

.brand-subtitle {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent-cyan);
  letter-spacing: 0.08em;
}

.desktop-nav {
  display: none;
  gap: 8px;
}

.nav-btn {
  background: none;
  border: none;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-card);
}

.nav-btn.active {
  color: var(--accent-cyan);
  background-color: var(--bg-card);
}

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

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
}

.badge-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--status-error);
}

.status-indicator.online {
  background-color: var(--status-online);
}

/* Main Content Area */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text-primary);
}

.last-sync {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* System Status Grid */
.status-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.status-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.status-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.status-badge-container {
  margin-bottom: 6px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 800;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}

.badge.online {
  background-color: var(--status-online-bg);
  color: var(--status-online);
  border: 1px solid var(--status-online);
}

.badge.degraded {
  background-color: var(--status-degraded-bg);
  color: var(--status-degraded);
  border: 1px solid var(--status-degraded);
}

.badge.not-verified {
  background-color: var(--status-not-verified-bg);
  color: var(--status-not-verified);
  border: 1px solid var(--status-not-verified);
}

.badge.error, .badge.offline {
  background-color: var(--status-error-bg);
  color: var(--status-error);
  border: 1px solid var(--status-error);
}

.status-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Summary Quick Metrics Bar */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}

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

.s-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.s-val {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* Cards & Grid */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-header h3 {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.text-link-btn {
  background: none;
  border: none;
  color: var(--accent-cyan);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

/* Camera Placeholder */
.camera-stream-wrapper {
  background-color: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-placeholder {
  padding: 24px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.camera-placeholder.large {
  min-height: 320px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.placeholder-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.placeholder-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--status-degraded);
  margin-bottom: 8px;
}

.placeholder-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto;
}

.camera-info-pill {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.camera-info-pill span {
  background-color: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Events List */
.events-list-compact {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.event-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.event-main-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.event-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

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

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

/* Filters Component */
.filters-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

.form-select, .form-control {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  outline: none;
  min-height: 44px;
}

.form-range {
  width: 100%;
  accent-color: var(--accent-cyan);
  height: 24px;
}

.filter-checkboxes {
  flex-direction: row;
  gap: 16px;
  margin-top: 4px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  min-height: 36px;
}

/* Storage Bar */
.storage-bar-wrapper {
  margin: 16px 0;
}

.progress-bar {
  width: 100%;
  height: 14px;
  background-color: var(--bg-secondary);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
  border-radius: 7px;
  transition: width 0.4s ease;
}

.storage-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.85rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s ease;
}

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

.btn-secondary {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-danger {
  background-color: var(--status-error);
  color: #fff;
}

.btn-sm {
  min-height: 34px;
  padding: 4px 12px;
  font-size: 0.8rem;
}

/* Table */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  color: var(--text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
}

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

.modal-dialog {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

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

.modal-event-id {
  font-size: 0.75rem;
  color: var(--accent-cyan);
  font-weight: 700;
}

.close-modal-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 8px;
}

.modal-body {
  padding: 16px;
}

.modal-media-wrapper {
  background-color: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
}

.modal-video, .modal-audio {
  width: 100%;
  display: block;
}

.event-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

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

.meta-item.full-width {
  grid-column: span 2;
}

.meta-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.meta-value {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.hash-code {
  font-family: monospace;
  font-size: 0.75rem;
  word-break: break-all;
  background-color: var(--bg-secondary);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.uncertainty-note {
  font-size: 0.8rem;
  color: var(--status-degraded);
  background-color: var(--status-degraded-bg);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--status-degraded);
  margin-top: 4px;
}

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 99;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 12px;
  min-width: 60px;
}

.nav-icon {
  font-size: 1.3rem;
}

.nav-text {
  font-size: 0.7rem;
  font-weight: 700;
}

.bottom-nav-item.active {
  color: var(--accent-cyan);
}

/* Responsive Desktop Enhancements */
@media (min-width: 768px) {
  body {
    padding-bottom: 24px;
  }

  .desktop-nav {
    display: flex;
  }

  .mobile-bottom-nav {
    display: none;
  }

  .status-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .summary-bar {
    grid-template-columns: repeat(4, 1fr);
  }

  .dashboard-duo {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }

  .filters-card {
    flex-direction: row;
    align-items: flex-end;
  }

  .filters-card .filter-group {
    flex: 1;
  }

  .storage-metrics-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 16px;
  }

  .settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  .settings-grid .danger-card {
    grid-column: span 2;
  }
}

/* ==========================================================================
   Mobile Field Capture Styles
   ========================================================================== */
.foreground-notice-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background-color: var(--status-degraded-bg);
  border: 1px solid var(--status-degraded);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 16px;
  font-size: 0.85rem;
}

.notice-icon {
  font-size: 1.4rem;
}

.field-viewport-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}

.field-camera-wrapper {
  position: relative;
  width: 100%;
  background-color: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 240px;
  max-height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

#field-preview-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.field-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  background-color: rgba(0, 0, 0, 0.7);
  padding: 6px 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--status-error);
  animation: pulseRec 1s infinite alternate;
}

@keyframes pulseRec {
  from { opacity: 0.4; }
  to { opacity: 1.0; }
}

.rec-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.05em;
}

.rec-timer {
  font-size: 0.8rem;
  font-family: monospace;
  color: var(--accent-cyan);
}

.field-controls-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.field-control-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-control-item label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}

.field-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.btn-lg {
  min-height: 52px;
  font-size: 1rem;
  flex: 1;
}

.field-telemetry-box {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.telemetry-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  padding-bottom: 4px;
}

.telemetry-row span {
  color: var(--text-muted);
}

.telemetry-row strong {
  color: var(--text-primary);
}
