/* ================================================================
   Xiaomi SU7 Dashcam Viewer - Complete Stylesheet
   Dark theme by default, light theme via .light class on body
   ================================================================ */

/* --- CSS Variables --- */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: #1c2128;
  --border-color: #30363d;
  --border-subtle: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #4fc3f7;
  --accent-dim: #2a7a9b;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --info: #58a6ff;
  --cam-front: #4fc3f7;
  --cam-back: #ff9800;
  --cam-left: #ab47bc;
  --cam-right: #66bb6a;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --radius: 8px;
  --radius-sm: 4px;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

body.light {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --bg-card: #ffffff;
  --border-color: #d0d7de;
  --border-subtle: #eaeef2;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8c959f;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  font-size: 14px;
}

/* --- Header --- */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 100;
}

#app-header h1 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

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

#file-summary {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 2px 10px;
  background: var(--bg-tertiary);
  border-radius: 12px;
}

/* --- Buttons --- */
.btn-primary {
  padding: 6px 14px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.btn-primary:hover { opacity: 0.9; }

.btn-large {
  padding: 12px 28px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
}
.btn-large:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-icon {
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  color: var(--text-primary);
}
.btn-icon:hover { background: var(--bg-tertiary); }

.btn-timeline {
  padding: 4px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
}
.btn-timeline:hover { background: var(--border-color); }
.btn-timeline.active { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-play { font-size: 16px; padding: 4px 14px; }

.speed-btn {
  padding: 2px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font-mono);
}
.speed-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.speed-btn:hover { border-color: var(--text-muted); }

/* --- Drop Zone --- */
#drop-zone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  transition: background 0.3s, border-color 0.3s;
}

#drop-zone.drag-over {
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-primary));
  border: 2px dashed var(--accent);
  margin: 16px;
  border-radius: var(--radius);
}

#drop-zone.loaded {
  display: none;
}

.drop-zone-content {
  text-align: center;
  max-width: 480px;
  padding: 40px 20px;
}

.drop-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.drop-zone-content h2 {
  font-size: 22px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.drop-zone-content p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.drop-hint {
  font-size: 12px !important;
  color: var(--text-muted) !important;
}

.drop-alt {
  margin-top: 16px;
  font-size: 12px !important;
  color: var(--text-muted) !important;
}

/* --- Loading --- */
#loading-status {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-content {
  text-align: center;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

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

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.loading-bar {
  width: 240px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 auto;
}

.loading-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s;
}

/* --- App Panel --- */
#app-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Layout Controls --- */
#layout-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.layout-section {
  display: flex;
  align-items: center;
  gap: 4px;
}

.layout-section-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.layout-btn, .cam-toggle-btn {
  padding: 2px 8px;
  background: var(--bg-tertiary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.layout-btn:hover, .cam-toggle-btn:hover {
  border-color: var(--border-color);
}
.layout-btn.active, .cam-toggle-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.cam-toggle-btn {
  font-size: 14px;
  padding: 2px 10px;
}

/* --- Main Content --- */
#main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* --- Map Panel --- */
#map-panel {
  width: 40%;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

#map-container {
  flex: 1;
  min-height: 200px;
}

#map-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
}

.map-placeholder-content {
  text-align: center;
  padding: 40px 20px;
}

.mph-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.map-placeholder-content h3 {
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.map-placeholder-content p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.mph-hint {
  font-size: 11px !important;
  color: var(--text-muted) !important;
  font-style: italic;
}

/* --- Info Panel --- */
#info-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  font-size: 12px;
  flex-shrink: 0;
  min-height: 80px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
}

.info-warning {
  color: var(--warning);
}

.info-icon {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.info-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.info-value.muted {
  color: var(--text-muted);
}

.speed-value {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  font-family: var(--font-mono);
}

.confidence-badge {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 3px;
  background: rgba(210, 153, 34, 0.2);
  color: var(--warning);
}

.confidence-badge.warning {
  background: rgba(210, 153, 34, 0.2);
  color: var(--warning);
}

/* --- Video Panel --- */
#video-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  overflow: hidden;
}

#video-grid {
  flex: 1;
  display: grid;
  gap: 2px;
  background: #111;
}

/* --- Video Slot --- */
.video-slot {
  display: flex;
  flex-direction: column;
  background: #000;
  position: relative;
  overflow: hidden;
}

.video-slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: rgba(0,0,0,0.8);
  cursor: grab;
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.video-slot-header:active {
  cursor: grabbing;
}

.video-slot.dragging {
  opacity: 0.5;
}

.video-slot.drag-over {
  outline: 2px solid var(--accent);
}

