:root {
    --brand-dark: #00497C;
    --brand-mid: #0066AD;
    --brand-accent: #1EA7DC;
    --bg-page: #F2F5F8;
    --bg-card: #FFFFFF;
    --border-subtle: #DCE3EA;
    --text-primary: #1B2733;
    --text-secondary: #526477;
    --green: #16A34A;
    --red: #DC2626;
    --orange: #EA580C;
    --teal: #0D9488;
    --blue: #2563EB;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(0, 35, 65, 0.06);
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-primary);
    background: var(--bg-page);
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.site-header {
    background: linear-gradient(135deg, #003860 0%, var(--brand-dark) 55%, #005B99 100%);
    color: #fff;
    padding: 22px 0 18px;
    text-align: center;
}

.site-header h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.1rem);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.site-header .tagline {
    margin: 6px 0 0;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.88);
}

/* Archive Notice & Year Bar */
.intro-bar {
    background: #E8F2FA;
    border-bottom: 1px solid #C8DFEF;
    padding: 12px 0;
}

.intro-bar__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
}

.intro-bar__notice {
    margin: 0;
    font-size: 0.9rem;
    color: #163C5A;
    flex: 1 1 480px;
}

.intro-bar__notice a {
    color: var(--brand-dark);
    font-weight: 600;
}

.year-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.9rem;
}

.year-picker label {
    font-weight: 600;
    color: var(--brand-dark);
}

.year-picker select {
    padding: 5px 10px;
    border: 1px solid #9FC3DF;
    border-radius: 6px;
    background: #fff;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
}

.year-picker__note {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

/* Main Grid */
.main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 20px;
    padding-top: 20px;
    padding-bottom: 32px;
    align-items: start;
}

.col-left, .col-right {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 16px;
    background: var(--brand-accent);
    color: #fff;
}

.card-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
}

.card-header__actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.card-body {
    padding: 16px;
}

/* Buttons */
.btn-header {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 6px;
    padding: 5px 11px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-header:hover {
    background: rgba(255, 255, 255, 0.32);
}

/* Loading Pill */
.loading-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: rgba(0, 45, 80, 0.24);
    color: #fff;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
}

.loading-pill[hidden] {
    display: none;
}

.spinner-ring {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* Map Toolbar & Search */
.map-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 14px;
    padding: 10px 14px;
    background: #F8FAFC;
    border-bottom: 1px solid var(--border-subtle);
}

.search-wrap {
    position: relative;
    flex: 1 1 240px;
}

.search-wrap input {
    width: 100%;
    padding: 7px 11px;
    border: 1px solid #C5D2DF;
    border-radius: 6px;
    font-size: 0.88rem;
    color: var(--text-primary);
    background: #fff;
}

.search-wrap input:focus {
    outline: 2px solid rgba(30, 167, 220, 0.35);
    border-color: var(--brand-accent);
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 1200;
    list-style: none;
    margin: 0;
    padding: 4px 0;
    background: #fff;
    border: 1px solid #C5D2DF;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 35, 65, 0.16);
    max-height: 260px;
    overflow-y: auto;
}

.search-results li {
    padding: 7px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.86rem;
}

.search-results li:hover,
.search-results li.active {
    background: #EDF6FC;
}

