/* =========================================================================
   Theme variables (ported from map-old)
   ========================================================================= */

:root {
  /* Light mode (default) */
  --bg-dark: #f5f7fa;
  --bg-card: #ffffff;
  --bg-card-alt: #f8fafc;
  --bg-input: #f8fafc;
  --bg-hover: #f1f5f9;
  --accent-red: #dc2626;
  --accent-orange: #ea580c;
  --accent-orange-dark: #c2410c;
  --accent-blue: #2563eb;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --shadow-sm: rgba(0, 0, 0, 0.08);
  --shadow-md: rgba(0, 0, 0, 0.1);
  --shadow-lg: rgba(0, 0, 0, 0.15);
  --shadow-xl: rgba(0, 0, 0, 0.2);
  --overlay-bg: rgba(0, 0, 0, 0.4);
  --muted-marker: #9ca3af;
  --btn-active-text: #fff;

  /* Tag colors (same in light and dark) */
  --tag-ccp-bg: rgba(217, 70, 239, 0.15);
  --tag-ccp-text: #d946ef;
  --tag-als-bg: rgba(190, 18, 60, 0.15);
  --tag-als-text: #be123c;
  --tag-bls-bg: rgba(37, 99, 235, 0.15);
  --tag-bls-text: #2563eb;
  --tag-mixed-bg: rgba(251, 191, 36, 0.15);
  --tag-mixed-text: #fbbf24;
  --tag-soc-bg: rgba(13, 148, 136, 0.15);
  --tag-soc-text: #0f766e;
  --tag-cp-bg: rgba(120, 130, 145, 0.15);
  --tag-cp-text: #64748b;
  --tag-ocuc-bg: rgba(120, 130, 145, 0.15);
  --tag-ocuc-text: #64748b;

  /* Station type colors */
  --type-station: #004a8d;
  --type-annex: #6b7280;
  --type-dispatch: #22c55e;
  --type-special: #ffd000;
  --type-cct: #ec1c24;

  --header-height: 81px;
}

:root[data-theme="dark"] {
  --bg-dark: #0f1419;
  --bg-card: #1a1f26;
  --bg-card-alt: #242b35;
  --bg-input: #0f1419;
  --bg-hover: #242b35;
  --accent-red: #e63946;
  --accent-orange: #f4a261;
  --accent-orange-dark: #e67e22;
  --accent-blue: #457b9d;
  --text-primary: #f1faee;
  --text-secondary: #a8b2c1;
  --border-color: #2d3748;
  --shadow-sm: rgba(0, 0, 0, 0.2);
  --shadow-md: rgba(0, 0, 0, 0.3);
  --shadow-lg: rgba(0, 0, 0, 0.4);
  --shadow-xl: rgba(0, 0, 0, 0.5);
  --overlay-bg: rgba(0, 0, 0, 0.7);
  --muted-marker: #3a3f47;
  --btn-active-text: #000;
}

/* =========================================================================
   Reset + base
   ========================================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  background: var(--bg-dark);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Map page locks the viewport so #map fills the remaining height
   under the (sticky) header without producing a vertical scrollbar. */
body.page-map {
  height: 100dvh;
  overflow: hidden;
}

a {
  color: inherit;
}

button {
  font: inherit;
  cursor: pointer;
}

/* =========================================================================
   Page layout
   ========================================================================= */

main.page {
  flex: 1;
  min-height: 0;
}

.page-stations main.page,
.page-station main.page {
  max-width: 60rem;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.page-map main.page {
  display: flex;
  flex-direction: column;
  padding: 0;
}

/* =========================================================================
   Header (ported from map-old)
   ========================================================================= */

.site-header {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-alt) 100%);
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 1px 3px var(--shadow-sm);
  flex-shrink: 0;
}

.site-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--accent-red),
    var(--accent-orange),
    var(--accent-red)
  );
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
}

.logo-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent-red), #c41e3a);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 4px 15px rgba(230, 57, 70, 0.3);
  flex-shrink: 0;
}

.logo-text h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.logo-text p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 400;
  margin: 0;
}

.site-nav {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.site-nav .nav-link {
  text-decoration: none;
  color: var(--text-secondary);
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 120ms ease, color 120ms ease;
}

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

.header-search {
  position: relative;
  flex: 1;
  max-width: 28rem;
  min-width: 0;
  margin: 0 auto;
}

.header-search-input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background-color 0.15s ease;
}

.header-search-input::placeholder {
  color: var(--text-secondary);
}

.header-search-input:hover {
  border-color: color-mix(in srgb, var(--accent-orange) 35%, var(--border-color));
}

.header-search-input:focus {
  outline: none;
  border-color: var(--accent-orange);
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--accent-orange) 20%, transparent);
}

/* Hide the native search clear button (we provide Esc / click-out) */
.header-search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.header-search-results {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 0;
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 8px 24px var(--shadow-lg);
  max-height: 22rem;
  overflow-y: auto;
  z-index: 1100;
}

.header-search-results[hidden] {
  display: none;
}

