:root {
    color-scheme: light dark;
    --bg: #fff;
    --text: #111;
    --muted: #555;
    --border: #888;
    --soft-border: #ddd;
    --surface: #fff;
    --header: #eee;
    --hover: #ddd;
    --link: #0645ad;
    --danger: #b00020;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #161616;
        --text: #eee;
        --muted: #aaa;
        --border: #666;
        --soft-border: #333;
        --surface: #1e1e1e;
        --header: #242424;
        --hover: #333;
        --link: #8ab4f8;
        --danger: #ff8a80;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 system-ui, sans-serif;
}

a {
    color: var(--link);
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

/* Map layout */

body.map-page {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

.map-shell {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

#map {
    position: absolute;
    inset: 0;
    background: var(--hover);
}

/* Header */

.site-header {
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--header);
    border-bottom: 1px solid var(--border);
}

.site-header__top,
.site-header__filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.site-header__titles {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
}

.site-header__brand {
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-header__meta {
    display: block;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-header__meta.is-expired {
    color: var(--danger);
}

.site-header__actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
}

.site-header__filters {
    width: 100%;
}

.filter-select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.site-header a {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
}

.feed-status {
    display: inline-flex;
    flex: 0 0 1.1rem;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    font-size: 0.75rem;
    font-weight: 700;
    visibility: hidden;
}

.feed-status.is-loading,
.feed-status.is-error {
    visibility: visible;
}

.feed-status.is-loading::after {
    content: "";
    width: 0.9rem;
    height: 0.9rem;
    border: 2px solid var(--border);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: feed-spin 0.7s linear infinite;
}

.feed-status.is-error {
    border-radius: 50%;
    background: #ffd166;
    color: #3a2a00;
}

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

/* Selectors */

.filter-select {
    max-width: 100%;
}

/* Side panel */

.app-view {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 6;
    width: min(420px, 92vw);
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.stop-main {
    padding: 0.75rem;
}

.stop-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.stop-kind {
    margin: 0;
    color: var(--muted);
    font-size: 0.75rem;
}

.stop-title {
    margin: 0.2rem 0 0.6rem;
    font-size: 1.3rem;
}

.detail-value {
    min-width: 0;
    overflow-wrap: anywhere;
}

.stop-empty,
.detail-note {
    color: var(--muted);
}

.panel-section {
    margin-bottom: 0.75rem;
}

.panel-section__title {
    margin: 0;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid var(--soft-border);
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: pre-line;
}

.panel-list {
    margin: 0.35rem 0 0;
    padding-left: 1.25rem;
    list-style: disc;
}

.panel-list--ordered {
    padding-left: 0;
    list-style: none;
    counter-reset: ordered-row;
}

.panel-list--ordered > .panel-row {
    counter-increment: ordered-row;
}

.panel-list--ordered .panel-row__inner {
    grid-template-columns: max-content max-content minmax(0, 1fr);
}

.panel-list--ordered .panel-row__inner::before {
    content: counter(ordered-row) ".";
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.panel-row__inner {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.5rem;
    align-items: baseline;
    width: 100%;
    padding: 0.35rem 0;
    border: 0;
    border-bottom: 1px solid var(--soft-border);
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
}

button.panel-row__inner {
    cursor: pointer;
}

.panel-row__time {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.panel-row__content {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    min-width: 0;
    overflow: hidden;
}

.panel-row__content > button {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-row__line {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: start;
    min-width: 1.5em;
    min-height: 1.5em;
    aspect-ratio: 1 / 1;
    background: var(--line-bg, var(--hover));
}

.panel-row__headsign {
    flex: 0 0 auto;
    white-space: nowrap;
}

.panel-row__meta {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-segment {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.detail-fields {
    display: grid;
    gap: 0.4rem;
    margin-bottom: 0.6rem;
}

.detail-row {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem;
}

.detail-label {
    color: var(--muted);
    font-size: 0.8rem;
}

.detail-segment button[aria-pressed="true"] {
    font-weight: 700;
}

.detail-select {
    max-width: 100%;
}

.detail-date-controls,
.detail-date-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Sources dialog */

.feeds-dialog {
    width: min(700px, 92vw);
    max-height: 85vh;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.feeds-dialog__header,
.feeds-dialog__body {
    padding: 0.75rem;
}

.feeds-dialog__header {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.feeds-dialog__header h2 {
    margin: 0;
}

.feeds-dialog__header p {
    margin: 0.2rem 0 0;
    font-size: 0.8rem;
}

.feeds-dialog__body {
    max-height: calc(85vh - 5rem);
    overflow-x: hidden;
    overflow-y: auto;
}

.feeds-upload {
    margin-bottom: 0.75rem;
}

.feeds-status {
    min-height: 1em;
    margin: 0.4rem 0 0;
    color: var(--muted);
    font-size: 0.8rem;
}

.feeds-filter {
    width: 100%;
    margin-bottom: 0.6rem;
}

.feeds-list,
.feeds-group__list {
    display: grid;
    gap: 0.4rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.feeds-group__title {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.feeds-group__list {
    margin-top: 0.4rem;
}

.feed-card {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--soft-border);
    background: var(--surface);
    color: inherit;
    text-align: left;
}

.feed-card__body {
    flex: 1 1 auto;
    min-width: 0;
}

.feed-card__name {
    display: block;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.feed-card__detail {
    display: block;
    color: var(--muted);
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.feed-card__kind {
    font-size: 0.7rem;
    text-transform: uppercase;
}

/* Info page */

.info-shell {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
}

.info-title {
    margin: 0 0 1rem;
}

.info-content {
    line-height: 1.6;
}

.info-content pre {
    padding: 0.5rem;
    overflow: auto;
    background: var(--header);
}

.info-content blockquote {
    margin: 0;
    padding-left: 0.75rem;
    border-left: 3px solid var(--border);
    color: var(--muted);
}

.info-content table {
    border-collapse: collapse;
}

.info-content th,
.info-content td {
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    text-align: left;
}

@media (max-width: 640px) {
    .site-header__titles {
        flex: 1 1 0;
        max-width: none;
    }

    .filter-select {
        flex: 1 1 10rem;
    }

    .app-view {
        top: auto;
        right: 0;
        bottom: 0;
        width: auto;
        max-height: 70vh;
        border-top: 1px solid var(--border);
        border-right: 0;
    }
}

.maplibregl-ctrl-group {
    background: var(--surface);
}

.maplibregl-ctrl-group button + button {
    border-top: 1px solid var(--border);
}

.maplibregl-ctrl-attrib {
    background: var(--surface);
    color: var(--muted);
}

.maplibregl-ctrl-attrib a {
    color: var(--muted);
}

@media (prefers-color-scheme: dark) {
    .maplibregl-ctrl.maplibregl-ctrl-attrib,
    .maplibregl-ctrl-attrib.maplibregl-compact,
    .maplibregl-ctrl-attrib.maplibregl-compact-show {
        background-color: var(--surface) !important;
        color: var(--muted) !important;
    }

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

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

    .maplibregl-ctrl-icon {
        filter: invert(1);
    }

    .maplibregl-ctrl-logo {
        filter: brightness(0) invert(1);
    }
}
