:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --glass: rgba(255, 255, 255, 0.8);
    --border: rgba(226, 232, 240, 0.8);

    /* Statuts */
    --status-red: #ef4444;
    --status-orange: #f59e0b;
    --status-green: #10b981;

    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    overflow: hidden;
    /* On gère le scroll dans les conteneurs */
    height: 100vh;
    width: 100vw;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.main-header {
    height: 70px;
    background: var(--glass);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    border-bottom: 1px solid var(--border);
    z-index: 1000;
}

.logo {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.logo-img {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.logo-geo {
    color: var(--primary);
}

.logo-bug {
    color: var(--text);
}

.commune {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}

.main-nav {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

/* Buttons and Inputs */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 12px -2px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.select-modern {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: white;
    color: var(--text);
    cursor: pointer;
    outline: none;
}

/* Content Area */
.content {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

#map-container {
    flex: 1;
    position: relative;
}

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

/* Sidebar */
.sidebar {
    width: 380px;
    background: white;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 900;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.hidden {
    transform: translateX(100%);
    position: absolute;
    right: 0;
    height: 100%;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    font-family: 'Outfit', sans-serif;
}

.issue-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.sidebar-footer {
    padding: 0.8rem 1.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    text-align: center;
    background: #fbfbfc;
}

.sidebar-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.sidebar-footer a:hover {
    text-decoration: underline;
}

.sidebar-filters {
    padding: 0.8rem 1rem;
    background: #f1f5f9;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.select-small {
    padding: 4px 8px;
    font-size: 0.8rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: white;
    flex: 1;
    min-width: 100px;
    outline: none;
}

/* Issue Card */
.issue-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
}

.issue-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--primary);
}

.card-status-info {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-recent {
    background: var(--status-red);
    color: var(--status-red);
}

.status-progress {
    background: var(--status-orange);
    color: var(--status-orange);
}

.status-treated {
    background: var(--status-green);
    color: var(--status-green);
}

.status-progress {
    background: var(--status-orange);
}

.status-treated {
    background: var(--status-green);
}

.issue-card h4 {
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    font-family: 'Outfit', sans-serif;
}

.issue-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.issue-meta {
    margin-top: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 4000 !important;
    /* Très haut pour passer devant la sidebar */
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 90%;
    max-width: 500px;
    background: white;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
}

.close-modal {
    background: #f1f5f9;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text);
    transition: background 0.2s;
}

.close-modal:hover {
    background: #e2e8f0;
}

.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.8rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    outline: none;
    font-size: 1rem;
}

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

.instruction {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-style: italic;
}

.location-picker {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem;
    background: #f1f5f9;
    border-radius: var(--radius);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

.form-row {
    display: flex;
    gap: 15px;
}

.flex-1 {
    flex: 1;
}

.location-status-badge {
    padding: 10px;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #475569;
    font-weight: 600;
    text-align: center;
    border: 1px dashed #cbd5e1;
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60vh;
        transform: translateY(100%);
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        transform: translateY(0);
    }

    .main-header {
        padding: 0 0.8rem;
    }

    .main-header h1 {
        font-size: 1.1rem;
    }

    .btn-mobile-list {
        display: block !important;
        bottom: 85px !important;
    }
}

.file-input {
    width: 100%;
    padding: 10px;
    background: #f8fafc;
    border-radius: 8px;
    border: 1px dashed #cbd5e1;
    cursor: pointer;
}

@media (min-width: 769px) {
    .btn-mobile-list {
        display: none;
    }
}

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

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(37, 99, 235, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.map-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 1.5rem 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1001;
}

/* Indicateur de sélection sur la carte */
.map-instruction-overlay {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border-radius: 99px;
    box-shadow: var(--shadow);
    z-index: 1002;
    display: none;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    animation: fadeInUp 0.3s ease-out;
}

.map-instruction-overlay.active {
    display: flex;
}

.reporting-mode #map {
    cursor: crosshair !important;
}

/* Leaflet Overrides */
.leaflet-container {
    background-color: #f1f5f9;
}

/* Popup Style */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    padding: 4px;
}

.popup-content h4 {
    margin-bottom: 4px;
    font-family: 'Outfit', sans-serif;
}

.popup-content .status-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 6px;
    text-transform: uppercase;
}

.tag-recent {
    background: #fee2e2;
    color: #ef4444;
}

.tag-progress {
    background: #fef3c7;
    color: #f59e0b;
}

.tag-treated {
    background: #d1fae5;
    color: #10b981;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000; /* Plus haut que tout, mais ne bloque pas les clics */
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none; /* TRÈS IMPORTANT : Laisse passer les clics au travers vers le menu */
}

