/* ==========================================================================
   Botkita — KRL Tracker
   Dark theme, aligned with landing page design tokens
   ========================================================================== */

:root {
    --bg: #0b0d12;
    --bg-elev: #121520;
    --bg-card: #161a27;
    --border: #222738;
    --text: #e7ebf5;
    --text-muted: #8b93a7;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.12);
    --accent-border: rgba(59, 130, 246, 0.3);
    --accent-glow: rgba(59, 130, 246, 0.32);
    --success: #10b981;
    --danger: #ef4444;
    --radius: 14px;
    --max: 100%;
}

/* Light theme — toggled via [data-theme="light"] on <html> */
:root[data-theme="light"] {
    --bg: #f8fafc;
    --bg-elev: #ffffff;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --accent-soft: rgba(59, 130, 246, 0.08);
    --accent-border: rgba(59, 130, 246, 0.35);
}
:root[data-theme="light"] .site-header {
    background: rgba(255, 255, 255, 0.85);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.container {
    width: 100%;
    max-width: var(--max);
}

.hidden { display: none !important; }

/* ---------- Site header (nav) ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(11, 13, 18, 0.8);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    width: 100%;
}
.logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
}
.logo-mark {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--accent);
    display: inline-grid;
    place-items: center;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 800;
}
.nav-links {
    display: flex;
    gap: 24px;
    align-items: center;
}
.nav-links a {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.15s ease;
}
.nav-links a:hover { color: var(--text); }

/* Theme toggle button (in nav) */
.theme-toggle {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.theme-toggle:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

/* Refresh interval dropdown — more compact than train-select default */
.refresh-interval {
    padding: 8px 10px;
    font-size: 0.82rem;
    min-width: 120px;
    max-width: 140px;
}

/* Line legend (under the map) */
.line-legend {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.line-legend-title {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-right: 6px;
    align-self: center;
}
.line-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 6px 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-weight: 500;
}
.line-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

/* ---------- Page layout ---------- */
.page {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 12px;
}

/* ---------- Page head (compact single row) ---------- */
.page-head {
    padding: 16px 0 12px;
}
.page-head .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.head-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}
.page-head h1 {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    white-space: nowrap;
}
.page-head .subtitle {
    display: none; /* hidden for compact layout */
}
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}
.tag.live {
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}
.head-meta {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}
.meta-item {
    display: flex;
    flex-direction: column;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.meta-label {
    font-size: 0.62rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-bottom: 2px;
}
.meta-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ---------- Controls bar ---------- */
.controls-bar {
    padding: 0 0 14px;
}
.controls-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}
.train-select {
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 500;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    max-width: 100%;
    min-width: 220px;
    cursor: pointer;
}
.train-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.train-select option {
    background: var(--bg-elev);
    color: var(--text);
}
.controls-button {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.train-name {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0 6px;
}
.train-name:empty { display: none; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 20px -6px var(--accent-glow);
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 10px 30px -8px var(--accent-glow);
}
.btn-danger {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #fecaca;
}
.btn-ghost {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-ghost:hover {
    background: var(--accent-soft);
    border-color: var(--accent-border);
    color: var(--accent);
}
.btn-ghost.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

/* ---------- Station search / combobox ---------- */
.station-search {
    position: relative;
    flex: 1;
    min-width: 220px;
    max-width: 320px;
}
/* When used inline in panels (departure board, trip planner), let it
   fill the available width of its flex parent. */
.station-search.combo-inline {
    max-width: none;
    min-width: 0;
    flex: 1 1 180px;
}
.station-search-input {
    width: 100%;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
    font-family: inherit;
    font-weight: 500;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.station-search-input::placeholder { color: var(--text-muted); }
.station-search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.station-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
    max-height: 260px;
    overflow-y: auto;
    z-index: 50;
}
.station-search-item {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.92rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s ease;
}
.station-search-item:last-child { border-bottom: none; }
.station-search-item:hover,
.station-search-item.active {
    background: var(--accent-soft);
    color: var(--accent);
}
.station-search-item .code {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.04em;
    margin-left: 10px;
}

/* ---------- Nearest station panel ---------- */
.nearest-section {
    padding: 0 0 20px;
}
.nearest-panel {
    padding: 18px 22px;
    background: var(--bg-card);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
}
.nearest-panel::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.nearest-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}
.nearest-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.nearest-distance {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.nearest-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    letter-spacing: -0.01em;
}
.nearest-departures {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.nearest-departures li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.88rem;
    padding: 6px 10px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.nearest-departures li .time {
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}
.nearest-departures li .dest {
    color: var(--text-muted);
    flex: 1;
    margin-left: 10px;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nearest-departures li.empty {
    color: var(--text-muted);
    justify-content: center;
    background: transparent;
    border: 1px dashed var(--border);
}

/* ---------- Tools strip ---------- */
.tools-strip {
    padding: 0 0 12px;
}
.tools-strip .container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ---------- Departure board panel ---------- */
.db-section {
    padding: 0 0 20px;
}
.db-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.db-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    background: var(--bg-elev);
}
.db-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-top: 4px;
}
.db-eyebrow {
    display: block;
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}
.btn-close {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.btn-close:hover {
    background: var(--bg-elev);
    color: var(--text);
    border-color: var(--accent);
}

.db-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
}
.db-controls .train-select { flex: 1; min-width: 0; }
.db-clock {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    padding: 8px 16px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    letter-spacing: 0.05em;
}

.db-list {
    max-height: 420px;
    overflow-y: auto;
    padding: 8px 0;
}
.db-list .db-empty {
    padding: 30px 22px;
    color: var(--text-muted);
    text-align: center;
    font-size: 0.95rem;
}
.db-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 16px;
    align-items: center;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s ease;
}
.db-row:last-child { border-bottom: none; }
.db-row:hover { background: var(--bg-elev); }
.db-time {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    min-width: 56px;
}
.db-train-info {
    min-width: 0;
}
.db-train-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.db-train-dest {
    font-size: 0.82rem;
    color: var(--text-muted);
}
.db-eta {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    padding: 4px 10px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 100px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.db-eta.now { color: var(--success); border-color: rgba(16,185,129,0.3); background: rgba(16,185,129,0.08); }

@media (max-width: 640px) {
    .db-header,
    .db-controls { padding-left: 16px; padding-right: 16px; }
    .db-row { padding-left: 16px; padding-right: 16px; }
}

/* ---------- Map ---------- */
.map-section {
    padding: 0 0 16px;
    flex: 1;
}
#map {
    width: 100%;
    height: 72vh;
    min-height: 480px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    overflow: hidden;
    box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.5);
}

