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

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f3f4f6;
    color: #111827;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header pleine largeur */
.app-header {
    flex-shrink: 0;
    padding: 1rem 1.75rem;
    background: linear-gradient(120deg, #1d4ed8, #0ea5e9);
    color: #f9fafb;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
    text-align: center;
}

.app-header h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

/* Corps : sidebar gauche + colonne droite (filtres + carte) */
.app-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Sidebar gauche */
.sidebar {
    flex-shrink: 0;
    width: 280px;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    padding: 0.75rem;
}

.sidebar-section {
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 0.6rem 0.75rem;
    background: #f9fafb;
}

.sidebar-section h2 {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #374151;
}

.info-parcelle {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.parcelle-demandeur {
    flex-shrink: 0;
    margin-bottom: 0.75rem;
}

.image-demandeur {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 0.4rem;
    background: #fff;
}

.image-demandeur .avatar-demandeur {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.info-parcelle .detail-panel {
    flex: 1;
    min-height: 0;
    margin: 0;
    padding: 0.5rem 0;
    background: transparent;
    border: none;
    overflow: auto;
}

/* Box modification de la parcelle (sidebar) */
.box-modification-parcelle {
    margin-top: 0.75rem;
}

.box-modification-parcelle h2 {
    margin: 0 0 0.5rem;
}

.form-modification-parcelle .form-group {
    margin-bottom: 0.5rem;
}

.form-modification-parcelle .form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.2rem;
}

.form-modification-parcelle .form-group input,
.form-modification-parcelle .form-group select,
.form-modification-parcelle .form-group textarea {
    width: 100%;
    padding: 0.35rem 0.45rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.85rem;
}

.form-modification-parcelle .form-group textarea {
    resize: vertical;
    min-height: 50px;
}

.form-actions-modification {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e5e7eb;
}

.form-actions-modification .btn {
    flex: 1;
}

/* Colonne droite : barre de filtres + carte */
.map-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0.75rem;
    background: #f3f4f6;
}

/* Barre de filtres (uniquement à droite, au-dessus de la carte) */
.filter-bar {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    margin-bottom: 0.75rem;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem 1rem;
    flex: 1;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 120px;
    max-width: 180px;
}

.filter-field label {
    font-size: 0.75rem;
    font-weight: 500;
    color: #4b5563;
}

.filter-field select {
    padding: 0.4rem 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid #d1d5db;
    font-size: 0.85rem;
    background: #fff;
    outline: none;
}

.filter-field select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.25);
}

.filter-buttons {
    display: flex;
    gap: 0.5rem;
}

.filter-extra select {
    padding: 0.4rem 0.5rem;
    border-radius: 0.5rem;
    border: 1px solid #d1d5db;
    font-size: 0.85rem;
    background: #fff;
}

/* Zone carte */
.map-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fff;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    padding: 0.75rem 1rem;
}

.map-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.map-title {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
}

.digitize-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-digitize {
    background: #059669;
    color: #fff;
    font-size: 0.85rem;
}

.btn-digitize:hover {
    background: #047857;
}

.digitize-state {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: #4b5563;
}

.digitize-hint {
    margin-right: 0.25rem;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.toolbar-right {
    display: flex;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: #4b5563;
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

#map {
    flex: 1;
    min-height: 200px;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    overflow: hidden;
}

.map-legend {
    flex-shrink: 0;
    margin-top: 0.4rem;
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    font-size: 0.75rem;
}

.legend-item {
    padding: 0.1rem 0.45rem;
    border-radius: 0.5rem;
}

.legend-approuve {
    background: #dcfce7;
    color: #166534;
}

.legend-non_approuve {
    background: #dbeafe;
    color: #1d4ed8;
}

/* Détail parcelle (contenu dynamique) */
.detail-panel h3 {
    margin: 0 0 0.35rem;
    font-size: 0.9rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

.detail-label {
    font-weight: 500;
    color: #4b5563;
}

.detail-value {
    text-align: right;
}

/* Boutons */
.btn {
    border-radius: 0.5rem;
    border: none;
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

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

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

.btn-secondary:hover {
    background: #d1d5db;
}

/* Leaflet */
.leaflet-control-zoom a {
    border-radius: 0.4rem !important;
}

.leaflet-control-attribution {
    font-size: 0.65rem;
}

/* Modal formulaire parcelle numérisée */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
}

.modal-content {
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #111827;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem;
}

.modal-close:hover {
    color: #111827;
}

.modal-form {
    padding: 1.25rem;
}

.modal-form .form-group {
    margin-bottom: 0.75rem;
}

.modal-form .form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
}

.modal-form .form-group input,
.modal-form .form-group select,
.modal-form .form-group textarea {
    width: 100%;
    padding: 0.45rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.9rem;
}

.modal-form .form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
}

.modal-actions .btn {
    flex: 1;
}

/* Boutons dans le popup des parcelles numérisées */
.btn-popup-edit {
    display: block;
    width: 100%;
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    cursor: pointer;
    color: #374151;
}
.btn-popup-edit:hover {
    background: #e5e7eb;
}

/* Responsive */
@media (max-width: 960px) {
    .app-body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 40vh;
    }

    .map-area {
        min-height: 50vh;
    }
}
