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

body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; background: #f1f5f9; }

/* ── Layout ── */

#app { display: flex; height: 100vh; }

#sidebar {
    width: 340px;
    min-width: 280px;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 8px rgba(0,0,0,.08);
    z-index: 10;
}

#map { flex: 1; }

/* ── Search panel ── */

#search-panel {
    padding: 20px 16px 16px;
    border-bottom: 1px solid #e2e8f0;
}

#search-panel h1 { font-size: 18px; font-weight: 700; margin-bottom: 14px; color: #1e293b; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: #64748b; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }

input[type=text], select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
}
input[type=text]:focus, select:focus { border-color: #3b82f6; }

/* Slider */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: linear-gradient(to right, #3b82f6 0%, #3b82f6 10%, #e2e8f0 10%, #e2e8f0 100%);
    outline: none;
    cursor: pointer;
    margin: 6px 0 4px;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3b82f6;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(59,130,246,.4);
    cursor: pointer;
    transition: box-shadow .15s;
}
input[type=range]::-webkit-slider-thumb:hover { box-shadow: 0 0 0 4px rgba(59,130,246,.15); }
input[type=range]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3b82f6;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(59,130,246,.4);
    cursor: pointer;
}
.radius-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.radius-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .1s;
}
.radius-btn:hover { background: #e2e8f0; }
#radius-label { color: #3b82f6; font-size: 13px; }

/* Autocomplete */
#autocomplete-wrapper { position: relative; }
#autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-top: none;
    border-radius: 0 0 6px 6px;
    list-style: none;
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
}
#autocomplete-list li { padding: 8px 10px; cursor: pointer; color: #334155; }
#autocomplete-list li:hover { background: #f1f5f9; }

/* Specificities checkboxes */
#specificities-checkboxes { display: flex; flex-wrap: wrap; gap: 6px; }
#specificities-checkboxes label {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: background .1s;
}
#specificities-checkboxes label:hover { background: #f8fafc; }
#specificities-checkboxes input { display: none; }
#specificities-checkboxes input:checked + * { /* checked state via JS sibling */ }
#specificities-checkboxes label:has(input:checked) { background: #eff6ff; border-color: #3b82f6; color: #1d4ed8; }

.spec-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

.filter-mode-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #475569; cursor: pointer; text-transform: none; letter-spacing: 0; font-weight: 400; }
.filter-mode-row input[type=checkbox] { display: inline; width: auto; }

#search-btn {
    width: 100%;
    padding: 10px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    margin-top: 4px;
}
#search-btn:hover { background: #2563eb; }

#reset-btn {
    width: 100%;
    padding: 8px;
    background: none;
    color: #64748b;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    margin-top: 6px;
}
#reset-btn:hover { background: #f8fafc; }

/* ── Results panel ── */

#results-panel {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
}

#results-panel h2 { font-size: 15px; font-weight: 700; color: #1e293b; margin-bottom: 10px; }
#results-count { color: #64748b; font-weight: 400; }

#results-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.result-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    transition: border-color .15s;
}
.result-item:hover { border-color: #93c5fd; }
.result-item.dimmed { opacity: .5; }

.result-name { font-weight: 600; color: #1e293b; font-size: 13px; }
.result-meta { font-size: 12px; color: #64748b; margin-top: 2px; }
.result-specs { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px; }
.result-actions { display: flex; gap: 6px; margin-top: 8px; }

.btn-detail {
    padding: 4px 10px;
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}
.btn-detail:hover { background: #dbeafe; }

.btn-itinerary {
    padding: 4px 10px;
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
    border-radius: 4px;
    font-size: 12px;
    text-decoration: none;
    display: inline-block;
}
.btn-itinerary:hover { background: #dcfce7; }

/* Sector badge */
.sector-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid;
    margin: 4px 0;
}

/* Spec badges */
.spec-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
}

/* ── Card popup ── */

#popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#popup-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    position: relative;
    box-shadow: 0 20px 40px rgba(0,0,0,.2);
}

#popup-close {
    position: absolute;
    top: 12px; right: 14px;
    background: none;
    border: none;
    font-size: 22px;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
}
#popup-close:hover { color: #475569; }

#popup-card h3 { font-size: 17px; font-weight: 700; color: #1e293b; margin-bottom: 8px; }
.card-address { color: #475569; font-size: 13px; line-height: 1.5; }
.card-specs { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.card-contacts { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #475569; }
.card-contacts a { color: #2563eb; text-decoration: none; }
.card-comment { margin-top: 10px; font-size: 13px; color: #64748b; font-style: italic; }
.card-actions { margin-top: 14px; }
.card-actions .btn-itinerary { padding: 8px 16px; font-size: 13px; }

/* ── Responsive ── */

/* Tablette portrait (≤ 900px) : sidebar plus étroite */
@media (max-width: 900px) {
    #sidebar { width: 280px; min-width: 0; }
}

/* Mobile (≤ 640px) : layout vertical, sidebar en bas en drawer */
@media (max-width: 640px) {

    #app {
        flex-direction: column-reverse; /* carte en haut, sidebar en bas */
        height: 100dvh;                 /* dvh = hauteur visible réelle sur mobile */
    }

    #map {
        flex: 1 1 auto;
        min-height: 45vh;
    }

    #sidebar {
        width: 100%;
        min-width: 0;
        height: auto;
        max-height: 55vh;
        overflow-y: auto;
        box-shadow: 0 -2px 8px rgba(0,0,0,.1);
        -webkit-overflow-scrolling: touch;
    }

    #search-panel {
        padding: 12px 12px 10px;
    }

    #search-panel h1 { font-size: 16px; margin-bottom: 10px; }

    .field { margin-bottom: 10px; }

    /* Boutons recherche / reset pleine largeur */
    #search-btn, #reset-btn { font-size: 13px; padding: 9px; }

    /* Résultats */
    #results-panel { padding: 10px 12px; }

    /* Popup carte plein écran sur mobile */
    #popup-overlay { padding: 0; align-items: flex-end; }
    #popup-card {
        border-radius: 16px 16px 0 0;
        max-width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        padding: 20px 16px 32px;
    }

    /* Spécificités : scroll horizontal si trop nombreuses */
    #specificities-checkboxes {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }
    #specificities-checkboxes label { flex-shrink: 0; }

    /* Slider row */
    .radius-row { gap: 6px; }
    .radius-btn { width: 32px; height: 32px; font-size: 18px; }
}
