/* ==========================================================================
   GPX Multi‑Track Viewer - Core Styles
   File: assets/css/app.css
   --------------------------------------------------------------------------
   Provides full styling for:
     - Layout grid (sidebar / map / elevation)
     - Theming (dark default + optional light)
     - Track list UI
     - Control panels & buttons
     - Elevation chart container & overlay
   ========================================================================== */

/* ---------- CSS Reset (scoped minimal) ---------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ---------- Design Tokens ------------------------------------------------ */
:root {
    color-scheme: dark;
    /* Layout */
    --sidebar-width: 320px;
    --radius-sm: 4px;
    --radius: 8px;

    /* Palette (Dark) */
    --c-bg: #0f1115;
    --c-bg-alt: #14171c;
    --c-panel: #1c2128;
    --c-panel-alt: #171c22;
    --c-border: #2d333b;
    --c-border-subtle: #23292f;

    --c-text: #e6edf3;
    --c-text-muted: #8b949e;
    --c-text-faint: #5f6a75;

    --c-accent: #3fa34d;
    --c-accent-hover: #31823f;
    --c-accent-fg: #ffffff;

    --c-danger: #e5534b;
    --c-warning: #f2c744;
    --c-info: #3793e0;

    --c-focus: #ffbf3c;

    --c-scroll-track: #1a1f25;
    --c-scroll-thumb: #2f3740;

    /* Elevation chart specific */
    --chart-grid: #2a3036;

    /* Typography */
    --font-base:
        system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Arial, sans-serif;
    --fs-xs: 0.6rem;
    --fs-sm: 0.68rem;
    --fs-sm2: 0.72rem;
    --fs-base: 0.8rem;
    --lh-tight: 1.25;

    /* Transitions */
    --t-fast: 120ms;
    --t-med: 200ms;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0 0 0 / 0.35);
    --shadow: 0 2px 5px rgba(0 0 0 / 0.4);
}

/* Optional light theme (toggle by adding .theme-light on <body>) */
.theme-light {
    color-scheme: light;
    --c-bg: #f3f5f7;
    --c-bg-alt: #ffffff;
    --c-panel: #ffffff;
    --c-panel-alt: #f3f6f9;
    --c-border: #d9dee3;
    --c-border-subtle: #d0d6dc;
    --c-text: #1c2228;
    --c-text-muted: #5b6570;
    --c-text-faint: #9099a3;
    --c-accent: #2e7d32;
    --c-accent-hover: #256428;
    --c-scroll-track: #e2e6ea;
    --c-scroll-thumb: #c0c6cc;
    --chart-grid: #d9dee3;
    --shadow-sm: 0 1px 2px rgba(0 0 0 / 0.12);
    --shadow: 0 2px 6px rgba(0 0 0 / 0.15);
}

/* ---------- Global ------------------------------------------------------- */
body {
    font-family: var(--font-base);
    background: var(--c-bg);
    color: var(--c-text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body.no-select {
    user-select: none;
}

::selection {
    background: var(--c-accent);
    color: #fff;
}

/* Scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--c-scroll-thumb) var(--c-scroll-track);
}
*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
*::-webkit-scrollbar-track {
    background: var(--c-scroll-track);
}
*::-webkit-scrollbar-thumb {
    background: var(--c-scroll-thumb);
    border-radius: 5px;
    border: 2px solid var(--c-scroll-track);
}
*::-webkit-scrollbar-thumb:hover {
    background: var(--c-accent);
}

/* ---------- Header / Toolbar -------------------------------------------- */
header.site {
    padding: 0.65rem 1rem;
    background: var(--c-bg-alt);
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: center;
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
}

header.site h1 {
    margin: 0;
    font-size: 0.98rem;
    letter-spacing: 0.5px;
    font-weight: 600;
}

header.site .toolbar {
    margin-left: auto;
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
}

/* ---------- Layout Grid -------------------------------------------------- */
#layout {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: 1fr 270px;
    grid-template-areas:
        "sidebar map"
        "elevation elevation";
    gap: 0.65rem;
    padding: 0.65rem;
    min-height: 0;
}

@media (max-width: 1100px) {
    #layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(300px, 55vh) 260px;
        grid-template-areas:
            "sidebar"
            "map"
            "elevation";
    }
    #sidebar {
        max-height: 320px;
    }
}

