@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap');

:root {
    --primary-color: #FC4C02; /* Strava Orange */
    --secondary-color: #FFFFFF;
    --background-color: #F7F7F7;
    --text-color: #333333;
    --light-gray: #f8f8f8;
    --shadow-color: #00000014;
    --action-color-a: #fb923c;
    --action-color-b: #2dd4bf;
    --line-color: #2563eb;
    --climb-line-color: #16a34a;
    --grade-line-color: #747880;
    --segment-color: #f97316;
    /* Additional color tokens for currently hard-coded values */
    --border-color: #ccc;
    --button-hover-border-color: #bbb;
    --strava-hover-color: #d64102;
    --list-active-background-color: #fcece4;
    --panel-background-color: #fdfdfd;
    --label-strong-color: #555;
    --muted-text-color: #6b7280;
    --divider-color: #d1d5db;
    --surface-white: #fff;
    --profile-hr-color: #cc0000;
    --profile-axis-color: #9ca3af;
    --profile-label-color: #4b5563;
    --profile-cursor-color: #881515;
    --profile-hr-grid-color: #ffcccc;
    --profile-hr-axis-color: #ffaaaa;
    --ground-speed-color: #8b5a2b;
    --slow-passage-color: #7c3f00;
    --top-compare-current-color: #0f766e;
    --top-compare-1-color: #c2410c;
    --top-compare-2-color: #7c3aed;
    --top-compare-3-color: #0284c7;
    --profile-area-fill: #2563EB1A;
    --profile-segment-fill: #F973162E;
    --profile-point-a-guide-color: #fdba74;
    --loader-track-color: #f3f3f3;
    --selected-marker-stroke-color: #b91c1c;
    --selected-marker-fill-color: #ef4444;
    --point-a-stroke-color: #7c2d12;
    --point-b-stroke-color: #0f766e;
    --fixed-point-stroke-color: #312e81;
    --fixed-point-fill-color: #6366f1;
    --legacy-red-color: red;
    --not-found-background-color: #ECEFF1;
    --not-found-text-color: #000000DE;
    --not-found-subtitle-color: #888;
    --not-found-accent-color: #ffa100;
    --not-found-heading-color: #00000099;
    --not-found-link-color: #039be5;
    --white-color: white;
    --elevation-shadow-color: #0000001A;
    --not-found-shadow-soft-color: #0000001F;
    --not-found-shadow-strong-color: #0000003D;
    --not-found-load-color: #00000066;
    --activity-trailrun-color: #16a34a;
    --activity-run-color: #22c55e;
    --activity-mtb-color: #8b5a2b;
    --activity-emtb-color: #a16207;
    --activity-gravel-color: #b45309;
    --activity-ride-color: #c2410c;
    --activity-ebike-color: #d97706;
    --activity-skitour-color: #2563eb;
    --activity-snowshoe-color: #7dd3fc;
    --activity-ski-color: #0ea5e9;
    --activity-nordic-color: #06b6d4;
    --activity-hike-color: #65a30d;
    --activity-walk-color: #84cc16;
    --activity-workout-color: #64748b;
    --activity-default-color: #64748b;
    --activities-list-visible-rows: 10;
    --activities-list-row-height: 3.35rem;
    --activities-list-padding-y: 1rem;
}

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

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    overflow: hidden; /* Prevent body scroll on desktop */
}

.app {
    display: grid;
    grid-template-columns: 380px 1fr;
    height: 100vh; /* Full viewport height */
}

.sidebar {
    border-right: 1px solid var(--light-gray);
    background: var(--secondary-color);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Allow the entire sidebar to scroll if content overflows */
}

.sidebar header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--light-gray);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.sidebar header h1 { font-size: 1.8rem; color: var(--primary-color); font-weight: 700; }
#auth-container { display: flex; gap: 0.5rem; }