/* ---------- Footer ---------- */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 28px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.site-footer a {
    color: var(--text);
    font-weight: 500;
}

/* ---------- Google Maps InfoWindow restyle ---------- */
.gm-style .gm-style-iw-c {
    padding: 14px !important;
    border-radius: 12px !important;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4) !important;
    background: var(--bg-card) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}
.gm-style .gm-style-iw-d {
    overflow: auto !important;
    color: var(--text) !important;
}
.gm-style .gm-style-iw-tc::after {
    background: var(--bg-card) !important;
}
.gm-ui-hover-effect > span {
    background-color: var(--text-muted) !important;
}

.info-window-content h3 {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 1rem;
    font-weight: 700;
}
.info-window-content p {
    margin: 3px 0;
    font-size: 0.88rem;
    color: var(--text);
}
.info-window-content hr {
    margin: 10px 0;
    border: none;
    border-top: 1px solid var(--border);
}
.info-window-content .schedule-title {
    font-weight: 600;
    margin-top: 10px;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .page-head .container {
        flex-direction: column;
        align-items: flex-start;
    }
    .head-meta {
        width: 100%;
        gap: 12px;
    }
    .meta-item {
        flex: 1;
        min-width: 0;
        padding: 10px 14px;
    }
    .controls-inner {
        flex-direction: column;
        align-items: stretch;
    }
    .train-select {
        min-width: 0;
        width: 100%;
    }
    .controls-button {
        justify-content: flex-start;
    }
    #map {
        height: 65vh;
        min-height: 380px;
    }
}
