*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
html,
body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #1a1a2e;
}

#app {
    display: flex;
    height: 100%;
}

/* ===== Sidebar ===== */
#sidebar {
    width: 340px;
    min-width: 240px;
    max-width: 600px;
    background: #16213e;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    padding: 20px 18px;
    gap: 14px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 1000;
    border-right: 1px solid #2a3a5e;
}
#sidebar-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    z-index: 1001;
}
#sidebar-resizer:hover {
    background: rgba(74,124,247,.3);
}
#sidebar h1 {
    font-size: 20px;
    font-weight: 600;
    color: #f0f4ff;
    letter-spacing: 0.3px;
    padding-bottom: 8px;
    border-bottom: 1px solid #2a3a5e;
}
#sidebar h1 small {
    font-size: 13px;
    font-weight: 400;
    color: #8899bb;
    display: block;
    margin-top: 2px;
}
#btnHelp:hover { background: #2a3a5e !important; color: #f0f4ff !important; }
.ctrl-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.ctrl-group label {
    font-size: 13px;
    font-weight: 500;
    color: #aabbdd;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.ctrl-group input {
    background: #0f1a30;
    border: 1px solid #2a3a5e;
    border-radius: 6px;
    padding: 9px 12px;
    color: #f0f4ff;
    font-size: 14px;
    outline: none;
    transition: border 0.2s;
    box-sizing: border-box;
    line-height: normal;
}
.ctrl-group input:focus {
    border-color: #4a7cf7;
}
.ctrl-group input[type="range"] {
    padding: 0;
    background: transparent;
    border: none;
    accent-color: #4a7cf7;
    height: 6px;
    cursor: pointer;
}
.ctrl-group input[type="range"]:focus {
    border: none;
}
.ctrl-group input::placeholder {
    color: #556688;
}
.time-input {
    width: 85px;
}
.time-input::-webkit-calendar-picker-indicator {
    display: none;
}
.ctrl-row {
    display: flex;
    gap: 12px;
}
.ctrl-row .ctrl-group {
    flex: 1;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    color: #fff;
}
.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
input:disabled, select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    color: #6a7a9a;
}
.btn-primary {
    background: #4a7cf7;
}
.btn-primary:hover:not(:disabled) {
    background: #3a6ae0;
}
.btn-success {
    background: #2ecc71;
}
.btn-success:hover:not(:disabled) {
    background: #27ae60;
}
.btn-danger {
    background: #e74c3c;
}
.btn-danger:hover:not(:disabled) {
    background: #c0392b;
}
.btn-warning {
    background: #f39c12;
}
.btn-warning:hover:not(:disabled) {
    background: #d68910;
}
.btn-outline {
    background: transparent;
    border: 1px solid #2a3a5e;
    color: #aabbdd;
}
.btn-outline:hover:not(:disabled) {
    background: #1a2a4e;
    border-color: #4a7cf7;
}

.btn-3d-toggle {
    padding: 8px 18px;
    background: linear-gradient(135deg, rgba(74, 124, 247, 0.12), rgba(120, 80, 220, 0.12));
    border: 1px solid rgba(74, 124, 247, 0.25);
    border-radius: 8px;
    color: #8aacf7;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all .25s cubic-bezier(.4, 0, .2, 1);
    white-space: nowrap;
    height: 100%;
}
.btn-3d-toggle:hover:not(:disabled) {
    border-color: rgba(74, 124, 247, 0.5);
    color: #c0d4ff;
    background: linear-gradient(135deg, rgba(74, 124, 247, 0.2), rgba(120, 80, 220, 0.2));
    transform: translateY(-1px);
}
.btn-3d-toggle.active {
    background: linear-gradient(135deg, #4a7cf7, #6b4fd4);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 0 8px rgba(74, 124, 247, 0.2), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn-3d-toggle.active:hover:not(:disabled) {
    background: linear-gradient(135deg, #5a8cf7, #7b5fe4);
    box-shadow: 0 0 12px rgba(74, 124, 247, 0.25), inset 0 1px 0 rgba(255, 255, 255, .15);
    transform: none;
}
.btn-3d-toggle:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #2a3a5e;
}
.tab-btn {
    flex: 1;
    padding: 8px 0;
    border: none;
    border-radius: 6px 6px 0 0;
    background: #0f1a30;
    color: #8899bb;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    position: relative;
}
.tab-btn.active {
    background: #1a2a4e;
    border-bottom-color: #4a7cf7;
    color: #f0f4ff;
}
.tab-btn:hover:not(.active) {
    color: #c0ccff;
    background: #152040;
}
.tab-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.mode-btn:hover {
    opacity: .8;
}
.mode-btn:disabled {
    opacity: .4;
    cursor: default;
}
.mode-btn.active {
    background: rgba(74,124,247,.2) !important;
    border-color: #4a7cf7 !important;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.btn-group .btn {
    flex: 1;
    min-width: 80px;
}

/* Info rows */
.info-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding: 6px 0;
    border-bottom: 1px solid #1a2a4e;
}
.info-row .label {
    color: #8899bb;
}
.info-row .value {
    color: #f0f4ff;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.info-row .value.highlight {
    color: #4a7cf7;
    font-weight: 700;
}

