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

/* =========================================================================
   TOKENS
   ========================================================================= */
:root {
    --primary: #01b8c6;
    --primary-dark: #018c97;
    --primary-soft: rgba(1, 184, 198, 0.12);
    --primary-soft-strong: rgba(1, 184, 198, 0.22);
    --amber: #f59e0b;
    --bg: #f2f6f7;
    --card-bg: #ffffff;
    --text: #0f2229;
    --text-soft: #4c6169;
    --muted: #8aa0a8;
    --border: rgba(15, 34, 41, 0.09);
    --border-strong: rgba(15, 34, 41, 0.16);
    --radius-lg: 22px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 2px 8px rgba(15, 34, 41, 0.06);
    --shadow-md: 0 10px 28px rgba(15, 34, 41, 0.12);
    --shadow-lg: 0 -14px 40px rgba(15, 34, 41, 0.20);
}

* { box-sizing: border-box; }

/* Author rules below set explicit `display` on several of these elements for
   their visible state; without !important here the [hidden] UA rule loses
   the cascade (equal specificity, author beats UA) and the element stays
   visible. This keeps the plain `hidden` attribute/property reliable everywhere. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

button, input { font-family: inherit; }
button { -webkit-appearance: none; appearance: none; }
svg { display: block; fill: currentColor; }

#app {
    position: fixed;
    inset: 0;
    height: 100dvh;
    overflow: hidden;
}

/* =========================================================================
   MAP — one shared instance, repositioned per breakpoint
   ========================================================================= */
#map {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: #dbe6e8;
}

.leaflet-popup-content-wrapper { border-radius: var(--radius-md); box-shadow: var(--shadow-md); }
.leaflet-popup-content { margin: 14px 16px; font-family: 'Inter', sans-serif; }
.store-map-popup-brand { font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--primary-dark); }
.store-map-popup-name { font-size: .92rem; font-weight: 700; color: var(--text); margin-top: 2px; }
.store-map-popup-address { font-size: .78rem; color: var(--text-soft); margin-top: 4px; line-height: 1.4; }
.store-map-popup-links { display: flex; gap: 14px; margin-top: 8px; }
.store-map-popup-link { display: inline-block; font-size: .78rem; font-weight: 700; color: var(--primary-dark); text-decoration: none; }
.marker-cluster-custom { background: transparent; }
.marker-cluster-custom div {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: .8rem;
    box-shadow: 0 0 0 6px rgba(1,184,198,0.25), var(--shadow-sm);
}

/* =========================================================================
   SHARED — chips, badges, cards used inside both desktop & mobile lists
   ========================================================================= */
.region-chip {
    flex-shrink: 0;
    padding: 7px 14px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-soft);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
}
.region-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.stat-line { font-size: .74rem; color: var(--muted); font-weight: 600; }

.store-group, .store-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color .15s, box-shadow .15s, background .4s;
}
.store-group.highlight, .store-card.highlight { background: var(--primary-soft); border-color: var(--primary); }

.store-group-head, .store-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    color: inherit;
}
.store-group-head { align-items: center; }
.store-card:hover, .store-group-head:hover { background: var(--bg); }

.brand-dot {
    width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0; margin-top: 3px;
    box-shadow: 0 0 0 4px var(--dot-ring, rgba(0,0,0,0.08));
}
.store-group-head .brand-dot { margin-top: 0; }

.store-card-body, .store-group-name-wrap { flex: 1; min-width: 0; }

.store-name-row { display: flex; align-items: center; gap: 6px; }
.store-name {
    font-weight: 700; font-size: .87rem; line-height: 1.5; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bike-badge { font-size: .82rem; line-height: 1; flex-shrink: 0; }
.store-address { font-size: .75rem; color: var(--muted); margin-top: 3px; line-height: 1.35; }

.store-group-count {
    flex-shrink: 0; font-size: .7rem; font-weight: 700; color: var(--primary-dark);
    background: var(--primary-soft); padding: 3px 9px; border-radius: 999px;
}
.store-group-caret { width: 15px; height: 15px; color: var(--muted); flex-shrink: 0; transition: transform .2s; }
.store-group.open .store-group-caret { transform: rotate(180deg); }
.store-card-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.store-link-btn { flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); background: transparent; }
.store-link-btn:hover { background: var(--primary-soft); color: var(--primary-dark); }
.store-link-btn svg { width: 13px; height: 13px; }
.store-directions-btn:hover { background: var(--primary-soft); color: var(--primary-dark); }

