/*
==============
THEME TOKENS
Same look as the fleet dashboard: dark base, glass panels, blue accent.
==============
*/
:root {
    --bg: #1a1a1a;
    --panel: rgba(26, 26, 26, 0.95);
    --panel-soft: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.3);
    --text: #ffffff;
    --muted: #a0a0a0;
    --accent: #4287f5;
    --accent-soft: rgba(66, 135, 245, 0.3);
    --accent-solid: rgba(66, 135, 245, 0.8);
    --good: #10b981;
    --warn: #f59e0b;
    --danger: #ef4444;

    --sidebar-w: 500px;
    --gap: 10px;
    --header-h: 76px;
}

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

html,
body {
    height: 100%;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    overflow: hidden;
}

button {
    font-family: inherit;
}

/*
==============
MAP
==============
*/
#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
}

/* Map controls */
.maplibregl-ctrl-group {
    background: var(--bg);
    border: 1px solid var(--border);
}

.maplibregl-ctrl-group button {
    width: 36px;
    height: 36px;
    border-color: var(--border) !important;
}

.maplibregl-ctrl button.maplibregl-ctrl-zoom-in .maplibregl-ctrl-icon {
    background-image: url(../img/plus-icon.svg);
}

.maplibregl-ctrl button.maplibregl-ctrl-zoom-out .maplibregl-ctrl-icon {
    background-image: url(../img/minus-icon.svg);
}

.maplibregl-ctrl button.maplibregl-ctrl-compass .maplibregl-ctrl-icon {
    background-image: url(../img/move-icon.svg);
}

/* Attribution: dark, to match the panels (MapLibre's own rules are more specific) */
.maplibregl-ctrl.maplibregl-ctrl-attrib,
.maplibregl-ctrl-attrib.maplibregl-compact {
    background: var(--panel) !important;
    color: var(--muted) !important;
    border: 1px solid var(--border);
}

.maplibregl-ctrl-attrib a,
.maplibregl-ctrl-attrib a:hover {
    color: var(--muted) !important;
}

.maplibregl-ctrl-attrib .maplibregl-ctrl-attrib-button {
    background-color: transparent;
    filter: invert(1);
}

/*
==============
HEADER (brand + view switch)
==============
*/
.header {
    position: absolute;
    top: var(--gap);
    left: var(--gap);
    z-index: 10;
    width: var(--sidebar-w);
    height: var(--header-h);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0px;
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    flex: 1;
}

.brand-logo {
    display: flex;
    flex: none;
    padding: 4px 8px;
    background: #f4f6fa;
    border-radius: 6px;
}

.brand>div {
    min-width: 0;
}

.brand img {
    height: 30px;
    width: auto;
    flex: none;
}

.brand h1 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.brand p {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Segmented switch */
.segmented {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    flex: none;
}

.segmented button {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.segmented button:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
}

.segmented button.active {
    color: var(--text);
    background: var(--accent-solid);
    border-color: var(--accent);
}

/* Header utility buttons */
#helpBtn,
#reportBtn {
    transition: all 0.2s ease;
}

#helpBtn:hover,
#reportBtn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

/*
==============
SIDEBAR
==============
*/
.sidebar {
    position: absolute;
    top: calc(var(--gap) + var(--header-h) + 10px);
    bottom: var(--gap);
    left: var(--gap);
    z-index: 10;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    backdrop-filter: blur(10px);
    overflow: hidden;
}

.sheet-handle {
    display: none;
}

.tabs {
    display: flex;
    flex: none;
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 14px 10px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab:hover {
    color: var(--text);
    background: var(--panel-soft);
}

.tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.tab-panel {
    display: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
}

.tab-panel.active {
    display: block;
}

.section-title {
    font-size: 12px;
    color: var(--muted);
    margin: 18px 0 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-title:first-child {
    margin-top: 0;
}

.empty-note {
    padding: 24px 8px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

/*
==============
KPI TILES
==============
*/
.period-row {
    flex: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 16px 0;
    border-bottom: 1px solid var(--border);
}

.period-row .range {
    margin-bottom: 12px;
    font-size: 11px;
    color: var(--muted);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.kpi-grid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.kpi-tile {
    padding: 10px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.kpi-tile-label {
    font-size: 11px;
    line-height: 1.3;
    color: var(--muted);
    min-height: 28px;
}

.kpi-tile-value {
    margin-top: 4px;
    font-size: 20px;
    font-weight: 600;
    white-space: nowrap;
}

.kpi-tile-value small {
    font-size: 11px;
    font-weight: 400;
    color: var(--muted);
}

.kpi-tile-value.good {
    color: var(--good);
}

.kpi-tile-value.warn {
    color: var(--warn);
}

.kpi-tile-value.danger {
    color: var(--danger);
}

.kpi-meta {
    margin-top: 8px;
    font-size: 11px;
    color: var(--muted);
}

/*
==============
CHARTS
==============
*/
.chart-block {
    margin-bottom: 6px;
}

.chart-title {
    font-size: 12px;
    color: var(--text);
    margin-bottom: 2px;
}

.chart-title .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
}

.chart {
    width: 100%;
    height: 170px;
}

.chart.tall {
    height: 210px;
}

/*
==============
PER-ROUTE TAB
==============
*/
.search-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}

.search-input:focus {
    border-color: var(--accent);
}

.route-list {
    margin-top: 10px;
    max-height: 220px;
    overflow-y: auto;
}

.route-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 10px;
    margin-bottom: 4px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.route-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-strong);
}

.route-item.active {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.route-item .name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    flex: none;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    color: #111;
    background: var(--muted);
}

#routeDetail {
    margin-top: 16px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.route-title {
    font-size: 15px;
    font-weight: 600;
    margin: 12px 0 4px;
}

/*
==============
MODALS (help, report picker)
==============
*/
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal.open {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    max-width: 600px;
    max-height: 80vh;
    width: 90%;
    overflow-y: auto;
    padding: 24px;
    animation: slideUp 0.3s ease;
    position: relative;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--text);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.modal-section {
    margin-bottom: 20px;
}

.modal-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 10px;
}