/* General Button Styles */
button,
.button-link {
    font-family: 'Roboto', sans-serif;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--light-gray);
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.6rem 1rem;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease-in-out;
}
button:hover,
.button-link:hover { transform: translateY(-1px); box-shadow: 0 2px 5px var(--elevation-shadow-color); border-color: var(--button-hover-border-color); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* Specific Button Styles */
#connect-strava { background-color: var(--primary-color); color: var(--secondary-color); border-color: var(--primary-color); }
#connect-strava:hover { border-color: var(--strava-hover-color); }

/* Panels & Activities */
#activities-container {
    padding-top: 1rem;
}
#activities-container h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
#activities-list {
    list-style: none;
    max-height: calc(var(--activities-list-visible-rows) * var(--activities-list-row-height) + var(--activities-list-padding-y));
    overflow-y: auto;
    border: 1px solid var(--light-gray);
    border-radius: 8px;
    padding: 0.5rem;
}
#activities-list li { display: flex; align-items: flex-start; gap: 0.65rem; padding: 0.8rem; border-bottom: 1px solid var(--light-gray); cursor: pointer; transition: background-color 0.2s ease; border-radius: 4px; }
#activities-list li:last-child { border-bottom: none; }
#activities-list li:hover, #activities-list li.active { background-color: var(--list-active-background-color); }
.activity-type-dot { width: 0.72rem; height: 0.72rem; border-radius: 50%; flex: 0 0 auto; margin-top: 0.28rem; box-shadow: 0 0 0 2px #ffffffcc; }
.activity-summary { min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem; }
.activity-date, .activity-separator { color: var(--muted-text-color); font-size: 0.83rem; }
.activity-name { font-weight: 600; overflow-wrap: anywhere; }
.activity-name.is-race { color: var(--primary-color); }
.sidebar-meta {
    margin-top: 0.9rem;
    padding-top: 0.8rem;
    border-top: 1px solid var(--light-gray);
    color: var(--muted-text-color);
    font-size: 0.85rem;
    line-height: 1.45;
}
.sidebar-meta p + p { margin-top: 0.2rem; }
.sidebar-meta a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}
.sidebar-meta a:hover { text-decoration: underline; }

#analysis-panels {
    flex-shrink: 0;
    margin-bottom: 1rem;
}
.panel { background: var(--panel-background-color); border: 1px solid var(--light-gray); border-radius: 8px; padding: 0.75rem; margin-bottom: 0.75rem; }
.panel h2 { margin: 0 0 0.55rem; font-size: 0.95rem; border-bottom: 1px solid var(--light-gray); padding-bottom: 0.5rem; color: var(--primary-color); }
.key-value { display: grid; grid-template-columns: auto 1fr; gap: 0.28rem 0.75rem; font-size: 0.88rem; }
.key-value strong { font-weight: 600; color: var(--label-strong-color); }
.track-info-activity-name { display: block; color: var(--primary-color); font-weight: 700; }
.track-info-activity-meta { display: block; margin-top: 0.1rem; color: var(--muted-text-color); font-size: 0.84rem; }
.track-info-activity-type { display: block; margin-top: 0.1rem; color: var(--muted-text-color); font-size: 0.84rem; }
.inline-strava-dot {
    display: inline-block;
    width: 0.45rem;
    height: 0.45rem;
    margin-left: 0.35rem;
    border-radius: 50%;
    background: var(--primary-color);
    vertical-align: middle;
}
.muted { color: var(--muted-text-color); font-size: 0.86rem; line-height: 1.35; margin: 0; }

/* Main Content & Map */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}
#map {
    flex-shrink: 0;
    height: 68vh;
    min-height: 460px;
}
.leaflet-container { cursor: crosshair !important; }

