/**
 * OXYMED PLUS - Master Stylesheet
 * Version 8.6.5 - Stability Standard (Fixed Design)
 * Design: Soft UI / Glassmorphism / Responsive Framework
 */

:root {
    /* Palette Signature - OxymedPlus v8 */
    --primary: #6366f1;
    --primary-soft: rgba(99, 102, 241, 0.1);
    --primary-dark: #4f46e5;
    --accent: #10b981;
    --danger: #f43f5e;
    --warning: #f59e0b;
    --info: #0ea5e9;
    
    /* Couleurs de fond et surfaces */
    --bg-main: #f0f2f5;     
    --bg-sidebar: #ffffff;
    --bg-input: #f8faff;    
    --surface: #ffffff;
    
    /* Typographie & Bordures */
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    
    /* Rayons et Effets signature */
    --gap-page: 2rem; 
    --radius-md: 15px;
    --radius-lg: 35px;      /* Arrondi signature des cartes */
    --radius-pill: 50px; 
    --shadow-soft: 0 10px 30px rgba(99, 102, 241, 0.05);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.1);

    /* Layers de sécurité */
    --z-login: 10000;
    --z-sidebar: 1000;
    --z-modal: 11000;
    --z-toast: 12000;
}

/* --- Base & Reset --- */
* {
    margin: 0; padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

/* --- Login Experience --- */
.login-overlay {
    position: fixed; inset: 0;
    background: linear-gradient(135deg, var(--primary-dark) 0%, #818cf8 100%);
    display: flex; align-items: center; justify-content: center;
    z-index: var(--z-login);
}

.login-card {
    background: var(--surface);
    padding: 3.5rem;
    border-radius: 45px; 
    box-shadow: var(--shadow-lg);
    width: 90%; max-width: 480px;
    text-align: center;
    animation: fadeIn 0.6s ease-out;
}

/* Cache l'overlay proprement en CSS quand l'ID est display:none */
#loginOverlay[style*="display: none"] {
    visibility: hidden;
    pointer-events: none;
}

.version-tag {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* --- Layout Structure --- */
#mainApp { display: flex; width: 100%; min-height: 100vh; position: relative; z-index: 1; }

.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    padding: 2.5rem 0;
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.02);
    z-index: var(--z-sidebar);
    transition: all 0.3s ease;
}

.logo { padding: 0 2.5rem; margin-bottom: 3rem; }
.logo h2 { font-weight: 800; font-size: 1.5rem; letter-spacing: -1px; }
.logo h2 span { color: var(--primary); }

#main-nav { list-style: none; flex-grow: 1; }
#main-nav li {
    padding: 14px 24px; margin: 4px 18px;
    border-radius: 18px;
    cursor: pointer;
    display: flex; align-items: center; gap: 14px;
    color: var(--text-muted);
    font-weight: 600;
    transition: all 0.25s ease;
}

#main-nav li i { font-size: 1.1rem; width: 20px; text-align: center; }
#main-nav li:hover { background: var(--bg-input); color: var(--primary); }
#main-nav li.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.25);
}

/* --- Header --- */
header {
    background: white;
    padding: 1.2rem 2rem;
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 2rem;
    border-radius: 0 0 25px 25px;
    box-shadow: var(--shadow-soft);
}

.burger-btn {
    display: none; background: none; border: none;
    font-size: 1.5rem; color: var(--primary); cursor: pointer;
}

.search-container {
    position: relative;
    width: 100%; max-width: 400px;
}

.search-container i {
    position: absolute; left: 18px; top: 50%;
    transform: translateY(-50%); color: var(--text-muted);
}

.search-container input {
    width: 100%;
    padding-left: 50px !important;
    border-radius: 20px !important;
}

/* --- Tables & Registry --- */
.table-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 1.5rem;
    overflow-x: auto;
    border: 1px solid white;
}

table { width: 100%; border-collapse: collapse; min-width: 900px; }
th { 
    text-align: left; color: var(--text-muted); 
    font-size: 0.75rem; padding: 1.2rem; 
    text-transform: uppercase; letter-spacing: 1px; 
    font-weight: 700; border-bottom: 2px solid var(--border-color); 
}
td { padding: 1.2rem; border-bottom: 1px solid var(--border-color); font-size: 0.95rem; }

/* Status & Dots */
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 8px; }
.dot-alive { background: var(--accent); box-shadow: 0 0 12px rgba(16, 185, 129, 0.4); }
.dot-deceased { background: var(--danger); box-shadow: 0 0 12px rgba(244, 63, 94, 0.4); }

