/* style.css - Version Polished & Dark Mode Fixed */
/* Bloque les transitions au chargement pour éviter le flash */
body.preload, body.preload * {
    transition: none !important;
}
:root {
    /* --- THÈME CLAIR --- */
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    
    --header-bg: #1e293b;
    --header-text: #ffffff;
    --accent: #3b82f6;

    /* Blocs de couleur (Clair) */
    --bg-add: #f0fdf4;  --border-add: #bbf7d0; --text-add-title: #15803d;
    --bg-verif: #eff6ff; --border-verif: #dbeafe; --text-verif: #3b82f6;
    --bg-rempl: #fff7ed; --border-rempl: #ffedd5; --text-rempl: #f97316;
    --bg-header-table: #f1f5f9;

    /* Status Pills (Clair) */
    --pill-ok-bg: #dcfce7; --pill-ok-text: #166534;
    --pill-warn-bg: #fef9c3; --pill-warn-text: #854d0e;
    --pill-danger-bg: #fee2e2; --pill-danger-text: #991b1b;
}

/* --- THÈME SOMBRE (Vrai Mode Sombre Carbone) --- */
body.dark-mode {
    /* Base Carbone / OLED */
    --bg-body: #121212;          /* Noir profond standard */
    --bg-card: #1e1e1e;          /* Gris très sombre pour détacher les cartes */
    --bg-input: #2a2a2a;         /* Fond des champs de saisie */
    --text-main: #e4e4e7;        /* Blanc cassé (moins agressif que du pur blanc) */
    --text-muted: #a1a1aa;       /* Gris neutre pour le texte secondaire */
    --border: #3f3f46;           /* Bordures nettes mais discrètes */
    
    --header-bg: #18181b;        /* En-tête presque noir */
    --header-text: #ffffff;      /* Texte d'en-tête éclatant */
    
    /* Blocs de couleur (Fonds ultra-profonds pour contraster avec les textes fluos) */
    --bg-add: #122217;           /* Vert abyssal */
    --border-add: #1c3d28; 
    --text-add-title: #4ade80;   /* Vert menthe éclatant */
    
    --bg-verif: #0d1b2a;         /* Bleu abyssal */
    --border-verif: #1b365d; 
    --text-verif: #38bdf8;       /* Bleu ciel éclatant */
    
    --bg-rempl: #2a1408;         /* Orange abyssal */
    --border-rempl: #5c270d; 
    --text-rempl: #fb923c;       /* Orange éclatant */
    
    --bg-header-table: #27272a;  /* Gris légèrement plus clair pour les entêtes de tableau */

    /* Status Pills (Lisibilité maximale) */
    --pill-ok-bg: #064e3b; 
    --pill-ok-text: #6ee7b7;     /* Vert d'eau */
    --pill-warn-bg: #713f12; 
    --pill-warn-text: #fde047;   /* Jaune vif */
    --pill-danger-bg: #7f1d1d; 
    --pill-danger-text: #fca5a5; /* Rouge pastel/rosé pour adoucir */
}

/* BASE */
* { box-sizing: border-box; }
body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-body); color: var(--text-main);
    margin: 0; padding: 0; font-size: 15px;
    transition: background-color 0.3s, color 0.3s;
}
.container { max-width: 950px; margin: 0 auto; padding: 15px; }

/* HEADER */
header {
    background: var(--header-bg); color: var(--header-text);
    padding: 15px 20px; border-radius: 12px; margin-bottom: 25px;
    display: flex; justify-content: space-between; align-items: center;
    border: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 1.3rem; }