/* Elevation Profile */
#profile-section {
    flex-shrink: 0; /* Prevent the profile from shrinking */
}
.map-profile { padding: 0.5rem; border-bottom: 1px solid var(--divider-color); background: var(--secondary-color); }
.map-profile-secondary { padding-top: 0; }
.profile-caption {
    margin: 0 0 0.45rem;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted-text-color);
}
.profile-wrap { position: relative; border: 1px solid var(--divider-color); border-radius: 6px; background: var(--surface-white); }
.profile-threshold-line { stroke: var(--profile-hr-color); stroke-width: 1.3; stroke-dasharray: 6 4; cursor: ns-resize; }
#elevationProfileSvg { width: 100%; height: 300px; display: block; user-select: none; -webkit-user-select: none; /* PREVENTS TEXT SELECTION */ }
#topElevationProfileSvg { width: 100%; height: 300px; display: block; user-select: none; -webkit-user-select: none; }
.profile-axis { stroke: var(--profile-axis-color); stroke-width: 1; pointer-events: none; }
.profile-area { fill: var(--profile-area-fill); pointer-events: none; }
.profile-line { fill: none; stroke: var(--line-color); stroke-width: 2; pointer-events: none; }
.profile-line-climb { fill: none; stroke: var(--climb-line-color); stroke-width: 2; opacity: 0.85; pointer-events: none; }
.profile-line-grade { fill: none; stroke: var(--grade-line-color); stroke-width: 2; opacity: 0.85; pointer-events: none; }
.profile-line-speed { fill: none; stroke: var(--ground-speed-color); stroke-width: 0.9; opacity: 0.95; pointer-events: none; }
.profile-line-climb.sink-mode { stroke-dasharray: 4 4; }
.profile-line-grade.sink-mode { stroke-dasharray: 4 4; }
.profile-line-compare { fill: none; stroke-width: 1.1; opacity: 0.96; pointer-events: none; }
.profile-line-compare-zero { stroke-dasharray: 4 3; opacity: 0.82; }
.profile-line-hr { pointer-events: none; }
.profile-line-hr-hfrc { fill: none; stroke: #ff1744; stroke-width: 2.4; opacity: 0.98; pointer-events: none; }
.profile-segment { fill: var(--profile-segment-fill); pointer-events: none; }
.profile-point-a-guide { stroke: var(--profile-point-a-guide-color); stroke-width: 1.6; stroke-dasharray: 6 4; opacity: 0.95; pointer-events: none; }
.profile-point-action-popup { position: absolute; z-index: 20; transform: translate(-50%, -100%); }
.profile-cursor, .profile-cursor-h, .profile-cursor-climb-h, .profile-cursor-speed-h { stroke: var(--profile-cursor-color); stroke-width: 1.6; pointer-events: none; }
.profile-cursor-h, .profile-cursor-climb-h, .profile-cursor-speed-h { stroke-dasharray: 4 3; }
[data-hr-tick-marker] { pointer-events: none; }
.profile-label { fill: var(--profile-label-color); font-size: 8px; font-weight: 400; pointer-events: none; /* PREVENTS TEXT SELECTION */ }
.profile-label[data-segment-effort-hover-label] { fill: var(--muted-text-color); font-size: 8px; font-weight: 500; opacity: 0.8; }
.profile-speed-label { fill: var(--ground-speed-color); font-size: 10px; font-weight: 600; pointer-events: none; }
.profile-slow-axis-span { fill: var(--slow-passage-color); opacity: 0.8; pointer-events: none; }

.heatmap-section {
    flex-shrink: 0;
    padding: 0.85rem;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-top: 1px solid var(--divider-color);
}

.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(320px, 1fr));
    gap: 0.9rem;
}

.heatmap-card {
    background: var(--surface-white);
    border: 1px solid var(--divider-color);
    border-radius: 10px;
    padding: 0.8rem;
    box-shadow: 0 10px 28px var(--elevation-shadow-color);
}

.heatmap-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.heatmap-card-head h3 {
    font-size: 0.98rem;
    color: var(--primary-color);
}

.heatmap-meta {
    color: var(--muted-text-color);
    font-size: 0.78rem;
    text-align: right;
}

.heatmap-frame {
    border: 1px solid #dbe3ec;
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(248, 250, 252, 0.95), rgba(239, 244, 248, 0.95)),
        repeating-linear-gradient(0deg, transparent, transparent 36px, rgba(148, 163, 184, 0.12) 36px, rgba(148, 163, 184, 0.12) 37px),
        repeating-linear-gradient(90deg, transparent, transparent 44px, rgba(148, 163, 184, 0.12) 44px, rgba(148, 163, 184, 0.12) 45px);
}