.store-group-locations-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .28s ease; }
.store-group.open .store-group-locations-wrap { grid-template-rows: 1fr; }
.store-group-locations { overflow: hidden; }
.store-loc-row {
    display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: none; font: inherit; color: inherit;
    background: transparent; cursor: pointer;
    padding: 10px 10px 10px 35px; border-top: 1px solid var(--border);
}
.store-loc-row:hover { background: var(--bg); }
.store-loc-row.highlight { background: var(--primary-soft); }
.loc-row-body { flex: 1; min-width: 0; }
.loc-name { font-weight: 600; font-size: .8rem; line-height: 1.5; color: var(--text); }
.loc-address { font-size: .73rem; color: var(--muted); margin-top: 2px; }

.online-card {
    display: flex; flex-direction: column; gap: 4px;
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: 14px; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s;
}
.online-card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.online-card-name { font-weight: 700; font-size: .85rem; color: var(--text); display: flex; align-items: center; gap: 6px; }
.online-card-note { font-size: .75rem; color: var(--muted); line-height: 1.4; }
.online-card-globe { color: var(--primary); }

.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); font-size: .85rem; font-weight: 500; }

/* =========================================================================
   DESKTOP GUI  (>= 900px)
   ========================================================================= */
.m-header, .m-fab, .m-sheet, .m-back-chip { display: none; }

@media (min-width: 900px) {
    #map { top: 64px; left: 400px; right: 0; bottom: 0; }

    .d-topbar {
        position: fixed; top: 0; left: 0; right: 0; height: 64px; z-index: 20;
        display: flex; align-items: center; gap: 20px; padding: 0 22px;
        background: rgba(255,255,255,0.92); backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
    }
    .d-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
    .d-brand img { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }
    .d-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
    .d-brand-title { font-weight: 800; font-size: 1.02rem; letter-spacing: -.01em; }
    .d-brand-sub { font-size: .74rem; color: var(--muted); font-weight: 600; }

    .d-search {
        flex: 1; max-width: 440px; height: 40px; border-radius: 999px;
        background: var(--bg); border: 1px solid var(--border);
        display: flex; align-items: center; gap: 9px; padding: 0 15px;
    }
    .d-search:focus-within { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
    .icon-search { width: 17px; height: 17px; color: var(--muted); flex-shrink: 0; }
    #d-search-input { flex: 1; border: none; background: transparent; outline: none; font-size: .88rem; color: var(--text); }

    .d-reset-btn {
        margin-left: auto; flex-shrink: 0; padding: 9px 18px; border-radius: 999px;
        border: 1px solid var(--border); background: #fff; color: var(--primary-dark);
        font-weight: 700; font-size: .8rem; cursor: pointer; transition: background .15s;
    }
    .d-reset-btn:hover { background: var(--primary-soft); }

    .d-sidebar {
        position: fixed; top: 64px; left: 0; bottom: 0; width: 400px; z-index: 15;
        background: var(--card-bg); border-right: 1px solid var(--border);
        display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow-md);
    }

    .d-chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 16px 16px 4px; flex-shrink: 0; scrollbar-width: thin; }
    .d-chip-row::-webkit-scrollbar { height: 5px; }
    .d-chip-row::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

    .d-tabs { display: flex; gap: 6px; padding: 12px 16px; flex-shrink: 0; }
    .d-tab {
        flex: 1; padding: 9px 0; border-radius: 10px; border: none; background: var(--bg);
        color: var(--text-soft); font-weight: 700; font-size: .8rem; cursor: pointer; transition: background .15s, color .15s;
    }
    .d-tab.active { background: var(--primary-soft); color: var(--primary-dark); }

    .d-list { flex: 1; overflow-y: auto; padding: 2px 14px 24px; display: flex; flex-direction: column; gap: 8px; }
    .d-online-grid { flex: 1; overflow-y: auto; padding: 2px 14px 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
}

