/* ════════════════════════════════════════════════════════════════
   Stoei Scout — app layout (every page: sidebar, top bar, badges, and
   the public map page). Admin-only parts are in css/admin.css.

   The Stoei Core kit in /ds/ (tokens, base, controls, stoei, app-shell) gives the
   reset, page colors, fonts and the light/dark switch. The look (colors,
   fonts, corners, sizes) is set in css/theme.css. This file only reads
   --st-* settings: no fixed colors, fonts, text sizes, corners, shadows
   or spacing.
   Check: php <stoei-core>/tools/check-css.php ds/css/tokens.css
          ds/css/base.css ds/css/controls.css ds/css/stoei.css ds/css/app-shell.css
          css/theme.css css/app.css   (add css/admin.css for admin pages)
════════════════════════════════════════════════════════════════ */

/* ─── Page ─────────────────────────────────────────────────────── */
body {
    color: var(--st-color-text);
}

/* The public map fills the window; only its panels scroll. */
.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar (dark in both modes) ─────────────────────────────── */
.nav-sidebar {
    width: var(--st-sidebar-width);
    background: var(--st-color-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    z-index: 100;
    transition: transform var(--st-motion);
}

.nav-logo {
    display: flex;
    align-items: center;
    padding: var(--st-space-5) var(--st-space-4);
    border-bottom: var(--st-line-width) solid var(--st-color-sidebar-line);
    flex-shrink: 0;
}

.nav-items {
    flex: 1;
    padding: var(--st-space-3) var(--st-space-2);
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    overflow-y: auto;
}

.nav-bottom {
    padding: var(--st-space-2) var(--st-space-2) var(--st-space-4);
    border-top: var(--st-line-width) solid var(--st-color-sidebar-line);
}

.nav-item {
    position: relative;
    padding: var(--st-space-3) var(--st-space-4);
    font-size: var(--st-text-2);
    color: var(--st-color-on-sidebar-muted);
}
.nav-item[aria-current="page"] {
    background: color-mix(in srgb, var(--st-color-accent-fill) 15%, transparent);
    color: var(--st-color-on-sidebar-active);
    font-weight: 500;
}
.nav-item[aria-current="page"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--st-color-accent-fill);
    border-radius: 0 2px 2px 0;
}
.nav-item.danger {
    color: var(--st-color-on-sidebar-bad);
}
.nav-item.danger:hover {
    background: color-mix(in srgb, var(--st-color-on-sidebar-bad) 10%, transparent);
}

.nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.7;
}
.nav-item[aria-current="page"] .nav-icon,
.nav-item:hover .nav-icon {
    opacity: 1;
}

.nav-label {
    flex: 1;
}

/* ─── Main column and top bar ──────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--st-color-surface);
}

.top-bar {
    height: var(--st-topbar-height);
    border-bottom: var(--st-line-width) solid var(--st-color-line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--st-space-3);
    padding: 0 var(--st-space-5);
    flex-shrink: 0;
    background: var(--st-color-surface);
    z-index: 10;
}

.top-bar-left,
.top-bar-right {
    display: flex;
    align-items: center;
    gap: var(--st-space-3);
}

/* Page titles in the Stoei serif */
.page-title,
.top-bar h1 {
    font-size: var(--st-text-3);
    letter-spacing: var(--st-tracking-heading);
    line-height: var(--st-leading-tight);
}

/* Light/dark switch in every top bar */
.scout-theme-switch {
    color: var(--st-color-text-soft);
}
/* …and floating top-right on pages without a top bar (login, review) */
.scout-theme-float {
    position: fixed;
    top: max(var(--st-space-3), env(safe-area-inset-top));
    right: max(var(--st-space-3), env(safe-area-inset-right));
    z-index: 50;
}

.shop-count {
    font-size: var(--st-text-1);
    color: var(--st-color-text-faint);
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--st-space-1);
    color: var(--st-color-text-muted);
}
.mobile-menu-btn svg {
    width: 18px;
    height: 18px;
}

/* ─── Buttons: the kit's .st-btn (small ones: .st-btn--sm) ─────── */
.filter-trigger-btn svg {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}
.reset-btn {
    width: 100%;
}

.filter-count-badge {
    background: var(--st-color-accent-fill);
    color: var(--st-color-on-accent);
    border-radius: var(--st-radius-pill);
    padding: 0.05rem var(--st-space-2);
    font-size: var(--st-text-0);
    font-weight: 600;
    min-width: 16px;
    text-align: center;
}