.search-results .stop-meta {
    font-size: 0.76rem;
    color: var(--text-secondary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.badge-mode {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.badge-mode--bus {
    background: #FEE2E2;
    color: #991B1B;
}

.badge-mode--tram {
    background: #CCFBF1;
    color: #115E59;
}

.map-legend {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot--bus { background: #E11D48; }
.dot--tram { background: var(--teal); }
.dot--origin { background: var(--green); }
.dot--dest { background: #991B1B; }

/* Map */
.map-container {
    width: 100%;
    height: 520px;
    background: #E5ECF2;
}

/* Muted Carto-Positron-style OpenStreetMap tiles (no API key needed) */
.map-light .leaflet-tile-pane {
    filter: saturate(0.28) brightness(1.06) contrast(0.93);
}

.map-status {
    padding: 8px 14px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    background: #F8FAFC;
    border-top: 1px solid var(--border-subtle);
}

/* Custom Leaflet Cluster Styling */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background-color: rgba(0, 102, 173, 0.25) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background-color: #0066AD !important;
    color: #fff !important;
    font-weight: 700;
    font-size: 12px !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}

/* Custom SVG Pin Markers */
.rjt-pin {
    background: transparent;
    border: none;
}

.rjt-pin svg {
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.32));
    transition: transform 0.12s ease;
}

.rjt-pin:hover svg {
    transform: scale(1.16);
}

.rjt-route-arrow {
    background: transparent;
    border: none;
}

/* Date Controls */
.date-controls {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    flex-wrap: wrap;
}

.control-group {
    flex: 1 1 200px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.control-group input,
.control-group select {
    padding: 8px 10px;
    border: 1px solid #C5D2DF;
    border-radius: 6px;
    font-size: 0.92rem;
    color: var(--text-primary);
    background: #fff;
}

.control-divider {
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding-bottom: 10px;
}

/* API Explorer */
.api-intro {
    margin: 0 0 12px;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.api-item {
    margin-bottom: 12px;
}

.api-item:last-child {
    margin-bottom: 0;
}

.api-item__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.api-item__row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #F4F7FA;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 6px 10px;
}

.api-url {
    flex: 1;
    min-width: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--brand-mid);
    text-decoration: none;
    overflow-wrap: anywhere;
}

.api-url:hover {
    text-decoration: underline;
}

.api-url--empty {
    color: #8797A8;
    pointer-events: none;
    font-family: inherit;
    font-style: italic;
}

.btn-copy {
    flex-shrink: 0;
    padding: 4px 9px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid #C5D2DF;
    border-radius: 5px;
    background: #fff;
    color: var(--text-primary);
    cursor: pointer;
}

.btn-copy:hover:not(:disabled) {
    background: #E8F2FA;
    border-color: var(--brand-accent);
}

.btn-copy:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Charts Column */
.empty-state {
    padding: 48px 28px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state__icon {
    color: var(--brand-accent);
    margin-bottom: 10px;
}

.empty-state h3 {
    margin: 0 0 8px;
    font-size: 1.15rem;
    color: var(--text-primary);
}

.empty-state p {
    margin: 0 auto;
    max-width: 440px;
    font-size: 0.92rem;
}

.empty-state--warn h3 {
    color: #B45309;
}

.journey-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    background: #F4F9FD;
    border: 1px solid #CFE3F3;
    border-radius: 8px;
    margin-bottom: 16px;
}

.journey-banner__stops {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--brand-dark);
}

.inline-control {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.85rem;
}

.inline-control label {
    font-weight: 600;
    color: var(--text-secondary);
}

.inline-control select {
    padding: 4px 8px;
    border: 1px solid #C5D2DF;
    border-radius: 5px;
    background: #fff;
    font-size: 0.85rem;
}

/* KPI Strip (4 cards) */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}

.kpi-card {
    background: #F8FAFC;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 10px 8px;
    text-align: center;
}

.kpi-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    line-height: 1.25;
}

.kpi-value {
    margin-top: 4px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

@media (max-width: 620px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.kpi-value--sched { color: var(--blue); }
.kpi-value--real { color: var(--orange); }
.kpi-value--p90 { color: var(--red); }

/* Chart Blocks */
.chart-block {
    margin-bottom: 24px;
}

.chart-block:last-child {
    margin-bottom: 0;
}

.chart-block__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.chart-block__head h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-subtitle {
    margin: 2px 0 0;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.canvas-wrap {
    position: relative;
    width: 100%;
}

.canvas-wrap--tall {
    height: 300px;
}

.canvas-wrap--med {
    height: 270px;
}

.timeline-scroll {
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 8px;
    background: #FCFDFE;
}

/* Footer */
.site-footer {
    background: var(--brand-dark);
    color: rgba(255, 255, 255, 0.9);
    padding: 26px 0 32px;
}

.footer-inner {
    max-width: 960px;
}

.site-footer h3 {
    margin: 0 0 12px;
    font-size: 1.05rem;
    color: #fff;
}

.credit-list {
    margin: 0;
    padding-left: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 6px 24px;
    font-size: 0.88rem;
}

.site-footer a {
    color: #7DD3FC;
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 980px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .map-container {
        height: 420px;
    }
}