.toast {
    pointer-events: auto; /* Mais réactive les clics sur le toast lui-même si besoin */
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================================
   DESIGN MOBILE RADICAL (Fix largeur 95%)
   ============================================================ */
@media (max-width: 768px) {

    /* Force le conteneur en colonne */
    #app,
    .content {
        flex-direction: column !important;
        height: 100vh !important;
        overflow: hidden !important;
    }

    /* Le header devient plus petit */
    .main-header {
        padding: 0 1rem !important;
        height: 55px !important;
    }

    .main-header h1 {
        font-size: 1.1rem !important;
    }

    .commune {
        display: block !important;
        margin-left: 10px !important;
        border-left: 1px solid var(--border) !important;
        padding-left: 10px !important;
        font-size: 0.8rem !important;
    }

    .logo-img {
        height: 28px !important;
    }

    .main-nav {
        display: flex !important;
        gap: 8px !important;
    }

    .main-nav #btn-report,
    .main-nav .filter-controls {
        display: none !important;
    }

    .main-nav .btn-secondary {
        padding: 4px 8px !important;
        font-size: 0.8rem !important;
        height: auto !important;
    }

    /* La carte prend tout le haut */
    #map-container {
        height: 100% !important;
        width: 100% !important;
        flex: 1 !important;
    }

    /* LA SIDEBAR MOBILE (Sheet) */
    .sidebar {
        position: fixed !important;
        bottom: 95px !important; /* Pour s'aligner sur la barre de nav */
        left: 0 !important;
        width: 100% !important;
        height: 70vh !important;
        background: white !important;
        border-radius: 20px 20px 0 0 !important;
        border-top: 6px solid var(--primary) !important;
        box-shadow: 0 -15px 40px rgba(0,0,0,0.2) !important;
        z-index: 5000 !important; /* Entre la carte et la nav bar */
        transform: translateY(calc(100% + 100px)) !important;
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
        visibility: visible !important;
        display: flex !important;
    }
    
    .sidebar.active {
        transform: translateY(0) !important;
    }

    /* On masque les boutons redondants */
    .btn-mobile-list, .btn-fab { 
        display: none !important; 
    }

    /* Ajustement modal */
    .modal-content {
        width: 95% !important;
        margin: 10px auto !important;
        padding: 1.5rem !important;
    }

    .form-row {
        flex-direction: column !important;
        gap: 0 !important;
    }

    /* Hide redundant elements in header */
    .logo-text, #btn-ideas, #btn-survey {
        display: none !important;
    }

    .commune {
        border-left: none !important;
        padding-left: 0 !important;
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        color: var(--primary) !important;
    }

    /* Fix Hauteur Totale pour Android Chrome */
    #app {
        height: 100dvh !important;
        /* Dynamic Viewport Height */
    }

    /* Bottom Navigation */
    .bottom-nav {
        display: flex !important;
        position: fixed !important; /* On repasse en fixed pour être SUR d'être au dessus de tout */
        bottom: 0;
        left: 0;
        width: 100%;
        height: auto !important; 
        min-height: 75px; 
        background: white;
        border-top: 2px solid var(--border);
        box-shadow: 0 -10px 30px rgba(0,0,0,0.1);
        z-index: 9999 !important; /* Priorité maximale */
        justify-content: space-around;
        align-items: center;
        padding: 5px 10px 20px 10px !important; 
        flex-shrink: 0;
        pointer-events: auto !important;
    }

    .nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        background: none;
        border: none;
        color: #475569;
        font-size: 0.8rem;
        font-weight: 800;
        cursor: pointer;
        width: 25%;
        padding: 5px 0;
        transition: all 0.2s;
    }

    /* Couleurs spécifiques par bouton */
    #nav-report {
        color: var(--primary);
    }

    #nav-list {
        color: #f59e0b;
    }

    #nav-ideas {
        color: #8b5cf6;
    }

    #nav-survey {
        color: #10b981;
    }

    .nav-item svg {
        width: 26px;
        height: 26px;
        stroke-width: 3;
        transition: transform 0.2s;
    }

    .nav-item.active {
        text-decoration: underline;
        text-underline-offset: 4px;
        color: var(--text) !important;
    }

    .nav-item.active svg {
        transform: scale(1.2) translateY(-3px);
    }

    .nav-item.disabled {
        opacity: 0.3;
        filter: grayscale(1);
    }

}

/* On cache le bouton sur PC */
@media (min-width: 769px) {

    .btn-mobile-list,
    .btn-fab {
        display: none !important;
    }
}

.file-input {
    width: 100%;
    padding: 8px;
    background: #f1f5f9;
    border-radius: 8px;
    border: 1px dashed #cbd5e1;
    margin-top: 5px;
}

/* Urgency Selector */
.urgency-selector {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.urgency-selector input[type="radio"] {
    display: none;
}

.urg-btn {
    flex: 1;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    color: #64748b;
}

.urgency-selector input[type="radio"]:checked+.urg-btn {
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Colors for levels when checked */
#urg1:checked+.urg-btn {
    background-color: #10b981;
    border-color: #10b981;
}

#urg2:checked+.urg-btn {
    background-color: #84cc16;
    border-color: #84cc16;
}

#urg3:checked+.urg-btn {
    background-color: #f59e0b;
    border-color: #f59e0b;
}

#urg4:checked+.urg-btn {
    background-color: #f97316;
    border-color: #f97316;
}

#urg5:checked+.urg-btn {
    background-color: #ef4444;
    border-color: #ef4444;
}

.urg-btn:hover {
    border-color: #cbd5e1;
    background-color: #e2e8f0;
}

/* PC Bottom Nav (Hidden by default) */
.bottom-nav {
    display: none;
}