:root {
    --visual-viewport-top: 0px;
    --visual-viewport-left: 0px;
    --visual-viewport-right: 0px;
    --visual-viewport-width: 100vw;
    --visual-viewport-height: 100dvh;
}

body, html { margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden; font-family: Arial, sans-serif; }
#map { position: fixed; top: 0; left: 0; width: 100%; height: 100%; }

/* --- Sidebar --- */
#controls {
    position: absolute; top: 10px; right: 10px; z-index: 1200;
    background: rgba(255, 255, 255, 0.55); padding: 10px 15px 15px; border-radius: 5px;
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 0 15px rgba(0,0,0,0.2); width: 280px;
    transition: right 0.25s ease;
    max-height: calc(100vh - 20px); overflow-y: auto; box-sizing: border-box;
}
#controls.collapsed {
    right: -120vw;
    pointer-events: none;
}

#controlsScrim { display: none; }

/* --- Toggle button --- */
/* Inline flex item inside .nav-row when open; moves to document.body when closed */
#toggleControls {
    flex: 0 0 40px; width: 40px; height: 40px; padding: 0; margin: 0; margin-top: 0;
    background: #333; color: white; border: none; border-radius: 5px;
    font-size: 1.3rem; cursor: pointer; touch-action: manipulation;
    box-sizing: border-box;
}
/* Floating state: toggle has been moved to document.body, positioned fixed */
#toggleControls.floating {
    position: fixed;
    top: calc(var(--visual-viewport-top) + 10px);
    right: calc(var(--visual-viewport-right) + 10px);
    z-index: 4001;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#toggleControls:hover { background: #555; }

/* --- Sidebar header with logo --- */
.sidebar-header { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 6px; }
.logo-link { flex-shrink: 0; line-height: 0; }
.sidebar-logo { width: 28px; height: 28px; border-radius: 5px; }
.sidebar-header h2 { margin: 0; }

/* --- Controls --- */
h2 { margin-top: 0; font-size: 1.2rem; }
h3 { font-size: 1rem; margin: 10px 0 8px 0; }
.control-group { margin-bottom: 15px; }
select, button { width: 100%; padding: 8px; margin-top: 5px; font-size: 0.95em; }
button { background-color: #007bff; color: white; border: none; border-radius: 3px; cursor: pointer; }
button:disabled { background-color: #cccccc; cursor: not-allowed; }
button:hover:not(:disabled) { background-color: #0056b3; }
/* Toast notifications — bottom-center ephemeral messages */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
    max-width: min(420px, calc(100vw - 32px));
}
.toast {
    pointer-events: auto;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.84rem;
    line-height: 1.4;
    color: #1e293b;
    background: #ffffffee;
    border: 1px solid #cbd5e1;
    box-shadow: 0 4px 16px rgba(15,23,42,0.14);
    animation: toast-in 0.25s ease, toast-out 0.3s ease 3.2s forwards;
}
.toast.toast-error {
    color: #991b1b;
    background: #fef2f2ee;
    border-color: #fecaca;
}
.toast a { color: #2563eb; text-decoration: underline; }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
    from { opacity: 1; }
    to   { opacity: 0; transform: translateY(-8px); }
}

/* Map overlay loader — shown during async operations on mobile */
.map-loader-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1100;
    padding: 14px 24px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.82);
    color: white;
    font-size: 0.9rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: none;
    animation: toast-in 0.2s ease;
}

/* Game log modal */
.game-log-modal {
    max-height: min(70vh, 560px);
}
.game-log-content {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 4px 0;
}
.game-log-entry {
    display: flex;
    gap: 10px;
    padding: 5px 0;
    font-size: 0.82rem;
    line-height: 1.4;
    border-bottom: 1px solid #f1f5f9;
}
.game-log-entry:last-child { border-bottom: none; }
.game-log-time {
    flex-shrink: 0;
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
}
.game-log-msg { color: #334155; }
.game-log-msg.is-error { color: #dc2626; }
.game-log-empty {
    text-align: center;
    padding: 32px 16px;
    color: #94a3b8;
    font-size: 0.88rem;
}
.game-log-actions {
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
}
.help-text { margin-top: 6px; font-size: 0.8rem; color: #666; line-height: 1.35; }
.range-field-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}
.range-field-header label {
    margin: 0;
}
.range-field-value {
    font-size: 0.82rem;
    font-weight: 700;
    color: #166534;
}
.walk-time-options {
    --walk-time-gap: 4px;
    --walk-time-radio-size: 18px;
    position: relative;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--walk-time-gap);
    margin-top: 8px;
}
.walk-time-options::before {
    content: '';
    position: absolute;
    top: calc(var(--walk-time-radio-size) / 2);
    left: calc((100% - (4 * var(--walk-time-gap))) / 10);
    right: calc((100% - (4 * var(--walk-time-gap))) / 10);
    border-top: 2px solid #166534;
    z-index: 0;
}
.walk-time-option {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-top: 0;
    cursor: pointer;
    text-align: center;
    color: #475569;
    font-size: 0.76rem;
    line-height: 1.2;
}
.walk-time-option input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: #166534;
    background: #ffffff;
}
.walk-time-option input:focus-visible {
    outline: 2px solid rgba(22, 163, 74, 0.25);
    outline-offset: 3px;
}
.walk-time-option-label {
    display: block;
}
.walk-time-option input:checked + .walk-time-option-label {
    color: #166534;
    font-weight: 700;
}

/* --- Nav row --- */
.nav-row { display: flex; gap: 6px; margin-bottom: 10px; }
.nav-pill {
    flex: 1; text-align: center; padding: 0 8px; font-size: 0.82rem;
    height: 40px; box-sizing: border-box; display: flex; align-items: center; justify-content: center;
    color: #007bff; text-decoration: none;
    border: 1px solid #007bff; border-radius: 3px;
}
.nav-pill:hover { background: #007bff; color: white; }

.sidebar-action-row {
    margin-bottom: 10px;
    display: flex;
    gap: 8px;
}

.sidebar-secondary-btn {
    margin-top: 0;
    background: #eef2f7;
    color: #213547;
    border: 1px solid #c9d4df;
}

.sidebar-secondary-btn:hover:not(:disabled) {
    background: #e0e8f0;
}

.heatmap-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: -4px;
}

