/* ===== CSS Custom Properties ===== */

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

:root {
    --bg: #0d1117;
    --panel: #161b22;
    --panel2: #1c2230;
    --panel3: #252d3d;
    --border: rgba(255,255,255,.07);
    --border2: rgba(255,255,255,.15);
    --text: #e6edf3;
    --text2: #8b949e;
    --text3: #606b7a;
    --accent: #1d6fa4;
    --accent2: #2589c7;
    --accent3: #1a7f3c;
    --success: #238636;
    --warn: #d29922;
    --radius: 5px;
    /* ff- prefix: these are font-family variables */
    --ff-mono: 'JetBrains Mono', ui-monospace, monospace;
    --ff-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --sidebar-w: 280px;
    --ctrl-h: 36px;
    /* --sb-h: height shared between #statusbar and .leaflet-control-attribution — defined in map.css */
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--ff-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
}

a {
    color: var(--accent2);
    text-decoration: none;
}

    a:hover {
        text-decoration: underline;
    }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
}

/* ===== SVG icon system =====
 * All toolbar/button icons are <symbol> elements in index.html,
 * referenced with <svg class="icon"><use href="#icon-*"></use></svg>.
 * They inherit currentColor so no separate colour declarations are needed. */

svg.icon {
    display: inline-block;
    vertical-align: -0.15em;
    flex-shrink: 0;
    overflow: visible;
}

/* ===== Utility classes ===== */

/* !important is intentional: this utility must win against any component
   display value (flex, inline-flex, etc.) regardless of selector order. */
.is-hidden {
    display: none !important;
}

.flag-img {
    width: 20px;
    height: auto;
    object-fit: cover;
    border: 1px solid rgba(255,255,255,.15);
}

.osm-img {
    display: block;
}

.osm-img-dim {
    display: block;
    filter: grayscale(1);
}

/* ===== Scrollbars ===== */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--panel2);
}

::-webkit-scrollbar-thumb {
    background: #3a4a60;
    border-radius: 3px;
}

    ::-webkit-scrollbar-thumb:hover {
        background: #4e6080;
    }

* {
    scrollbar-width: thin;
    scrollbar-color: #3a4a60 var(--panel2);
}

/* ===== Layout ===== */

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

#sidebar {
    position: relative;
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: visible;
    transition: width .2s ease, min-width .2s ease;
}

    #sidebar.sidebar-closed {
        width: 0;
        min-width: 0;
        border-right-color: transparent;
    }

#map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
}

/* ===== Button shared foundations =====
 *
 * Three categories based on size and context:
 *
 * Group 1 — Action (text) buttons: toolbar (.tbtn) and popup footer (.pu-action-btn).
 *   Large enough for a label; var(--radius) rounding; var(--ff-sans) font.
 *
 * Group 2 — Small square icon buttons: popup nav (.pu-nav-btn).
 *   Fixed 24 x 24 px; 3 px radius; icon-only.
 *   Popup-specific icon buttons (.pu-osm-locate, .pu-osm-retry, .pu-node-preview-btn)
 *   are defined in popup.css with their own sizing.
 *
 * Group 3 — Basemap selector (.basemap-btn): wider, image thumbnail, unique style.
 *   Defined in sidebar.css with the rest of the Settings tab.
 *
 * The language selector (.lang-select-btn) has its own shape (full-width
 * dropdown trigger) and intentionally does not share a base. */

/* ----- Group 1: action buttons ----- */

.tbtn,
.pu-action-btn {
    font-family: var(--ff-sans);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.4;
    white-space: nowrap;
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: background .2s, border-color .2s, color .2s;
}

/* ----- Group 2: small square icon buttons ----- */

/* .pu-nav-btn: popup navigation arrows (24x24).
 * .pu-osm-btn: OSM status indicator (22x22) — 4 states in popup.css.
 * .pu-node-preview-btn is defined in popup.css with its own sizing. */
.pu-osm-btn,
.pu-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--panel2);
    border: 1px solid var(--border2);
    border-radius: 3px;
    padding: 0;
    flex-shrink: 0;
    text-decoration: none;
    cursor: pointer;
    transition: color .2s, border-color .2s, background .2s;
}

    .pu-osm-btn:hover,
    .pu-nav-btn:hover {
        border-color: var(--accent2);
    }

/* ===== Toggle switch component ===== */

/* Toggle switch: 28×16 px — shared by filter panel and Settings behavior toggles.
 * Flexbox + padding instead of absolute positioning avoids DPR rounding artifacts
 * that cause the thumb to appear off-center at non-integer device pixel ratios.
 * Activated by CSS :checked + .toggle-track (no JS class manipulation).
 * Use .toggle-input on the <input type=checkbox> to hide it visually while
 * keeping it interactive — the <label> wrapper provides the accessible name. */
.toggle-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.toggle-track {
    display: inline-flex;
    align-items: center;
    width: 28px;
    height: 16px;
    padding: 0 3px;
    background: var(--panel3);
    border: 1px solid var(--border2);
    border-radius: 8px;
    transition: background .2s, border-color .2s;
    cursor: pointer;
}

.toggle-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text3);
    transition: transform .2s, background .2s, border-color .2s;
}

/* Activated state — driven by CSS, no JS class manipulation. */
input:checked + .toggle-track {
    background: var(--accent);
    border-color: var(--accent2);
}

    input:checked + .toggle-track .toggle-thumb {
        transform: translateX(12px);
        background: #fff;
    }