@media (max-width: 620px) {
    header.site h1 {
        flex: 1 1 100%;
    }
    header.site .toolbar {
        width: 100%;
        justify-content: flex-start;
    }
    header.site .toolbar button {
        flex: 1 1 auto;
    }
}

/* ---------- Sidebar ------------------------------------------------------ */
#sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    min-height: 0;
    overflow: hidden;
    position: relative;
}

#sidebar h2 {
    margin: 0;
    padding: 0.65rem 0.85rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--c-text-muted);
    border-bottom: 1px solid var(--c-border-subtle);
}

/* Track List */
#trackList {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
    font-size: 0.7rem;
}

#trackList li {
    border-bottom: 1px solid var(--c-border-subtle);
    padding: 0.55rem 0.7rem 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    background: linear-gradient(to right, #0000, #0000 40%, #ffffff06 100%);
    transition: background var(--t-med);
}

#trackList li:last-child {
    border-bottom: none;
}

#trackList li:hover {
    background: linear-gradient(to right, #ffffff07, #ffffff05 60%, #0000);
}

label.track-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    font-weight: 600;
    user-select: none;
    line-height: 1.2;
}

label.track-toggle input {
    cursor: pointer;
}

.color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    outline: 2px solid #0008;
    box-shadow: 0 0 0 1px #0004;
    flex-shrink: 0;
    position: relative;
}

.color-dot::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 1px #ffffff20;
    pointer-events: none;
}

.meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 0.75rem;
    font-size: 0.62rem;
    color: var(--c-text-muted);
}

/* Panel Sections */
.panel-section {
    padding: 0.7rem 0.75rem 0.8rem;
    border-top: 1px solid var(--c-border);
    background: var(--c-panel-alt);
}

.panel-section:first-of-type {
    border-top: 1px solid var(--c-border-subtle);
}

.controls-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.1rem;
    font-size: 0.63rem;
    line-height: 1.3;
}

.controls-group label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    cursor: pointer;
}

.small-note {
    margin: 0.6rem 0 0;
    font-size: 0.6rem;
    line-height: 1.35;
    color: var(--c-text-muted);
}

/* ---------- Map ---------------------------------------------------------- */
#map {
    grid-area: map;
    width: 100%;
    height: 100%;
    background: var(--c-bg-alt);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

/* ---------- Elevation Panel --------------------------------------------- */
#elevationPanel {
    grid-area: elevation;
    display: flex;
    flex-direction: column;
    background: var(--c-panel);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    min-height: 0;
    position: relative;
}

#elevationPanel header {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--c-border-subtle);
}

#elevationPanel header h2 {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--c-text-muted);
}

#elevationChartContainer {
    flex: 1 1 auto;
    position: relative;
    padding: 0.55rem 0.75rem 0.95rem;
    min-height: 0;
}

#elevationCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Chart overlay */
#chartOverlay {
    display: none;
    position: absolute;
    inset: 0;
    background: #0e1217d9;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    color: var(--c-text);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    z-index: 10;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.65rem;
}

#chartOverlay.active {
    display: flex;
}

#chartOverlayMsg {
    font-weight: 600;
}

#chartOverlaySub {
    font-size: 0.6rem;
    font-weight: 400;
    color: var(--c-text-muted);
}

/* ---------- Buttons ------------------------------------------------------ */
button {
    font: inherit;
    background: var(--c-accent);
    color: var(--c-accent-fg);
    border: none;
    padding: 0.48rem 0.85rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    box-shadow: var(--shadow-sm);
    transition:
        background var(--t-fast),
        transform var(--t-fast),
        box-shadow var(--t-fast);
}

button.secondary {
    background: #3c4550;
    color: var(--c-text);
}

.theme-light button.secondary {
    background: #dfe4e9;
    color: #222;
}

button:hover {
    background: var(--c-accent-hover);
}

button.secondary:hover {
    filter: brightness(0.93);
}

button:active {
    transform: translateY(1px);
}

button:focus-visible {
    outline: 2px solid var(--c-focus);
    outline-offset: 2px;
}

button[disabled],
button[disabled]:hover {
    cursor: not-allowed;
    opacity: 0.55;
    background: var(--c-border);
    color: var(--c-text-muted);
}