.cam-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.video-area {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-area video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.video-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  color: rgba(255,255,255,0.3);
  font-size: 14px;
}

.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.placeholder-icon {
  font-size: 32px;
  opacity: 0.6;
}

/* --- Timeline --- */
#timeline {
  padding: 8px 12px 10px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.time-display {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  margin: 0 12px;
  white-space: nowrap;
}

.speed-controls {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.timeline-bar-container {
  position: relative;
  height: 32px;
}

.timeline-progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  cursor: pointer;
  margin-top: 4px;
}

.timeline-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width 0.1s linear;
}

.segment-markers {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  height: 12px;
  pointer-events: none;
}

.segment-marker {
  position: absolute;
  top: 0;
  height: 12px;
  border-radius: 2px;
  pointer-events: all;
  cursor: pointer;
  transition: opacity 0.15s;
}

.seg-has-loc {
  background: rgba(79, 195, 247, 0.4);
}
.seg-has-loc:hover {
  background: rgba(79, 195, 247, 0.7);
}

.seg-no-loc {
  background: rgba(158, 158, 158, 0.3);
}
.seg-no-loc:hover {
  background: rgba(158, 158, 158, 0.5);
}

.seg-missing-cam {
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 3px,
    rgba(255, 255, 255, 0.1) 3px,
    rgba(255, 255, 255, 0.1) 6px
  );
}

.gap-marker {
  position: absolute;
  top: 0;
  height: 12px;
  background: rgba(248, 81, 73, 0.25);
  border-radius: 2px;
  cursor: default;
}

.loc-indicator {
  position: absolute;
  top: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-left: -3px;
  margin-top: 3px;
}

.loc-valid {
  background: var(--success);
}

.loc-invalid {
  background: var(--text-muted);
}

/* --- Map Position Marker --- */
.position-marker-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #03a9f4;
  border: 3px solid #fff;
  box-shadow: 0 0 8px rgba(3, 169, 244, 0.5);
  transition: background 0.3s, opacity 0.3s;
}

.leaflet-control-zoom {
  border: 1px solid var(--border-color) !important;
}
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}
.leaflet-control-attribution {
  background: rgba(0,0,0,0.6) !important;
  font-size: 9px !important;
}

/* --- Mobile Prompt --- */
#mobile-prompt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.3s;
}

#mobile-prompt-overlay.closing {
  animation: fadeOut 0.3s forwards;
}

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

.mobile-prompt {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 32px 28px;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.mobile-prompt-icon {
  font-size: 56px;
  margin-bottom: 12px;
}

.mobile-prompt h2 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.mobile-prompt p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.mobile-prompt-features {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
}

.mp-feature {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-secondary);
}

.mpf-icon {
  font-size: 24px;
}

.mobile-prompt-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.mp-btn-primary {
  padding: 10px 24px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.mp-btn-primary:hover { opacity: 0.9; }

.mp-btn-continue {
  padding: 10px 24px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
}
.mp-btn-continue:hover { background: var(--bg-tertiary); }

.mobile-prompt-hint {
  font-size: 11px !important;
  color: var(--text-muted) !important;
  margin-top: 12px;
  margin-bottom: 0 !important;
  font-style: italic;
}

/* --- Keyboard Shortcuts Panel --- */
#shortcuts-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.2s;
}

.shortcuts-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  max-width: 360px;
  width: 90%;
}

.shortcuts-content h3 {
  margin-bottom: 16px;
  font-size: 16px;
}

.shortcuts-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

.shortcuts-content td {
  padding: 6px 8px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
}

.shortcuts-content td:first-child {
  text-align: right;
  width: 60px;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-primary);
}

#shortcuts-close {
  width: 100%;
  padding: 8px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

/* --- Mobile Simplified --- */
body.mobile-simplified #map-panel {
  width: 100% !important;
  min-width: unset;
  max-height: 35vh;
}

body.mobile-simplified #main-content {
  flex-direction: column;
}

body.mobile-simplified #video-panel {
  flex: 1;
}

body.mobile-simplified #video-grid {
  grid-template-columns: 1fr !important;
  grid-template-rows: 1fr !important;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  #main-content {
    flex-direction: column;
  }

  #map-panel {
    width: 100%;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  #video-panel {
    flex: 1;
  }

  #layout-controls {
    gap: 8px;
    padding: 4px 8px;
  }

  .layout-section-label {
    display: none;
  }

  .timeline-controls {
    flex-wrap: wrap;
    gap: 4px;
  }

  .speed-controls {
    margin-left: 0;
  }
}
