/* ======================================================
   VARIABLES & THÈME autourdemoi.css
   ====================================================== */
:root {
    --primary:       #2563eb;
    --primary-dk:    #1d4ed8;
    --primary-lt:    #eff6ff;
    --accent:        #0ea5e9;
    --danger:        #ef4444;
    --success:       #22c55e;
    --warning:       #f59e0b;

    --bg-page:       #f1f5f9;
    --bg-card:       #ffffff;
    --bg-alt:        #f8fafc;
    --bg-input:      #ffffff;

    --txt:           #0f172a;
    --txt-2:         #475569;
    --txt-3:         #94a3b8;

    --border:        #e2e8f0;
    --border-2:      #cbd5e1;

    --shadow-sm:     0 1px 3px rgba(15,23,42,.07);
    --shadow-md:     0 4px 16px rgba(15,23,42,.09);
    --shadow-lg:     0 12px 40px rgba(15,23,42,.13);

    --r-sm: 6px;  --r-md: 10px;  --r-lg: 16px;  --r-xl: 24px;  --r-full: 9999px;
    --ease: cubic-bezier(.4,0,.2,1);
    --tr: all 0.2s var(--ease);

    --sidebar-w:     340px;
    --topbar-h:      60px;
    --font:          'Inter', system-ui, -apple-system, sans-serif;
}

body.dark-mode {
    --primary:       #60a5fa;
    --primary-dk:    #3b82f6;
    --primary-lt:    #1e3a5f;
    --accent:        #38bdf8;
    --danger:        #f87171;
    --success:       #4ade80;
    --warning:       #fbbf24;

    --bg-page:       #0f172a;
    --bg-card:       #1e293b;
    --bg-alt:        #162032;
    --bg-input:      #1e293b;

    --txt:           #f1f5f9;
    --txt-2:         #94a3b8;
    --txt-3:         #475569;

    --border:        #334155;
    --border-2:      #475569;

    --shadow-sm:     0 1px 3px rgba(0,0,0,.3);
    --shadow-md:     0 4px 16px rgba(0,0,0,.4);
    --shadow-lg:     0 12px 40px rgba(0,0,0,.55);
}

/* ======================================================
   RESET
   ====================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg-page);
    color: var(--txt);
    transition: background .3s, color .3s;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: var(--font); cursor: pointer; }

/* ======================================================
   LAYOUT PRINCIPAL — Sidebar + Carte
   ====================================================== */
.app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh; /* dynamic viewport height pour iOS */
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    z-index: 300;
    transition: transform .3s var(--ease), background .3s;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.sidebar-title h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--txt);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-title h1 i { color: var(--primary); font-size: 18px; }

/* Barre de recherche */
.search-bar {
    position: relative;
    margin-bottom: 10px;
}

.search-bar i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--txt-3);
    font-size: 14px;
    pointer-events: none;
}

.search-bar input {
    width: 100%;
    padding: 8px 10px 8px 32px;
    font-size: 13px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    color: var(--txt);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.search-bar input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.search-bar input::placeholder { color: var(--txt-3); }

/* Filtres */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Slider distance */
.distance-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.distance-row label {
    font-size: 12px;
    font-weight: 600;
    color: var(--txt-2);
    white-space: nowrap;
    min-width: 60px;
}

.distance-row input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
    height: 4px;
    cursor: pointer;
}

.distance-val {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    min-width: 40px;
    text-align: right;
}

/* Stats bar */
.stats-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.stats-count {
    font-size: 12px;
    color: var(--txt-2);
    font-weight: 500;
}

.stats-count strong { color: var(--primary); font-weight: 700; }

/* Tabs commerces / coups de cœur */
.tab-row {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 10px 8px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 12px;
    font-weight: 600;
    color: var(--txt-3);
    transition: var(--tr);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn i { font-size: 13px; }

/* Liste des commerces */
.commerce-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px;
}

/* Scrollbar fine */
.commerce-list::-webkit-scrollbar { width: 4px; }
.commerce-list::-webkit-scrollbar-track { background: transparent; }
.commerce-list::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }

/* Carte commerce */
.commerce-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--tr);
    margin-bottom: 4px;
}

.commerce-card:hover {
    background: var(--bg-alt);
    border-color: var(--border);
}

.commerce-card.active {
    background: var(--primary-lt);
    border-color: var(--primary);
}

.commerce-avatar {
    width: 46px;
    height: 46px;
    border-radius: var(--r-sm);
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-alt);
}