.badge {
    padding: 6px 14px; border-radius: 12px;
    font-size: 0.72rem; font-weight: 800;
    display: inline-block; text-align: center;
    text-transform: uppercase;
}
.badge-success { background: #ecfdf5; color: #10b981; }
.badge-warning { background: #fffbeb; color: #f59e0b; }
.badge-danger { background: #fef2f2; color: #f43f5e; }
.badge-info { background: #f0f9ff; color: #0ea5e9; }

/* --- Dashboard Stats --- */
.content { flex-grow: 1; padding: var(--gap-page); max-width: 100%; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px; margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--surface);
    padding: 28px;
    border-radius: var(--radius-lg);
    display: flex; align-items: center; gap: 22px;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(255,255,255,0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.stat-card:hover { 
    transform: translateY(-8px); 
    box-shadow: 0 15px 35px rgba(99, 102, 241, 0.1);
}

.modal {
    z-index: 11000; /* Doit être plus élevé que la sidebar et le header */
    display: none; 
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex !important; /* Force l'affichage */
}

.modal-content {
    background: white; padding: 3rem;
    border-radius: 42px; position: relative;
    box-shadow: var(--shadow-lg);
    width: 95%; max-width: 1100px;
    max-height: 90vh; overflow-y: auto;
    transform: translateY(20px); transition: all 0.4s ease;
}

.patient-horizontal-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 25px; margin-top: 25px;
    width: 100%;
}

.modal-column {
    background: #f8fafc; padding: 25px;
    border-radius: 28px; border: 1px solid var(--border-color);
    min-width: 0; /* Empêche l'écrasement des colonnes */
}

.modal-column h4 {
    font-size: 0.85rem; color: var(--primary);
    text-transform: uppercase; font-weight: 800;
    margin-bottom: 20px; padding-bottom: 12px;
    display: flex; align-items: center; gap: 10px;
    border-bottom: 2px solid var(--primary-soft);
}

.close {
    position: absolute; top: 25px; right: 25px;
    width: 45px; height: 45px; border-radius: 50%;
    background: #f1f5f9; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.3s; color: var(--text-muted);
}
.close:hover { background: #fee2e2; color: var(--danger); transform: rotate(90deg); }

/* --- Forms & Controls --- */
.form-group { margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); padding-left: 4px; }

input, select, textarea {
    background: #ffffff !important;
    border: 1.5px solid var(--border-color) !important;
    border-radius: 16px !important; 
    padding: 14px 20px !important;
    font-size: 0.95rem; color: var(--text-main);
    transition: all 0.25s ease;
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    background: white !important;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 4px var(--primary-soft);
    outline: none;
}

/* --- Buttons --- */
.btn-primary, .btn-logout {
    background: var(--primary) !important;
    color: white !important;
    border-radius: 20px !important;
    padding: 16px 32px !important;
    font-weight: 700 !important;
    border: none !important;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.25);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 0.9rem;
}

.btn-primary:hover, .btn-logout:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 30px rgba(99, 102, 241, 0.4);
    background: var(--primary-dark) !important;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    padding: 10px 20px;
    border-radius: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
}
.btn-outline:hover { background: var(--primary-soft); }
.btn-icon[style*="var(--danger)"]:hover {
    background-color: #fee2e2 !important; /* Rouge très clair au survol */
    color: #dc2626 !important; /* Rouge vif */
    transform: scale(1.15);
}
.btn-icon {
    background: none; border: none; cursor: pointer;
    padding: 10px; border-radius: 12px; transition: 0.2s;
    font-size: 1.2rem;
}
.btn-icon:hover { background: var(--bg-input); transform: scale(1.1); }
/* Style des petits boutons d'action dans les tableaux */
.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--bg-main);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.btn-icon:hover {
    transform: scale(1.1);
    background: var(--primary-soft);
}

/* Style spécifique pour le bouton de capture GPS dans la modale */
.btn-gps-capture {
    background: var(--primary);
    color: white;
    width: 45px;
    height: 45px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
    margin-top: auto; /* Aligne avec le bas des inputs */
}

.btn-gps-capture:hover {
    background: var(--primary-dark);
    box-shadow: 0 5px 15px rgba(99, 102, 241, 0.3);
}

.btn-gps-capture i.spinning {
    animation: spin 1s linear infinite;
}
/* Capture GPS & Drive (Classes Utilitaires) */
.btn-gps-capture {
    background: var(--info);
    color: white;
    width: 48px; height: 48px;
    border-radius: 12px;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: 0.3s;
}
.btn-gps-capture i.spinning { animation: spin 1s linear infinite; }

/* --- Cartographie & Planning --- */
#map, #global-map { width: 100%; height: 550px; border-radius: 30px; z-index: 1; }

.planning-container { display: flex; flex-direction: column; gap: 15px; }

.task-card {
    background: var(--surface);
    padding: 20px;
    border-radius: 25px;
    box-shadow: var(--shadow-soft);
    border-left: 6px solid var(--primary);
    display: flex; justify-content: space-between; align-items: center;
}
.task-card.urgent { border-left-color: var(--danger); }
.task-card.completed { border-left-color: var(--accent); opacity: 0.7; }

/* --- Sidebar Footer --- */
.sidebar-footer {
    padding: 25px;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

/* --- Toasts (v8) --- */
.toast {
    background: white;
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.1);
    margin-bottom: 12px;
    overflow: hidden;
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border-left: 6px solid var(--primary);
    z-index: var(--z-toast);
}
.toast.show { transform: translateX(0); }

/* --- Responsive Adaptations --- */
@media (max-width: 1200px) {
    .patient-horizontal-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Bouton fermer caché par défaut */
.mobile-close {
    display: none;
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 1.5rem;
    color: white;
    cursor: pointer;
    z-index: 10001;
}

@media (max-width: 1024px) {
    .mobile-close { display: block; } /* Visible sur mobile */

    .sidebar {
        position: fixed;
        left: -100%; /* Caché à gauche */
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 9999;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 10px 0 30px rgba(0,0,0,0.3);
    }

    .sidebar.active {
        left: 0; /* Ouvre le menu */
    }

    /* Overlay : Assombrit l'écran quand le menu est ouvert */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9998;
    }
    
    .sidebar-overlay.active { display: block; }
}

@media (max-width: 768px) {
    .burger-btn { display: block; }
    
    .sidebar {
        position: fixed; left: -280px;
        top: 0; bottom: 0; z-index: 10005;
        height: 100vh;
    }
    .sidebar.active { left: 0; }

    .sidebar-overlay {
        display: none; position: fixed; inset: 0;
        background: rgba(15, 23, 42, 0.5); z-index: 10004;
        backdrop-filter: blur(4px);
    }
    .sidebar-overlay.active { display: block; }

    .patient-horizontal-grid { grid-template-columns: 1fr; }
    .content { padding: 1rem; }
    header { padding: 1rem; }
    .modal-content { padding: 2rem 1.2rem; border-radius: 35px; }
    .stats-grid { grid-template-columns: 1fr; }
    
/* --- COMPOSANTS MISSIONS (INTERVENTIONS) --- */
.planning-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.intervention-card {
    background: white;
    padding: 20px;
    border-radius: 20px;
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(0,0,0,0.02);
    position: relative;
    overflow: hidden;
    animation: fadeInUp 0.5s ease backwards;
}

.intervention-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.08);
}