/* ─── Active filter chips ──────────────────────────────────────── */
.active-filters-bar {
    display: flex;
    overflow-x: auto;
    gap: var(--st-space-1);
    padding: var(--st-space-2) var(--st-space-5);
    border-bottom: var(--st-line-width) solid var(--st-color-sunk);
    flex-shrink: 0;
    scrollbar-width: none;
    background: var(--st-color-bg);
}
.active-filters-bar::-webkit-scrollbar {
    display: none;
}

.filter-chip,
.filter-chip-clear-all {
    display: inline-flex;
    align-items: center;
    gap: var(--st-space-1);
    padding: 0.15rem var(--st-space-2);
    border-radius: var(--st-radius-1);
    font-size: var(--st-text-1);
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
}
.filter-chip {
    background: var(--st-color-accent-tint);
    color: var(--st-color-accent);
    border: var(--st-line-width) solid color-mix(in srgb, var(--st-color-accent-fill) 15%, transparent);
}
.filter-chip button {
    background: none;
    border: none;
    color: var(--st-color-accent);
    cursor: pointer;
    font-size: var(--st-text-2);
    font-weight: 600;
    line-height: 1;
    opacity: 0.6;
    padding: 0;
    transition: opacity var(--st-motion);
}
.filter-chip button:hover {
    opacity: 1;
}
.filter-chip-clear-all:hover {
    border-color: var(--st-color-accent-fill);
    color: var(--st-color-accent);
    background: var(--st-color-accent-tint);
}
.filter-chip-clear-all {
    background: none;
    border: var(--st-line-width) solid var(--st-color-line-strong);
    color: var(--st-color-text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: background var(--st-motion), border-color var(--st-motion), color var(--st-motion);
}

/* ─── Views ────────────────────────────────────────────────────── */
.view-map,
.view-table,
.view-about {
    display: none;
    flex: 1;
    overflow: hidden;
}
.view-map.active,
.view-table.active,
.view-about.active {
    display: flex;
    flex-direction: column;
}

.map-container {
    flex: 1;
    width: 100%;
}

.table-container {
    flex: 1;
    overflow: auto;
    padding: var(--st-space-5);
    background: var(--st-color-bg);
}

/* ─── Filter drawer ────────────────────────────────────────────── */
.filter-drawer-overlay,
.mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--st-color-backdrop);
}
.filter-drawer-overlay {
    z-index: 1999;
}
.filter-drawer-overlay.open,
.mobile-nav-overlay.open {
    display: block;
}

.filter-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: var(--st-color-surface);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--st-motion);
    box-shadow: var(--st-shadow-raised);
}
.filter-drawer.open {
    transform: translateX(0);
}

.filter-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--st-space-4) var(--st-space-5);
    border-bottom: var(--st-line-width) solid var(--st-color-line);
    flex-shrink: 0;
}
.filter-drawer-header h2 {
    font-size: var(--st-text-3);
    font-weight: 600;
}

.filter-drawer-close {
    background: none;
    border: none;
    color: var(--st-color-text-faint);
    font-size: var(--st-text-8);
    cursor: pointer;
    padding: var(--st-space-1);
    line-height: 1;
    transition: color var(--st-motion);
}
.filter-drawer-close:hover {
    color: var(--st-color-text-soft);
}

.filter-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--st-space-3);
    scrollbar-width: thin;
    scrollbar-color: var(--st-color-line) transparent;
}
.filter-search-wrap {
    padding: var(--st-space-3);
}

.filter-drawer-footer {
    padding: var(--st-space-4) var(--st-space-5);
    border-top: var(--st-line-width) solid var(--st-color-line);
    flex-shrink: 0;
}

/* ─── Search field ─────────────────────────────────────────────── */
#searchInput {
    width: 100%;
    padding: var(--st-space-2) var(--st-space-3);
    border: var(--st-line-width) solid var(--st-color-line);
    border-radius: var(--st-radius-control);
    font-family: inherit;
    font-size: var(--st-text-1);
    color: var(--st-color-text);
    background: var(--st-color-bg);
    outline: none;
    transition: border-color var(--st-motion), box-shadow var(--st-motion);
}
#searchInput::placeholder {
    color: var(--st-color-text-faint);
}
#searchInput:focus {
    border-color: var(--st-color-accent-fill);
    box-shadow: var(--st-ring-field);
    background: var(--st-color-surface);
}

