:root {
    /* Palette sombre */
    --bg: #0d1420;
    --bg-elevated: #121a28;
    --bg-card: #17202f;
    --bg-hover: #1e2a3c;
    --bg-input: #0f1826;
    --bordure: #263349;
    --texte: #e7edf5;
    --texte-att: #ffffff;
    --gris: #8a97ab;
    --gris-clair: #1c2637;

    /* Couleurs sémantiques (mêmes noms que dans les pages PHP, valeurs adaptées au fond sombre) */
    --bleu: #38bdf8;
    --bleu-fonce: #0ea5e9;
    --vert: #34d399;
    --orange: #fb923c;
    --rouge: #f87171;
    --accent: #2dd4bf;
    --accent-soft: rgba(45, 212, 191, 0.14);

    --radius: 12px;
    --radius-lg: 16px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--texte);
    font-size: 15px;
}

a { color: var(--bleu); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===================== Mise en page générale (sidebar) ===================== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 92px;
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-right: 1px solid var(--bordure);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 0 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100%;
    flex: 1;
}

.side-sep { width: 40px; height: 1px; background: var(--bordure); margin: 6px 0; }

.side-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 76px;
    padding: 5px 4px;
    border-radius: var(--radius);
    color: var(--gris);
    text-decoration: none;
    font-size: 10.5px;
    text-align: center;
    line-height: 1.2;
}
.side-link svg { flex-shrink: 0; }
.side-link:hover { background: var(--bg-hover); color: var(--texte); text-decoration: none; }
.side-link.actif { background: var(--accent-soft); color: var(--accent); }
.side-logout { margin-top: auto; color: var(--gris); }
.side-logout:hover { background: rgba(248, 113, 113, 0.12); color: var(--rouge); }

.side-cta {
    font-weight: 700;
    margin-top: auto;
    margin-bottom: 6px;
}
.side-cta-reservation { background: var(--vert); color: #052e21 !important; }
.side-cta-reservation:hover { background: #6ee7b7; color: #052e21 !important; text-decoration: none; }
.side-cta-materiel { background: #a78bfa; color: #2e1065 !important; margin-top: 0; }
.side-cta-materiel:hover { background: #c4b5fd; color: #2e1065 !important; text-decoration: none; }

/* Barre compacte mobile (masquée sur ordinateur) */
.mobile-topbar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--bordure);
    position: sticky;
    top: 0;
    z-index: 50;
}
.mobile-menu-btn {
    background: var(--bg-card);
    border: 1px solid var(--bordure);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--texte);
    flex-shrink: 0;
    cursor: pointer;
}
.mobile-cta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 700;
    padding: 7px 11px;
    border-radius: 999px;
    white-space: nowrap;
    text-decoration: none;
}
.mobile-cta:hover { text-decoration: none; }
.mobile-cta-vert { background: var(--vert); color: #052e21; }
.mobile-cta-violet { background: #a78bfa; color: #2e1065; }

/* Voile de fond derrière le tiroir de menu mobile (masqué sur ordinateur) */
.drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 900;
}
.drawer-header { display: none; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar-mini {
    height: 58px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 28px;
    border-bottom: 1px solid var(--bordure);
}
.user-chip { font-size: 13px; color: var(--gris); }

main.container {
    max-width: 1240px;
    width: 100%;
    margin: 0 auto;
    padding: 26px 28px 60px;
}

h1 { font-size: 22px; margin: 0 0 4px; color: var(--texte-att); }
h2 { font-size: 18px; margin: 26px 0 12px; color: var(--texte-att); }
.souligne { color: var(--gris); font-size: 14px; margin-bottom: 20px; }

/* ===================== Cartes / tableau de bord ===================== */
.grille-cartes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}
.carte {
    background: var(--bg-card);
    border: 1px solid var(--bordure);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
}
.carte .chiffre { font-size: 28px; font-weight: 700; color: var(--texte-att); }
.carte .libelle { color: var(--gris); font-size: 13px; margin-top: 3px; }
.carte.alerte { border-color: var(--orange); background: rgba(251, 146, 60, 0.08); }
.carte.alerte .chiffre { color: var(--orange); }

/* ===================== Tableaux ===================== */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    overflow: hidden;
}
th, td {
    text-align: left;
    padding: 11px 13px;
    border-bottom: 1px solid var(--bordure);
    font-size: 14px;
}
th { background: var(--bg-elevated); font-weight: 600; color: var(--texte-att); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }
code { background: var(--bg-input); padding: 2px 6px; border-radius: 5px; font-size: 13px; color: var(--accent); }