.commerce-avatar-fallback {
    width: 46px;
    height: 46px;
    border-radius: var(--r-sm);
    background: var(--primary-lt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    color: var(--primary);
}

.commerce-info { flex: 1; min-width: 0; }

.commerce-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--txt);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.commerce-meta {
    font-size: 11px;
    color: var(--txt-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.commerce-dist {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
    text-align: right;
}

.badge-coeur {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    background: #fef2f2;
    color: #991b1b;
    border-radius: var(--r-full);
    font-size: 10px;
    font-weight: 700;
}

body.dark-mode .badge-coeur {
    background: #450a0a;
    color: #fca5a5;
}

/* Message vide */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
    color: var(--txt-3);
    text-align: center;
    gap: 8px;
}

.empty-state i { font-size: 32px; }
.empty-state p { font-size: 13px; margin: 0; }

/* Chip filtre catégorie */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    font-size: 11px;
    font-weight: 600;
    color: var(--txt-2);
    background: var(--bg-card);
    cursor: pointer;
    transition: var(--tr);
    white-space: nowrap;
}

.chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-lt); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ======================================================
   ZONE CARTE
   ====================================================== */
.map-zone {
    flex: 1;
    position: relative;
    overflow: hidden;
}

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

/* Contrôles flottants sur la carte */
.map-controls {
    position: absolute;
    top: 14px;
    right: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 500;
}

.map-btn {
    width: 38px;
    height: 38px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    color: var(--txt-2);
    transition: var(--tr);
    box-shadow: var(--shadow-sm);
}

.map-btn:hover { background: var(--bg-alt); color: var(--primary); border-color: var(--primary); }
.map-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Bouton localisation flottant en bas */
.locate-btn {
    position: absolute;
    bottom: 24px;
    right: 14px;
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--r-full);
    font-size: 13px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transition: var(--tr);
}

.locate-btn:hover { background: var(--primary-dk); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.locate-btn i { font-size: 15px; }

/* Popup Leaflet customisé */
.leaflet-popup-content-wrapper {
    background: var(--bg-card) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--r-md) !important;
    box-shadow: var(--shadow-lg) !important;
    padding: 0 !important;
}

.leaflet-popup-content { margin: 0 !important; }
.leaflet-popup-tip { background: var(--bg-card) !important; }

.popup-inner {
    padding: 14px 16px;
    min-width: 200px;
}

.popup-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--txt);
    margin-bottom: 6px;
}

.popup-meta {
    font-size: 12px;
    color: var(--txt-2);
    margin-bottom: 2px;
    display: flex;
    align-items: flex-start;
    gap: 5px;
}

.popup-meta i { color: var(--txt-3); flex-shrink: 0; margin-top: 2px; }

.popup-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.popup-btn {
    flex: 1;
    padding: 6px 10px;
    border-radius: var(--r-sm);
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    transition: var(--tr);
}

.popup-btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
}

.popup-btn-primary:hover { background: var(--primary-dk); }

.popup-btn-secondary {
    background: var(--bg-alt);
    color: var(--txt-2);
    border: 1px solid var(--border);
}

.popup-btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

/* Marker icône commerces */
.custom-marker {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
    overflow: hidden;
    background: var(--bg-alt);
}

.custom-marker img { width: 100%; height: 100%; object-fit: cover; }

/* ======================================================
   TOPBAR MOBILE
   ====================================================== */
.mobile-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: var(--topbar-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 600;
}

.mobile-topbar h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--txt);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mobile-topbar h1 i { color: var(--primary); }

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: var(--txt-2);
    transition: var(--tr);
}

.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.icon-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Bouton mode sombre fixe */
.theme-toggle {
    position: fixed;
    bottom: 24px;
    left: 16px;
    z-index: 600;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: var(--tr);
}

.theme-toggle:hover { transform: rotate(20deg) scale(1.1); }

/* ======================================================
   PANNEAU DÉTAIL (slide-over mobile)
   ====================================================== */
.detail-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 450;
    transform: translateY(100%);
    transition: transform .3s var(--ease);
    padding: 16px;
    max-height: 60%;
    overflow-y: auto;
}

.detail-panel.open { transform: translateY(0); }

.panel-handle {
    width: 36px;
    height: 4px;
    background: var(--border-2);
    border-radius: 2px;
    margin: 0 auto 14px;
}

.panel-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 28px;
    height: 28px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--txt-2);
    cursor: pointer;
}

/* ======================================================
   OVERLAY + DRAWER SIDEBAR MOBILE
   ====================================================== */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 290;
    backdrop-filter: blur(2px);
}

.overlay.show { display: block; }

/* ======================================================
   ÉVÉNEMENTS — styles
   ====================================================== */
.event-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--tr);
    margin-bottom: 4px;
}
.event-card:hover { background: var(--bg-alt); border-color: var(--border); }
.event-card.active { background: #fef3c7; border-color: var(--warning); }
body.dark-mode .event-card.active { background: #44310a; border-color: var(--warning); }

.event-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--r-sm);
    background: #fef3c7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    color: #92400e;
}
body.dark-mode .event-icon { background: #44310a; color: #fbbf24; }

.event-date-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    background: #fef3c7;
    color: #92400e;
    border-radius: var(--r-full);
    font-size: 10px;
    font-weight: 700;
    margin-top: 3px;
}
body.dark-mode .event-date-badge { background: #44310a; color: #fbbf24; }

.badge-today {
    background: #dcfce7;
    color: #166534;
}
body.dark-mode .badge-today { background: #14532d; color: #4ade80; }

/* Marker événement */
.event-marker {
    width: 36px;
    height: 36px;
    background: var(--warning);
    border: 3px solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
    position: relative;
}
.event-marker::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--warning);
}

