:root {
    /* Colors - SBB Theme */
    --accent: #EB0000;
    /* SBB Red */
    --accent-hover: #CC0000;
    --accent-light: rgba(235, 0, 0, 0.1);

    --bg-page: #F6F6F6;
    /* Lighter background resembling SBB map */
    --bg-panel: rgba(255, 255, 255, 0.95);
    --bg-input: #F0F0F0;

    --text-main: #111111;
    --text-muted: #666666;
    --border: #E0E0E0;

    /* Layout */
    --sidebar-width: 400px;
    --border-radius: 12px;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.12);

    /* Transitions */
    --trans-fast: 0.15s ease-out;
    --trans-spring: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-page);
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#app {
    display: flex;
    width: 100vw;
    height: 100vh;
    position: relative;
    background-color: var(--bg-page);
}

/* Map specific tweaks */
#map {
    flex-grow: 1;
    height: 100%;
    z-index: 1;
    background: var(--bg-page);
    /* Prevent gray flash before tiles load */
}

/* Make water/background tiles blend well if possible */
.leaflet-container {
    background: var(--bg-page);
}


/* Adjust zoom controls */
.leaflet-control-zoom {
    margin-left: calc(var(--sidebar-width) + 20px) !important;
    border: none !important;
    box-shadow: var(--shadow-soft) !important;
    border-radius: 8px !important;
    overflow: hidden;
}

.leaflet-control-zoom a {
    color: var(--text-main) !important;
    background: white !important;
    border-bottom: 1px solid var(--border) !important;
}

.leaflet-control-zoom a:hover {
    background: #F8F8F8 !important;
}

/* Leaflet layer selector */
.leaflet-control-layers {
    border: none !important;
    border-radius: 10px !important;
    box-shadow: var(--shadow-soft) !important;
    overflow: hidden;
    font-family: inherit;
}

/* Collapsed state: make it look like a button (like zoom) */
.leaflet-control-layers .leaflet-control-layers-toggle {
    width: 40px !important;
    height: 40px !important;
    background-color: #fff !important;
    border: none !important;
    background-size: 18px 18px !important;
    opacity: 1 !important;
}

.leaflet-control-layers .leaflet-control-layers-toggle:hover {
    background-color: #F8F8F8 !important;
}

/* Expanded panel */
.leaflet-control-layers-expanded {
    padding: 10px 10px 8px !important;
    background: rgba(255, 255, 255, 0.96) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: var(--text-main) !important;
    min-width: 190px;
}

.leaflet-control-layers-expanded .leaflet-control-layers-list {
    margin: 0 !important;
}

.leaflet-control-layers-expanded .leaflet-control-layers-separator {
    border-top: 1px solid var(--border) !important;
    margin: 8px 0 !important;
}

/* Labels + inputs */
.leaflet-control-layers label {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 8px 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    user-select: none;
}

.leaflet-control-layers label:hover {
    background: var(--bg-input);
}

.leaflet-control-layers input[type="radio"],
.leaflet-control-layers input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0 !important;
    accent-color: var(--accent);
    cursor: pointer;
}

.leaflet-control-layers label span {
    line-height: 1.2;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-soft);
}

/* Sidebar Styling */
#sidebar {
    position: absolute;
    top: 20px;
    left: 20px;
    bottom: 20px;
    width: var(--sidebar-width);
    border-radius: var(--border-radius);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform var(--trans-spring);
}

header {
    padding: 24px;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 2px;
}

header p {
    font-size: 13px;
    opacity: 0.9;
    font-weight: 500;
}

/* Routing Inputs */
.route-search-container {
    padding: 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }

.stations-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stations-row .input-group {
    flex: 1;
    min-width: 0;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.swap-button {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg-input);
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--trans-fast);
    font-size: 16px;
}

.swap-button:hover {
    background: white;
    box-shadow: var(--shadow-soft);
}