header nav a, header button.theme-btn { 
    color: #94a3b8; text-decoration: none; margin-left: 15px; font-weight: 600; 
    background:none; border:none; cursor:pointer; font-size:1.1rem; transition: color 0.2s;
}
header nav a:hover, header button.theme-btn:hover { color: #fff; }

/* BARRE DE TRI */
.sort-bar {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
    display: flex; align-items: center; gap: 15px;
    padding: 15px; margin-bottom: 30px; /* Espace augmenté ici */
}

/* CARTES VÉHICULES (Wrapper principal) */
.v-card-wrapper { 
    margin-bottom: 25px; 
    background: var(--bg-card); 
    border: 1px solid var(--border); 
    border-radius: 12px;
    /* La bordure de couleur sera gérée par le style inline PHP sur cet élément */
    border-left-width: 6px; 
    border-left-style: solid;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow: hidden; /* Important pour que le contenu ne dépasse pas les coins */
}

.v-summary { 
    padding: 20px; cursor: pointer; 
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-card);
}
.v-summary:hover { background-color: var(--bg-header-table); }

/* Zone Statut (Vérifier/Remplacer) */
.v-status-box { 
    text-align: right; min-width: 180px; 
    border-left: 1px solid var(--border); padding-left: 20px; 
    display: flex; flex-direction: column; gap: 8px; /* Espacement vertical */
}
.v-status-box > div { display: flex; justify-content: space-between; align-items: center; width: 100%; }

.type-label { font-size: 0.7rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-right: 10px; }

/* DÉTAILS */
.details-container { 
    display: none; 
    border-top: 1px solid var(--border); 
    background: var(--bg-card); 
    padding: 25px; 
}

.plaque { margin: 0 12px; padding: 4px 10px; background: var(--bg-body); border-radius: 6px; font-family: monospace; font-weight: bold; border: 1px solid var(--border); color: var(--text-main); font-size: 0.9rem; }

/* INPUTS */
input, select { 
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; 
    font-size: 0.95rem; width: 100%; background: var(--bg-input); color: var(--text-main);
    outline: none; transition: border-color 0.2s;
}
input:focus, select:focus { border-color: var(--accent); }

/* BOUTONS */
.btn-save { background: var(--accent); color: white; padding: 10px 20px; border-radius: 6px; font-weight: 600; border:none; }
.btn-save:hover { filter: brightness(110%); }

/* TABLEAU ENTRETIENS & WRAPPER RESPONSIVE */
.table-responsive {
    width: 100%;
    overflow-x: auto; /* Permet le scroll horizontal */
    -webkit-overflow-scrolling: touch; /* Scroll fluide sur iOS */
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 15px;
    background: var(--bg-card);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 650px; /* Empêche le texte de s'écraser */ }
thead tr { background-color: var(--bg-header-table) !important; }
th { text-align: left; padding: 12px 15px; font-size: 0.75em; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--border); }
td { padding: 15px; background: var(--bg-card); border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; } 
td:first-child { font-weight: 600; color: var(--text-main); border-right: 1px solid var(--border); width: 25%; }

/* PILLS */
.status-pill { padding: 5px 12px; border-radius: 20px; font-size: 0.75rem; font-weight: 800; display: inline-block; min-width: 80px; text-align: center; text-transform: uppercase; }
.bg-ok { background: var(--pill-ok-bg); color: var(--pill-ok-text); border: 1px solid var(--pill-ok-bg); }
.bg-warning { background: var(--pill-warn-bg); color: var(--pill-warn-text); border: 1px solid var(--pill-warn-bg); }
.bg-danger { background: var(--pill-danger-bg); color: var(--pill-danger-text); border: 1px solid var(--pill-danger-bg); }

/* Check Button */
.btn-validate { background: var(--bg-body); border: 1px solid var(--border); color: var(--text-muted); padding: 6px 12px; border-radius: 6px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; margin-top: 5px; cursor: pointer; }
.btn-validate:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* BARRE KM */
.update-km-bar { background: var(--bg-header-table); padding: 15px; border-radius: 8px; margin-bottom: 25px; display: flex; justify-content: flex-end; align-items: center; gap: 15px; border: 1px solid var(--border); }

/* ADMIN & DOCS */
.admin-box, .doc-card, .hist-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; color: var(--text-main); }
.admin-box { padding: 25px; margin-bottom: 25px; }
.admin-box h3 { margin-top: 0; border-bottom: 1px solid var(--border); padding-bottom: 15px; color: var(--text-main); }

