:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-hover: #1a2744;
  --primary: #0f3460;
  --accent: #e94560;
  --accent-hover: #d63851;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --text: #eee;
  --text-muted: #94a3b8;
  --border: #2a3a5c;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}

#header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

#saved-btn {
  background: var(--primary);
  color: var(--text);
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
}

/* Map */
#map {
  flex: 1;
  min-height: 40vh;
  z-index: 1;
}

/* Controls overlay */
#controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 500;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  overflow-y: auto;
  background: linear-gradient(transparent, var(--bg) 20px);
  padding-top: 30px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card h2 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* File drop zone */
.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}

.file-drop:hover, .file-drop.dragover {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.05);
}

.drop-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* File & track lists */
#file-list, #track-list, #saved-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.track-item, .saved-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.track-item input[type="checkbox"] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
}

.track-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.track-info {
  flex: 1;
  min-width: 0;
}

.track-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.track-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
}

/* Buttons */
.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  text-align: center;
  transition: background 0.15s;
}

.btn:hover { background: var(--surface-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
}

.btn.primary:hover { background: #123d70; }

.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
}

.btn.accent:hover { background: var(--accent-hover); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* Analysis results */
.issue-item {
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  border-left: 3px solid var(--warning);
}

.issue-item.car-detected { border-left-color: var(--danger); }
.issue-item.gap-detected { border-left-color: var(--warning); }
.issue-item.ok { border-left-color: var(--success); }

.issue-type {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.issue-type.car { color: var(--danger); }
.issue-type.gap { color: var(--warning); }
.issue-type.clean { color: var(--success); }

.issue-desc {
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.issue-action {
  display: flex;
  gap: 6px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn-sm.apply {
  background: var(--accent);
  border-color: var(--accent);
}

/* Slide-in panel */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 85vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.panel:not([hidden]) {
  transform: translateX(0);
}

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

.panel-header h2 {
  font-size: 1rem;
}

#saved-list {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
}

.saved-item {
  cursor: pointer;
  transition: background 0.15s;
}

.saved-item:hover { background: var(--surface-hover); }

.saved-item .saved-name {
  font-weight: 500;
  flex: 1;
}

.saved-item .saved-date {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.saved-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 6px;
}

/* Toast */
#toast-container {
  position: fixed;
  top: 60px;
  right: 12px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  animation: slideIn 0.25s ease, fadeOut 0.3s ease 2.7s;
  max-width: 280px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

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

@keyframes fadeOut {
  to { opacity: 0; }
}

/* Responsive: landscape / wider screens */
@media (min-width: 768px) {
  body { flex-direction: row; }

  #map { flex: 1; min-height: 100vh; }

  #controls {
    position: relative;
    width: 380px;
    max-height: 100vh;
    background: var(--bg);
    padding-top: 12px;
  }
}