.modal-section p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
    margin-bottom: 10px;
    text-align: justify;
}

.modal-section ul {
    font-size: 13px;
    line-height: 1.8;
    color: var(--text);
    margin-left: 20px;
}

.modal-section li {
    margin-bottom: 8px;
}

.modal-section li em {
    color: var(--accent);
}

.index-item {
    margin-bottom: 16px;
    padding: 12px;
    background: var(--panel-soft);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
}

.index-item strong {
    display: block;
    margin-bottom: 6px;
}

.index-item .formula {
    background: rgba(0, 0, 0, 0.2);
    padding: 8px;
    border-radius: 3px;
    font-family: "Courier New", monospace;
    font-size: 12px;
    margin-top: 8px;
    overflow-x: auto;
}

/* Report picker */
#reportYear {
    background: var(--panel-soft) !important;
    border: 1px solid var(--border) !important;
    color: var(--text) !important;
}

#reportYear option {
    background: var(--bg);
    color: var(--text);
}

.month-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.month-btn {
    padding: 12px;
    background: var(--panel-soft);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.month-btn:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

/*
==============
MAP LEGEND
==============
*/
.legend {
    position: absolute;
    bottom: var(--gap);
    /* leave room for the map attribution */
    right: var(--gap);
    z-index: 10;
    padding: 14px 16px;
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    backdrop-filter: blur(10px);
    font-size: 12px;
}

.legend:empty {
    display: none;
}

.legend-title {
    margin-bottom: 8px;
    font-weight: 600;
}

.legend-title:has(+ .legend-subtitle) {
    margin-bottom: 2px;
}

.legend-subtitle {
    margin-bottom: 8px;
    font-size: 11px;
    color: var(--muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

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

.legend-color {
    width: 18px;
    height: 18px;
    border-radius: 3px;
}

/*
==============
SCROLLBAR
==============
*/
::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

/*
==============
RESPONSIVE: narrower panel on small laptop screens
(mapPadding() in functions-classes.js reads --sidebar-w, so keep it a plain px value)
==============
*/
@media (max-width: 1100px) {
    :root {
        --sidebar-w: 440px;
    }
}

/*
==============
RESPONSIVE: sidebar becomes a bottom sheet
==============
*/
@media (max-width: 800px) {
    :root {
        --gap: 10px;
        --header-h: 56px;
    }

    .header {
        width: calc(100% - 2 * var(--gap));
    }

    .brand p {
        display: none;
    }

    .brand h1 {
        font-size: 14px;
    }

    .sidebar {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 58vh;
        border-radius: 12px 12px 0 0;
        border-bottom: none;
        transition: height 0.3s ease-in-out;
    }

    .sidebar.collapsed {
        height: 30px;
    }

    .sheet-handle {
        display: block;
        flex: none;
        height: 26px;
        width: 100%;
        background: transparent;
        border: none;
        cursor: pointer;
    }

    .sheet-handle::after {
        content: "";
        display: block;
        width: 44px;
        height: 4px;
        margin: 0 auto;
        border-radius: 2px;
        background: var(--border-strong);
    }

    .tab {
        padding: 10px 8px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* keep the zoom controls below the (full-width) header */
    .maplibregl-ctrl-top-right {
        top: calc(var(--gap) + var(--header-h) + 10px);
    }

    .legend {
        top: calc(var(--gap) + var(--header-h) + 10px);
        bottom: auto;
        left: var(--gap);
        right: auto;
        padding: 8px 10px;
        font-size: 11px;
    }

    .legend-color {
        width: 14px;
        height: 14px;
    }

    .legend-item {
        margin-bottom: 3px;
    }
}