.input-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--text-main);
    color: white;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.autocomplete-wrapper {
    position: relative;
    flex-grow: 1;
}

input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-main);
    transition: all var(--trans-fast);
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    background: white;
    box-shadow: 0 0 0 3px var(--accent-light);
}

.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    border: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1010;
    list-style: none;
}

.autocomplete-item {
    padding: 12px 16px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--bg-input);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: var(--bg-input);
}

/* Buttons */
.w-full {
    width: 100%;
}

.mt-12 {
    margin-top: 12px;
}

.btn {
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    border: none;
    transition: all var(--trans-fast);
    text-align: center;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    background: var(--border);
    color: var(--text-muted);
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    border-color: var(--text-muted);
}

.btn-small {
    padding: 8px 12px;
    font-size: 12px;
}

#draw-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

/* Section Headers */
.section-header {
    padding: 20px 24px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-header h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
}

.header-badges {
    display: flex;
    gap: 6px;
    align-items: center;
}

.badge {
    background: var(--text-main);
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
}

.badge-muted {
    background: var(--text-muted);
    font-weight: 500;
}

.badge-success {
    background: #1f8f4a; /* accessible green */
    font-weight: 600;
}

.badge-danger {
    background: #c62828; /* accessible red */
    font-weight: 600;
}

.drive-status-hidden {
    display: none;
}

.saved-toolbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 0 24px 8px;
}

.saved-toolbar-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
}

.btn-sync {
    min-width: 0;
}

.btn-sync.btn-sync-connected {
    border-color: #1f8f4a;
    color: #1f8f4a;
}

.btn-sync.btn-sync-connected:hover {
    border-color: #166334;
    color: #166334;
}

.btn-sync.btn-sync-error {
    border-color: #c62828;
    color: #c62828;
}

.saved-actions {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    padding: 0 24px 12px;
}

/* Content Areas */
#saved-lines-container,
#route-options-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
}

#data-management-container {
    border-bottom: 1px solid var(--border);
}

#lines-list,
#route-options-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0 24px 24px;
}

#empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.6;
    margin-top: 20px;
    padding: 30px;
    border: 2px dashed var(--border);
    border-radius: 8px;
}

/* Loading State */
#loading-indicator {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Line Items */
.route-item,
.line-item {
    padding: 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.route-item:hover,
.line-item:hover {
    border-color: #CCC;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.line-select {
    flex-shrink: 0;
    margin-right: 14px;
    display: flex;
    align-items: center;
}

.line-select-checkbox {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.line-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
    overflow: hidden;
    padding-right: 12px;
    min-width: 0;
}

.line-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.line-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.line-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--bg-input);
    color: var(--accent);
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

/* Eraser mode */
body.eraser-mode,
body.eraser-mode #map {
    cursor: none !important; /* The drawing brush will act as the cursor */
}

/* Toast */
.toast {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--text-main);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 500;
    font-size: 14px;
    z-index: 2000;
    box-shadow: var(--shadow-hover);
    opacity: 0;
    pointer-events: none;
    transition: all var(--trans-spring);
}

.toast:not(.hidden) {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.hidden {
    display: none !important;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #CCC;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #999;
}

@media (max-width: 768px) {
    body {
        /* Allow vertical scrolling on small screens */
        overflow: auto;
    }

    #app {
        /* Stack map and sidebar vertically */
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    #map {
        /* Give the map a fixed height on mobile */
        height: 55vh;
        flex-grow: 0;
    }

    #sidebar {
        /* Make the card full‑width under the map */
        position: static;
        width: 100%;
        left: auto;
        right: auto;
        top: auto;
        bottom: auto;
        height: auto;
        max-height: none;
        border-radius: 16px 16px 0 0;
        margin: 0;
    }

    .leaflet-control-zoom {
        /* Keep zoom controls visible when the sidebar is full-width */
        margin: 16px 0 0 16px !important;
    }
}