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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3344;
  --text: #e1e4ed;
  --text-dim: #8b90a0;
  --accent: #4f8ff7;
  --accent-dim: #3a6bc5;
  --red: #e85454;
  --orange: #e8a534;
  --green: #42c96a;
  --yellow: #e8d44d;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

h1 {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 2px;
}

.stats-bar {
  display: flex;
  gap: 16px;
}

.stat {
  background: var(--surface2);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border);
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  gap: 0;
}

.tab {
  padding: 12px 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: var(--font);
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Map */
#map {
  height: 500px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

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

.section-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.btn-refresh, .btn-primary {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}

.btn-refresh:hover, .btn-primary:hover {
  background: var(--border);
}

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

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

/* Filters */
.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filters select,
.filters input {
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
}

.filters input[type="date"] {
  color-scheme: dark;
}

/* Incident list */
.incident-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.incident-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.incident-card:hover {
  border-color: var(--accent);
  background: var(--surface2);
}

.incident-card .top-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.incident-card .route-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.incident-card .type-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.type-badge.accident { background: var(--red); color: #fff; }
.type-badge.congestion { background: var(--orange); color: #000; }
.type-badge.disabled { background: var(--yellow); color: #000; }
.type-badge.construction { background: #8b5cf6; color: #fff; }
.type-badge.closure { background: #e85454; color: #fff; }
.type-badge.other { background: var(--text-dim); color: #000; }

.incident-card .priority {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-left: auto;
}

.incident-card .active-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.incident-card .message {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.5;
}

.incident-card .meta {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 6px;
}

/* History meta */
.history-meta {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* Pagination */
.pagination {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}

.pagination button {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font);
}

.pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 20px;
  overflow-y: auto;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 700px;
  width: 100%;
  padding: 24px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
}

.modal h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.modal .detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 12px;
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.modal .detail-grid .label {
  color: var(--text-dim);
  font-weight: 500;
}

.modal .detail-grid .value {
  color: var(--text);
  word-break: break-word;
}

.modal .snapshots h4 {
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.modal .snapshot-item {
  background: var(--surface2);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.modal .snapshot-item .snap-time {
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 4px;
}

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* Leaflet popup styling */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4) !important;
}

.leaflet-popup-tip {
  background: var(--surface) !important;
}

.leaflet-popup-content {
  font-family: var(--font) !important;
  font-size: 0.85rem !important;
  line-height: 1.5 !important;
}

.leaflet-popup-content strong {
  color: var(--accent);
}

/* Responsive */
@media (max-width: 768px) {
  header {
    padding: 12px 16px;
  }
  h1 { font-size: 1.1rem; }
  main { padding: 12px 16px; }
  .tabs { padding: 0 16px; }
  .tab { padding: 10px 14px; font-size: 0.85rem; }
  #map { height: 350px; }
  .filters { flex-direction: column; }
  .modal .detail-grid {
    grid-template-columns: 1fr;
  }
  .stats-bar { gap: 8px; }
  .stat { padding: 4px 10px; font-size: 0.8rem; }
}
