:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent-dim: #0ea5e9;
    --header-h: 3.25rem;
    --sidebar-w: min(22rem, 100vw);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-header {
    height: var(--header-h);
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
}

.app-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.app-subtitle {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.app-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-h));
}

@media (min-width: 900px) {
    .app-layout {
        flex-direction: row;
    }
}

.sidebar {
    width: 100%;
    max-height: 40vh;
    overflow: auto;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

@media (min-width: 900px) {
    .sidebar {
        width: var(--sidebar-w);
        max-height: none;
        border-bottom: none;
        border-right: 1px solid var(--border);
    }
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.panel-growth {
    flex: 1;
    min-height: 0;
}

.panel-title {
    margin: 0;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.field-label {
    font-size: 0.75rem;
    color: var(--muted);
}

.field-input {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.875rem;
}

.field-input:focus {
    outline: 1px solid var(--accent);
}

.route-meta {
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--muted);
    padding: 0.5rem;
    border-radius: 0.375rem;
    background: var(--bg);
    border: 1px solid var(--border);
}

.direction-toggle {
    display: flex;
    gap: 0.35rem;
}

.direction-btn {
    flex: 1;
    padding: 0.45rem 0.5rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
}

.direction-btn.active {
    border-color: var(--accent);
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent);
}

.direction-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.geocode-status {
    margin: 0 0 0.5rem;
    font-size: 0.8rem;
    color: var(--muted);
}

.geocode-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    min-width: 6.5rem;
    padding: 0.45rem 0.6rem;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    cursor: pointer;
    border: 1px solid var(--border);
}

.btn-primary {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: #0f172a;
    font-weight: 600;
}

.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
}

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 0.45rem;
    font-size: 0.75rem;
    color: var(--muted);
    cursor: pointer;
}

.geocode-log {
    margin: 0;
    max-height: 8rem;
    overflow: auto;
    padding: 0.5rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 0.7rem;
    line-height: 1.35;
    white-space: pre-wrap;
    color: var(--muted);
}

.waypoint-list {
    margin: 0;
    padding-left: 1.25rem;
    font-size: 0.8rem;
    max-height: 28vh;
    overflow-y: auto;
}

.waypoint-list li {
    margin-bottom: 0.35rem;
}

.waypoint-list li.missing-coords {
    color: #f87171;
}

.map-wrap {
    position: relative;
    flex: 1;
    min-height: 45vh;
}

.map {
    width: 100%;
    height: 100%;
    min-height: 45vh;
}

@media (min-width: 900px) {
    .map,
    .map-wrap {
        min-height: 0;
    }
}

.map-toast {
    position: absolute;
  top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    max-width: min(90vw, 24rem);
    padding: 0.5rem 0.85rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.map-toast.error {
    border-color: #f87171;
    color: #fecaca;
}

.hidden {
    display: none !important;
}