/* ═══════════════════════════════════════════════════════════════════════════
   American CDL Incident Tracker — Stylesheet
   Aesthetic: Industrial / utilitarian. Steel, asphalt, danger orange.
   Font: Barlow Condensed (headers) + Barlow (body)
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  --black:       #0d0f12;
  --steel-dark:  #1a1e26;
  --steel:       #252b36;
  --steel-mid:   #2f3847;
  --steel-light: #3d4a5c;
  --border:      #3a4455;
  --text-primary: #e8edf4;
  --text-secondary: #8fa0b8;
  --text-muted:  #5a6a80;

  --red:         #d63030;
  --red-light:   #e84040;
  --orange:      #e07020;
  --yellow:      #d4a820;
  --green:       #2e9e58;
  --blue:        #2970c8;
  --blue-light:  #3a85e0;

  --header-h:    58px;
  --controls-h:  52px;
  --stats-h:     44px;
  --footer-h:    48px;

  --font-head: 'Barlow Condensed', sans-serif;
  --font-body: 'Barlow', sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--black);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  overflow: hidden;
}

a { color: var(--blue-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.site-header {
  height: var(--header-h);
  background: var(--steel-dark);
  border-bottom: 2px solid var(--red);
  position: relative;
  z-index: 1000;
  display: flex;
  align-items: center;
}

.header-inner {
  width: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.header-flag {
  font-size: 28px;
  line-height: 1;
}

.header-title {
  font-family: var(--font-head);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-primary);
  line-height: 1.1;
}

.header-sub {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.header-nav {
  display: flex;
  gap: 4px;
}

.nav-link {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background: var(--steel-mid);
  text-decoration: none;
}

.nav-link.active {
  border-bottom: 2px solid var(--red);
  border-radius: 3px 3px 0 0;
}

/* ── Controls Bar ─────────────────────────────────────────────────────────── */
.controls-bar {
  height: var(--controls-h);
  background: var(--steel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  position: relative;
  z-index: 999;
}

.controls-inner {
  width: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.control-label {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.control-select {
  background: var(--steel-dark);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.control-select:focus, .control-select:hover {
  border-color: var(--blue-light);
}

.btn-reset {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  margin-left: auto;
}

.btn-reset:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ── Stats Bar ────────────────────────────────────────────────────────────── */
.stats-bar {
  height: var(--stats-h);
  background: var(--steel-dark);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 4px;
  position: relative;
  z-index: 998;
  overflow-x: auto;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 3px;
  background: var(--steel-mid);
  border-left: 3px solid var(--border);
  flex-shrink: 0;
}

.stat-pill.stat-red   { border-left-color: var(--red); }
.stat-pill.stat-orange{ border-left-color: var(--orange); }
.stat-pill.stat-blue  { border-left-color: var(--blue-light); }
.stat-pill.stat-green { border-left-color: var(--green); }
.stat-pill.stat-yellow{ border-left-color: var(--yellow); }
.stat-pill.stat-gray  { border-left-color: var(--text-muted); }

.stat-num {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 18px;
  line-height: 1;
  color: var(--text-primary);
}

.stat-label {
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Map ──────────────────────────────────────────────────────────────────── */
#map {
  position: absolute;
  top: calc(var(--header-h) + var(--controls-h) + var(--stats-h));
  bottom: var(--footer-h);
  left: 0;
  right: 0;
  z-index: 1;
  background: var(--steel-dark);
}

.leaflet-container {
  background: #1a2030;
  font-family: var(--font-body);
}

/* Custom marker styles */
.cdl-marker {
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  cursor: pointer;
  transition: transform 0.1s;
}
.cdl-marker:hover { transform: scale(1.3); }
.cdl-marker.fault-AT_FAULT      { background: var(--red); box-shadow: 0 0 6px rgba(214,48,48,0.7); }
.cdl-marker.fault-NOT_AT_FAULT  { background: var(--green); box-shadow: 0 0 6px rgba(46,158,88,0.7); }
.cdl-marker.fault-NO_FAULT_STATED { background: var(--text-muted); }

.cdl-marker.sz-fatal  { width: 16px; height: 16px; }
.cdl-marker.sz-injury { width: 11px; height: 11px; }
.cdl-marker.sz-pdo    { width: 7px;  height: 7px;  }

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  background: var(--steel);
  color: var(--text-primary);
  border-radius: 4px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}
.leaflet-popup-tip { background: var(--steel); }
.leaflet-popup-content { margin: 12px 14px; min-width: 240px; max-width: 320px; }
.leaflet-popup-close-button { color: var(--text-secondary) !important; }

/* ── Incident Side Panel ──────────────────────────────────────────────────── */
.incident-panel {
  position: absolute;
  top: calc(var(--header-h) + var(--controls-h) + var(--stats-h));
  right: 0;
  bottom: var(--footer-h);
  width: 360px;
  background: var(--steel);
  border-left: 1px solid var(--border);
  z-index: 500;
  overflow-y: auto;
  padding: 20px;
  transition: transform 0.25s ease;
}

.incident-panel.hidden {
  transform: translateX(100%);
}

.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--steel-mid);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}
.panel-close:hover { color: var(--red); border-color: var(--red); }

/* Panel content styles */
.panel-id {
  font-family: var(--font-head);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.panel-date {
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.panel-desc {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.fault-badge {
  display: inline-block;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 3px;
  margin-bottom: 12px;
}
.fault-badge.AT_FAULT       { background: var(--red);   color: #fff; }
.fault-badge.NOT_AT_FAULT   { background: var(--green); color: #fff; }
.fault-badge.NO_FAULT_STATED{ background: var(--steel-light); color: var(--text-secondary); }

.foreign-badge {
  display: inline-block;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 3px;
  background: var(--yellow);
  color: var(--black);
  margin-left: 6px;
  margin-bottom: 12px;
}

.panel-section {
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.panel-section-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.panel-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.panel-row-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.panel-row-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
  max-width: 200px;
}

.cost-stated  { color: var(--text-primary); }
.cost-est     { color: var(--yellow); }
.cost-note    { font-size: 10px; color: var(--text-muted); font-style: italic; margin-top: 2px; }

.severity-fatal   { color: var(--red); }
.severity-injury  { color: var(--orange); }

.source-link {
  display: block;
  font-size: 11px;
  color: var(--blue-light);
  word-break: break-all;
  margin-bottom: 3px;
}

/* ── Legend ───────────────────────────────────────────────────────────────── */
.map-legend {
  position: absolute;
  bottom: calc(var(--footer-h) + 16px);
  left: 16px;
  z-index: 500;
  background: var(--steel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  min-width: 140px;
}

.legend-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-red   { background: var(--red); }
.dot-green { background: var(--green); }
.dot-gray  { background: var(--text-muted); }

.legend-size {
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.legend-size.large  { width: 14px; height: 14px; }
.legend-size.medium { width: 10px; height: 10px; }
.legend-size.small  { width: 6px;  height: 6px; }

.legend-divider {
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
.site-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-h);
  background: var(--steel-dark);
  border-top: 1px solid var(--border);
  z-index: 999;
  display: flex;
  align-items: center;
}

.footer-inner {
  width: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.footer-left {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
}

.footer-right {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.footer-right a { color: var(--text-secondary); }
.footer-right a:hover { color: var(--text-primary); }

/* ── Popup mini styles ────────────────────────────────────────────────────── */
.popup-header {
  font-family: var(--font-head);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.popup-row { font-size: 12px; color: var(--text-secondary); margin-bottom: 3px; }
.popup-row strong { color: var(--text-primary); }
.popup-open-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 6px;
  background: var(--steel-mid);
  border: 1px solid var(--border);
  color: var(--blue-light);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s;
}
.popup-open-btn:hover { background: var(--blue); color: #fff; text-decoration: none; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--steel-dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--steel-light); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .header-nav { display: none; }
  .incident-panel { width: 100%; }
  .map-legend { display: none; }
  .stats-bar { gap: 2px; padding: 0 8px; }
  .stat-pill { padding: 4px 8px; }
  .stat-num { font-size: 15px; }
}

/* ── Page-specific (incidents.html, companies.html) ──────────────────────── */
.page-body {
  overflow: auto;
  height: calc(100vh - var(--header-h) - var(--footer-h));
  padding: 24px;
}

.page-title {
  font-family: var(--font-head);
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  text-align: left;
  background: var(--steel-dark);
  position: sticky;
  top: 0;
  cursor: pointer;
}

.data-table th:hover { color: var(--text-primary); }

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text-secondary);
}

.data-table tr:hover td { background: var(--steel-mid); }

.badge {
  display: inline-block;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 2px;
}
.badge-red    { background: rgba(214,48,48,0.2); color: var(--red-light); border: 1px solid var(--red); }
.badge-green  { background: rgba(46,158,88,0.2); color: #4ec97e; border: 1px solid var(--green); }
.badge-gray   { background: rgba(90,106,128,0.2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-yellow { background: rgba(212,168,32,0.2); color: var(--yellow); border: 1px solid var(--yellow); }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE OVERHAUL — Android Chrome optimized
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Hamburger button ─────────────────────────────────────────────────────── */
.hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 10px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Mobile nav drawer ────────────────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  background: var(--steel-dark);
  border-bottom: 2px solid var(--red);
  z-index: 2000;
  flex-direction: column;
  padding: 8px 0;
}
.mobile-nav.open { display: flex; }
.mobile-nav a {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.mobile-nav a:last-child { border-bottom: none; }
.mobile-nav a.active, .mobile-nav a:active { color: var(--text-primary); background: var(--steel-mid); }

@media (max-width: 768px) {
  /* Header */
  .hamburger { display: flex; align-items: center; justify-content: center; }
  .header-nav { display: none !important; }
  .header-title { font-size: 16px; }
  .header-sub { display: none; }
  .header-flag { font-size: 22px; }

  /* Controls bar — horizontal scroll on mobile */
  .controls-bar { height: auto; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .controls-inner {
    padding: 8px 12px;
    gap: 10px;
    flex-wrap: nowrap;
    width: max-content;
    min-width: 100%;
  }
  .control-label { font-size: 10px; }
  .control-select { font-size: 12px; padding: 4px 6px; }

  /* Year multi-select on map */
  #filter-year { height: 44px !important; min-width: 70px !important; font-size: 11px; }
  #btn-load-years, #btn-load-all-years { font-size: 10px !important; padding: 4px 8px !important; height: 44px !important; }

  /* Stats bar — horizontal scroll */
  .stats-bar {
    height: auto;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 8px;
    gap: 4px;
  }
  .stat-pill { padding: 4px 8px; flex-shrink: 0; }
  .stat-num { font-size: 14px; }
  .stat-label { font-size: 9px; }

  /* Map — full remaining height */
  #map {
    top: calc(var(--header-h) + 60px + 56px); /* header + controls + stats */
    bottom: 0;
  }

  /* Incident panel — full screen on mobile */
  .incident-panel {
    width: 100%;
    top: var(--header-h);
    bottom: 0;
    z-index: 1500;
  }

  /* Legend — hidden on mobile */
  .map-legend { display: none; }

  /* Footer — hidden on mobile to save space */
  .site-footer { display: none; }
  #map { bottom: 0; }

  /* Page containers */
  .page-container { padding: 12px; }
  .page-title { font-size: 20px; }

  /* Filter rows on incidents/companies — stack vertically */
  .filter-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .filter-row .search-input { width: 100%; }
  .filter-row .control-select { width: 100%; }
  .record-count { margin-left: 0; text-align: right; }

  /* Table — horizontal scroll */
  .table-wrap { max-height: calc(100vh - 240px); }

  /* Pagination */
  .pagination { flex-wrap: wrap; gap: 6px; }
}

/* ── Touch targets — minimum 44px ────────────────────────────────────────── */
@media (max-width: 768px) {
  .page-btn, .load-btn, .btn-reset, .nav-link { min-height: 44px; }
  .control-select { min-height: 36px; }
}
