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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    background: #f0f0f0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: #1a1a2e;
    color: white;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

header h1 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#map {
    flex: 1;
    height: 100%;
}

.sidebar {
    width: 280px;
    background: white;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #ddd;
    overflow-y: auto;
    flex-shrink: 0;
}

.panel {
    padding: 14px;
    border-bottom: 1px solid #eee;
}

.panel h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #888;
    margin-bottom: 10px;
}

.stats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.stats-header h2 {
    margin-bottom: 0;
}

.btn-units {
    background: #eee;
    color: #555;
    font-size: 11px;
    padding: 3px 8px;
}

.activity-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.activity-btn {
    padding: 5px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}

.activity-btn.active {
    background: #1a1a2e;
    color: white;
    border-color: #1a1a2e;
}

.stats {
    display: flex;
    gap: 16px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label {
    font-size: 11px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a2e;
}

.stat-unit {
    font-size: 11px;
    color: #888;
}

#elevation-chart-container {
    padding: 14px;
    border-bottom: 1px solid #eee;
}

#elevation-chart-container h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #888;
    margin-bottom: 8px;
}

.chart-wrap {
    position: relative;
    height: 90px;
}

#elevation-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

.actions {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid #eee;
}

.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.btn-locate { background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.5); font-size: 13px; }
.btn.btn-locate:hover { background: rgba(255,255,255,0.25); opacity: 1; }
.btn-primary { background: #1a1a2e; color: white; }
.btn-secondary { background: #eee; color: #333; }
.btn-danger { background: #e74c3c; color: white; }
.btn-edit { background: #eee; color: #333; border: 2px solid transparent; width: 100%; }
.btn-edit.active { background: #e8f5e9; color: #2e7d32; border-color: #2e7d32; }

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

.btn-row .btn { flex: 1; }

input[type="text"] {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
}

input[type="text"]:focus {
    outline: none;
    border-color: #1a1a2e;
}

.saved-routes {
    padding: 14px;
}

.saved-routes h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #888;
    margin-bottom: 10px;
}

.route-item {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    gap: 8px;
    cursor: pointer;
}

.route-item:hover .route-name { text-decoration: underline; }

.route-info { flex: 1; min-width: 0; }

.route-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.route-meta {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

.route-delete {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
}

.route-delete:hover { color: #e74c3c; }

.activity-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    background: #eef;
    color: #555;
    flex-shrink: 0;
}

.btn-help { background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.5); font-size: 13px; }
.btn-help:hover { background: rgba(255,255,255,0.25); opacity: 1; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay[hidden] { display: none; }

.modal {
    background: white;
    border-radius: 8px;
    width: 100%;
    max-width: 540px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 16px;
    color: #1a1a2e;
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #888;
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover { color: #333; }

.modal-body {
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-body section h3 {
    font-size: 13px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 6px;
}

.modal-body section p {
    font-size: 13px;
    color: #444;
    line-height: 1.6;
    margin-bottom: 6px;
}

.modal-body section ul {
    font-size: 13px;
    color: #444;
    line-height: 1.8;
    padding-left: 18px;
    margin-bottom: 6px;
}

.search-wrap {
    position: relative;
    flex: 1;
    max-width: 280px;
}

.search-wrap input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.12);
    color: white;
    font-size: 13px;
    outline: none;
}

.search-wrap input::placeholder { color: rgba(255,255,255,0.55); }
.search-wrap input:focus { border-color: rgba(255,255,255,0.6); background: rgba(255,255,255,0.18); }

#search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    list-style: none;
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 240px;
    overflow-y: auto;
}

#search-results[hidden] { display: none; }

#search-results li {
    padding: 8px 12px;
    font-size: 12px;
    color: #333;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    line-height: 1.4;
}

#search-results li:last-child { border-bottom: none; }
#search-results li:hover { background: #f5f5f5; }
#search-results li.search-no-results { color: #999; cursor: default; }

.header-auth {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.btn-auth {
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.5);
    font-size: 13px;
}

.btn-auth:hover { background: rgba(255,255,255,0.25); opacity: 1; }

#auth-user {
    font-size: 12px;
    color: rgba(255,255,255,0.8);
}

.modal-sm { max-width: 360px; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: #555;
}

.form-group input {
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
}

.form-group input:focus {
    outline: none;
    border-color: #1a1a2e;
}

.auth-switch {
    text-align: center;
    font-size: 12px;
    color: #888;
    margin-top: 12px;
}

.auth-switch a { color: #1a1a2e; }

.auth-error {
    background: #fdecea;
    color: #c0392b;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12px;
    margin-bottom: 12px;
}

.saved-routes-empty {
    font-size: 12px;
    color: #aaa;
}

#status {
    padding: 6px 14px;
    font-size: 12px;
    color: #666;
    background: #f9f9f9;
    border-top: 1px solid #eee;
    min-height: 28px;
}

/* --- Distance markers --- */
.dist-marker {
    background: #1a1a2e;
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 10px;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* --- Map style control --- */
.map-style-control {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 8px;
}

.map-style-btn {
    background: white;
    border: 1px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    text-align: left;
    width: 80px;
}

.map-style-btn:hover { background: #f4f4f4; }
.map-style-btn.active { background: #1a1a2e; color: white; border-color: #1a1a2e; }

/* --- Mobile --- */
.btn-sidebar-toggle {
    display: none;
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.5);
    font-size: 13px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 499;
}

@media (max-width: 768px) {
    .btn-sidebar-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        right: -300px;
        top: 0;
        height: 100%;
        z-index: 500;
        transition: right 0.25s ease;
        box-shadow: -4px 0 16px rgba(0,0,0,0.2);
    }

    .sidebar.open {
        right: 0;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .header-auth {
        margin-left: 0;
    }

    .search-wrap {
        display: none;
    }

    .btn.btn-locate {
        display: none;
    }

    #auth-user {
        display: none;
    }

    .btn-help {
        display: none;
    }
}
