@import url("https://cdn.jsdelivr.net/npm/@mdi/font@7.4.47/css/materialdesignicons.min.css");

/* --- Base & Typography --- */
@font-face {
    font-family: "FF DIN Pro";
    src: url("/public/fonts/D-DIN-PRO-400-Regular.otf") format("opentype");
    font-weight: 400;
    font-style: normal;
}
@font-face {
    font-family: "FF DIN Pro";
    src: url("/public/fonts/D-DIN-PRO-600-SemiBold.otf") format("opentype");
    font-weight: 600;
    font-style: normal;
}

/* --- Popup styling (bikes etc.) --- */
.bike-popup {
    font-family: "FF DIN Pro", sans-serif;
    font-size: 0.85rem;
    color: #000;
}
.depart-soon  { background-color: #00b934; }
.depart-medium { color: #c89600; }
.depart-late  { color: #ff0000; }

.bike-popup strong { color: #007cbf; }

.route-icon { width: 36px; }

body {
    font-family: "FF DIN Pro", sans-serif;
    background-color: #181a20;
    color: #fff;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* --- Header & Navigation --- */
header {
    background-color: #111;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 100;
}

nav {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
}

.logo {
    font-size: 1.5rem;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
}
.logo:hover { color: #63b3ed; }

.nav-links a {
    color: #fff;
    text-decoration: none;
    padding: 8px 15px;
    margin-left: 10px;
    border-radius: 6px;
    transition: background-color 0.2s;
    font-weight: 500;
}
.nav-links a.active {
    background-color: #63b3ed;
    color: #181a20;
    font-weight: 600;
}
.nav-links a:hover:not(.active) { background-color: #222; }

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

/* --- General flex layout (non-map pages) --- */
.content {
    display: flex;
    gap: 20px;
    margin-top: 30px;
    align-items: center;
    flex-wrap: wrap;
}

.sidebar {
    width: 350px;
    max-height: 80vh;
    overflow-y: auto;
    flex-shrink: 0;
}

.table-container {
    background-color: #1e1f26;
    border-radius: 12px;
    overflow-x: auto;
    padding: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    animation: fadeIn 1s ease;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #333;
}

thead tr { background-color: #252731; }

th {
    color: #aaa;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
}

tbody tr:hover {
    background-color: #2b2d36;
    transition: background-color 0.15s;
}
tbody tr:nth-child(even) { background-color: #212229; }

/* --- General map container (non-map pages) --- */
#map {
    flex: 1;
    height: 80vh;
    min-height: 300px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.routeicon {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

/* =============================================
   TRAIN POPUP GRID (general)
============================================= */
.popup-route {
    display: grid;
    grid-template-columns: 20px 28px 1fr;
    align-items: center;
    gap: 8px;
    margin: 8px 0 10px;
    padding: 6px 8px;
    background: #b0b0b0;
    border-radius: 8px;
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}
.popup-header b {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
}

.agency-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    flex-shrink: 0;
}

.popup-route .mdi {
    font-size: 18px;
    color: #aaa;
}

.route-text {
    font-size: 0.85rem;
    font-weight: 600;
    text-align: end;
}

/* =============================================
   MAP PAGE LAYOUT
   .map-shell overrides the general sidebar/#map
   styles above for the full-screen map view
============================================= */

body:has(.map-shell) {
    overflow: hidden;
}

.map-shell {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: 1fr;
    /* subtract the sticky header height */
    height: calc(100vh - 57px);
    width: 100%;
}

/* Reset #map inside the shell to fill its cell */
.map-shell #map {
    flex: unset;
    height: 100%;
    min-height: unset;
    border-radius: 0;
    box-shadow: none;
}

/* ── Departures panel ── */
.map-shell .sidebar,
.departures-panel {
    display: flex;
    flex-direction: column;
    width: auto;
    max-height: unset;
    height: 100%;
    overflow: hidden;
    background-color: #13151d;
    border-right: 1px solid #2a2d3d;
    flex-shrink: unset;
}

/* ── Empty state ── */
.panel-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 28px 28px 32px;
    text-align: center;
    color: #5a6080;
    /* Push to bottom of the sidebar flex/grid container */
    margin-top: auto;
}
.panel-empty-icon {
    font-size: 44px;
    opacity: 0.4;
    line-height: 1;
}
.panel-empty p {
    font-size: 0.83rem;
    line-height: 1.6;
    max-width: 210px;
}

/* ── Panel station container ── */
.panel-station {
    display: grid;
    grid-template-rows: auto auto 1fr;
    height: 100%;
    overflow: hidden;
}

/* ── Panel header ── */
.panel-header {
    padding: 16px 18px 14px;
    border-bottom: 1px solid #2a2d3d;
    background-color: #1a1d2a;
}

.panel-header-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}

.panel-agency-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    padding: 3px;
    flex-shrink: 0;
}

.panel-station-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #e8eaf0;
    line-height: 1.25;
}

.panel-station-id {
    font-size: 0.72rem;
    color: #5a6080;
    margin-top: 3px;
}

/* Route color badges */
.panel-route-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.route-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px 3px 6px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: #fff;
    white-space: nowrap;
}

.route-badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(255,255,255,0.55);
    flex-shrink: 0;
}

/* ── Section label ── */
.panel-section-label {
    padding: 9px 18px 8px;
    font-size: 0.67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #5a6080;
    background: #13151d;
    border-bottom: 1px solid #2a2d3d;
}

/* ── Scrollable table area ── */
.panel-scroll {
    overflow-y: auto;
    height: 100%;
}

.panel-scroll::-webkit-scrollbar { width: 4px; }
.panel-scroll::-webkit-scrollbar-track { background: transparent; }
.panel-scroll::-webkit-scrollbar-thumb {
    background: #2a2d3d;
    border-radius: 2px;
}

/* ── Departures table (sidebar) ── */
.departures-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.departures-table thead tr {
    background: #1a1d2a;
    position: sticky;
    top: 0;
    z-index: 1;
}

.departures-table th {
    padding: 9px 14px;
    text-align: left;
    font-size: 0.67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #5a6080;
    border-bottom: 1px solid #2a2d3d;
}

.departures-table td {
    padding: 11px 14px;
    vertical-align: middle;
    border-bottom: 1px solid #1e2030;
    color: #c8cad8;
}

.departures-table tbody tr:hover td { background: #1e2133; }

/* Line pill */
.dep-line-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 0.71rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
}

/* Time column */
.dep-time {
    font-weight: 700;
    color: #e8eaf0;
    white-space: nowrap;
}
.dep-mins {
    font-size: 0.71rem;
    color: #5a6080;
    margin-top: 2px;
}

/* Loading / empty rows */
.loading-row td,
.empty-row td {
    text-align: center;
    color: #5a6080;
    padding: 28px 14px;
}

.loading-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #2a2d3d;
    border-top-color: #4f7fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 5px;
}

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

/* =============================================
   MAPLIBRE POPUP — dark theme override
============================================= */
.maplibregl-popup-content {
    background: #1a1d2a !important;
    border: 1px solid #2a2d3d !important;
    border-radius: 10px !important;
    padding: 0 !important;
    box-shadow: 0 8px 28px rgba(0,0,0,0.55) !important;
    min-width: 230px;
    max-width: 290px;
    overflow: hidden;
    font-family: "FF DIN Pro", sans-serif;
}

.maplibregl-popup-tip {
    border-top-color: #1a1d2a !important;
    border-bottom-color: #1a1d2a !important;
}

.maplibregl-popup-close-button {
    color: #5a6080 !important;
    font-size: 20px !important;
    right: 8px !important;
    top: 6px !important;
    background: none !important;
    border: none !important;
    line-height: 1;
    z-index: 1;
}
.maplibregl-popup-close-button:hover { color: #e8eaf0 !important; }

/* ── Popup shell ── */
.popup {
    padding: 0;
    color: #e8eaf0;
    font-family: "FF DIN Pro", sans-serif;
    font-size: 0.82rem;
    border-bottom: none; /* override old rule */
}

/* ── Popup header ── */
.popup .popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px 10px;
    border-bottom: 1px solid #2a2d3d;
    background: #1e2133;
    /* override old justify-content so title fills left */
    justify-content: flex-start;
    width: auto;
}

.popup-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: #e8eaf0;
    flex: 1;
    line-height: 1.2;
}