.header-search-result {
  display: block;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-search-result:hover,
.header-search-result[aria-selected="true"] {
  background: var(--bg-hover);
}

.header-search-result-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.header-search-empty {
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-item {
  text-align: center;
  padding: 0 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-orange);
  line-height: 1;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.15rem;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, transform 120ms ease;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none;
  font-size: 1.05rem;
  line-height: 1;
}

/* In light mode show the moon (next state); in dark show the sun. */
:root:not([data-theme="dark"]) .theme-toggle .icon-moon {
  display: inline-block;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: inline-block;
}

/* =========================================================================
   Tag pills (used on station detail + sidebar)
   ========================================================================= */

.station-tags {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0 0;
  padding: 0;
}

.tag {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.4;
}

.tag-ccp   { background: var(--tag-ccp-bg);   color: var(--tag-ccp-text); }
.tag-als   { background: var(--tag-als-bg);   color: var(--tag-als-text); }
.tag-bls   { background: var(--tag-bls-bg);   color: var(--tag-bls-text); }
.tag-mixed { background: var(--tag-mixed-bg); color: var(--tag-mixed-text); }
.tag-soc   { background: var(--tag-soc-bg);   color: var(--tag-soc-text); }
.tag-cp    { background: var(--tag-cp-bg);    color: var(--tag-cp-text); }
.tag-ocuc  { background: var(--tag-ocuc-bg);  color: var(--tag-ocuc-text); }

/* =========================================================================
   Response Data section (used on station detail + sidebar)
   ========================================================================= */

.station-response {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.response-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.response-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  letter-spacing: -0.005em;
}

.response-title-icon {
  font-size: 1rem;
  line-height: 1;
}

/* Year selector pill (matches map-old) */
.year-selector {
  position: relative;
}

.year-selector::after {
  content: "\25BE";
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--accent-orange);
  font-size: 0.7rem;
}

.response-year-select {
  appearance: none;
  -webkit-appearance: none;
  background: color-mix(in srgb, var(--text-primary) 5%, transparent);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.3rem 1.7rem 0.3rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-orange);
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.response-year-select:hover {
  background-color: color-mix(in srgb, var(--text-primary) 8%, transparent);
  border-color: var(--accent-orange);
}

.response-year-select:focus {
  outline: none;
  border-color: var(--accent-orange);
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--accent-orange) 20%, transparent);
}

.response-year-select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Aggregate notice */
.response-aggregate {
  background: color-mix(in srgb, var(--accent-blue) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-blue) 25%, transparent);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  margin: 0 0 0.7rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.response-aggregate strong {
  color: var(--accent-blue);
  font-weight: 700;
}

/* Total calls line */
.response-total {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 0 0 0.55rem;
}

.response-total strong {
  color: var(--accent-orange);
  font-size: 1.05rem;
  font-weight: 700;
}

/* Priority cards */
.response-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.priority {
  background: color-mix(in srgb, var(--text-primary) 3%, transparent);
  border-radius: 8px;
  padding: 0.6rem 0.55rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

.priority-critical { border-left: 3px solid var(--accent-red); }
.priority-urgent   { border-left: 3px solid var(--accent-orange); }
.priority-routine  { border-left: 3px solid #f1c40f; }

.priority-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.priority-stats {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.priority-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.1;
}

.priority-time {
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  color: var(--text-secondary);
}

/* Year panel toggle - JS sets data-active-year on .station-response;
   matching panel becomes visible, the rest hide. */
.response-year-panel {
  display: none;
}

.station-response[data-active-year="2018"] .response-year-panel[data-year="2018"],
.station-response[data-active-year="2019"] .response-year-panel[data-year="2019"],
.station-response[data-active-year="2020"] .response-year-panel[data-year="2020"],
.station-response[data-active-year="2021"] .response-year-panel[data-year="2021"],
.station-response[data-active-year="2022"] .response-year-panel[data-year="2022"],
.station-response[data-active-year="2023"] .response-year-panel[data-year="2023"],
.station-response[data-active-year="2024"] .response-year-panel[data-year="2024"],
.station-response[data-active-year="2025"] .response-year-panel[data-year="2025"],
.station-response[data-active-year="2026"] .response-year-panel[data-year="2026"] {
  display: block;
}

/* =========================================================================
   Internal shift patterns
   ========================================================================= */

.station-shifts {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.shifts-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.6rem;
}

.shifts-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
  letter-spacing: -0.005em;
}

.shifts-badge {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-orange);
  background: color-mix(in srgb, var(--accent-orange) 12%, transparent);
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
  line-height: 1;
}

.shifts-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.shifts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.shifts-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.shifts-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 50%, transparent);
  color: var(--text-primary);
  vertical-align: top;
}

.shifts-table tr:last-child td {
  border-bottom: none;
}

.shifts-table th:nth-child(4),
.shifts-table td:nth-child(4) {
  min-width: 4.25rem;
}


/* =========================================================================
   Mobile
   ========================================================================= */

@media (max-width: 768px) {
  .site-header {
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
  }

  .logo-text p {
    display: none;
  }

  .logo-text h1 {
    font-size: 1.15rem;
  }

  .logo-icon {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }

  .logo-section {
    order: 1;
  }

  .site-nav {
    order: 2;
    flex: 0 0 auto;
    margin-left: auto;
    justify-content: flex-end;
  }

  .header-actions {
    order: 3;
  }

  .header-search {
    order: 4;
    flex: 1 1 100%;
    min-width: 0;
    max-width: none;
    margin: 0;
  }

  /* On the map/stations listing pages, hide the "current page" nav link on
     mobile so the remaining single link sits cleanly next to the theme toggle. */
  body.page-map .site-nav .nav-link[href="/"],
  body.page-stations .site-nav .nav-link[href="/stations/"] {
    display: none;
  }

  .stat-item {
    display: none;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
  }
}
