/* Art direction: utility map webapp -> clean, practical, mobile-first
   Palette: neutral surfaces + teal accent
   Typography: Satoshi for clarity and dense UI
   Density: balanced/compact
*/

:root,
[data-theme="light"] {
    --font-body: 'Satoshi', 'Inter', sans-serif;
    --font-display: 'Satoshi', 'Inter', sans-serif;

    --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
    --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
    --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
    --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2rem);

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    --color-bg: #f7f6f2;
    --color-surface: #f9f8f5;
    --color-surface-2: #fbfbf9;
    --color-surface-offset: #f3f0ec;
    --color-surface-dynamic: #e6e4df;
    --color-border: #d4d1ca;
    --color-divider: #dcd9d5;
    --color-text: #28251d;
    --color-text-muted: #6f6c66;
    --color-text-faint: #a9a69f;
    --color-primary: #01696f;
    --color-primary-hover: #0c4e54;
    --color-primary-highlight: #d8e6e4;
    --color-success: #437a22;
    --color-warning: #b07a00;
    --color-danger: #a13544;

    --radius-sm: 0.375rem;
    --radius-md: 0.625rem;
    --radius-lg: 0.9rem;
    --radius-xl: 1.25rem;
    --radius-full: 999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.08);

    --sidebar-width: 360px;
    --detail-width: 380px;
    --topbar-height: 68px;
    --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
    --color-bg: #171614;
    --color-surface: #1c1b19;
    --color-surface-2: #201f1d;
    --color-surface-offset: #262320;
    --color-surface-dynamic: #302d29;
    --color-border: #393836;
    --color-divider: #2a2927;
    --color-text: #d7d5d1;
    --color-text-muted: #9d9991;
    --color-text-faint: #67635d;
    --color-primary: #4f98a3;
    --color-primary-hover: #227f8b;
    --color-primary-highlight: #263638;
    --color-success: #6daa45;
    --color-warning: #e8af34;
    --color-danger: #dd6974;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.18);
    --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.35);
}

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

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

body {
    margin: 0;
    min-height: 100vh;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
}

button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
}

a {
    color: var(--color-primary);
}

.hidden {
    display: none !important;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
}

.skip-link:focus {
    left: var(--space-4);
    top: var(--space-4);
    z-index: 9999;
    background: var(--color-surface);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4);
    border-right: 1px solid var(--color-border);
    background: var(--color-surface);
    min-height: 100vh;
}

.sidebar__top,
.panel,
.topbar,
.detail-panel,
.result-item,
.mobile-filters-sheet__panel {
    background: var(--color-surface-2);
    border: 1px solid color-mix(in srgb, var(--color-text) 10%, transparent);
    box-shadow: var(--shadow-sm);
}

.sidebar__top,
.panel,
.topbar,
.detail-panel {
    border-radius: var(--radius-xl);
}

.sidebar__top,
.panel {
    padding: var(--space-4);
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.brand-row h1 {
    margin: 0;
    font-size: var(--text-lg);
    line-height: 1.15;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-lg);
    background: var(--color-primary-highlight);
    color: var(--color-primary);
    flex: 0 0 auto;
}

.sidebar-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.eyebrow {
    margin: 0 0 var(--space-1);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
}

.panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.panel__header h2 {
    margin: 0;
    font-size: var(--text-base);
}

.filters {
    display: grid;
    gap: var(--space-3);
}

.field {
    display: grid;
    gap: var(--space-2);
}

.field__label {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.field__hint {
    font-size: var(--text-xs);
    color: var(--color-text-faint);
    line-height: 1.4;
}

input[type="text"],
select {
    width: 100%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    padding: 0.85rem 0.95rem;
    border-radius: var(--radius-md);
}

input:focus,
select:focus,
button:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-sm);
}

.text-btn,
.icon-btn,
.action-btn {
    border: 0;
    border-radius: var(--radius-md);
    transition: all var(--transition);
}

.text-btn,
.icon-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    padding: 0.7rem 0.9rem;
}

.text-btn--full {
    width: 100%;
}

.text-btn:hover,
.icon-btn:hover,
.action-btn:hover {
    background: var(--color-surface-offset);
}

.counter,
.pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 700;
}

.counter {
    background: var(--color-primary-highlight);
    color: var(--color-primary);
}

.pill {
    background: var(--color-surface-offset);
    color: var(--color-text-muted);
}

.pill--visited {
    background: color-mix(in srgb, var(--color-success) 18%, var(--color-surface));
    color: var(--color-success);
}

.pill--todo {
    background: color-mix(in srgb, var(--color-warning) 18%, var(--color-surface));
    color: var(--color-warning);
}

.panel--results {
    min-height: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

.results-list {
    display: grid;
    gap: var(--space-3);
    overflow: auto;
    padding-right: var(--space-1);
}

.result-item {
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    cursor: pointer;
}

.result-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.result-item.is-active {
    border-color: var(--color-primary);
    background: color-mix(in srgb, var(--color-primary) 6%, var(--color-surface-2));
}

.result-item__title {
    margin: 0 0 var(--space-2);
    font-size: var(--text-base);
}

.result-item__meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.result-chip {
    display: inline-flex;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-full);
    background: var(--color-surface-offset);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.result-item__coords {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
}

.main {
    display: grid;
    grid-template-rows: auto 1fr;
    min-width: 0;
}

.topbar {
    height: var(--topbar-height);
    margin: var(--space-4) var(--space-4) 0;
    padding: var(--space-4) var(--space-5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.topbar__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    width: 100%;
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.topbar__title {
    margin: 0;
    font-weight: 700;
}

.topbar__meta {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}

.mobile-theme-toggle {
    display: none;
}

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--detail-width);
    gap: var(--space-4);
    padding: var(--space-4);
    min-height: calc(100vh - var(--topbar-height) - var(--space-4));
}

.map,
.detail-panel {
    min-height: 0;
    height: calc(100vh - var(--topbar-height) - var(--space-8));
}

.map {
    border-radius: var(--radius-xl);
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--color-text) 10%, transparent);
    box-shadow: var(--shadow-sm);
}