.grid-v-master { display: grid; grid-template-columns: 3fr 1.6fr 1.8fr 1.8fr auto; gap: 15px; align-items: end; background: var(--bg-card); padding: 15px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 15px; }
.box-add { background: var(--bg-add); border: 1px solid var(--border-add); padding: 20px; border-radius: 10px; margin-bottom: 25px; }
.sub-grid-thresholds { display: grid; grid-template-columns: 1.2fr 1fr; gap: 8px; padding: 10px; border-radius: 6px; margin-top: 5px; }
.bg-rempl { background: var(--bg-rempl); border: 1px solid var(--border-rempl); }
.bg-verif { background: var(--bg-verif); border: 1px solid var(--border-verif); }
.task-grid-row { display: grid; grid-template-columns: 2fr 0.7fr 0.7fr 0.8fr 0.8fr auto; gap: 10px; align-items: center; padding: 12px; background: var(--bg-card); border-bottom: 1px solid var(--border); }

.lbl-mini { font-size: 0.7rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-bottom: 5px; display: block; }
.btn-sq { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 6px; color: white; border: none; font-size: 1.1rem; }
.sub-row-infos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 5px; }
.grid-global { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; }

/* POPUP SHARE */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1000; display: flex; justify-content: center; align-items: center; }
.modal-content { background: var(--bg-header-table); padding: 20px; border-radius: 8px; width: 90%; max-width: 400px; border: 1px solid var(--border); box-shadow: 0 10px 25px rgba(0,0,0,0.5); }

/* --- DOCUMENTS --- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 15px; margin-top: 20px; }
.doc-card { text-align: center; padding: 15px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; position: relative; transition: transform 0.2s; }
.doc-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.doc-icon { font-size: 2.5rem; display: block; margin-bottom: 5px; color: var(--text-muted); }
.doc-title { font-weight: bold; font-size: 0.85rem; color: var(--text-main); display: block; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-cat { font-size: 0.65rem; background: var(--bg-header-table); padding: 2px 6px; border-radius: 4px; color: var(--text-muted); text-transform: uppercase; border: 1px solid var(--border); }
.btn-view { display: block; background: var(--accent); color: white; text-decoration: none; padding: 6px; border-radius: 4px; font-size: 0.8rem; margin-top: 10px; font-weight: 600; text-align: center; }
.btn-del-abs { position: absolute; top: 5px; right: 5px; background: var(--pill-danger-bg); color: var(--pill-danger-text); border: none; border-radius: 50%; width: 22px; height: 22px; line-height: 22px; text-align: center; cursor: pointer; font-size: 0.9rem; padding: 0; }

/* --- MOBILE (Mise à jour totale) --- */
@media (max-width: 768px) {
    /* Menu Navigation */
    header { flex-direction: column; align-items: flex-start; gap: 15px; }
    header nav { display: flex; flex-wrap: wrap; gap: 12px; width: 100%; justify-content: space-between; align-items: center; }
    header nav a { margin-left: 0; }
    
    /* Boutons et formulaires */
    .btn-sq { width: 100%; }
    .sort-bar { flex-direction: column; align-items: stretch; }
    
    /* Barre de Mise à jour KM */
    .update-km-bar form { flex-direction: column; align-items: stretch !important; gap: 15px; }
    .update-km-bar form > div { justify-content: space-between; width: 100%; }
    .update-km-bar form input { width: 60% !important; } /* Agrandir l'input sur mobile */
    .update-km-bar button { width: 100%; }

    /* Admin Grids */
    .grid-v-master, .task-grid-row { grid-template-columns: 1fr !important; gap: 12px; }
    .v-summary { flex-direction: column; align-items: flex-start; gap: 15px; }
    .v-status-box { width: 100%; padding-left: 0; border-left: none; border-top: 1px solid var(--border); padding-top: 15px; gap: 10px; }
}