.heatmap-btn {
    flex: 1;
    min-width: 0;
    margin-top: 0;
    background: #f8f9fa;
    color: #0b3d91;
    border: 1px solid #b6ccf5;
}

.heatmap-btn:hover:not(:disabled) {
    background: #e7f0ff;
}

.heatmap-btn.active {
    background: #0b5ed7;
    border-color: #0b5ed7;
    color: #fff;
}

.reference-toggle-group {
    margin-top: -6px;
}

.reference-toggle-group .compact-toggle + .compact-toggle,
.compact-toggle-group .compact-toggle + .compact-toggle {
    margin-top: 8px;
}

.compact-toggle-group {
    margin-top: -10px;
}

.compact-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
}

.compact-toggle-label {
    color: #334155;
    font-size: 0.85rem;
    line-height: 1.2;
    font-weight: 500;
}

.compact-toggle-switch {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
    width: 40px;
    height: 24px;
}

.compact-toggle-input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.compact-toggle-track {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 999px;
    border: 1px solid #cbd5e1;
    background: #e2e8f0;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.compact-toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
    transition: transform 0.15s ease;
}

.compact-toggle-input:checked + .compact-toggle-track {
    background: #0b5ed7;
    border-color: #0b5ed7;
}

.compact-toggle-input:checked + .compact-toggle-track::after {
    transform: translateX(16px);
}

.compact-toggle-input:focus-visible + .compact-toggle-track {
    outline: 2px solid rgba(11, 94, 215, 0.35);
    outline-offset: 2px;
}

.compact-toggle-input:disabled + .compact-toggle-track {
    opacity: 0.7;
}

/* --- Shared container for all icon-based map popups --- */
.draw-icon-popup,
.station-picker-popup {
    display: flex;
    gap: 4px;
    background: white;
    border-radius: 8px;
    padding: 4px;
    /* border-box so Leaflet's iconSize matches the actual rendered outer size */
    box-sizing: border-box;
    box-shadow: 0 0 0 1px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.25);
}