#status-bar {
    font-size: 13px;
    color: #8899bb;
    padding: 6px 0;
    min-height: 26px;
}
#status-bar.active {
    color: #2ecc71;
}
#status-bar.error {
    color: #e74c3c;
}
#status-bar.warning {
    color: #f39c12;
}

/* ===== Map container ===== */
#map {
    flex: 1;
    height: 100%;
    position: relative;
}
#map3d {
    flex: 1;
    height: 100%;
    position: relative;
}
.map3d-marker-label {
    pointer-events: none;
    white-space: nowrap;
}
.map3d-label-text {
    background: rgba(10, 21, 40, 0.8);
    color: #f0f4ff;
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.map3d-marker-icon {
    font-size: 16px;
    text-shadow: 0 0 3px rgba(0,0,0,0.5);
    text-align: center;
    line-height: 1;
}

.bottom-widgets {
    position: fixed;
    bottom: 24px;
    right: 4px;
    z-index: 10000;
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-end;
    gap: 6px;
    pointer-events: none;
}

#sunView {
    display: block;
    border-radius: 8px 8px 0 0;
    background: #1a1a2e;
    cursor: default;
    pointer-events: none;
}

.sun-controls {
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    background: #1a1a2e;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    transition: opacity .3s, transform .3s;
    flex-shrink: 0;
}

.sun-controls.collapsed #sunView {
    display: none;
}
.sun-controls.collapsed {
    background: none;
    border: none;
    box-shadow: none;
}
.sun-controls.collapsed .sun-caption {
    background: none;
}
.sun-controls.collapsed .sun-info {
    display: none;
}
.sun-controls.collapsed #sunViewToggle {
    font-size: 0;
}
.sun-controls.collapsed #sunViewToggle::before {
    content: '\2600';
    font-size: 16px;
    line-height: 1;
}

.sun-caption, .elev-caption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: rgba(0,0,0,0.55);
    border-radius: 0 0 6px 6px;
    min-height: 38px;
    gap: 6px;
    pointer-events: auto;
}
.sun-info {
    color: #fff;
    font-size: 12px;
    font-family: -apple-system, sans-serif;
    white-space: nowrap;
}
#sunViewToggle {
    width: 30px;
    height: 30px;
    background: #16213e;
    border: 2px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    color: #8899bb;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}
#sunViewToggle:hover {
    background: #2a3a5e;
    color: #f0f4ff;
}

/* ===== Elevation widget ===== */
.elev-controls {
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    background: #1a1a2e;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    transition: opacity .3s, transform .3s;
    flex-shrink: 0;
}
#elevView {
    display: block;
    width: 800px;
    height: 180px;
    background: #0d1a2d;
    border-radius: 8px 8px 0 0;
    cursor: default;
    pointer-events: none;
}
.elev-controls.collapsed #elevView {
    display: none;
}
.elev-controls.collapsed {
    background: none;
    border: none;
    box-shadow: none;
}
.elev-controls.collapsed .elev-caption {
    background: none;
}
.elev-controls.collapsed .elev-info {
    display: none;
}
.elev-controls.collapsed #elevViewToggle {
    font-size: 0;
}
.elev-controls.collapsed #elevViewToggle::before {
    content: '\26F0';
    font-size: 16px;
    line-height: 1;
}
.elev-info {
    color: #fff;
    font-size: 12px;
    font-family: -apple-system, sans-serif;
    white-space: nowrap;
}
#elevViewToggle {
    width: 30px;
    height: 30px;
    background: #16213e;
    border: 2px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    color: #8899bb;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}
