:root {
    --primary: #2563eb;
    --danger: #dc2626;
    --warning: #d97706;
    --bg: #f8fafc;
    --carte-bg: #ffffff;
    --texte: #1e293b;
    --hauteur-topbar: 56px;
    --border: #e2e8f0;
    --ombre-carte: 0 1px 4px rgba(0, 0, 0, 0.08);
    --ombre-carte-survol: 0 8px 20px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--texte);
}

/* ---------- Connexion ---------- */

.page-connexion {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.carte-connexion {
    background: var(--carte-bg);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}

.carte-connexion h1 { margin: 0 0 4px; font-size: 22px; }
.carte-connexion p { margin: 0 0 20px; color: #64748b; }

.groupe-champ { margin-bottom: 16px; }
.groupe-champ label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; }
.groupe-champ input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 15px;
}

.btn-connexion {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.alerte-erreur {
    background: #fee2e2;
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.connexion-pied { margin-top: 20px; text-align: center; font-size: 12px; color: #94a3b8; }

/* ---------- App shell : sidebar bleu nuit + topbar, capitalisé depuis
   GestiPro (public/assets/css/layout.css) — cf. decisions.md.
   8 écrans seulement (contre 25+ chez GestiPro) : pas de regroupement par
   section, liste plate dans la sidebar. ---------- */

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: var(--hauteur-topbar) auto;
    min-height: 100vh;
}

.sidebar {
    grid-column: 1;
    grid-row: 1 / 3;
    background: #1e293b;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
    align-self: start;
    z-index: 300;
}

/* Espace plateforme (super_admin) : nuance plus sombre, même précédent GestiPro (admin.css). */
.sidebar-plateforme { background: #12263f; }

.sidebar-marque {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    height: var(--hauteur-topbar);
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-nom {
    font-size: 15px;
    font-weight: 700;
    color: #f1f5f9;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-fermer {
    display: none;
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    line-height: 1;
}
.sidebar-fermer:hover { color: #f1f5f9; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-lien {
    display: block;
    padding: 10px 16px;
    color: #94a3b8;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s, color .15s;
}
.nav-lien:hover { background: #334155; color: #f1f5f9; text-decoration: none; }
.nav-lien.actif { background: var(--primary); color: #fff; }

.sidebar-pied { border-top: 1px solid #334155; padding: 8px 0; flex-shrink: 0; }
.nav-deconnexion { color: #f87171 !important; }
.nav-deconnexion:hover { background: #7f1d1d !important; color: #fef2f2 !important; }

/* ---------- Topbar ---------- */

.topbar {
    grid-column: 2;
    grid-row: 1;
    height: var(--hauteur-topbar);
    position: sticky;
    top: 0;
    z-index: 200;
    background: var(--carte-bg);
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.topbar-gauche { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-droite { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }

.topbar-societe {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-utilisateur { color: #64748b; font-size: 14px; white-space: nowrap; }

.topbar-logout { color: var(--primary); text-decoration: none; font-size: 18px; line-height: 1; }
.topbar-logout:hover { color: var(--danger); }

.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    gap: 5px;
    padding: 4px;
    border-radius: 6px;
    flex-shrink: 0;
}
.hamburger:hover { background: var(--bg); }
.hamburger span { display: block; width: 20px; height: 2px; background: var(--texte); border-radius: 2px; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 250;
}
.sidebar-overlay.actif { display: block; }

.main-content { grid-column: 2; grid-row: 2; min-width: 0; }

@media (max-width: 768px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        grid-column: unset;
        grid-row: unset;
        position: fixed;
        top: 0;
        left: 0;
        width: 240px;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }
    .sidebar.ouvert { transform: translateX(0); box-shadow: 4px 0 24px rgba(0, 0, 0, .25); }
    .topbar { grid-column: 1; grid-row: 1; }
    .main-content { grid-column: 1; grid-row: 2; }
    .hamburger { display: flex; }
    .topbar-utilisateur { display: none; }
    .sidebar-fermer { display: flex; }
}

.contenu { padding: 20px; max-width: 1100px; margin: 0 auto; }

.bloc-kpi {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi {
    background: var(--carte-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--ombre-carte);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

/* border-top/right/bottom seulement : border-left reste piloté par
   .kpi-succes/.kpi-danger (accent sémantique), jamais écrasé au survol. */
.kpi:hover {
    transform: translateY(-3px);
    box-shadow: var(--ombre-carte-survol);
    border-top-color: var(--primary);
    border-right-color: var(--primary);
    border-bottom-color: var(--primary);
}

.kpi-label { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: #64748b; }
.kpi-valeur { display: block; font-size: 26px; font-weight: 700; margin-top: 8px; }
.kpi-solde .kpi-valeur { color: var(--primary); }

.kpi-niveau { display: block; font-size: 12px; font-weight: 600; margin-top: 4px; }

.rappel-abonnement { font-size: 13px; color: #64748b; margin: -8px 0 16px; }
.rappel-abonnement-attention { font-size: 13px; color: var(--warning); font-weight: 600; margin: -8px 0 16px; }
.rappel-abonnement-danger { font-size: 13px; color: var(--danger); font-weight: 600; margin: -8px 0 16px; }
.kpi-succes { border-left: 4px solid #15803d; }
.kpi-succes .kpi-niveau { color: #15803d; }
.kpi-danger { border-left: 4px solid var(--danger); }
.kpi-danger .kpi-niveau { color: var(--danger); }

/* ---------- Filtre de période (dashboard) ---------- */

.filtre-periode {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.btn-periode {
    padding: 8px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: var(--carte-bg);
    color: var(--texte);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
}

.btn-periode-actif {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.filtre-periode-date { margin-left: auto; }
.filtre-periode-date input { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; }

.table-repartition { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-repartition th, .table-repartition td { text-align: left; padding: 8px; border-bottom: 1px solid #e2e8f0; }
.table-repartition td:not(:first-child) { text-align: right; }
.table-repartition th:not(:first-child) { text-align: right; }

.bloc-alertes {
    background: var(--carte-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--ombre-carte);
    transition: box-shadow .15s ease, border-color .15s ease;
}

.bloc-alertes:hover { border-color: var(--primary); box-shadow: var(--ombre-carte-survol); }

.bloc-alertes h2 { margin: 0 0 16px; font-size: 16px; }

.table-alertes { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-alertes th, .table-alertes td { text-align: left; padding: 8px; border-bottom: 1px solid #e2e8f0; }
.table-alertes .alerte-urgente td:last-child { color: var(--danger); font-weight: 700; }
.table-alertes .alerte-proche td:last-child { color: var(--warning); font-weight: 700; }

.etat-vide { color: #94a3b8; font-size: 14px; }

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    .bloc-kpi { grid-template-columns: 1fr; }
    .table-alertes, .table-repartition { display: block; overflow-x: auto; }
    .filtre-periode-date { margin-left: 0; width: 100%; }
}

@media (max-width: 480px) {
    .carte-connexion { padding: 24px 20px; }
    .contenu { padding: 12px; }
}

/* ---------- Module : en-tête, formulaires, cartes d'opération ---------- */

.entete-module {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.entete-module h1 { margin: 0; }

.btn-secondaire {
    padding: 10px 16px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: transparent;
    color: var(--primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.carte-formulaire {
    background: var(--carte-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    box-shadow: var(--ombre-carte);
    margin-bottom: 20px;
}

.carte-formulaire h2 { margin: 0 0 16px; font-size: 16px; }
.carte-formulaire.masque { display: none; }

.champ-optionnel { font-weight: 400; color: #94a3b8; font-size: 12px; }

/* ---------- Combo recherche filtrée (véhicule, chauffeur…) ---------- */

.combo-filtre { position: relative; }
.combo-recherche {
    width: 100%;
    padding: 10px 36px 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    background: var(--carte-bg);
    color: var(--texte);
}
.combo-recherche:focus { outline: none; border-color: var(--primary); }
.combo-effacer {
    position: absolute;
    right: 4px;
    top: 4px;
    width: 30px;
    height: calc(100% - 8px);
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
}
.combo-effacer:hover { background: #f1f5f9; }
.combo-options {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 60;
    background: var(--carte-bg);
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 260px;
    overflow-y: auto;
    display: none;
}
.combo-options.ouvert { display: block; }
.combo-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #eef2f6;
}
.combo-option:last-child { border-bottom: none; }
.combo-option:hover, .combo-option.actif { background: #eff4ff; }
.combo-option-sub { font-size: 13px; color: #94a3b8; white-space: nowrap; }
.combo-vide { padding: 10px 12px; color: #94a3b8; font-size: 13px; font-style: italic; }
.combo-donnees { display: none; }

.alerte-succes {
    background: #dcfce7;
    color: #15803d;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.liste-cartes { display: flex; flex-direction: column; gap: 10px; }

.carte-operation {
    background: var(--carte-bg);
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    border-left: 4px solid var(--primary);
}

.carte-operation-depense { border-left-color: var(--danger); }

.carte-operation-ligne1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.carte-operation-depot .carte-operation-montant { color: #15803d; }
.carte-operation-depense .carte-operation-montant { color: var(--danger); }

.carte-operation-source { font-weight: 400; color: #94a3b8; font-size: 12px; }

.carte-operation-ligne2 {
    margin-top: 4px;
    font-size: 13px;
    color: #64748b;
}

.carte-operation-annuler { margin-top: 8px; }

.btn-lien-danger {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 13px;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
}

@media (max-width: 480px) {
    .entete-module { flex-direction: column; align-items: stretch; }
}

/* ---------- Cartes génériques (véhicules, chauffeurs, documents...) ---------- */

.carte-item {
    background: var(--carte-bg);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: var(--ombre-carte);
    transition: box-shadow .15s ease, border-color .15s ease;
}

.carte-item:hover { box-shadow: var(--ombre-carte-survol); }

.carte-item-alerte { border-left-color: var(--warning); }
.carte-item-urgente { border-left-color: var(--danger); }

.carte-item-ligne1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.carte-item-ligne2 { margin-top: 4px; font-size: 13px; color: #64748b; }

.carte-item-actions { margin-top: 8px; display: flex; gap: 16px; align-items: center; }

.lien-discret { color: var(--primary); font-size: 13px; text-decoration: none; font-weight: 600; }

.badge-alerte { color: var(--warning); }
.badge-urgente { color: var(--danger); }

.carte-item-source { font-weight: 400; color: #94a3b8; font-size: 12px; }

.entete-module-liens { display: flex; gap: 16px; align-items: center; }

.fil-ariane { font-size: 13px; color: #64748b; text-decoration: none; display: inline-block; margin-bottom: 8px; }
