:root {
    --primary: #3b82f6;
    --primary-light: #e5edff;
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text-main);
}

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

h1 {
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
}

.page-intro {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.filters-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .filters-grid {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 18px 20px 20px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
    border: 1px solid rgba(148, 163, 184, 0.15);
}

.card + .card {
    margin-top: 16px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.card-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.field-label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.field-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
}

.field-value {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.range-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.range-row span {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.double-slider {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.double-slider-track {
    position: relative;
    height: 24px;
}

.double-slider-track::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 4px;
    border-radius: 999px;
    background: #e5e7eb;
}

.double-slider-range {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 4px;
    border-radius: 999px;
    background: var(--primary);
}

.double-slider-track input[type="range"] {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    background: transparent;
    pointer-events: none;
}

.double-slider-track input[type="range"]::-webkit-slider-thumb {
    pointer-events: auto;
}

.double-slider-track input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
}

.double-slider-values {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}

input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 999px;
    background: #e5e7eb;
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
    cursor: pointer;
    margin-top: -6px;
}
input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #ffffff;
    cursor: pointer;
}

select, input[type="number"] {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #f9fafb;
    font-size: 0.9rem;
}

select:focus, input[type="number"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary-light);
    background: #ffffff;
}

.filters-actions {
    margin-top: 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.btn-primary {
    border: none;
    border-radius: 999px;
    background: var(--primary);
    color: white;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 10px 20px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.results-placeholder {
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.autocomplete-wrapper {
    position: relative;
}

.autocomplete-wrapper input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #f9fafb;
    font-size: 0.9rem;
}

.autocomplete-wrapper input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary-light);
    background: #ffffff;
}

.autocomplete-list {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 20;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 2px;
    max-height: 220px;
    overflow-y: auto;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
    font-size: 0.85rem;
    display: none;
}

.autocomplete-item {
    padding: 6px 10px;
    cursor: pointer;
}

.autocomplete-item:hover {
    background: #eff6ff;
}

.slider-value {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 500;
    margin-left: 6px;
    white-space: nowrap;
}

.hidden-filter {
    display: none !important;
}

.results-table th,
th[data-sort-type] {
    position: relative;
    padding: 8px;
    border: 1px solid #e5e7eb;
}

th[data-sort-type] {
    cursor: pointer;
    padding-right: 24px;
}

.th-left {
    text-align: left;
}

.th-right {
    text-align: right;
}

th[data-sort-type].sorted-asc::after,
th[data-sort-type].sorted-desc::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    color: #6b7280;
}

th[data-sort-type].sorted-asc::after {
    content: '\25B2'; /* ▲ */
}

th[data-sort-type].sorted-desc::after {
    content: '\25BC'; /* ▼ */
}

.results-table-wrapper {
    margin-top: 4px;
    overflow-x: auto;
}

.results-table {
    width: 100%;
    min-width: 1050px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
}

.results-table thead tr {
    background: #f3f4f6;
}

.results-table td {
    padding: 8px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}

.results-table tbody tr:hover {
    background: #f8fafc;
}

.summary-row {
    cursor: default;
}

.summary-cell {
    min-width: 150px;
}

.commune-postal {
    color: #64748b;
    font-size: 0.78rem;
}

.type-summary-cell {
    min-width: 128px;
}

.type-summary .summary-price {
    padding: 7px 8px;
}

.type-summary .summary-price strong {
    font-size: 0.86rem;
}

.type-summary .summary-price span {
    display: none;
}

.type-summary .summary-price small {
    font-size: 0.68rem;
}

.type-summary-empty {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 54px;
    color: #94a3b8;
    border: 1px dashed #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
}

.commune-detail-types {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.commune-type-detail {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    padding: 12px;
}

.commune-type-detail h3 {
    margin: 0 0 10px;
    font-size: 0.9rem;
    color: #0f172a;
}

.details-toggle-cell {
    text-align: center;
    vertical-align: middle !important;
}

.details-toggle {
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 7px 12px;
    cursor: pointer;
    white-space: nowrap;
}

.details-toggle:hover {
    background: #dbeafe;
}

.details-toggle[aria-expanded="true"] {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
}

.dvf-mutations-toggle {
    margin-top: 8px;
    width: 100%;
    border: 1px solid #ddd6fe;
    border-radius: 8px;
    background: #f5f3ff;
    color: #6d28d9;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 6px 8px;
    cursor: pointer;
}

.dvf-mutations-toggle:hover,
.dvf-mutations-toggle[aria-expanded="true"] {
    background: #7c3aed;
    border-color: #7c3aed;
    color: #ffffff;
}

.dvf-mutations-table-wrapper {
    margin-top: 12px;
    overflow-x: auto;
}

.dvf-mutations-table {
    min-width: 760px;
}

.detail-row td {
    background: #f8fafc;
    padding: 12px 14px 16px;
}

.detail-price-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 12px;
}

.summary-price,
.price-source {
    border-radius: 10px;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
}

.summary-price {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #eff6ff;
    border-color: #bfdbfe;
    text-align: right;
}

.summary-price strong {
    color: #1d4ed8;
    font-size: 0.95rem;
}

.summary-price span,
.summary-price small {
    color: #64748b;
    font-size: 0.72rem;
}

.summary-price-empty {
    color: #94a3b8;
    text-align: center;
}

.price-source {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.price-source-name {
    font-weight: 700;
    font-size: 0.76rem;
    margin-bottom: 2px;
}

.price-line {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #64748b;
    font-size: 0.76rem;
}

.price-line strong {
    color: #0f172a;
    font-weight: 600;
    white-space: nowrap;
}

.price-line-main {
    color: #111827;
}

.price-line-main strong {
    font-size: 0.86rem;
    font-weight: 800;
}

.price-source-lybox {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.price-source-lybox .price-source-name {
    color: #0f172a;
}

.price-source-meilleursagents {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.price-source-meilleursagents .price-source-name {
    color: #16a34a;
}

.price-source-moteurimmo {
    border-color: #bfdbfe;
    background: #eff6ff;
}

.price-source-moteurimmo .price-source-name {
    color: #1d4ed8;
}

.price-source-dvf {
    border-color: #ddd6fe;
    background: #f5f3ff;
}

.price-source-dvf .price-source-name {
    color: #7c3aed;
}

.price-source-empty {
    background: #f8fafc;
    color: #94a3b8;
    min-height: 84px;
    justify-content: center;
}

.price-empty {
    font-size: 0.75rem;
    color: #94a3b8;
}

@media (max-width: 900px) {
    .detail-price-grid {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
    }
}

@media (max-width: 600px) {
    .page {
        padding: 16px 10px 28px;
    }

    .card {
        padding: 14px 14px 16px;
    }

    .card-title {
        font-size: 1rem;
        margin-bottom: 8px;
    }

    .field-group {
        margin-bottom: 8px;
    }

    .filters-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-primary {
        justify-content: center;
        width: 100%;
    }

    .detail-price-grid {
        grid-template-columns: 1fr;
    }
}