/* Button micro animation */
@media (prefers-reduced-motion: no-preference) {
    button:not([disabled]) {
        position: relative;
    }
    button:not([disabled])::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: inherit;
        background: linear-gradient(
            120deg,
            #ffffff20,
            #ffffff08 42%,
            #ffffff00 60%
        );
        opacity: 0;
        transition: opacity var(--t-med);
        pointer-events: none;
    }
    button:not([disabled]):hover::after {
        opacity: 1;
    }
}

/* ---------- Form Inputs -------------------------------------------------- */
input[type="file"] {
    font-size: 0.62rem;
    color: var(--c-text-muted);
    background: var(--c-panel-alt);
    border: 1px solid var(--c-border-subtle);
    padding: 0.35rem 0.45rem;
    border-radius: 5px;
    max-width: 100%;
}

input[type="checkbox"] {
    accent-color: var(--c-accent);
}

/* ---------- Utility Classes --------------------------------------------- */
.hidden {
    display: none !important;
}
.flex {
    display: flex;
}
.flex-wrap {
    flex-wrap: wrap;
}
.gap-sm {
    gap: 0.4rem;
}
.gap {
    gap: 0.65rem;
}
.grow {
    flex: 1 1 auto;
}
.nowrap {
    white-space: nowrap;
}
.text-muted {
    color: var(--c-text-muted);
}
.text-faint {
    color: var(--c-text-faint);
}
.upper {
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

/* ---------- Animations --------------------------------------------------- */
@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fade-in 0.35s var(--t-fast) both;
}

/* ---------- Leaflet Overrides (minimal) ---------------------------------- */
.leaflet-container {
    font: var(--fs-sm2) / 1.2 var(--font-base);
    background: #0e1114;
}

.theme-light .leaflet-container {
    background: #e8ebef;
}

.leaflet-control-layers {
    background: var(--c-panel-alt);
    border: 1px solid var(--c-border-subtle);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.leaflet-bar a,
.leaflet-bar a:hover {
    background: var(--c-panel-alt);
    border-bottom: 1px solid var(--c-border-subtle);
    color: var(--c-text);
}

.leaflet-bar a:hover {
    filter: brightness(1.1);
}

.leaflet-bar a:last-child {
    border-bottom: none;
}

/* ---------- Chart.js Overrides ------------------------------------------ */
.theme-light canvas {
    filter: none;
}

/* Provide slightly softer grid lines via Chart.js plugin (optional)
   See assets/js/app.js for plugin registration if desired. */

/* ---------- Mobile / Responsive Enhancements ----------------------------- */
/* Off‑canvas sidebar + stacked layout for narrow screens */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 300px;
    }
}

@media (max-width: 760px) {
    body {
        overscroll-behavior-y: none;
    }
    header.site {
        position: sticky;
        top: 0;
        z-index: 700;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
    #layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(52vh, 60vh) 300px;
        grid-template-areas:
            "map"
            "elevation";
        padding: 0;
        gap: 0;
    }
    #map,
    #elevationPanel {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 82%;
        max-width: 330px;
        transform: translateX(-100%);
        transition: transform var(--t-med) ease;
        z-index: 800;
        border-radius: 0;
        border: 0;
        border-right: 1px solid var(--c-border);
        box-shadow:
            0 0 0 1px #000a,
            8px 0 28px -6px #000c;
    }
    body.sidebar-open #sidebar {
        transform: translateX(0);
    }
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: #000c;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--t-med);
        z-index: 750;
    }
    body.sidebar-open .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
    #trackList {
        -webkit-overflow-scrolling: touch;
        font-size: 0.72rem;
    }
    #elevationPanel {
        border-top: 1px solid var(--c-border);
        min-height: 260px;
    }
    button {
        font-size: 0.7rem;
        padding: 0.55rem 0.75rem;
    }
}

@media (max-width: 480px) {
    #elevationPanel {
        min-height: 240px;
    }
    #trackList {
        font-size: 0.7rem;
    }
    header.site h1 {
        font-size: 0.9rem;
    }
}

/* Helper class for a potential floating toggle button (if added in HTML) */
.sidebar-toggle-btn {
    display: none;
}

@media (max-width: 760px) {
    .sidebar-toggle-btn {
        display: inline-flex;
    }
}

/* End of file */