/* --- Shared button style for all icon-based map popup buttons --- */
.draw-icon-btn,
.station-picker-btn {
    width: 28px; height: 28px;
    border: 1px solid #ddd; border-radius: 6px;
    background: #f8f9fa;
    cursor: pointer; font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
    padding: 0; margin: 0; margin-top: 0;
    box-sizing: border-box;
    line-height: 1;
}
.draw-icon-btn:hover,
.station-picker-btn:hover { background: #e2e6ea; border-color: #adb5bd; }

/* --- Line type selector --- */
.line-type-selector { margin-top: 5px; }
.radio-label {
    display: block; padding: 6px 8px; margin: 3px 0;
    font-size: 0.85em; cursor: pointer; border-radius: 3px;
    background: #f8f9fa; border: 1px solid #e9ecef;
}
.radio-label:hover { background: #e9ecef; }
.radio-label input { margin-right: 6px; }
.secondary-btn { background: #6c757d; }
.secondary-btn:hover:not(:disabled) { background: #5a6268; }
.drawing-toolbar-icon { overflow: visible; }
.drawing-toolbar {
    position: absolute;
    left: 10px;
    top: 0;
    transform: translateY(-50%);
    display: flex;
    flex-direction: row;
    gap: 4px;
}
.draw-tool-btn {
    width: 28px;
    height: 28px;
    font-size: 16px;
    line-height: 1;
    border: none;
    background: white;
    border-radius: 6px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.draw-tool-btn:hover:not(:disabled) { background: #eef4ff; }
.draw-tool-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* --- Stats --- */
#catchmentStats { margin-top: 15px; padding-top: 10px; border-top: 1px solid #eee; }
.stat-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.stat-label { font-size: 0.85rem; color: #555; }
.stat-value { font-size: 1rem; font-weight: bold; }
.stat-bar-container { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: #eee; margin: 4px 0; }
.stat-bar-in { background: #007bff; transition: width 0.3s; }
.stat-bar-out { background: #ddd; transition: width 0.3s; }
.stat-detail { font-size: 0.78rem; color: #777; margin-bottom: 2px; }

/* --- Lines list --- */
#linesList { margin-top: 15px; padding-top: 10px; border-top: 1px solid #eee; }
/* Sidebar tabs */
.sidebar-tabs {
    display: flex; gap: 0; margin-bottom: 6px; border-bottom: 2px solid #e2e8f0;
}
.sidebar-tab {
    flex: 1; padding: 6px 10px; border: none; background: none;
    font-size: 0.85em; font-weight: 600; color: #94a3b8; cursor: pointer;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.sidebar-tab:hover { color: #475569; }
.sidebar-tab.active { color: #1e293b; border-bottom-color: #3b82f6; }
.sidebar-tab-content.hidden { display: none; }

.line-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 5px 8px; margin: 3px 0; border-radius: 3px;
    font-size: 0.85em; background: #f8f9fa;
    cursor: pointer; transition: background 0.15s;
}
.line-item:hover { background: #e2e8f0; }
.line-item.active { background: #dbeafe; outline: 2px solid #3b82f6; }
.line-item-info { flex: 1; }
.line-item-type { display: flex; align-items: center; gap: 8px; font-weight: bold; }
.line-item-swatch {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    flex: 0 0 12px;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.12);
}
.line-item-meta { font-size: 0.8em; color: #666; }
.line-item .delete-btn {
    width: auto; padding: 2px 8px; margin: 0; font-size: 0.8em;
    background: #dc3545; border-radius: 3px;
}
.line-item .delete-btn:hover { background: #c82333; }

/* --- Project summary --- */
#projectSummary { margin-top: 15px; padding-top: 10px; border-top: 1px solid #eee; }
.summary-grid { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 0.85em; }
.summary-label { color: #555; }
.ancestor-link { font-size: 0.75em; font-weight: normal; }
.ancestor-link a { color: #0066cc; text-decoration: none; }
.ancestor-link a:hover { text-decoration: underline; }
.summary-value { font-weight: bold; text-align: right; }

/* --- Save / Share --- */
.save-section-sticky {
    position: sticky;
    bottom: 0;
    padding: 10px 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10;
}
.save-actions { display: flex; gap: 8px; }
#saveProject { flex: 1; }
#shareProject { flex: 1; }
#shareProject.share-unavailable { opacity: 0.45; cursor: not-allowed; }
#shareProject.share-unavailable:hover { background-color: #6c757d; }

.share-popup {
    position: absolute;
    right: 0;
    left: 0;
    bottom: calc(100% + 10px);
    z-index: 1300;
    padding: 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(15, 23, 42, 0.12);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.16);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}
.share-popup::after {
    content: '';
    position: absolute;
    right: 22px;
    top: 100%;
    border-width: 8px 8px 0 8px;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.98) transparent transparent transparent;
    filter: drop-shadow(0 1px 0 rgba(15, 23, 42, 0.08));
}
.share-popup-label { font-size: 0.8em; color: #555; display: block; margin-bottom: 4px; }
.share-popup-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.share-popup-section { margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(148, 163, 184, 0.22); }
.share-link-input {
    width: 100%;
    font-size: 0.82em;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    min-width: 0;
}
.share-copy-btn {
    width: auto;
    margin-top: 0;
    font-size: 0.82em;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: #007bff;
    color: #fff;
    cursor: pointer;
    white-space: nowrap;
}
.share-copy-btn:hover { background: #0056b3; }
.share-export-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.share-export-btn {
    margin-top: 0;
    padding: 9px 10px;
    font-size: 0.8em;
    border-radius: 8px;
    background: #0b5ed7;
}
.share-export-btn:hover:not(:disabled) { background: #094db1; }
.share-export-btn-secondary {
    background: #e2e8f0;
    color: #1e293b;
    border: 1px solid #cbd5e1;
}
.share-export-btn-secondary:hover:not(:disabled) { background: #cbd5e1; }
.share-popup-help {
    margin: 8px 0 0;
    font-size: 0.76em;
    line-height: 1.45;
    color: #64748b;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    box-sizing: border-box;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
             env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
#discardDraftModal { z-index: 2100; }
.modal {
    background: white; border-radius: 8px; padding: 24px; width: min(320px, calc(100vw - 24px));
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.modal h3 { margin: 0 0 16px 0; font-size: 1.1rem; }
.modal-message { margin: 0; font-size: 0.92rem; line-height: 1.5; color: #4b5563; }
.modal label { display: block; font-size: 0.85rem; color: #555; margin-bottom: 6px; }
.modal input[type="text"] {
    width: 100%; padding: 10px; font-size: 0.95rem; border: 1px solid #ccc;
    border-radius: 4px; box-sizing: border-box; outline: none;
}
.modal input[type="text"]:focus { border-color: #007bff; box-shadow: 0 0 0 2px rgba(0,123,255,0.15); }
.modal-error { margin: 10px 0 0; font-size: 0.85rem; color: #dc2626; }
.modal-buttons { display: flex; gap: 8px; margin-top: 16px; }
.modal-btn-cancel {
    flex: 1; padding: 8px; background: #e9ecef; color: #333;
    border: 1px solid #ccc; border-radius: 4px; cursor: pointer; font-size: 0.9rem;
}
.modal-btn-cancel:hover { background: #dee2e6; }
.modal-btn-confirm {
    flex: 1; padding: 8px; background: #007bff; color: white;
    border: none; border-radius: 4px; cursor: pointer; font-size: 0.9rem;
}
.modal-btn-confirm:hover { background: #0056b3; }
.modal-btn-danger {
    flex: 1; padding: 8px; background: #dc2626; color: white;
    border: none; border-radius: 4px; cursor: pointer; font-size: 0.9rem;
}
.modal-btn-danger:hover { background: #b91c1c; }

.info-modal {
    width: min(560px, calc(100vw - 24px));
    max-height: min(80vh, 720px);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.info-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.info-modal-header h3 {
    margin: 0;
}

.info-close-btn {
    width: 36px;
    min-width: 36px;
    height: 36px;
    margin-top: 0;
    padding: 0;
    font-size: 1.4rem;
    line-height: 1;
    background: #eef2f7;
    color: #334155;
    border: 1px solid #d3dce6;
}

.info-close-btn:hover:not(:disabled) {
    background: #e2e8f0;
}

.info-modal-content {
    overflow-y: auto;
    padding-right: 4px;
}

.info-modal-content section + section {
    margin-top: 16px;
}

.info-modal-content h4 {
    margin: 0 0 8px;
    font-size: 0.95rem;
    color: #0f172a;
}

.info-modal-content p,
.info-modal-content li {
    font-size: 0.88rem;
    line-height: 1.5;
    color: #475569;
}

.info-modal-content ol,
.info-modal-content ul {
    margin: 0;
    padding-left: 20px;
}

.info-modal-content li + li {
    margin-top: 6px;
}

.info-modal-content p {
    margin: 0;
}

.info-modal-content p + p {
    margin-top: 10px;
}

.info-modal-content a {
    color: #0b5ed7;
    text-decoration: underline;
}

.info-modal-content a:hover {
    color: #084298;
}

/* --- Misc --- */
.hidden { display: none !important; }
#loading { display: flex; align-items: center; margin-top: 10px; color: #007bff; }
.spinner { border: 3px solid #f3f3f3; border-top: 3px solid #007bff; border-radius: 50%; width: 15px; height: 15px; animation: spin 1s linear infinite; margin-right: 8px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.snap-marker { width: 14px; height: 14px; background: #007bff; border: 2px solid white; border-radius: 50%; box-shadow: 0 0 4px rgba(0,0,0,0.4); opacity: 0.8; }
.snap-marker-transfer { width: 18px; height: 18px; background: #f59f00; border: 2px solid white; box-shadow: 0 0 8px rgba(245,159,0,0.6); }
.snap-marker-junction { width: 18px; height: 18px; background: #6b7280; border: 2px solid white; border-radius: 50%; box-shadow: 0 0 8px rgba(107,114,128,0.7); }
.catchment-origin-marker { width: 18px; height: 18px; background: #16a34a; border: 3px solid white; border-radius: 50%; box-shadow: 0 0 8px rgba(0,0,0,0.35); }
.station-marker { width: 16px; height: 16px; border: 3px solid white; box-shadow: 0 0 6px rgba(0,0,0,0.5); }
.station-marker-linked::after { content: ''; position: absolute; width: 6px; height: 6px; background: #f59f00; border-radius: 50%; top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.station-marker-near-transfer { box-shadow: 0 0 0 4px rgba(245, 159, 0, 0.55), 0 0 6px rgba(0,0,0,0.5) !important; }
.station-marker-round { border-radius: 50%; }
.station-marker-square { border-radius: 3px; }
.station-marker-underground { background: #3b82f6; }
.station-marker-overground { background: #ef4444; }
.rail-station-marker {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    pointer-events: none;
}

.rail-station-marker-diamond {
    width: 10px;
    height: 10px;
    background: #111;
    border: 2px solid #fff;
    box-shadow: 0 0 6px rgba(0,0,0,0.45);
    transform: rotate(45deg);
}

.tram-stop-marker {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    pointer-events: none;
}

.tram-stop-marker-dot {
    width: 8px;
    height: 8px;
    background: #d97706;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(0,0,0,0.4);
}

body.is-exporting #toggleControls,
body.is-exporting #loading,
body.is-exporting #sharePopup,
body.is-exporting #infoModal,
body.is-exporting #saveModal {
    display: none !important;
}
/* ─── Sim Panel (floating top-left clock + speed controls) ─────────── */
.sim-panel {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1100;
    width: 200px;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 10px;
    overflow: hidden;
    user-select: none;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.sim-panel .sky-strip {
    height: 36px;
    margin-bottom: 0;
    border-radius: 0;
}
.sim-panel-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    color: rgba(255, 255, 255, 0.9);
}
.sim-panel-row .time-clock-icon {
    font-size: 1rem;
    line-height: 1;
}
.sim-panel-row .time-clock-display {
    font-variant-numeric: tabular-nums;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #fff;
}
.sim-panel-spacer { flex: 1; }
.sim-clock-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}
.sim-clock-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}
.sim-clock-speed {
    min-width: 28px;
    text-align: center;
    font-weight: bold;
    font-size: 12px;
    color: #94a3b8;
}

.train-marker {
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
}
.train-marker-shell {
    position: relative;
    width: 30px;
    height: 30px;
}
.train-marker-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 10px;
    margin-left: -8px;
    margin-top: -5px;
    border-radius: 3px;
    border: 1.5px solid rgba(255,255,255,0.95);
    background: var(--train-color, #334155);
    box-shadow: 0 1px 5px rgba(15,23,42,0.35);
    transform: translateZ(0) rotate(var(--train-angle, 0deg));
    transform-origin: center center;
    will-change: transform;
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.train-marker-icon::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 4px;
    height: 4px;
    border-radius: 1px;
    background: rgba(255,255,255,0.9);
}
.train-marker-underground .train-marker-icon {
    height: 10px;
}
.train-marker-overground .train-marker-icon {
    height: 8px;
    margin-top: -4px;
}
.train-stop-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-left: -12px;
    margin-top: -12px;
    border-radius: 999px;
    border: 2px solid rgba(255,255,255,0.96);
    background: var(--train-color, #334155);
    box-shadow: 0 6px 18px rgba(15,23,42,0.28);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.02em;
    opacity: 0;
    transform: scale(0.82);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.train-marker.is-stopped .train-marker-icon {
    opacity: 0;
    transform: translateZ(0) scale(0.7) rotate(var(--train-angle, 0deg));
}
.train-marker.is-stopped .train-stop-indicator {
    opacity: 1;
    transform: scale(1);
}

/* --- Selection panel (kept in DOM but hidden; replaced by popup/sheet) --- */
#selectionPanel { display: none !important; }
.selection-title-button {
    display: block;
    width: 100%;
    margin: 0 0 6px 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: #0b5ed7;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: left;
    cursor: default;
}
.selection-title-button.is-editable { cursor: text; }
.selection-title-input {
    width: 100%;
    margin: 0 0 8px 0;
    padding: 8px 10px;
    border: 1px solid rgba(15, 23, 42, 0.18);
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 700;
    color: #0b5ed7;
    background: #fff;
}
#selectionDetails { font-size: 0.85rem; color: #333; line-height: 1.5; }
#selectionDetails .sel-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
#selectionDetails .sel-label { color: #555; }
#selectionDetails .sel-value { font-weight: bold; }
#selectionDetails .sel-catchment-group {
    border: 2px solid #1e293b;
    border-radius: 6px;
    padding: 4px 8px;
    margin: 4px 0;
}
/* --- Depot map popup --- */
.depot-popup-icon { background: transparent; border: 0; }
.depot-popup {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.25);
    white-space: nowrap;
    font-size: 0.8rem;
    font-weight: 600;
    min-width: min(200px, 90vw);
}
.depot-line-row { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 2px 4px; border-radius: 4px; transition: background 0.15s; }
.depot-line-row:hover { background: rgba(0, 0, 0, 0.05); }
.depot-popup-train { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.depot-popup-train .train-marker-shell { width: 22px; height: 22px; }
.depot-line-label { color: #334155; font-weight: 700; min-width: 2em; }
.depot-line-info { color: #64748b; font-weight: 400; flex: 1; }
.depot-popup-add-train, .depot-popup-delete-line {
    width: 24px; height: 24px; border-radius: 4px; border: 1px solid #cbd5e1;
    background: #fff; cursor: pointer; font-size: 0.7rem; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.depot-popup-add-train:hover { background: #e0f2fe; }
.depot-popup-delete-line { color: #dc2626; border-color: #fca5a5; }
.depot-popup-delete-line:hover { background: #fee2e2; }
.depot-popup-new-line {
    padding: 6px 10px; border-radius: 4px; border: 2px solid #16a34a;
    background: #fff; color: #16a34a; font-size: 0.8rem; font-weight: 700;
    cursor: pointer; transition: background 0.15s, color 0.15s; margin-top: 2px;
    width: 100%;
}
.depot-popup-new-line:hover { background: #16a34a; color: #fff; }
/* Placement: above station (tip points down) or below station (tip points up) */
.depot-popup-above { transform: translate(-50%, calc(-100% - 14px)); }
.depot-popup-below { transform: translate(-50%, 14px); }
/* Line building picker */
.line-picker-icon { background: transparent; border: 0; }
.line-picker-popup {
    display: flex; flex-direction: column; gap: 4px;
    padding: 6px 8px; border-radius: 6px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    font-size: 0.8rem; font-weight: 600;
    transform: translate(-50%, 0);
    min-width: min(180px, 90vw);
    margin-top: 8px;
    position: relative;
}
.line-picker-popup::before {
    content: '';
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    width: 0; height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 7px solid rgba(255, 255, 255, 0.95);
    filter: drop-shadow(0 -1px 1px rgba(0,0,0,0.1));
}
.line-picker-btn {
    padding: 6px 10px; border-radius: 4px; border: 1px solid #cbd5e1;
    background: #fff; color: #334155; cursor: pointer; text-align: left;
    transition: background 0.15s;
}
.line-picker-btn:hover { background: #e0f2fe; }
.line-picker-finish {
    padding: 6px 10px; border-radius: 4px; border: 2px solid #2563eb;
    background: #fff; color: #2563eb; cursor: pointer; font-weight: 700;
    transition: background 0.15s, color 0.15s; margin-top: 2px;
}
.line-picker-finish:hover { background: #2563eb; color: #fff; }
.line-picker-cancel {
    padding: 6px 10px; border-radius: 4px; border: 1px solid #cbd5e1;
    background: #fff; color: #64748b; cursor: pointer; font-size: 0.8em;
    transition: background 0.15s, color 0.15s;
}
.line-picker-cancel:hover { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.station-marker-candidate { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.5), 0 0 6px rgba(0,0,0,0.5) !important; }
.line-picker-confirm { align-items: center; }
.line-picker-confirm-label { font-weight: 700; font-size: 0.9rem; color: #0f172a; margin-bottom: 2px; text-align: center; }
.line-picker-confirm-actions { display: flex; gap: 6px; }
.line-picker-confirm-btn {
    padding: 6px 14px; border-radius: 4px; border: 2px solid #16a34a;
    background: #16a34a; color: #fff; cursor: pointer; font-weight: 700;
    transition: background 0.15s;
}
.line-picker-confirm-btn:hover { background: #15803d; border-color: #15803d; }
.line-picker-cancel-btn {
    padding: 6px 14px; border-radius: 4px; border: 1px solid #cbd5e1;
    background: #fff; color: #334155; cursor: pointer;
    transition: background 0.15s;
}
.line-picker-cancel-btn:hover { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.line-building-label { font-size: 0.75rem; font-weight: 600; padding: 2px 6px !important; }

.selection-actions { display: flex; gap: 8px; margin-top: 8px; }
.selection-delete-btn { flex: 1; background: #dc3545; font-size: 0.85em; padding: 6px; }
.selection-delete-btn:hover:not(:disabled) { background: #c82333; }
.selection-deselect-btn { flex: 1; background: #6c757d; font-size: 0.85em; padding: 6px; }
.selection-deselect-btn:hover:not(:disabled) { background: #5a6268; }

/* --- Line hit area for easier hover/click --- */
.line-hit-area { pointer-events: stroke !important; }

/* --- Selected object highlights --- */
.station-marker-hover { box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.3), 0 0 6px rgba(0,0,0,0.5) !important; }
.station-marker-selected { box-shadow: 0 0 0 4px rgba(0, 123, 255, 0.5), 0 0 6px rgba(0,0,0,0.5) !important; }

/* --- Transfer link popup --- */
.transfer-choice-popup .leaflet-popup-content-wrapper { border-radius: 8px; padding: 0; }
.transfer-choice-popup .leaflet-popup-content { margin: 0; min-width: min(200px, 90vw); }
.transfer-popup { padding: 10px 12px; }
.transfer-popup-question { font-size: 13px; color: #333; margin-bottom: 8px; line-height: 1.4; }
.transfer-popup-detail { font-size: 12px; color: #666; }
.transfer-popup-actions { display: flex; gap: 6px; }
.transfer-popup-btn {
    flex: 1; padding: 7px 10px; margin-top: 0;
    border: 1px solid #ddd; border-radius: 5px;
    font-size: 13px; cursor: pointer; text-align: center; transition: background 0.15s;
}
.transfer-popup-yes { background: #007bff; color: white; border-color: #0056b3; font-weight: 600; }
.transfer-popup-yes:hover { background: #0056b3; color: white; }
.transfer-popup-no { background: #f8f9fa; color: #333; }
.transfer-popup-no:hover { background: #e9ecef; color: #333; }

/* --- Selection popup (desktop, L.popup anchored to map object) --- */
.selection-map-popup .leaflet-popup-content-wrapper {
    border-radius: 10px;
    padding: 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.22);
    border: 2px solid #007bff;
    background: rgba(255,255,255,0.97);
}
.selection-map-popup .leaflet-popup-tip { background: rgba(255,255,255,0.97); }
.selection-map-popup .leaflet-popup-content { margin: 0; }
.sel-popup-inner { padding: 12px 14px 10px; min-width: min(190px, 90vw); }
.sel-popup-title {
    display: block; width: 100%;
    font-size: 0.93rem; font-weight: 700; color: #0b5ed7;
    margin-bottom: 6px; cursor: default;
    background: transparent; border: 0; padding: 0; text-align: left;
}
.sel-popup-title.is-editable { cursor: text; }
.sel-popup-title.hidden { display: none; }
.sel-popup-title-input {
    display: block; width: 100%; margin-bottom: 8px; padding: 6px 8px;
    border: 1px solid rgba(15,23,42,0.18); border-radius: 6px;
    font-size: 0.93rem; font-weight: 700; color: #0b5ed7; background: #fff;
    box-sizing: border-box;
}
.sel-popup-title-input.hidden { display: none; }
.sel-popup-details { font-size: 0.82rem; color: #333; line-height: 1.5; }
.sel-popup-details .sel-row { display: flex; justify-content: space-between; margin-bottom: 2px; gap: 12px; }
.sel-popup-details .sel-label { color: #555; }
.sel-popup-details .sel-value { font-weight: bold; }
/* Station catchment group — bordered cluster for walk/pop/jobs */
.sel-catchment-group {
    border: 2px solid #1e293b;
    border-radius: 6px;
    padding: 4px 8px;
    margin: 4px 0;
}
.sel-catchment-group .sel-row { margin-bottom: 1px; }
.sel-walk-value {
    cursor: pointer;
    color: #2563eb;
    user-select: none;
}
.sel-walk-value:hover { text-decoration: underline; }
.sel-walk-picker {
    display: flex;
    gap: 2px;
    padding: 4px 0 2px;
}
.sel-walk-picker.hidden { display: none; }
.sel-walk-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    font-size: 0.75rem;
    color: #475569;
    flex: 1;
    text-align: center;
}
.sel-walk-option input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: #166534;
}
.sel-walk-option input:checked + span {
    color: #166534;
    font-weight: 700;
}
.sel-popup-actions { display: flex; gap: 6px; margin-top: 8px; }
.sel-popup-btn {
    flex: 1; font-size: 0.82em; padding: 5px 8px;
    border: none; border-radius: 4px; cursor: pointer;
    background: #dc3545; color: white;
}
.sel-popup-btn:hover { background: #c82333; }
.sel-popup-btn.sel-popup-btn-neutral { background: #6c757d; }
.sel-popup-btn.sel-popup-btn-neutral:hover { background: #5a6268; }

/* Click popup on real-world ZET trams / HŽ trains: line label + "U kabinu" button. */
.tram-cab-popup { min-width: 130px; text-align: center; }
.tram-cab-popup-line { font-weight: 700; margin-bottom: 6px; font-size: 0.95em; }
.tram-cab-popup-btn {
    width: 100%; font-size: 0.85em; padding: 6px 10px;
    border: none; border-radius: 4px; cursor: pointer;
    background: #1d4ed8; color: white;
}
.tram-cab-popup-btn:hover { background: #1e40af; }

/* --- Selection bottom sheet (mobile ≤768px, fixed at bottom of visual viewport) --- */
#selectionSheet {
    display: none;
    position: fixed;
    left: var(--visual-viewport-left, 0px);
    width: var(--visual-viewport-width, 100vw);
    bottom: calc(100dvh - var(--visual-viewport-top, 0px) - var(--visual-viewport-height, 100dvh));
    z-index: 2000;
    background: rgba(255, 255, 255, 0.93);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -4px 28px rgba(0,0,0,0.18);
    border-top: 2px solid #007bff;
    box-sizing: border-box;
    max-height: calc(var(--visual-viewport-height, 100dvh) * 0.55);
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: bottom 0.18s ease;
}
#selectionSheet:not(.hidden) { display: block; }
#selectionSheet::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(0, 0, 0, 0.22);
    border-radius: 2px;
    margin: 10px auto 4px;
}
#selectionSheet.dragging {
    transition: none !important;
    overflow-y: hidden;
}
#selectionSheet .sel-popup-inner {
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
}
#selectionSheet .sel-popup-title { font-size: 1rem; }
#selectionSheet .sel-popup-details { font-size: 0.9rem; }
#selectionSheet .sel-popup-btn { font-size: 0.9em; padding: 9px 12px; }

/* --- Clickable links in selection popups --- */
.sel-link { color: #1d4ed8; cursor: pointer; text-decoration: underline; text-decoration-color: transparent; transition: text-decoration-color 0.15s; }
.sel-link:hover { text-decoration-color: #1d4ed8; }

/* --- Depot lines in station popup --- */
.sel-depot-lines { margin: 6px 0 2px; display: flex; flex-direction: column; gap: 3px; }
.sel-depot-line-row { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 4px; cursor: pointer; font-size: 0.85em; font-weight: 600; }
.sel-depot-line-row:hover { background: #eef5ff; }
.sel-depot-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.sel-depot-line-meta { font-weight: 400; color: #64748b; margin-left: auto; }
.sel-popup-btn-add-line { background: #16a34a !important; color: white !important; }
.sel-popup-btn-add-line:hover { background: #15803d !important; }
.sel-popup-btn-3d { background: #1d4ed8 !important; color: white !important; }
.sel-popup-btn-3d:hover:not(:disabled) { background: #1e40af !important; }
.sel-popup-btn-3d:disabled { background: #94a3b8 !important; color: #e5e7eb !important; cursor: not-allowed; opacity: 0.75; }

/* --- Station 3D modal --- */
.station-3d-modal {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    /* Above the floating #toggleControls (z-index 4001) so it can't peek through. */
    z-index: 4100;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}
.station-3d-modal.hidden { display: none; }
.station-3d-frame {
    background: #ffffff;
    border-radius: 10px;
    width: min(1100px, 100%);
    height: min(720px, 100%);
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}
.station-3d-header {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    background: #0f172a;
    color: #f8fafc;
    border-bottom: 1px solid #1e293b;
}
.station-3d-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    flex: 0 1 auto;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.station-3d-title-prefix { white-space: nowrap; }
.station-3d-line-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.8em;
    padding: 0.18em 0.46em;
    border-radius: 0.45em;
    background: #f5a800;
    color: #111827;
    font-size: 0.95em;
    font-weight: 800;
    line-height: 1;
    box-shadow: inset 0 0 0 1px rgba(17, 24, 39, 0.18);
}
.station-3d-info {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    font-size: 0.85rem;
    color: #cbd5e1;
}
.station-3d-info-item {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}
.station-3d-close {
    flex: 0 0 auto;
    margin-left: auto;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #f8fafc;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.station-3d-close:hover { color: #fca5a5; }
.station-3d-container {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    background: #87ceeb;
}
.station-3d-container canvas { display: block; width: 100% !important; height: 100% !important; }
.station-3d-route-overlay {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    color: #f8fafc;
    font-size: 1.1rem;
    font-weight: 800;
    line-height: 1.2;
    pointer-events: none;
    white-space: nowrap;
    background: rgba(15, 23, 42, 0.72);
    padding: 5px 16px;
    border-radius: 20px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 4;
}
.station-3d-route-line {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.station-3d-route-line-paused {
    color: #fca5a5;
}
.station-3d-status {
    position: absolute;
    left: 20px;
    bottom: 20px;
    transform: none;
    background: rgba(15, 23, 42, 0.85);
    color: #f8fafc;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    max-width: min(420px, calc(100% - 180px));
}
.station-3d-status.hidden { display: none; }
.station-3d-status .station-3d-status-line {
    display: block;
}
.station-3d-toast {
    position: absolute;
    left: 50%;
    bottom: 34px;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.9);
    color: #f8fafc;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 7;
}
.station-3d-toast.hidden,
.station-3d-route-overlay.hidden { display: none; }
@media (max-width: 768px) {
    .station-3d-modal { padding: 0; }
    .station-3d-frame { border-radius: 0; height: 100%; width: 100%; }
    .station-3d-status {
        left: 16px;
        bottom: 16px;
        max-width: calc(100% - 168px);
        font-size: 0.9rem;
        padding: 10px 14px;
    }
    .station-3d-route-overlay {
        top: 12px;
        max-width: calc(100% - 32px);
        font-size: 1rem;
    }
    .station-3d-toast {
        bottom: 22px;
        max-width: calc(100% - 32px);
    }
}

/* --- Line popup --- */
.line-popup-content { max-height: 400px; overflow-y: auto; }
#selectionSheet .line-popup-content { max-height: none; overflow-y: auto; }
.line-popup-station-list,
.line-popup-train-list { margin: 2px 0 6px; line-height: 1.6; font-size: 0.85em; color: #334155; }
.line-popup-station-link,
.line-popup-train-link,
.line-popup-depot-link { color: #1d4ed8; cursor: pointer; text-decoration: underline; text-decoration-color: transparent; transition: text-decoration-color 0.15s; }
.line-popup-station-link:hover,
.line-popup-train-link:hover,
.line-popup-depot-link:hover { text-decoration-color: #1d4ed8; }
.line-popup-add-train { background: #16a34a !important; color: white !important; }
.line-popup-add-train:hover { background: #15803d !important; }

/* --- Vertex editing handles --- */
.vertex-handle {
    width: 12px;
    height: 12px;
    background: white;
    border: 2px solid #333;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 0 4px rgba(0,0,0,0.4);
}
.vertex-handle:active { cursor: grabbing; }
.vertex-handle-extend {
    width: 20px;
    height: 20px;
    box-sizing: border-box;
    background: #6b7280;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 6px rgba(107,114,128,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}
.vertex-handle-extend::after {
    content: '+';
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    pointer-events: none;
    margin-top: -1px;
}
.vertex-handle-preview { opacity: 0.5; cursor: copy; }

/* --- Catchment polygon colors --- */
.catchment-preview { opacity: 0.15; }
.catchment-confirmed { opacity: 0.25; }

/* --- Hover tooltip --- */
.hover-tooltip {
    position: absolute; z-index: 1100;
    background: rgba(255,255,255,0.95); padding: 6px 10px;
    border-radius: 4px; box-shadow: 0 1px 6px rgba(0,0,0,0.2);
    font-size: 0.8rem; pointer-events: none; white-space: nowrap;
}

.station-distance-label-icon {
    background: transparent;
    border: 0;
}

.station-distance-label {
    transform: translate(-50%, -50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 56px;
    padding: 4px 9px;
    border-radius: 999px;
    border: 2px solid var(--distance-color, #2563eb);
    background: rgba(255, 255, 255, 0.94);
    color: var(--distance-color, #2563eb);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.22);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.01em;
    white-space: nowrap;
    pointer-events: none;
}

.station-distance-label.is-preview {
    background: var(--distance-color, #2563eb);
    color: #fff;
}

/* --- Sky animation --- */
.sky-strip {
    position: relative;
    width: 100%;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
    background: #0f172a;
    transition: background 2s linear;
}
.sky-body {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    transform: translate(-50%, 50%);
    transition: box-shadow 2s linear;
    pointer-events: none;
}
/* Revenue row in sim panel */
.sim-panel-revenue { padding: 4px 10px; border-top: 1px solid rgba(255,255,255,0.1); }
.time-clock-revenue { font-size: 0.8rem; font-weight: 600; color: #4ade80; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Demand labels above stations --- */
.demand-label-icon { background: transparent; border: 0; }
.demand-label {
    transform: translate(-50%, calc(-100% - 12px));
    display: inline-flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
    pointer-events: none;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.01em;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
.demand-label-supply {
    color: #16a34a;
}
.demand-label-supply::before { content: '('; }
.demand-label-supply::after  { content: ')'; }
.demand-label-demand {
    color: #dc2626; /* waiting count — red = pressure */
}
.demand-label-sep {
    color: #94a3b8;
    font-weight: 400;
}

/* Ephemeral boarding/alighting toast that floats up and fades out */
@keyframes boarding-toast-rise {
    0%   { opacity: 1;   transform: translate(-50%, -100%); }
    70%  { opacity: 1;   transform: translate(-50%, -180%); }
    100% { opacity: 0;   transform: translate(-50%, -220%); }
}
.boarding-toast-icon { background: transparent; border: 0; }
.boarding-toast {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    white-space: nowrap;
    pointer-events: none;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 6px rgba(0,0,0,0.22);
    animation: boarding-toast-rise 2.2s ease-out forwards;
}
.boarding-toast-on  { color: #16a34a; }  /* boarded — green */
.boarding-toast-off { color: #dc2626; }  /* alighted — red  */

/* --- Mobile --- */
@media (max-width: 768px) {
    #controlsScrim {
        position: fixed;
        top: var(--visual-viewport-top);
        left: var(--visual-viewport-left);
        width: var(--visual-viewport-width);
        height: var(--visual-viewport-height);
        display: block;
        z-index: 999;
        background: rgba(15, 23, 42, 0.28);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    #controls {
        position: fixed;
        top: var(--visual-viewport-top);
        right: var(--visual-viewport-right);
        bottom: auto;
        left: auto;
        width: var(--visual-viewport-width);
        max-width: var(--visual-viewport-width);
        height: var(--visual-viewport-height);
        max-height: var(--visual-viewport-height);
        padding: calc(10px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
        border-radius: 0;
        background: rgba(255, 255, 255, 0.82);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        box-shadow: none;
        font-size: 0.92em;
        overscroll-behavior: contain;
    }
    .nav-row {
        position: sticky;
        top: 0;
        z-index: 10;
        background: rgba(255, 255, 255, 0.85);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        margin: calc(-10px - env(safe-area-inset-top)) -16px 10px;
        padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
    }
    .nav-pill { height: 48px; }
    #toggleControls {
        flex: 0 0 48px; width: 48px; height: 48px;
        border-radius: 14px;
        font-size: 1.45rem;
        background: rgba(15, 23, 42, 0.92);
    }
    #controls.collapsed {
        right: -120vw;
    }
    #toggleControls.floating {
        top: calc(var(--visual-viewport-top) + 10px + env(safe-area-inset-top));
        right: calc(var(--visual-viewport-right) + 10px);
        width: 48px;
        height: 48px;
    }
    .heatmap-buttons { gap: 5px; }
    .draw-icon-btn, .station-picker-btn { width: 44px; height: 44px; font-size: 1.2rem; }
    .draw-tool-btn { width: 44px; height: 44px; font-size: 20px; }
    .share-popup-row { grid-template-columns: 1fr; }
    .share-copy-btn { width: 100%; }
    .info-modal {
        width: calc(100vw - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
        max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        padding: 16px;
    }
    /* Sim panel: compact for mobile with sky background */
    .sim-panel {
        width: auto;
        min-width: 180px;
        left: calc(10px + env(safe-area-inset-left, 0px));
        top: calc(10px + env(safe-area-inset-top, 0px));
        position: fixed;
    }
    .sim-panel .sky-strip {
        position: absolute;
        inset: 0;
        height: auto;
        margin: 0;
        border-radius: 10px;
        opacity: 0.55;
        z-index: 0;
    }
    .sim-panel-row { padding: 6px 10px; gap: 6px; position: relative; z-index: 1; }
    .sim-panel-row .time-clock-display { font-size: 1rem; }
    .sim-panel-revenue { padding: 4px 10px; position: relative; z-index: 1; }
    .sim-clock-btn { width: 36px; height: 36px; border-radius: 6px; font-size: 16px; min-width: 36px; }
    /* Touch targets */
    .walk-time-option { padding: 8px 4px; margin: -8px -4px; }
    .walk-time-option input { width: 22px; height: 22px; }
    #selectionSheet .sel-popup-btn { padding: 11px 14px; }
    .toast-container { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* ─── Touch devices: suppress sticky hover states ─────────────────── */
@media (hover: none) {
    button:hover:not(:disabled) { background-color: #007bff; }
    #toggleControls:hover { background: #333; }
    .nav-pill:hover { background: transparent; color: #007bff; }
    .sidebar-secondary-btn:hover:not(:disabled) { background: #eef2f7; }
    .heatmap-btn:hover:not(:disabled) { background: #f8f9fa; }
    .draw-icon-btn:hover,
    .station-picker-btn:hover { background: #f8f9fa; border-color: #ddd; }
    .radio-label:hover { background: #f8f9fa; }
    .secondary-btn:hover:not(:disabled) { background: #6c757d; }
    .draw-tool-btn:hover:not(:disabled) { background: white; }
    .line-item:hover { background: #f8f9fa; }
    .sidebar-tab:hover { color: #94a3b8; }
    .share-copy-btn:hover { background: #007bff; }
    .share-export-btn:hover:not(:disabled) { background: #0b5ed7; }
    .share-export-btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
    .modal-btn-cancel:hover { background: #e9ecef; }
    .modal-btn-confirm:hover { background: #007bff; }
    .modal-btn-danger:hover { background: #dc2626; }
    .info-close-btn:hover:not(:disabled) { background: #eef2f7; }
    .sim-clock-btn:hover { background: rgba(255, 255, 255, 0.15); }
    .sel-popup-btn:hover { background: #dc3545; }
    .sel-popup-btn.sel-popup-btn-neutral:hover { background: #6c757d; }
    .sel-popup-btn-add-line:hover { background: #16a34a !important; }
    .sel-depot-line-row:hover { background: transparent; }
    .line-picker-btn:hover { background: #fff; }
    .line-picker-finish:hover { background: #fff; color: #2563eb; }
    .line-picker-cancel:hover { background: #fff; color: #64748b; border-color: #cbd5e1; }
    .line-picker-confirm-btn:hover { background: #16a34a; border-color: #16a34a; }
    .line-picker-cancel-btn:hover { background: #fff; border-color: #cbd5e1; color: #334155; }
    .transfer-popup-yes:hover { background: #007bff; color: white; }
    .transfer-popup-no:hover { background: #f8f9fa; color: #333; }
    .line-popup-add-train:hover { background: #16a34a !important; }
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