.detail-panel {
    padding: var(--space-4);
    overflow: auto;
}

.detail-card__head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.detail-card__head h2 {
    margin: 0;
    font-size: var(--text-lg);
}

.meta-grid {
    display: grid;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.meta-row {
    display: grid;
    gap: var(--space-1);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-divider);
}

.meta-row__label {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
}

.meta-row__value {
    font-size: var(--text-sm);
}

.detail-actions {
    margin-bottom: var(--space-4);
}

.action-btn {
    width: 100%;
    background: var(--color-primary);
    color: white;
    padding: 0.9rem 1rem;
    font-weight: 700;
}

.action-btn:hover {
    background: var(--color-primary-hover);
}

.prose {
    font-size: var(--text-sm);
    color: var(--color-text);
}

.prose h2,
.prose h3 {
    margin: var(--space-4) 0 var(--space-2);
    font-size: var(--text-base);
}

.prose p,
.prose ul {
    margin: 0 0 var(--space-3);
}

.prose a {
    word-break: break-word;
}

.detail-panel__empty h2 {
    margin: 0 0 var(--space-3);
    font-size: var(--text-lg);
}

.mobile-only {
    display: none;
}

.mobile-filters-sheet {
    display: none;
}

.filter-dropdown {
    position: relative;
    display: grid;
    gap: var(--space-2);
}

.filter-dropdown__trigger {
    width: 100%;
    min-height: 48px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: var(--space-2);
    text-align: left;
    padding: 0.85rem 0.95rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
}

.filter-dropdown__label {
    font-size: var(--text-sm);
    font-weight: 600;
}

.filter-dropdown__summary {
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

.filter-dropdown__chevron {
    color: var(--color-text-muted);
    transition: transform var(--transition);
}

.filter-dropdown.is-open .filter-dropdown__chevron {
    transform: rotate(180deg);
}

.filter-dropdown.has-value .filter-dropdown__trigger {
    border-color: color-mix(in srgb, var(--color-primary) 45%, var(--color-border));
    background: color-mix(in srgb, var(--color-primary) 5%, var(--color-surface));
}

.filter-dropdown.has-value .filter-dropdown__summary {
    color: var(--color-primary);
    font-weight: 700;
}

.filter-dropdown__panel {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow: auto;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--text-sm);
    padding: 0.35rem 0.1rem;
}

.filter-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--color-primary);
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--color-surface-2);
    color: var(--color-text);
}

.map-popup h3 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
}

.map-popup p {
    margin: 0.2rem 0;
    font-size: 0.9rem;
}

.custom-marker {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.08);
    opacity: 1;
    filter: saturate(1);
}

.custom-marker--todo {
    opacity: 1;
    filter: saturate(1);
}

.custom-marker--visited {
    opacity: 0.58;
    filter: saturate(0.9);
}

.custom-marker--trek {
    background: #3f8f3d;
}

.custom-marker--walk {
    background: #d9a400;
}

.custom-marker--snow {
    background: #42a5f5;
}

.custom-marker--mixed {
    background: linear-gradient(135deg, #3f8f3d 0 48%, #42a5f5 52% 100%);
}
}

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background: color-mix(in srgb, var(--color-primary) 18%, transparent);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 320px 1fr;
    }

    :root {
        --detail-width: 320px;
    }
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .mobile-only {
        display: inline-flex;
    }

    .mobile-theme-toggle {
        display: inline-flex;
    }

    .topbar {
        margin: var(--space-4);
        height: auto;
        align-items: stretch;
        flex-direction: column;
    }

    .topbar__head {
        flex-direction: row;
        align-items: flex-start;
    }

    .topbar__actions {
        justify-content: flex-end;
    }

    .map-layout {
        grid-template-columns: 1fr;
    }

    .detail-panel {
        height: auto;
        min-height: 260px;
    }

    .map {
        height: 58vh;
        min-height: 420px;
    }

    .mobile-filters-sheet.is-open {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 9999;
    }

    .mobile-filters-sheet__backdrop {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
    }

    .mobile-filters-sheet__panel {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: var(--space-4);
        max-height: 80vh;
        overflow: auto;
        background: var(--color-surface-2);
    }

    .mobile-filters-sheet__header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: var(--space-4);
    }
}

@media (max-width: 640px) {
    .topbar {
        height: auto;
    }

    .topbar__head {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-3);
    }

    .topbar__actions {
        width: 100%;
        justify-content: space-between;
    }

    .map-layout {
        padding-top: 0;
    }

    .map {
        height: 52vh;
        min-height: 360px;
    }
}

.map-popup--interactive {
    cursor: pointer;
}

.map-popup__hint {
    margin-top: 0.45rem;
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

.user-location-marker {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #2563eb;
    border: 3px solid rgba(255, 255, 255, 0.95);
    box-shadow:
            0 0 0 4px rgba(37, 99, 235, 0.22),
            0 0 0 1px rgba(0, 0, 0, 0.08);
}