.heatmap-frame svg {
    display: block;
    width: 100%;
    height: 320px;
}

.heatmap-axis {
    stroke: #94a3b8;
    stroke-width: 1.2;
}

.heatmap-axis-label {
    fill: #475569;
    font-size: 11px;
    font-weight: 600;
}

.heatmap-axis-tick {
    fill: #64748b;
    font-size: 10px;
    font-weight: 500;
}

.heatmap-placeholder-note {
    fill: #94a3b8;
    font-size: 12px;
    font-weight: 600;
}


/* Popup */
.leaflet-popup.point-action-popup .leaflet-popup-content-wrapper { padding: 0; }
.leaflet-popup.point-action-popup .leaflet-popup-content { margin: 0; }
.leaflet-popup-content .popup-single-action { min-width: 112px; }
.leaflet-popup-content .popup-button { width: 100%; margin: 0; font-size: 0.95rem; padding: 8px 12px; white-space: nowrap; }

/* Loader */
.loader-container { text-align: center; padding: 1rem; }
.loader { border: 5px solid var(--loader-track-color); border-top: 5px solid var(--primary-color); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    body {
        overflow-y: auto; /* Allow the entire page to scroll */
        -webkit-overflow-scrolling: touch; /* Smoother scrolling on iOS */
    }
    .app {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        order: 2;
        border-right: none;
        border-bottom: none;
        border-top: 1px solid var(--light-gray);
        overflow-y: visible; /* Show all sidebar content */
        padding-top: 0.85rem;
    }
    .main-content {
        order: 1;
        display: block; /* Override desktop flex behavior */
        height: auto;
        overflow: visible;
        padding: 0;
    }
    #map {
        height: 65vh; /* Give map a large, predictable height */
        width: 100%;
        min-height: 360px;
    }
    #map,
    .leaflet-container {
        touch-action: pan-y;
    }
    #elevationProfileSvg,
    #topElevationProfileSvg {
        touch-action: pan-y;
    }
    .sidebar header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    #auth-container {
        width: 100%;
    }
    #auth-container button {
        flex: 1 1 0;
    }
    #activities-list {
        max-height: calc(var(--activities-list-visible-rows) * var(--activities-list-row-height) + var(--activities-list-padding-y));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .heatmap-grid { grid-template-columns: 1fr; }
    .heatmap-card-head { display: block; }
    .heatmap-meta { text-align: left; margin-top: 0.25rem; }
}


/* Styling für die neue Profil-Toolbar */
.profile-toolbar {
    padding: 0.5rem;
    background: var(--secondary-color);
    border-bottom: 1px solid var(--light-gray);
    display: none;
    gap: 0.5rem;
    flex-shrink: 0;
}

.profile-toolbar button.is-active { background: var(--primary-color); color: var(--secondary-color); border-color: var(--primary-color); }
.profile-toolbar button.is-segment-rate { color: var(--primary-color); }
.profile-toolbar button.is-segment-rate.is-active { background: var(--list-active-background-color); color: var(--primary-color); border-color: var(--primary-color); }
.profile-segment-effort-group { cursor: pointer; }
.profile-segment-effort-hitbox { fill: transparent; pointer-events: all; }
.profile-segment-effort { fill: var(--primary-color); pointer-events: none; }
.profile-segment-effort.is-private { opacity: 0.6; }
.profile-segment-effort.is-public { opacity: 0.3; }
.profile-segment-effort-hitbox:hover + .profile-segment-effort, .profile-segment-effort-group.is-active .profile-segment-effort { opacity: 1; }
.profile-segment-effort-group.is-active .profile-segment-effort { stroke: var(--surface-white); stroke-width: 1; }

@media (max-width: 768px) {
    .profile-toolbar {
        position: sticky;
        top: 0;
        z-index: 500;
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.45rem 0.5rem;
    }

    .profile-toolbar button {
        flex: 1 1 calc(33.333% - 0.4rem);
        min-width: 88px;
        padding: 0.55rem 0.6rem;
        font-size: 0.85rem;
        position: relative;
        z-index: 1;
        touch-action: manipulation;
    }
}
