:root {
    --bg: #ffffff;
    --panel: #f6f7f9;
    --fg: #1d2433;
    --muted: #6b7280;
    --border: #d9dde3;
    --accent: #1d3557;
    --accent-fg: #ffffff;
    --danger: #b42318;
    --radius: 8px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --panel: #1c2027;
        --fg: #e6e8eb;
        --muted: #9aa3ae;
        --border: #313742;
        --accent: #7aa7d9;
        --accent-fg: #0d1117;
        --danger: #f97066;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

#route-status {
    white-space: pre-line;
}

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

body {
    display: flex;
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--fg);
    background: var(--bg);
}

#sidebar {
    width: 360px;
    flex: none;
    overflow-y: auto;
    padding: 16px;
    background: var(--panel);
    border-right: 1px solid var(--border);
}

#map {
    flex: 1;
    min-width: 0;
}

header h1 {
    margin: 0;
    font-size: 20px;
}

header p {
    margin: 2px 0 12px;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 12px;
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

#lang {
    width: auto;
    padding: 4px 6px;
    font-size: 12px;
}

details {
    border-top: 1px solid var(--border);
    padding: 10px 0;
}

summary {
    cursor: pointer;
    font-weight: 600;
    padding: 2px 0 8px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    font-size: 13px;
}

label.check {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

input[type="text"],
input[type="search"],
input[type="number"],
select {
    width: 100%;
    padding: 7px 9px;
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

input[type="color"] {
    width: 56px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
}

button {
    padding: 7px 12px;
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

button:hover:not(:disabled) {
    border-color: var(--accent);
}

button:disabled {
    opacity: 0.5;
    cursor: default;
}

button.primary {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: var(--accent);
}

button.danger {
    color: var(--danger);
}

button.link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    text-decoration: underline;
}

.row {
    display: flex;
    gap: 8px;
}

.row > * {
    flex: 1;
}

.row.wrap {
    flex-wrap: wrap;
}

.row.wrap > * {
    flex: 0 0 auto;
}

progress {
    width: 100%;
    margin-top: 10px;
}

/* Search */

.search {
    position: relative;
    margin-bottom: 10px;
}

#search-results {
    position: absolute;
    z-index: 10;
    top: 100%;
    left: 0;
    right: 0;
    margin: 4px 0 0;
    padding: 4px;
    list-style: none;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}

#search-results li {
    padding: 7px 8px;
    border-radius: 6px;
    cursor: pointer;
}

#search-results li.active,
#search-results li:hover {
    background: var(--panel);
}

/* Stops and legs */

.stop {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stop.dragging {
    opacity: 0.4;
}

.stop.drop-target {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.stop .handle {
    cursor: grab;
    color: var(--muted);
    user-select: none;
}

.stop .num {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    flex: none;
    border-radius: 50%;
    background: #1d3557;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
}

.stop .name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stop button {
    padding: 2px 6px;
    border: 0;
    background: none;
    color: var(--muted);
}

.stop button:hover:not(:disabled) {
    color: var(--fg);
}

.segment {
    display: flex;
    gap: 6px;
    margin: 4px 0 4px 18px;
    padding-left: 14px;
    border-left: 2px dashed var(--border);
}

.segment select {
    padding: 4px 6px;
    font-size: 12px;
}

/* Toast */

#toast {
    position: fixed;
    z-index: 20;
    left: 50%;
    bottom: 24px;
    max-width: calc(100% - 32px);
    transform: translateX(-50%);
    padding: 10px 16px;
    background: var(--fg);
    color: var(--bg);
    border-radius: var(--radius);
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);
}

/* Mobile: map on top, controls below */

@media (max-width: 760px) {
    body {
        flex-direction: column-reverse;
    }

    #sidebar {
        width: 100%;
        flex: 1;
        border-right: 0;
        border-top: 1px solid var(--border);
    }

    #map {
        flex: none;
        height: 45vh;
    }
}