/* ─── Accordion (filter groups) ────────────────────────────────── */
.accordion-item {
    border: var(--st-line-width) solid var(--st-color-line);
    border-radius: var(--st-radius-control);
    overflow: hidden;
    background: var(--st-color-surface);
    margin-bottom: var(--st-space-2);
}

.accordion-header {
    background: var(--st-color-surface);
    padding: var(--st-space-3);
    cursor: pointer;
    font-weight: 500;
    font-size: var(--st-text-1);
    color: var(--st-color-text-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: background var(--st-motion);
}
.accordion-header:hover {
    background: var(--st-color-bg);
}

.accordion-icon {
    font-size: var(--st-text-0);
    color: var(--st-color-text-faint);
    transition: transform var(--st-motion);
}
.accordion-item.open .accordion-icon {
    transform: rotate(180deg);
}

.accordion-content {
    padding: var(--st-space-3);
    border-top: var(--st-line-width) solid var(--st-color-sunk);
    display: none;
    background: var(--st-color-surface);
}
.accordion-item.open .accordion-content {
    display: block;
}

/* ─── Check box pills ──────────────────────────────────────────── */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--st-space-1);
}
.checkbox-group label {
    background: var(--st-color-bg);
    padding: var(--st-space-1) var(--st-space-3);
    border-radius: var(--st-radius-1);
    font-size: var(--st-text-1);
    display: inline-flex;
    align-items: center;
    gap: var(--st-space-1);
    cursor: pointer;
    color: var(--st-color-text-muted);
    border: var(--st-line-width) solid var(--st-color-line);
    transition: background var(--st-motion), border-color var(--st-motion), color var(--st-motion);
}
.checkbox-group label:hover,
.checkbox-label:hover {
    border-color: var(--st-color-line-strong);
    color: var(--st-color-text);
    background: var(--st-color-surface);
}
.checkbox-group label input[type="checkbox"] {
    display: none;
}
.checkbox-group label:has(input:checked),
.checkbox-label:has(input:checked) {
    background: var(--st-color-accent-tint);
    color: var(--st-color-accent);
    border-color: color-mix(in srgb, var(--st-color-accent-fill) 20%, transparent);
    font-weight: 500;
}

/* ─── Range sliders (noUiSlider) ───────────────────────────────── */
.slider-container {
    padding: var(--st-space-2) var(--st-space-1);
}
.slider-values {
    display: flex;
    justify-content: space-between;
    font-size: var(--st-text-1);
    color: var(--st-color-text-faint);
    margin-top: var(--st-space-2);
    font-variant-numeric: tabular-nums;
}
/* !important: these override the slider library's own stylesheet */
.noUi-handle {
    width: 14px !important;
    height: 14px !important;
    right: -7px !important;
    top: -5px !important;
    border-radius: 50% !important;
    background: var(--st-color-accent-fill) !important;
    border: 2px solid var(--st-color-surface) !important;
    box-shadow: var(--st-shadow-1) !important;
    cursor: pointer !important;
}
.noUi-handle::before,
.noUi-handle::after {
    display: none !important;
}
.noUi-connect {
    background: var(--st-color-accent-fill) !important;
}
.noUi-target {
    background: var(--st-color-line) !important;
    border: none !important;
    box-shadow: none !important;
    height: 2px !important;
    border-radius: 2px !important;
}

/* ─── Grid view (table) ────────────────────────────────────────── */
.export-wrapper {
    margin-bottom: var(--st-space-4);
    display: flex;
    justify-content: flex-end;
    gap: var(--st-space-2);
}

.table-scroll {
    overflow-x: auto;
}

