/* ========================================
   WASH-FIT DASHBOARD - STYLES COMPLETS
   ======================================== */

/* ========== VARIABLES ET BASE ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-blue: #2196F3;
    --primary-green: #4CAF50;
    --secondary-blue: #1976D2;
    --light-gray: #f5f7fa;
    --border-gray: #e1e8ed;
    --text-dark: #2c3e50;
    --text-light: #6c757d;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --sidebar-width: 380px;
    --sidebar-width-tablet: 300px;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-dark);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

/* ========== LAYOUT PRINCIPAL ========== */
.dashboard-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: white;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    transition: width 0.3s ease, transform 0.3s ease;
}

.sidebar-header {
    padding: 24px 20px;
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--secondary-blue) 100%);
    color: white;
    flex-shrink: 0;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo {
    width: 48px;
    height: 48px;
    background: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.dashboard-title {
    font-size: 22px;
    font-weight: 700;
    margin: 0;
}

.dashboard-subtitle {
    font-size: 14px;
    opacity: 0.9;
    margin: 0;
}

/* FILTRES */
.filters-section {
    padding: 20px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.filter-label i {
    color: var(--primary-blue);
    font-size: 16px;
}

.filter-select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-gray);
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(33,150,243,0.1);
}

.update-button {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-green) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s, box-shadow 0.2s;
    min-height: 44px;
}

.update-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(33,150,243,0.3);
}

.update-button:active {
    transform: translateY(0);
}

/* GUIDE DE NAVIGATION */
.navigation-guide {
    padding: 20px;
    background: var(--light-gray);
}

.guide-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 16px;
}

.guide-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: transform 0.2s;
}

.guide-step:hover {
    transform: translateX(4px);
}

.step-number {
    width: 28px;
    height: 28px;
    min-width: 28px;
    background: linear-gradient(135deg, var(--primary-blue), var(--secondary-blue));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.step-text {
    font-size: 14px;
    color: var(--text-dark);
    line-height: 1.5;
}

/* STATISTIQUES */
.statistics-section {
    padding: 20px;
    background: white;
    border-top: 1px solid var(--border-gray);
}

.stats-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: 16px;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-card {
    padding: 16px;
    background: var(--light-gray);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-size: 14px;
    color: var(--text-light);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-blue);
}

.stat-card.functional .stat-value  { color: var(--primary-green); }
.stat-card.non-functional .stat-value { color: #f44336; }

.functionality-rate {
    margin-top: 16px;
    padding: 16px;
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    border-radius: 10px;
}

.rate-label {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.rate-bar {
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.rate-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-green), #66bb6a);
    transition: width 0.5s ease;
}

.rate-percentage {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-green);
    text-align: right;
}

/* ZONE DE SÉLECTION */
.selection-info {
    padding: 20px;
    background: #e3f2fd;
    border-radius: 12px;
    margin: 20px;
}

.selection-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
}

.selection-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: white;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 14px;
}

.selection-item i { color: var(--primary-blue); }

.establishment-count {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 8px;
}

/* LÉGENDE */
.legend-section {
    padding: 20px;
    background: #fffde7;
    border-radius: 12px;
    margin: 20px;
}

.legend-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    font-size: 14px;
}

.legend-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.legend-icon.functional     { background: #e8f5e9; color: var(--primary-green); }
.legend-icon.non-functional { background: #ffebee; color: #f44336; }

.legend-tip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-light);
}