/* ======================================================
   RESPONSIVE MOBILE (portrait prioritaire)
   ====================================================== */
@media (max-width: 768px) {
    /* On autorise le scroll uniquement dans les zones prévues */
    html, body { overflow: hidden; height: 100%; }

    .mobile-topbar { display: flex; }

    /* La carte occupe TOUT l'espace sous la topbar */
    .app-shell {
        display: block;           /* pas de flex : la carte est absolute */
        position: relative;
        height: calc(100dvh - var(--topbar-h));
        margin-top: var(--topbar-h);
        overflow: hidden;
    }

    /* Carte plein écran */
    .map-zone {
        position: absolute;
        inset: 0;
        height: 100%;
        width: 100%;
    }

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

    /* Sidebar : drawer latéral par-dessus la carte */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(88vw, 320px);
        z-index: 550;
        transform: translateX(-110%);
        padding-top: var(--topbar-h);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }

    /* Contrôles remontés pour ne pas gêner le bottom sheet */
    .map-controls { top: 10px; right: 10px; }

    /* Bouton "Ma position" : au-dessus du bottom sheet */
    .locate-btn {
        bottom: 16px;
        right: 12px;
        padding: 9px 14px;
        font-size: 12px;
    }

    /* Thème : en bas à gauche, au-dessus du bottom sheet */
    .theme-toggle {
        bottom: 16px;
        left: 12px;
        width: 38px;
        height: 38px;
    }
}

/* Orientation paysage mobile : sidebar + carte côte à côte */
@media (max-width: 768px) and (orientation: landscape) {
    .app-shell {
        display: flex;
        flex-direction: row;
        height: calc(100dvh - var(--topbar-h));
        margin-top: var(--topbar-h);
        overflow: hidden;
    }
    .sidebar {
        position: relative;
        transform: none;
        width: 260px;
        flex-shrink: 0;
        padding-top: 0;
    }
    .sidebar.open { transform: none; }
    .map-zone { flex: 1; position: relative; height: 100%; }
}

/* ======================================================
   TABLETTE (768–1024px)
   ====================================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-w: 280px; }
}

/* ======================================================
   GRAND ÉCRAN (≥1400px) — sidebar → barre horizontale
   La liste verticale latérale laisse place à une barre
   compacte en haut, la carte récupère tout le reste.
   ====================================================== */
@media (min-width: 1400px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 14px;
        border-bottom: none;
        flex: 0 1 auto;
    }

    /* Le gros titre "Commerces" prend trop de place à l'horizontale */
    .sidebar-title { display: none; }

    .search-bar { width: 220px; margin-bottom: 0; }

    .field-group { padding: 0; margin: 0; min-width: 170px; }
    .field-label { display: none; }

    .distance-row {
        border-bottom: none;
        padding: 10px 14px;
        flex: 0 0 auto;
        width: auto;
        min-width: 220px;
    }
    .distance-row label { min-width: auto; }

    .stats-bar {
        border-bottom: none;
        background: none;
        padding: 10px 14px;
        flex: 0 0 auto;
    }

    .tab-row {
        border-bottom: none;
        flex: 1 1 auto;
        justify-content: flex-end;
    }
    .tab-btn { flex: 0 0 auto; padding: 10px 14px; }

    /* La liste passe en scroll horizontal, sous la barre */
    .commerce-list {
        flex: 0 0 100%;
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 8px;
        padding: 8px 14px 12px;
        max-height: 146px;
    }
    .commerce-list::-webkit-scrollbar { height: 4px; width: auto; }

    .commerce-card, .event-card, .produit-card {
        flex: 0 0 230px;
        margin-bottom: 0;
    }

    .empty-state { flex: 0 0 100%; padding: 16px; }

    .map-zone { flex: 1 1 auto; }
}

/* ======================================================
   ACCESSIBILITY
   ====================================================== */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

@media (hover: none) {
    .commerce-card:hover { background: none; border-color: transparent; }
}

/* Loader géolocalisation */
.geo-loader {
    position: absolute;
    inset: 0;
    background: var(--bg-card);
    z-index: 900;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.geo-loader i { font-size: 36px; color: var(--primary); animation: pulse 1.2s ease-in-out infinite; }
.geo-loader p { font-size: 14px; color: var(--txt-2); margin: 0; }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: .5; transform: scale(.9); }
}

@keyframes userPulse {
    0%, 100% { transform: scale(1); opacity: .6; }
    50% { transform: scale(2.2); opacity: 0; }
}

/* Cercle rayon sur la carte */
.leaflet-interactive.radius-circle {
    stroke: var(--primary);
    fill: var(--primary);
    fill-opacity: .05;
    stroke-width: 1.5;
    stroke-dasharray: 6 4;
}