/* Tables: the grid view and the admin shop database */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--st-text-1);
}
.data-table th {
    background: var(--st-color-bg);
    font-weight: 500;
    color: var(--st-color-text-muted);
    font-size: var(--st-text-1);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: var(--st-space-3) var(--st-space-4);
    text-align: left;
    border-bottom: var(--st-line-width) solid var(--st-color-line);
    position: sticky;
    top: 0;
    white-space: nowrap;
}
.data-table td {
    padding: var(--st-space-3) var(--st-space-4);
    text-align: left;
    border-bottom: var(--st-line-width) solid var(--st-color-sunk);
    color: var(--st-color-text-soft);
    vertical-align: top;
    line-height: 1.4;
}
.data-table tr:last-child td {
    border-bottom: none;
}
.data-table tr:hover td {
    background: var(--st-color-bg);
}
/* The grid view's table is its own box */
.table-container .data-table {
    min-width: 900px;
    background: var(--st-color-surface);
    border-radius: var(--st-radius-card);
    overflow: hidden;
    box-shadow: var(--st-shadow-1);
    border: var(--st-line-width) solid var(--st-color-line);
}

.data-table .cell-muted {
    color: var(--st-color-text-muted);
}
.cell-nowrap {
    white-space: nowrap;
}
.data-table .cell-pitch {
    max-width: 280px;
    color: var(--st-color-text-muted);
    font-style: italic;
    font-size: var(--st-text-1);
}
.table-empty {
    padding: var(--st-space-6);
    color: var(--st-color-text-muted);
    font-size: var(--st-text-3);
}

.contact-link,
.brands,
.data-table .brands {
    color: var(--st-color-info);
    font-weight: 500;
}
/* Shop names: plain strong text, also when they link to the website */
.data-table .shop-name {
    font-weight: 600;
    color: var(--st-color-text);
}
.contact-link-small {
    font-size: var(--st-text-1);
}
.na-text {
    color: var(--st-color-line-strong);
}

/* ─── Lead score badges (also on the admin pages) ──────────────── */
/* Markup: class="st-badge lead-badge st-badge--ok" (leadBadgeClass() in js/leadscore.js) */
.lead-badge {
    padding: 0.15rem var(--st-space-2);
    border-radius: var(--st-radius-1);
    font-size: var(--st-text-0);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ─── Map pins and clusters ────────────────────────────────────── */
.map-pin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--pin-color, var(--st-color-text-faint));
    border: 2px solid var(--st-color-surface);
    box-shadow: var(--st-shadow-1);
}
.map-pin.high {
    --pin-color: var(--st-color-ok-fill);
}
.map-pin.medium {
    --pin-color: var(--st-color-warn-fill);
}
.map-pin.low {
    --pin-color: var(--st-color-accent-fill);
}

.marker-cluster-small {
    --cluster-color: var(--st-color-accent-fill);
}
.marker-cluster-medium {
    --cluster-color: var(--st-color-warn-fill);
}
.marker-cluster-large {
    --cluster-color: var(--st-color-sidebar);
}
.marker-cluster {
    background-color: color-mix(in srgb, var(--cluster-color) 18%, transparent);
}
.marker-cluster div {
    background-color: var(--cluster-color);
    color: var(--st-color-on-accent);
    font-family: inherit;
    font-weight: 600;
    font-size: var(--st-text-1);
}

/* Leaflet popups and controls follow the theme */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip,
.leaflet-bar a {
    background: var(--st-color-surface);
    color: var(--st-color-text-soft);
}
.leaflet-container {
    background: var(--st-color-sunk);
    font-family: inherit;
}

/* Dark mode: dim the street map so it doesn't glare */
:root[data-theme="dark"] .leaflet-tile-pane {
    filter: var(--st-map-dim);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .leaflet-tile-pane {
        filter: var(--st-map-dim);
    }
}

/* ─── Shop details dialog ──────────────────────────────────────── */
#shop-modal {
    position: fixed;
    inset: 0;
    background: var(--st-color-backdrop);
    backdrop-filter: blur(3px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--st-space-4);
}
#shop-modal.active {
    display: flex;
}

#modal-content {
    background: var(--st-color-surface);
    border-radius: var(--st-radius-card);
    max-width: 440px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--st-shadow-dialog);
    border: var(--st-line-width) solid var(--st-color-line);
}