#elevViewToggle:hover {
    background: #2a3a5e;
    color: #f0f4ff;
}

/* Custom Leaflet overrides */
.leaflet-container {
    background: #1a1a2e;
}
.leaflet-tooltip {
    background: #16213e;
    color: #e0e0e0;
    border: 1px solid #2a3a5e;
    border-radius: 4px;
    padding: 3px 7px;
    font-size: 11px;
    font-weight: 500;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.leaflet-tooltip-top:before {
    border-top-color: #2a3a5e;
}

/* Waypoint markers */
.waypoint-marker {
    background: #4a7cf7;
    border: 2px solid #fff;
    border-radius: 50%;
    width: 12px;
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
}

/* 508 teardrop marker */
.marker-508 {
    background: none !important;
    border: none !important;
}
.marker-508-shape {
    position: absolute;
    left: 6px;
    top: 3px;
    width: 32px;
    height: 32px;
    background: #e74c3c;
    border: 2px solid #fff;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.marker-508-shape span {
    transform: rotate(45deg);
    line-height: 1;
}

/* Moving marker */
.move-marker {
    background: #e74c3c;
    border: 3px solid #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    box-shadow: 0 0 12px rgba(231, 76, 60, 0.7);
}

/* Scrollbar styling */
#sidebar, #sidebar * {
    scrollbar-width: thin;
    scrollbar-color: #2a3a5e #0f1a30;
}
#sidebar::-webkit-scrollbar, #sidebar ::-webkit-scrollbar {
    width: 6px;
}
#sidebar::-webkit-scrollbar-track, #sidebar ::-webkit-scrollbar-track {
    background: #0f1a30;
}
#sidebar::-webkit-scrollbar-thumb, #sidebar ::-webkit-scrollbar-thumb {
    background: #2a3a5e;
    border-radius: 3px;
}

