/* ─── Design Tokens ─── */
:root {
    --green-900: #1a4d24;
    --green-700: #2d7a3a;
    --green-600: #35903f;
    --green-500: #43a84d;
    --green-100: #e8f5e9;
    --green-50: #f1f9f2;

    --lime: #7ab648;
    --amber: #e8a838;
    --red: #e53935;

    --ink: #1a1f16;
    --ink-secondary: #4a5240;
    --ink-muted: #7a8570;
    --ink-faint: #a3b094;

    --surface: #fafcf8;
    --surface-raised: #ffffff;
    --surface-sunken: #f0f3ec;
    --border: #dfe5d8;
    --border-light: #ecf0e6;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(26, 77, 36, .06);
    --shadow-md: 0 4px 16px rgba(26, 77, 36, .08);
    --shadow-lg: 0 8px 32px rgba(26, 77, 36, .1);
    --shadow-glow: 0 0 0 3px rgba(45, 122, 58, .12);

    --font-display: 'Fraunces', Georgia, serif;
    --font-body: 'DM Sans', system-ui, sans-serif;

    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Reset & Base ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    font-family: var(--font-body);
    height: 100vh;
    overflow: hidden;
    color: var(--ink);
    background: var(--surface);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── App Layout ─── */
.app-layout {
    display: flex;
    height: 100vh;
}

#map {
    flex: 1;
    min-width: 0;
    position: relative;
}

.side-panel {
    width: 420px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
    position: relative;
}

/* ─── Panel Header ─── */
.panel-header {
    padding: 22px 24px 18px;
    background: linear-gradient(135deg, var(--green-900) 0%, var(--green-700) 100%);
    border-bottom: none;
    position: relative;
}

.panel-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--lime), var(--amber), var(--red));
}

.panel-header h1 {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
    margin-bottom: 3px;
    font-optical-sizing: auto;
}

.panel-header p {
    font-size: 12.5px;
    color: rgba(255, 255, 255, .7);
    letter-spacing: 0.01em;
}

/* ─── Search ─── */
.search-container {
    padding: 14px 24px;
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border);
    position: relative;
}

.search-input-wrap {
    position: relative;
}

#search-input {
    width: 100%;
    padding: 11px 40px 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--ink);
    background: var(--surface);
    outline: none;
    transition: border-color .2s var(--ease-out), box-shadow .2s var(--ease-out), background .2s;
}

#search-input::placeholder {
    color: var(--ink-faint);
}

#search-input:focus {
    border-color: var(--green-600);
    box-shadow: var(--shadow-glow);
    background: var(--surface-raised);
}

.search-spinner {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}

.spinner-icon {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--green-700);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ─── Results Dropdown ─── */
#results-list {
    display: none;
    position: absolute;
    left: 24px;
    right: 24px;
    top: 100%;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    animation: dropdownIn .2s var(--ease-out);
}

#results-list.visible { display: block; }

@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

#results-list::-webkit-scrollbar { width: 6px; }
#results-list::-webkit-scrollbar-track { background: transparent; }
#results-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.result-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: background .15s, transform .1s;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.result-item:hover {
    background: var(--green-50);
}

.result-item.selected {
    background: var(--green-100);
}

.result-item:active {
    transform: scale(0.995);
}

.result-item:last-child { border-bottom: none; }

.result-name {
    font-weight: 600;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
}

.result-address {
    font-size: 12px;
    color: var(--ink-muted);
    margin-top: 3px;
    padding-left: 20px;
}

.result-activity {
    font-size: 11.5px;
    color: var(--ink-faint);
    margin-top: 1px;
    padding-left: 20px;
}

.result-badge {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .8);
}

.no-result {
    color: var(--ink-faint);
    cursor: default;
    text-align: center;
    font-size: 13px;
    padding: 20px 16px;
}

.error-result {
    color: var(--red);
    cursor: default;
    text-align: center;
    font-size: 13px;
    padding: 20px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #fef2f2;
}

.error-result svg {
    flex-shrink: 0;
    stroke: var(--red);
}

/* ─── Filters ─── */
.filters-bar {
    padding: 12px 0 12px 24px;
    background: var(--surface-raised);
    border-bottom: 1px solid var(--border);
    overflow: visible;
}

.filters-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 24px;
}

.filter-badges {
    flex-wrap: wrap;
    padding-right: 24px;
}

.filter-badges::-webkit-scrollbar { display: none; }

.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface-raised);
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 500;
    color: var(--ink-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all .2s var(--ease-out);
    min-height: 34px;
}

.filter-badge:hover {
    border-color: var(--ink-faint);
    background: var(--surface-sunken);
}

.filter-badge.active {
    border-color: var(--green-700);
    background: var(--green-50);
    color: var(--green-900);
    box-shadow: 0 0 0 1px var(--green-700);
}

.filter-badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.filter-badge-label {
    line-height: 1;
}