/* Style de base pour les champs de formulaire même en dehors de .champ (ex: select dans un tableau) */
select, input[type="text"], input[type="number"], input[type="email"], input[type="password"], input[type="date"], input[type="search"] {
    background: var(--bg-input);
    color: var(--texte);
    border: 1px solid var(--bordure);
    border-radius: 8px;
    padding: 6px 8px;
    font-family: inherit;
    font-size: 14px;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
select option { background: var(--bg-elevated); color: var(--texte); }

/* ===================== Badges de statut ===================== */
.badge {
    display: inline-block;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-gris { background: rgba(138, 151, 171, 0.18); color: #c3cbd8; }
.badge-bleu { background: rgba(56, 189, 248, 0.18); color: var(--bleu); }
.badge-orange { background: rgba(251, 146, 60, 0.18); color: var(--orange); }
.badge-vert { background: rgba(52, 211, 153, 0.18); color: var(--vert); }
.badge-rouge { background: rgba(248, 113, 113, 0.18); color: var(--rouge); }

/* ===================== Boutons ===================== */
.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: var(--radius);
    background: var(--accent);
    color: #06251f;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}
.btn:hover { background: #5eead4; text-decoration: none; color: #06251f; }
.btn.secondaire { background: var(--bg-card); color: var(--texte); border: 1px solid var(--bordure); }
.btn.secondaire:hover { background: var(--bg-hover); }
.btn.danger { background: var(--rouge); color: #2b0b0b; }
.btn.danger:hover { background: #fca5a5; }
.btn.vert { background: var(--vert); color: #052e21; }
.btn.vert:hover { background: #6ee7b7; }
.btn-sm { padding: 5px 11px; font-size: 13px; }

.barre-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

/* ===================== Formulaires ===================== */
form.formulaire { background: var(--bg-card); border: 1px solid var(--bordure); border-radius: var(--radius-lg); padding: 22px; max-width: 700px; }
.champ { margin-bottom: 16px; }
.champ label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 14px; color: var(--texte-att); }
.champ input, .champ select, .champ textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--bordure);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--texte);
}
.champ input::placeholder, .champ textarea::placeholder { color: #56637a; }
.champ input:focus, .champ select:focus, .champ textarea:focus { outline: none; border-color: var(--accent); }
.champ .aide { color: var(--gris); font-size: 12px; margin-top: 4px; }
.ligne-champs { display: flex; gap: 14px; }
.ligne-champs .champ { flex: 1; }

/* ===================== Messages d'alerte ===================== */
.alerte-msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}
.alerte-msg.succes { background: rgba(52, 211, 153, 0.12); color: var(--vert); border-color: rgba(52, 211, 153, 0.3); }
.alerte-msg.erreur { background: rgba(248, 113, 113, 0.12); color: var(--rouge); border-color: rgba(248, 113, 113, 0.3); }
.alerte-msg.info { background: rgba(56, 189, 248, 0.12); color: var(--bleu); border-color: rgba(56, 189, 248, 0.3); }
.alerte-msg.attention { background: rgba(251, 146, 60, 0.12); color: var(--orange); border-color: rgba(251, 146, 60, 0.3); }

/* ===================== Scan ===================== */
.scan-zone {
    background: var(--bg-card);
    border: 2px dashed var(--accent);
    border-radius: var(--radius-lg);
    padding: 30px;
    text-align: center;
    margin-bottom: 20px;
}
.scan-zone input {
    font-size: 22px;
    text-align: center;
    padding: 14px;
    width: 100%;
    max-width: 400px;
    border: 2px solid var(--accent);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--texte);
}

/* Flash plein écran de confirmation lors d'un scan caméra réussi */
#flash-succes {
    position: fixed;
    inset: 0;
    background: var(--vert);
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.12s ease-out;
}
#flash-succes.actif { opacity: 0.75; }

/* ===================== Connexion ===================== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at 30% 20%, #16283a 0%, var(--bg) 60%);
}
.login-box {
    background: var(--bg-card);
    border: 1px solid var(--bordure);
    padding: 36px;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 360px;
}
.login-box h1 { text-align: center; margin-bottom: 24px; }

/* ===================== Bon de sortie (reste clair, pensé pour l'impression) ===================== */
.bon-sortie {
    background: #ffffff;
    color: #111827;
    padding: 30px;
    max-width: 800px;
    margin: 0 auto;
    border: 1px solid #e5e7eb;
}
.bon-sortie h1 { text-align: center; color: #111827; }
.bon-logo { display: block; max-width: 160px; max-height: 90px; margin-bottom: 10px; }
.bon-ligne-info { display: flex; justify-content: space-between; gap: 20px; color: #111827; font-size: 14px; margin-bottom: 6px; }
.bon-ligne-info-pleine { color: #111827; font-size: 14px; margin-bottom: 6px; }
.bon-sortie table { margin: 20px 0; background: #ffffff; border-color: #e5e7eb; }
.bon-sortie th { background: #f3f4f6; color: #111827; }
.bon-sortie td { color: #111827; border-color: #e5e7eb; }
.bon-sortie .signatures { display: flex; justify-content: space-between; margin-top: 60px; }
.bon-sortie .signatures div { width: 45%; border-top: 1px solid #111827; padding-top: 6px; text-align: center; }
.bon-pied { text-align: center; font-size: 11px; font-style: italic; color: #6b7280; margin-top: 40px; }

/* Cartes de l'historique des réservations */
.historique-carte {
    background: var(--bg-card);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}
.historique-entete { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }

/* Planche d'étiquettes code-barres (reste claire, pensée pour l'impression) */
.planche-etiquettes {
    width: 210mm;
    max-width: 100%;
    margin: 10mm auto;
    background: #ffffff;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3mm;
    padding: 8mm;
    border-radius: 8px;
}
.planche-etiquettes .etiquette {
    border: 1px dashed #bbb;
    border-radius: 2mm;
    padding: 2mm 3mm;
    height: 30mm;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    page-break-inside: avoid;
    background: #ffffff;
}
.planche-etiquettes .nom {
    font-size: 10px;
    font-weight: bold;
    color: #111827;
    margin-bottom: 1mm;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.planche-etiquettes svg { max-width: 100%; height: 16mm; }
.planche-etiquettes .emplacement { font-size: 8px; color: #555; margin-top: 1mm; }

@media print {
    .planche-etiquettes { margin: 0; border-radius: 0; }
    .planche-etiquettes .etiquette { border: none; }
}

@media print {
    .no-print { display: none !important; }
    body { background: white; }
    .bon-sortie { border: none; }
}

/* ===================== Agenda ===================== */
.agenda-mois { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.agenda-jour-nom { text-align: center; font-weight: 600; font-size: 12px; color: var(--gris); padding: 4px; }
.agenda-case {
    min-height: 90px;
    border: 1px solid var(--bordure);
    border-radius: 8px;
    background: var(--bg-card);
    padding: 5px;
    font-size: 12px;
    display: flex;
    flex-direction: column;
}
.agenda-case.hors-mois { background: transparent; border-color: rgba(38, 51, 73, 0.4); color: #3a4864; }
.num-jour { font-weight: 600; margin-bottom: 4px; color: var(--texte-att); }
.num-jour-lien { text-decoration: none; display: inline-block; }
.num-jour-lien:hover { color: var(--accent); text-decoration: none; }
.agenda-compteur { font-weight: 400; color: var(--gris); font-size: 11px; }
.agenda-voir-plus { display: block; font-size: 11px; color: var(--accent); margin-top: 2px; text-decoration: none; }
.agenda-voir-plus:hover { text-decoration: underline; }
.agenda-evenement {
    background: var(--bleu);
    color: #04202e;
    border-radius: 5px;
    padding: 2px 5px;
    margin-bottom: 2px;
    font-size: 11px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}
.agenda-evenement.sortie { background: var(--orange); color: #341603; }
.agenda-evenement.retournee { background: var(--vert); color: #04291d; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

table.items-form td { vertical-align: middle; }
.ajouter-ligne { margin-top: 8px; }

/* ===================== Responsive (mobile / tablette) ===================== */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
.table-scroll table { border-radius: 0; }

.agenda-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Vue liste mobile : masquée sur ordinateur, affichée en @media plus bas */
.agenda-vue-liste { display: none; }

.agenda-jour-mobile {
    background: var(--bg-card);
    border: 1px solid var(--bordure);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
}
.agenda-jour-mobile.aujourdhui { border-color: var(--bleu); border-width: 2px; }
.agenda-jour-mobile-titre {
    display: block;
    font-weight: 600;
    color: var(--texte-att);
    margin-bottom: 8px;
    text-decoration: none;
    font-size: 14px;
}
.agenda-jour-mobile-titre:hover { color: var(--accent); text-decoration: none; }
.agenda-evenement-mobile {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--bleu);
    color: #04202e;
    text-decoration: none;
    margin-bottom: 6px;
    font-size: 13px;
}
.agenda-evenement-mobile:last-child { margin-bottom: 0; }
.agenda-evenement-mobile:hover { text-decoration: none; opacity: 0.9; }
.agenda-evenement-mobile span { font-size: 12px; opacity: 0.85; }
.agenda-evenement-mobile.sortie { background: var(--orange); color: #341603; }
.agenda-evenement-mobile.retournee { background: var(--vert); color: #04291d; }

/* Vue zoom sur une journée précise */
.agenda-jour-zoom { display: flex; flex-direction: column; gap: 10px; max-width: 700px; }
.agenda-carte-evenement {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--bordure);
    border-radius: 10px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--texte);
}
.agenda-carte-evenement:hover { border-color: var(--accent); text-decoration: none; }
.agenda-carte-entete { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.agenda-carte-entete strong { color: var(--texte-att); font-size: 15px; }
.agenda-carte-details { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--gris); }

@media (max-width: 900px) {
    .app-layout { flex-direction: column; }

    .mobile-topbar { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        z-index: 1000;
        padding: 14px 10px;
    }
    .sidebar.ouvert { transform: translateX(0); }

    .drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 4px 8px 12px;
        color: var(--texte-att);
        font-weight: 600;
        border-bottom: 1px solid var(--bordure);
        margin-bottom: 8px;
    }
    .drawer-close { background: none; border: none; color: var(--gris); padding: 4px; cursor: pointer; display: flex; }

    .sidebar-nav { flex-direction: column; align-items: stretch; gap: 2px; }
    .side-sep { width: auto; height: 1px; margin: 6px 4px; }
    .side-link {
        width: auto;
        flex-direction: row;
        justify-content: flex-start;
        gap: 10px;
        padding: 10px 10px;
        font-size: 14px;
    }
    .side-link span { display: inline; }

    .side-cta { display: none; }

    .drawer-overlay.ouvert { display: block; }

    main.container { padding: 16px 12px 40px; }

    .barre-actions { flex-direction: column; align-items: stretch; }
    .barre-actions > div:first-child { margin-bottom: 4px; }

    .ligne-champs { flex-direction: column; gap: 0; }

    table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; max-width: 100%; }
    table thead, table tbody, table tr { display: table; width: auto; }

    .grille-cartes { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
    .carte { padding: 12px 14px; }
    .carte .chiffre { font-size: 22px; }

    .agenda-vue-grille { display: none; }
    .agenda-vue-liste { display: block; }
    .agenda-carte-details { flex-direction: column; gap: 4px; }

    form.formulaire { padding: 16px; }

    .bon-sortie { padding: 16px; }
    .bon-ligne-info { flex-direction: column; gap: 2px; }
    .bon-sortie .signatures { flex-direction: column; gap: 30px; }
    .bon-sortie .signatures div { width: 100%; }
}

@media (max-width: 480px) {
    .login-box { padding: 24px; margin: 0 16px; }
    h1 { font-size: 19px; }
}