/* ===== Help modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-box {
    background: #16213e;
    border: 1px solid #2a3a5e;
    border-radius: 10px;
    max-width: 640px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #2a3a5e;
    color: #f0f4ff;
    font-weight: 600;
    font-size: 15px;
}
.modal-close {
    background: none;
    border: none;
    color: #8899bb;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.modal-close:hover { color: #f0f4ff; }
.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    color: #d0d8e8;
    font-size: 13px;
    line-height: 1.6;
    background: #16213e;
    scrollbar-width: thin;
    scrollbar-color: #2a3a5e #0f1a30;
}
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-track { background: #0f1a30; }
.modal-body::-webkit-scrollbar-thumb { background: #2a3a5e; border-radius: 3px; }
.modal-body h1 { font-size: 20px; color: #f0f4ff; margin: 0 0 10px; }
.modal-body h2 { font-size: 16px; color: #f0f4ff; margin: 18px 0 8px; border-bottom: 1px solid #2a3a5e; padding-bottom: 4px; }
.modal-body h3 { font-size: 14px; color: #d0d8e8; margin: 12px 0 4px; }
.modal-body p { margin: 6px 0; }
.modal-body ul, .modal-body ol { padding-left: 20px; margin: 6px 0; }
.modal-body li { margin: 3px 0; }
.modal-body code { background: #1a1a2e; padding: 1px 5px; border-radius: 3px; font-size: 12px; color: #aabbdd; }
.modal-body pre { background: #1a1a2e; padding: 10px 14px; border-radius: 6px; overflow-x: auto; font-size: 12px; margin: 8px 0; }
.modal-body strong { color: #f0f4ff; }
.modal-body a { color: #4a7cf7; }

@media (max-width: 720px) {
    #app {
        flex-direction: column;
    }
    #sidebar {
        width: 100%;
        min-width: unset;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid #2a3a5e;
    }
    #map {
        height: 50vh;
    }
}

/* Terrain slowdown checkbox help tooltip */
.help-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #2a3a5e;
    color: #8ab4f8;
    font-size: 11px;
    font-weight: 700;
    cursor: help;
    user-select: none;
    transition: background 0.15s;
    flex-shrink: 0;
}
.help-icon:hover { background: #3a4a6e; }

.tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #16213e;
    color: #c8d4e8;
    font-size: 12px;
    font-weight: 400;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #2a3a5e;
    width: 240px;
    text-align: left;
    white-space: normal;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 1000;
    transition: opacity 0.18s, visibility 0.18s;
    pointer-events: none;
}
.help-icon:hover .tooltip-text,
.help-icon:focus-visible .tooltip-text {
    visibility: visible;
    opacity: 1;
}
.tooltip-text::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #2a3a5e;
}
.photo-icon-only {
    font-size: 15px;
    line-height: 1;
    filter: drop-shadow(0 0 3px rgba(0,0,0,.8));
}
.photo-label-only {
    white-space: nowrap;
    line-height: 1.05;
    color: #eee;
}
.point-label {
    background: rgba(0,0,0,.65) !important;
    border: none !important;
    border-radius: 6px !important;
    box-shadow: none !important;
    color: #eee !important;
    font-size: 10px !important;
    font-weight: 400 !important;
    line-height: 1.15 !important;
    padding: 2px 6px !important;
    white-space: nowrap !important;
}
.point-label::before {
    display: none !important;
}
.point-label-stop {
    background: rgba(100, 60, 5, 0.8) !important;
}
.point-label-speed {
    background: rgba(15, 90, 45, 0.8) !important;
}
.point-label-custom {
    background: rgba(70, 35, 90, 0.8) !important;
}
.point-label-112 {
    background: rgba(130, 30, 30, 0.8) !important;
}
.photo-text {
    display: inline-block;
    background: rgba(0,0,0,.65);
    border-radius: 6px;
    padding: 2px 6px;
}
.photo-line {
    font-size: 11px;
    font-weight: 600;
}
.photo-time {
    font-size: 11px;
    font-weight: 400;
}
.photo-desc {
    font-size: 10px;
    opacity: 0.85;
    font-weight: 400;
}
.poi-labels-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}
.poi-labels-toggle input {
    display: none;
}
.toggle-slider {
    position: relative;
    display: inline-block;
    width: 28px;
    height: 16px;
    flex-shrink: 0;
    background: #2a3a5e;
    border-radius: 8px;
    transition: background .2s;
}
.toggle-slider::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #8899bb;
    top: 2px;
    left: 2px;
    transition: transform .2s;
}
.poi-labels-toggle input:checked + .toggle-slider {
    background: #4a7cf7;
}
.poi-labels-toggle input:checked + .toggle-slider::after {
    transform: translateX(12px);
    background: #fff;
}
.poi-labels-toggle input:disabled + .toggle-slider {
    opacity: 0.4;
    cursor: default;
}
.drain-btn {
    width: 16px;
    height: 16px;
    padding: 0;
    line-height: 1;
    font-size: 11px;
    border: 1px solid #2a3a5e;
    border-radius: 3px;
    background: #0f1a30;
    color: #8899bb;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.drain-btn:hover {
    background: #1a2a4a;
    color: #f0f4ff;
}
.drain-arr {
    width: 14px;
    height: 9px;
    font-size: 6px;
    border-radius: 2px;
    line-height: 1;
    background: #667aad;
    color: #0a1220;
}
.drain-arr:hover {
    background: #4a7cf7;
    color: #fff;
}

/* ===== Update Bar ===== */
.update-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: 1000;
    background: rgba(22,33,62,0.92);
    border: 1px solid #4a7cf7;
    border-radius: 0 6px 0 0;
    padding: 2px 8px;
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    color: #c0d0f0;
    pointer-events: none;
    width: max-content;
    line-height: 1.2;
}
.update-bar kbd {
    background: #0f1a30;
    border: 1px solid #3a4a6e;
    border-radius: 3px;
    padding: 0 4px;
    font-family: inherit;
    font-size: 10px;
    color: #e0e8ff;
}