.activity-select {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-raised);
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
    outline: none;
    transition: border-color .2s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237a8570' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.activity-select:focus {
    border-color: var(--green-600);
    box-shadow: var(--shadow-glow);
}

/* ─── Sanitary Badges ─── */
.badge-1, .result-badge.badge-1, .filter-badge-dot.badge-1 { background: var(--green-700); }
.badge-2, .result-badge.badge-2, .filter-badge-dot.badge-2 { background: var(--lime); }
.badge-3, .result-badge.badge-3, .filter-badge-dot.badge-3 { background: var(--amber); }
.badge-4, .result-badge.badge-4, .filter-badge-dot.badge-4 { background: var(--red); }

/* ─── Detail Panel ─── */
#detail-panel {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: none;
    animation: detailSlideIn .35s var(--ease-out);
}

#detail-panel.visible { display: block; }

@keyframes detailSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

#detail-panel::-webkit-scrollbar { width: 6px; }
#detail-panel::-webkit-scrollbar-track { background: transparent; }
#detail-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.detail-close {
    float: right;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-sunken);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 20px;
    cursor: pointer;
    color: var(--ink-muted);
    line-height: 1;
    transition: all .15s;
}

.detail-close:hover {
    background: var(--border);
    color: var(--ink);
}

.detail-name {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 4px;
    padding-right: 40px;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.detail-enseigne {
    font-size: 13px;
    color: var(--ink-muted);
    margin-bottom: 14px;
    font-style: italic;
}

.detail-sanit {
    margin: 14px 0 20px;
}

.sanit-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.sanit-smiley { font-size: 18px; }

.detail-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.detail-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.detail-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-faint);
    margin-bottom: 4px;
}

.detail-section > div:not(.detail-label):not(.detail-approx) {
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink-secondary);
}

.detail-approx {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--ink-faint);
    font-style: italic;
}

/* ─── Panel Hint (Empty State) ─── */
.panel-hint {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    transition: opacity .3s var(--ease-out);
}

.hint-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.hint-icon {
    stroke: var(--border);
    opacity: .6;
}

.hint-content p {
    color: var(--ink-faint);
    font-size: 13.5px;
    line-height: 1.6;
}

#detail-panel.visible ~ #panel-hint { display: none; }

/* ─── Map Overlays ─── */
.marker-icon { background: none !important; border: none !important; }

.map-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(250, 252, 248, .4);
    backdrop-filter: blur(1px);
    pointer-events: none;
}

.map-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--green-700);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    background: var(--surface-raised);
    box-shadow: var(--shadow-md);
}

.zoom-message {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 800;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-secondary);
    box-shadow: var(--shadow-md);
    pointer-events: none;
    animation: floatIn .3s var(--ease-out);
}

.zoom-message svg {
    stroke: var(--green-700);
    flex-shrink: 0;
}

@keyframes floatIn {
    from { opacity: 0; transform: translateX(-50%) translateY(8px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.geolocate-btn {
    position: absolute;
    top: 80px;
    right: 10px;
    z-index: 800;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-raised);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--ink-secondary);
    box-shadow: var(--shadow-sm);
    transition: all .2s;
}

.geolocate-btn:hover {
    background: var(--green-50);
    border-color: var(--green-700);
    color: var(--green-700);
}

.geolocate-btn svg {
    stroke: currentColor;
}

.geolocate-btn.loading svg {
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}

/* ─── Mobile Toggle Button ─── */
.toggle-view-btn {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1100;
    padding: 12px 28px;
    background: var(--green-700);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: background .2s, transform .1s;
    min-height: 48px;
}

.toggle-view-btn:hover {
    background: var(--green-600);
}

.toggle-view-btn:active {
    transform: translateX(-50%) scale(0.96);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .app-layout {
        flex-direction: column-reverse;
    }

    .side-panel {
        width: 100%;
        height: 45vh;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    #map {
        height: 55vh;
    }

    body.mobile-map-view .side-panel {
        display: none;
    }

    body.mobile-map-view #map {
        height: 100vh;
    }

    #results-list {
        max-height: 50vh;
    }

    .filter-badges {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .panel-header {
        padding: 14px 20px 12px;
    }

    .panel-header h1 {
        font-size: 18px;
    }

    .search-container {
        padding: 10px 20px;
    }

    .filters-bar {
        padding: 10px 20px;
    }

    #detail-panel {
        padding: 20px;
    }

    .toggle-view-btn {
        bottom: 16px;
    }

    .result-item {
        padding: 14px 16px;
        min-height: 48px;
    }

    .filter-badge {
        min-height: 40px;
        padding: 8px 14px;
    }

    .detail-close {
        width: 40px;
        height: 40px;
    }
}

/* ─── Leaflet Overrides ─── */
.leaflet-control-zoom a {
    font-family: var(--font-body) !important;
    color: var(--ink-secondary) !important;
    border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--green-50) !important;
    color: var(--green-700) !important;
}