.legend-tip i { color: #ffc107; }

/* ========== CARTE ========== */
.map-container {
    flex: 1;
    position: relative;
    min-width: 0;
}

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

.district-label {
    background: rgba(255,255,255,0.7);
    border-radius: 4px;
    padding: 2px 5px;
    font-weight: bold;
}

/* ========== MARQUEURS ========== */
.custom-marker {
    background: transparent !important;
    border: none !important;
}

.custom-marker:hover { z-index: 1000 !important; }

.establishment-marker {
    display: flex;
    align-items: center;
    justify-content: center;
}

.establishment-marker.functional     { color: green; }
.establishment-marker.non-functional { color: red; }

/* ========== POPUPS ========== */
.establishment-popup {
    min-width: 300px;
    max-width: 700px;
}

.establishment-popup h3 {
    margin: 0 0 10px;
    color: var(--text-dark);
    font-size: 18px;
}

.establishment-popup p {
    margin: 5px 0;
    font-size: 14px;
}

.indicators-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 15px 0;
}

.indicator-section {
    padding: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #007bff;
    text-align: center;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.indicator-section h4 {
    margin: 0 0 8px;
    font-size: 12px;
    color: #333;
    line-height: 1.3;
    min-height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.indicator-percentage {
    font-size: 16px;
    font-weight: bold;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.status-section {
    grid-column: span 2;
    border-left-color: #4CAF50;
}

.overall-status {
    font-weight: bold;
    padding: 8px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 14px;
}

.overall-status.operational     { background: #e8f5e9; color: #2e7d32; }
.overall-status.non-operational { background: #ffebee; color: #c62828; }

.status-details { font-size: 12px; }
.status-details p { margin: 0; }

.indicator-bar {
    width: 100%;
    height: 20px;
    background: #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    margin-bottom: 8px;
}

.indicator-segment { height: 100%; transition: width 0.3s ease; }
.indicator-segment.red    { background: #dc3545; }
.indicator-segment.yellow { background: #ffc107; }
.indicator-segment.green  { background: #28a745; }

.indicator-details {
    display: flex;
    justify-content: space-between;
    gap: 5px;
    flex-wrap: wrap;
}

.indicator-badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    color: white;
}

.indicator-badge.red    { background: #dc3545; }
.indicator-badge.yellow { background: #ffc107; color: #000; }
.indicator-badge.green  { background: #28a745; }

/* ========== COMMENTAIRES ========== */
.comment-section {
    margin: 15px 0;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 5px;
    border-left: 4px solid #4CAF50;
}

.comment-display {
    padding: 8px;
    background: white;
    border-radius: 3px;
    margin: 5px 0;
    min-height: 20px;
    font-size: 13px;
}

.comment-edit { margin-top: 10px; }

.comment-textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    margin: 5px 0;
    font-family: inherit;
    font-size: 13px;
    min-height: 44px;
}

.save-comment-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
    min-height: 44px;
}

.save-comment-btn:hover { background: #0b7dda; }

/* ========== BOUTON DRONE ========== */
.show-drone-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 12px;
    margin-top: 10px;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
    text-align: center;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s;
    min-height: 44px;
}

.show-drone-btn:hover { background: #45a049; }

/* ========== VUE DRONE FULLSCREEN ========== */
.drone-fullscreen {
    position: fixed;
    top: 0; left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.9);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
    padding: 1rem;
}

@keyframes fadeIn { to { opacity: 1; } }

.drone-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    text-align: center;
}

.drone-content h3 {
    color: white;
    margin-bottom: 20px;
    font-size: 20px;
}

.drone-content img {
    max-height: 80vh;
    max-width: 90vw;
    object-fit: contain;
    border: 2px solid #fff;
    animation: zoomIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoomIn {
    from { transform: scale(0.8); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.close-btn {
    position: absolute;
    top: -40px; right: 0;
    background: #ff4444;
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    z-index: 10000;
    line-height: 1;
    transition: background 0.2s;
}

.close-btn:hover { background: #cc0000; }

/* ========== BOUTON DÉCONNEXION ADMIN ========== */
.admin-logout-btn {
    position: absolute;
    top: 70px; right: 10px;
    z-index: 1000;
    background: #ff4444;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: var(--shadow);
    transition: background 0.2s;
    min-height: 44px;
}

.admin-logout-btn:hover { background: #cc0000; }

/* ========== NOTIFICATIONS ========== */
.notification {
    position: fixed;
    top: 20px; right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 10000;
    color: white;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease-out;
    max-width: calc(100vw - 40px);
}

@keyframes slideIn {
    from { transform: translateX(100px); opacity: 0; }
    to   { transform: translateX(0);     opacity: 1; }
}

.notification.success { background: #4CAF50; }
.notification.error   { background: #f44336; }

/* ========== COMMUNE ========== */
.commune-label {
    background: rgba(139,69,19,0.8);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-weight: bold;
    font-size: 12px;
}

.commune-popup { min-width: 200px; }
.commune-popup h3 { color: #8B4513; margin-bottom: 8px; font-size: 16px; }
.commune-popup p  { margin: 4px 0; font-size: 13px; }

/* ========== LEAFLET ========== */
.leaflet-container { transition: transform 0.5s ease; }

/* ========== SCROLLBAR ========== */
.sidebar::-webkit-scrollbar       { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: var(--light-gray); }
.sidebar::-webkit-scrollbar-thumb { background: var(--primary-blue); border-radius: 3px; }

/* ========== BOUTON MENU MOBILE ========== */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary-blue);
    color: white;
    border: none;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(33,150,243,0.4);
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.sidebar-toggle:hover { background: var(--secondary-blue); }

/* overlay sombre quand sidebar ouverte sur mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
}

/* ============================================================
   RESPONSIVE — du plus grand au plus petit
   ============================================================ */

/* ── Grand écran (> 1280px) ── */
@media (min-width: 1280px) {
    :root { --sidebar-width: 400px; }

    .establishment-popup { min-width: 650px; }
}

/* ── Laptop standard (1024–1279px) ── */
@media (max-width: 1279px) and (min-width: 1025px) {
    :root { --sidebar-width: 340px; }

    .dashboard-title { font-size: 19px; }
    .indicators-grid { grid-template-columns: repeat(2, 1fr); }
    .status-section  { grid-column: span 2; }
}

/* ── Tablette paysage / petit laptop (768–1024px) ── */
@media (max-width: 1024px) and (min-width: 768px) {
    :root { --sidebar-width: 300px; }

    .sidebar { min-width: var(--sidebar-width); }

    .sidebar-header  { padding: 18px 16px; }
    .dashboard-title { font-size: 18px; }
    .logo            { width: 40px; height: 40px; font-size: 20px; }

    .filters-section,
    .navigation-guide,
    .statistics-section { padding: 14px; }

    .selection-info,
    .legend-section { margin: 14px; padding: 14px; }

    .indicators-grid { grid-template-columns: repeat(2, 1fr); }
    .status-section  { grid-column: span 2; }
    .establishment-popup { min-width: 340px; }
}

/* ── Tablette portrait (600–767px) ── */
@media (max-width: 767px) and (min-width: 600px) {
    .dashboard-container { flex-direction: column; }

    .sidebar {
        width: 100%;
        min-width: unset;
        height: auto;
        max-height: 42vh;
        overflow-y: auto;
        transform: none !important;
    }

    .map-container { height: 58vh; }

    .navigation-guide { display: none; }

    .indicators-grid { grid-template-columns: repeat(2, 1fr); }
    .status-section  { grid-column: span 2; }
    .establishment-popup { min-width: 280px; max-width: 95vw; }

    .stats-grid { flex-direction: row; flex-wrap: wrap; }
    .stat-card  { flex: 1 1 calc(50% - 6px); }
}

/* ── Smartphone (< 600px) ── */
@media (max-width: 599px) {
    .dashboard-container { flex-direction: column; }

    /* Sidebar cachée par défaut, slide-in via .open */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 85vw;
        max-width: 320px;
        height: 100vh;
        max-height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        overflow-y: auto;
    }

    .sidebar.open { transform: translateX(0); }

    .sidebar-overlay.open { display: block; }

    .sidebar-toggle { display: flex; }

    .map-container { height: 100vh; width: 100%; }

    .sidebar-header  { padding: 16px; }
    .dashboard-title { font-size: 17px; }
    .logo            { width: 36px; height: 36px; font-size: 18px; }
    .dashboard-subtitle { font-size: 12px; }

    .filters-section,
    .navigation-guide,
    .statistics-section { padding: 12px; }

    .selection-info,
    .legend-section { margin: 12px; padding: 12px; }

    .navigation-guide { display: none; }

    .indicators-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .status-section  { grid-column: span 2; }
    .indicator-section { min-height: 110px; padding: 8px; }
    .indicator-section h4 { font-size: 11px; }
    .indicator-percentage { font-size: 14px; }

    .establishment-popup { min-width: 260px; max-width: 92vw; }
    .establishment-popup h3 { font-size: 15px; }

    .stat-card { padding: 12px; }
    .stat-value { font-size: 20px; }

    .admin-logout-btn { top: auto; bottom: 90px; right: 10px; }

    .notification { top: auto; bottom: 16px; right: 12px; left: 12px; text-align: center; }
}

/* ── iPhone SE / très petits écrans (< 375px) ── */
@media (max-width: 374px) {
    .dashboard-title { font-size: 15px; }
    .logo            { width: 32px; height: 32px; font-size: 16px; }
    .filter-select   { padding: 10px 12px; font-size: 13px; }
    .update-button   { font-size: 13px; padding: 12px; }

    .indicators-grid { grid-template-columns: 1fr; }
    .status-section  { grid-column: span 1; }
    .sidebar { width: 92vw; }
}

/* ── Paysage mobile (hauteur < 500px) ── */
@media (max-height: 500px) and (orientation: landscape) {
    .dashboard-container { flex-direction: row; }

    .sidebar {
        position: relative;
        transform: none;
        width: 260px;
        min-width: 260px;
        height: 100vh;
        max-height: 100vh;
    }

    .sidebar-toggle  { display: none; }
    .sidebar-overlay { display: none !important; }

    .map-container { height: 100vh; }

    .navigation-guide,
    .legend-section,
    .statistics-section { display: none; }

    .sidebar-header  { padding: 12px; }
    .dashboard-title { font-size: 15px; }
    .filters-section { padding: 10px; }
    .filter-group    { margin-bottom: 10px; }
    .filter-select   { padding: 8px 10px; font-size: 13px; }
    .update-button   { padding: 10px; font-size: 13px; }
}

/* ── iPad Pro 12.9" et grandes tablettes (1024px exactement) ── */
@media (min-width: 1024px) and (max-width: 1024px) {
    :root { --sidebar-width: 320px; }
}

/* ── Tactile : zones de tap suffisamment grandes ── */
@media (pointer: coarse) {
    .filter-select,
    .update-button,
    .save-comment-btn,
    .show-drone-btn,
    .guide-step,
    .close-btn { min-height: 48px; }

    .establishment-marker { width: 38px !important; height: 38px !important; }
    .leaflet-control-zoom a { width: 40px !important; height: 40px !important; line-height: 40px !important; }
}

/* ── Notch iPhone X+ ── */
@supports (padding: max(0px)) {
    .sidebar {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sidebar-toggle {
        bottom: max(24px, env(safe-area-inset-bottom, 24px));
        right:  max(24px, env(safe-area-inset-right, 24px));
    }
}

/* ── Mode sombre système ── */
@media (prefers-color-scheme: dark) {
    .leaflet-container { background: #1a1a2e !important; }
}

/* ── Haute résolution (Retina) ── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .logo { image-rendering: -webkit-optimize-contrast; }
}

/* ========== COMPATIBILITÉ ANCIENNES CLASSES ========== */
.container {
    display: flex;
    height: 100vh;
}

.inside-commune { z-index: 1000; }

.filter-select option[value=""] {
    color: #6c757d;
    font-style: italic;
}