/* =========================================================================
   MOBILE GUI  (< 900px) — full-bleed map, draggable bottom sheet
   ========================================================================= */
@media (max-width: 899px) {
    .d-topbar, .d-sidebar { display: none; }
    #map { inset: 0; }

    .m-header {
        display: block; position: fixed; top: 0; left: 0; right: 0; z-index: 30;
        background: rgba(255,255,255,0.88); backdrop-filter: blur(12px);
        border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
        padding-top: env(safe-area-inset-top);
    }
    .m-header-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; }
    .m-logo { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; }
    .m-title { flex: 1; font-weight: 800; font-size: .98rem; letter-spacing: -.01em; }
    .m-search-toggle {
        width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--bg);
        color: var(--text-soft); display: flex; align-items: center; justify-content: center;
    }
    .m-search-toggle svg { width: 17px; height: 17px; }
    .m-search-toggle.active { background: var(--primary); color: #fff; }

    .m-search-row { padding: 0 16px 12px; }
    #m-search-input {
        width: 100%; height: 40px; border-radius: 999px; border: 1px solid var(--border);
        background: var(--bg); padding: 0 16px; font-size: .88rem; outline: none; color: var(--text);
    }
    #m-search-input:focus { border-color: var(--primary); background: #fff; }

    .m-chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 12px; -webkit-overflow-scrolling: touch; }
    .m-chip-row::-webkit-scrollbar { display: none; }

    .m-fab {
        position: fixed; right: 16px; bottom: 154px; z-index: 45;
        width: 48px; height: 48px; border-radius: 50%; border: none;
        background: #fff; color: var(--primary-dark); box-shadow: var(--shadow-md);
        display: flex; align-items: center; justify-content: center;
        transition: bottom .32s cubic-bezier(.22,1,.36,1), opacity .2s, transform .15s;
    }
    .m-fab:active { transform: scale(0.92); }
    .m-fab svg { width: 22px; height: 22px; }
    .m-fab.is-hidden { opacity: 0; pointer-events: none; }

    .m-back-chip {
        display: flex; align-items: center; gap: 6px;
        position: fixed; left: 50%; z-index: 44; transform: translateX(-50%);
        background: rgba(15,34,41,0.88); color: #fff; border: none;
        padding: 9px 16px 9px 12px; border-radius: 999px; font-weight: 700; font-size: .8rem;
        box-shadow: var(--shadow-md); backdrop-filter: blur(6px);
        transition: bottom .32s cubic-bezier(.22,1,.36,1);
    }
    .m-back-chip svg { width: 15px; height: 15px; }

    .m-sheet {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
        height: 86vh; height: 86dvh;
        background: var(--card-bg);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: var(--shadow-lg);
        display: flex; flex-direction: column; overflow: hidden;
        touch-action: none;
        transition: transform .32s cubic-bezier(.22,1,.36,1);
        transform: translateY(46%);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .m-sheet[data-state="peek"] { transform: translateY(calc(100% - 138px)); }
    .m-sheet[data-state="half"] { transform: translateY(46%); }
    .m-sheet[data-state="full"] { transform: translateY(0%); }
    .m-sheet.dragging { transition: none; }

    .m-sheet-drag { flex-shrink: 0; cursor: grab; }
    .m-sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: var(--border-strong); margin: 10px auto 8px; }
    .m-sheet-stat { text-align: center; font-size: .78rem; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
    .m-tabs { display: flex; gap: 6px; padding: 0 16px 12px; }
    .m-tab {
        flex: 1; padding: 9px 0; border-radius: 10px; border: none; background: var(--bg);
        color: var(--text-soft); font-weight: 700; font-size: .8rem; cursor: pointer;
    }
    .m-tab.active { background: var(--primary-soft); color: var(--primary-dark); }

    .m-sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 32px; }
    .m-list { display: flex; flex-direction: column; gap: 8px; }
    .m-online-grid { display: flex; flex-direction: column; gap: 8px; }
}

@media (max-width: 420px) {
    .d-online-grid { grid-template-columns: 1fr; }
}