.modal-header {
    background: var(--st-color-sidebar);
    color: var(--st-color-on-sidebar-strong);
    padding: var(--st-space-5);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 {
    font-size: var(--st-text-7);
    color: var(--st-color-on-sidebar-strong);
}
.close-modal {
    cursor: pointer;
    font-size: var(--st-text-10);
    font-weight: 700;
    line-height: 1;
    color: var(--st-color-on-sidebar-muted);
}

.modal-body {
    padding: var(--st-space-5);
    color: var(--st-color-text-soft);
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}
.modal-score {
    margin-bottom: var(--st-space-4);
    display: flex;
    align-items: center;
    gap: var(--st-space-2);
}
.modal-score-note {
    font-size: var(--st-text-1);
    color: var(--st-color-text-muted);
}
.modal-row {
    margin-bottom: var(--st-space-3);
}
.modal-note {
    margin-top: var(--st-space-4);
    padding: var(--st-space-4);
    background: var(--st-color-bg);
    border-radius: var(--st-radius-2);
}
.modal-note.pitch {
    border-left: 3px solid var(--st-color-accent-fill);
}
.modal-note-label {
    font-size: var(--st-text-1);
    font-weight: 600;
    color: var(--st-color-text-faint);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--st-space-2);
}
.modal-note-text {
    font-style: italic;
    color: var(--st-color-text-soft);
    font-size: var(--st-text-2);
}
.modal-note:not(.pitch) .modal-note-text {
    color: var(--st-color-text-muted);
}

/* ─── Help & About ─────────────────────────────────────────────── */
.view-about {
    overflow-y: auto;
    background: var(--st-color-bg);
}

.about-content {
    max-width: 680px;
    margin: 0 auto;
    padding: var(--st-space-8) var(--st-space-7);
}

.about-header {
    display: flex;
    align-items: center;
    gap: var(--st-space-4);
    margin-bottom: var(--st-space-8);
    padding-bottom: var(--st-space-6);
    border-bottom: var(--st-line-width) solid var(--st-color-line);
}

.about-logo-mark,
.about-step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--st-color-accent-fill);
    color: var(--st-color-on-accent);
    font-weight: 700;
}
.about-logo-mark {
    width: 48px;
    height: 48px;
    border-radius: var(--st-radius-4);
    font-size: var(--st-text-8);
}

.about-title {
    font-size: var(--st-text-8);
    font-weight: 700;
    margin-bottom: var(--st-space-1);
}

.about-subtitle {
    font-size: var(--st-text-2);
    color: var(--st-color-text-muted);
}

.about-section {
    margin-bottom: var(--st-space-7);
}
.about-section h2 {
    font-size: var(--st-text-1);
    font-weight: 600;
    color: var(--st-color-text-faint);
    text-transform: uppercase;
    letter-spacing: var(--st-tracking-label);
    margin-bottom: var(--st-space-4);
}
.about-section p {
    font-size: var(--st-text-3);
    color: var(--st-color-text-muted);
    line-height: 1.6;
    margin-bottom: var(--st-space-3);
}
.about-section .about-teaser {
    font-weight: 600;
    color: var(--st-color-text-soft);
    font-style: italic;
}
.about-section .about-note {
    margin-top: var(--st-space-2);
    color: var(--st-color-text-faint);
    font-size: var(--st-text-1);
}


.about-steps {
    display: flex;
    flex-direction: column;
    gap: var(--st-space-4);
}
.about-step {
    display: flex;
    gap: var(--st-space-4);
    align-items: flex-start;
}
.about-step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: var(--st-text-1);
    margin-top: 0.1rem;
}
.about-step strong {
    display: block;
    font-size: var(--st-text-2);
    color: var(--st-color-text);
    margin-bottom: 0.2rem;
}
.about-section .about-step p {
    font-size: var(--st-text-1);
    margin: 0;
    line-height: 1.5;
}

.about-behind {
    background: var(--st-color-surface);
    border: var(--st-line-width) solid var(--st-color-line);
    border-left: 3px solid var(--st-color-accent-fill);
    border-radius: var(--st-radius-card);
    padding: var(--st-space-5) var(--st-space-6);
}

/* ─── Phones ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* The open menu and its dimmed backdrop sit above the map's zoom
       buttons (Leaflet controls use z-index 1000). Filters and dialogs
       (z-index 1999+) still sit above the menu. */
    .nav-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 1101;
        transform: translateX(-100%);
    }
    .nav-sidebar.open {
        transform: translateX(0);
    }
    .mobile-nav-overlay {
        z-index: 1100;
    }
    .mobile-menu-btn {
        display: flex;
    }

    .filter-drawer {
        width: 90%;
        max-width: 320px;
    }

    .data-table th,
    .data-table td {
        font-size: var(--st-text-1);
        padding: var(--st-space-2);
    }

    .about-content {
        padding: var(--st-space-6) var(--st-space-4);
    }
}