.popup-agency-logo {
    width: 24px;
    height: 24px;
    object-fit: contain;
    border-radius: 4px;
    background: #fff;
    padding: 2px;
    flex-shrink: 0;
}

.popup-route-icon {
    width: 26px;
    height: 26px;
    object-fit: contain;
    flex-shrink: 0;
}

/* ── Popup key-value rows ── */
.popup-body {
    padding: 10px 14px;
    display: grid;
    gap: 6px;
}

.popup-row {
    display: grid;
    grid-template-columns: 76px 1fr;
    gap: 6px;
    font-size: 0.8rem;
    line-height: 1.3;
}
.popup-row-label { color: #5a6080; }
.popup-row-value { color: #c8cad8; font-weight: 600; }

/* Metrolink delay colours */
.popup-body.On-Time .popup-status { color: #00c853; }
.popup-body.Late    .popup-status { color: #ff5252; }
.popup-body.Early   .popup-status { color: #ffab40; }

/* Delay Status Styling */
.ontime,
.ontime .mdi {
  color: #2e7d32;
  padding: 2px 2px;
  border-radius: 2px;
  font-weight: 600;
}

/* Early: arriving before scheduled time */
.early,
.early .mdi {
  color: #1976d2;
  padding: 2px 2px;
  border-radius: 2px;
  font-weight: 600;
}

/* Mild delay: 1-5 minutes */
.mild,
.mild .mdi {
  color: #ff6f00;
  padding: 2px 4px;
  border-radius: 2px;
  font-weight: 600;
}

/* Late: 5-10 minutes */
.late,
.late .mdi {
  color: #d32f2f;
  padding: 2px 4px;
  border-radius: 2px;
  font-weight: 600;
}

/* Extreme delay: 10+ minutes */
.extreme,
.extreme .mdi {
  color: #b71c1c;
  padding: 2px 4px;
  border-radius: 2px;
  font-weight: 700;
}

/* ── Popup mini departure table — removed (departures are sidebar-only) ── */

/* =============================================
   RESPONSIVE
============================================= */
@media (max-width: 1024px) {
    .content { flex-direction: column; }
    .sidebar { width: 100%; max-height: 300px; }
    #map { height: 60vh; min-height: 300px; }
}

@media (max-width: 768px) {
    .map-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 55vh 1fr;
        height: calc(100vh - 57px);
    }

    .map-shell #map { order: 1; border-radius: 0; }

    .departures-panel,
    .map-shell .sidebar {
        order: 2;
        border-right: none;
        border-top: 1px solid #2a2d3d;
        height: auto;
        max-height: 45vh;
    }
}