/* --- CATALOGUE (SERVICES & PRODUITS) --- */
#catalog-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* --- DASHBOARD MÉDECIN (DRIVE CARD) --- */
.drive-card {
    max-width: 800px;
    margin: 40px auto;
    padding: 40px;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(66, 133, 244, 0.1);
    background: linear-gradient(to bottom right, #ffffff, #f8faff);
    text-align: center;
}

/* --- RESPONSIVE ADAPTATIONS --- */
@media (max-width: 1200px) {
    .patient-horizontal-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .burger-btn { display: block; }
    
    .sidebar {
        position: fixed; left: -280px;
        top: 0; bottom: 0; z-index: 10005;
        height: 100vh;
    }
    .sidebar.active { left: 0; }

    .patient-horizontal-grid { grid-template-columns: 1fr; }
    .planning-container, #catalog-list { grid-template-columns: 1fr; }
    .content { padding: 1rem; }
}

/* --- UTILS --- */
.mgr-only { display: none; } /* Géré par JS */

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}
.user-location-dot div {
    animation: pulse-primary 2s infinite;
}

@keyframes pulse-primary {
    0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 15px rgba(99, 102, 241, 0); }
    100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* Fix pour Leaflet dans les grilles */
.leaflet-container {
    width: 100% !important;
    height: 100% !important;
    z-index: 1;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }

