/* ===========================================================================
   Suivi des temps et des frais — Nouvel Envol
   Feuille de style unique. Mobile d'abord, puis tablette et ordinateur.
   =========================================================================== */

:root {
    color-scheme: light dark;

    /* Palette reprise de l'identité visuelle de nouvel-envol.fr */
    --accent:        #df4c2b;
    --accent-fonce:  #bd3e21;
    --accent-clair:  #fff4ec;

    --fond:        #f7fafc;
    --surface:     #ffffff;
    --surface-2:   #f7fafc;
    --bord:        #e2e8f0;
    --bord-fort:   #cbd5e0;

    --texte:       #1a202c;
    --doux:        #4a5568;
    --tres-doux:   #718096;

    --rouge:       #9b2c2c;
    --rouge-fond:  #fff5f5;
    --ambre:       #975a16;
    --ambre-fond:  #fffaf0;

    /* Police des titres. Pour passer un jour sur la typographie du site (Futura PT),
       il suffira d'héberger la police et de la déclarer ici. */
    --police-titre: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;

    --rayon:       14px;
    --rayon-sm:    10px;
    --ombre:       0 1px 2px rgba(16,24,20,.05), 0 6px 18px rgba(16,24,20,.05);

    --haut:        env(safe-area-inset-top, 0px);
    --bas:         env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --accent:       #f08560;
        --accent-fonce: #e56d44;
        --accent-clair: #35211a;

        --fond:       #12151c;
        --surface:    #1a202c;
        --surface-2:  #232a38;
        --bord:       #2d3748;
        --bord-fort:  #4a5568;

        --texte:      #f7fafc;
        --doux:       #a0aec0;
        --tres-doux:  #718096;

        --rouge:      #fc8181;
        --rouge-fond: #2c1b1b;
        --ambre:      #ecc94b;
        --ambre-fond: #2a2416;

        --ombre:      0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--fond);
    color: var(--texte);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-family: var(--police-titre); letter-spacing: -0.01em; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }

a { color: var(--accent); }

[hidden] { display: none !important; }

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

.page-connexion { display: grid; place-items: center; min-height: 100svh; padding: 1.25rem; }

.connexion { width: 100%; max-width: 24rem; }

.connexion-carte {
    background: var(--surface);
    border: 1px solid var(--bord);
    border-radius: 18px;
    padding: 2rem 1.6rem;
    box-shadow: var(--ombre);
}

.connexion-carte h1 { font-size: 1.3rem; margin-bottom: 1.25rem; }

.marque {
    font-family: var(--police-titre);
    display: flex; align-items: center; gap: .55rem;
    color: var(--accent); font-weight: 650; font-size: .95rem;
    margin-bottom: 1.5rem;
}

.connexion-carte label {
    display: block; font-size: .85rem; font-weight: 600;
    margin: 1rem 0 .35rem; color: var(--doux);
}

.connexion-carte input {
    width: 100%; padding: .75rem .85rem; font: inherit;
    border: 1px solid var(--bord-fort); border-radius: var(--rayon-sm);
    background: var(--surface-2); color: inherit;
}

.connexion-carte input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.alerte { border-radius: var(--rayon-sm); padding: .7rem .85rem; font-size: .9rem; margin: 0 0 1rem; }
.alerte-rouge { background: var(--rouge-fond); color: var(--rouge); border: 1px solid color-mix(in srgb, var(--rouge) 25%, transparent); }

/* ------------------------------------------------------------- Mise en page */

.appli { min-height: 100svh; }

.laterale { display: none; }

.contenu {
    padding: calc(var(--haut) + 1rem) 1rem calc(5.5rem + var(--bas));
    max-width: 56rem;
    margin: 0 auto;
}

.vue { display: none; }
.vue.active { display: block; animation: apparait .18s ease; }

@keyframes apparait { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.vue-entete {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}

/* ------------------------------------------------------------------ Cartes */

.carte, .bloc {
    background: var(--surface);
    border: 1px solid var(--bord);
    border-radius: var(--rayon);
    padding: 1.1rem;
    margin-bottom: 1rem;
    box-shadow: var(--ombre);
}

.bloc { padding: .5rem .5rem .25rem; }

.bloc-entete {
    display: flex; align-items: center; justify-content: space-between;
    padding: .6rem .65rem .5rem; gap: .75rem;
}

.sous-titre { font-size: 1rem; margin-bottom: .9rem; }

.carte-info { font-size: .9rem; color: var(--doux); }
.carte-info p { margin: 0 0 .75rem; }

/* ------------------------------------------------------------ Formulaires */

.champ { margin-bottom: 1rem; }
.champ:last-child { margin-bottom: 0; }

.champ > label, .bascule > span {
    display: block; font-size: .85rem; font-weight: 600;
    color: var(--doux); margin-bottom: .4rem;
}

.facultatif { font-weight: 400; color: var(--tres-doux); }

input[type=text], input[type=password], input[type=email], input[type=date], select {
    width: 100%;
    padding: .72rem .8rem;
    font: inherit; font-size: 1rem;
    border: 1px solid var(--bord-fort);
    border-radius: var(--rayon-sm);
    background: var(--surface-2);
    color: var(--texte);
    appearance: none;
    min-height: 46px;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%235d6a65' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .8rem center;
    background-size: 12px;
    padding-right: 2.2rem;
}

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}

input::placeholder { color: var(--tres-doux); }

.champ-suffixe { position: relative; display: flex; align-items: center; }
.champ-suffixe input { padding-right: 4.5rem; }
.champ-suffixe > span {
    position: absolute; right: .85rem; font-size: .88rem; color: var(--doux); pointer-events: none;
}

.aide { font-size: .8rem; color: var(--tres-doux); margin: .4rem 0 0; line-height: 1.45; }

.duo { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.bascule { display: flex; align-items: center; gap: .6rem; cursor: pointer; padding: .45rem 0; }
.bascule input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; flex: none; }
.bascule > span { margin: 0; color: var(--texte); font-weight: 500; font-size: .95rem; }

.actions-formulaire { display: flex; flex-direction: column; gap: .5rem; margin-top: 1.25rem; }

.calcul {
    background: var(--accent-clair); color: var(--accent-fonce);
    border-radius: var(--rayon-sm); padding: .7rem .85rem;
    font-weight: 600; font-size: .95rem; text-align: center; margin-bottom: 1rem;
}
@media (prefers-color-scheme: dark) { .calcul { color: var(--accent); } }

.ligne-ajout { display: flex; gap: .5rem; margin-top: .85rem; flex-wrap: wrap; }
.ligne-ajout input { flex: 1 1 8rem; min-width: 0; }
.ligne-ajout input#trajet-km { flex: 0 1 5.5rem; }

/* --------------------------------------------------------------- Boutons */

.bouton {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .7rem 1.05rem; min-height: 46px;
    font: inherit; font-size: .95rem; font-weight: 600;
    border: 1px solid transparent; border-radius: var(--rayon-sm);
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color .12s ease, opacity .12s ease;
}

.bouton-principal { background: var(--accent); color: #fff; }
.bouton-principal:hover { background: var(--accent-fonce); }
@media (prefers-color-scheme: dark) { .bouton-principal { color: #08140f; } }

.bouton-secondaire { background: var(--surface-2); color: var(--texte); border-color: var(--bord-fort); }
.bouton-secondaire:hover { background: var(--bord); }

.bouton-discret { background: transparent; color: var(--doux); }
.bouton-discret:hover { color: var(--texte); }

.bouton-danger { background: transparent; color: var(--rouge); border-color: color-mix(in srgb, var(--rouge) 35%, transparent); }

.bouton-large { width: 100%; padding: .85rem; font-size: 1rem; }

.bouton:disabled { opacity: .5; cursor: default; }

.bouton-icone {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; flex: none;
    font: inherit; font-size: 1.15rem; line-height: 1;
    background: var(--surface-2); color: var(--texte);
    border: 1px solid var(--bord-fort); border-radius: var(--rayon-sm);
    cursor: pointer;
}
.bouton-icone:hover { background: var(--bord); }

.lien-discret { color: var(--doux); font-size: .88rem; text-decoration: none; border-bottom: 1px solid var(--bord-fort); }
.lien-discret:hover { color: var(--texte); }

/* ----------------------------------------------------------------- Puces */

.puces { display: flex; flex-wrap: wrap; gap: .45rem; margin-top: .55rem; }

.puce {
    padding: .5rem .8rem; min-height: 40px;
    font: inherit; font-size: .88rem; font-weight: 500;
    background: var(--surface-2); color: var(--doux);
    border: 1px solid var(--bord-fort); border-radius: 999px;
    cursor: pointer;
}
.puce:hover { color: var(--texte); }
.puce.actif { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .puce.actif { color: #08140f; } }

.puces-periode { margin: 0 0 .85rem; }

.segments { display: flex; gap: .35rem; background: var(--surface-2); padding: .25rem;
            border: 1px solid var(--bord-fort); border-radius: var(--rayon-sm); }
.segment {
    flex: 1; padding: .55rem .5rem; min-height: 40px;
    font: inherit; font-size: .9rem; font-weight: 600;
    background: transparent; color: var(--doux);
    border: 0; border-radius: 7px; cursor: pointer;
}
.segment.actif { background: var(--surface); color: var(--texte); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ------------------------------------------------------------ Barre date */

.barre-date { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.date-champ { flex: 1; min-width: 0; }
.date-champ input { width: 100%; text-align: center; font-weight: 600; }
.bouton-aujourdhui {
    padding: 0 .85rem; height: 42px; flex: none;
    font: inherit; font-size: .85rem; font-weight: 600;
    background: var(--surface-2); color: var(--doux);
    border: 1px solid var(--bord-fort); border-radius: var(--rayon-sm); cursor: pointer;
}
.date-libelle {
    margin: -.6rem 0 1rem; text-align: center;
    font-size: .85rem; font-weight: 600; color: var(--doux);
}
.periode-libelle { flex: 1; text-align: center; font-weight: 650; font-size: .98rem; }

.compteur { display: flex; align-items: center; gap: .4rem; }
.compteur input { text-align: center; flex: 1; min-width: 0; }

/* La case « aller-retour » s'aligne sur le compteur plutôt que sur son libellé. */
#bloc-km .duo { align-items: end; }
#bloc-km .duo > .champ:last-child { padding-bottom: .15rem; }

/* ----------------------------------------------------------------- Listes */

.liste { display: flex; flex-direction: column; }

.ligne {
    display: flex; align-items: flex-start; gap: .75rem;
    padding: .8rem .65rem;
    border-top: 1px solid var(--bord);
}
.liste > .ligne:first-child { border-top: 0; }

.ligne-corps { flex: 1; min-width: 0; }
.ligne-titre { font-weight: 600; font-size: .95rem; }
.ligne-detail { font-size: .83rem; color: var(--doux); margin-top: .15rem; word-break: break-word; }
.ligne-valeur { font-weight: 650; font-size: .95rem; white-space: nowrap; text-align: right; }
.ligne-actions { display: flex; gap: .3rem; flex: none; }

.mini-bouton {
    width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center;
    font: inherit; font-size: .95rem; background: transparent; color: var(--tres-doux);
    border: 1px solid transparent; border-radius: 8px; cursor: pointer;
}
.mini-bouton:hover { background: var(--surface-2); color: var(--texte); border-color: var(--bord); }
.mini-bouton.danger:hover { color: var(--rouge); }

.liste-compacte .ligne { padding: .6rem .35rem; }

.ligne-cliquable { cursor: pointer; }
.ligne-cliquable:hover { background: var(--surface-2); }

.vide { padding: 1.5rem .65rem; text-align: center; color: var(--tres-doux); font-size: .9rem; }

.etiquette {
    display: inline-block; padding: .25rem .6rem;
    background: var(--accent-clair); color: var(--accent-fonce);
    border-radius: 999px; font-size: .82rem; font-weight: 650; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .etiquette { color: var(--accent); } }

.badge {
    display: inline-block; padding: .1rem .45rem; margin-left: .35rem;
    font-size: .7rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
    border-radius: 5px; background: var(--surface-2); color: var(--doux);
    border: 1px solid var(--bord-fort); vertical-align: 2px;
}
.badge-interne { background: var(--ambre-fond); color: var(--ambre); border-color: color-mix(in srgb, var(--ambre) 28%, transparent); }
.badge-forfait { background: var(--accent-clair); color: var(--accent-fonce); border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
@media (prefers-color-scheme: dark) { .badge-forfait { color: var(--accent); } }

/* -------------------------------------------------------------- Vignettes */

.vignettes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: 1rem; }

.vignette {
    background: var(--surface); border: 1px solid var(--bord);
    border-radius: var(--rayon); padding: .9rem; box-shadow: var(--ombre);
}
.vignette-libelle { font-size: .78rem; color: var(--doux); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.vignette-valeur { font-family: var(--police-titre); font-size: 1.5rem; font-weight: 600; margin-top: .25rem; letter-spacing: -.02em; }
.vignette-note { font-size: .78rem; color: var(--tres-doux); margin-top: .15rem; }

.jauge { height: 6px; border-radius: 3px; background: var(--bord); overflow: hidden; margin-top: .55rem; }
.jauge > div { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s ease; }
.jauge.alerte > div { background: var(--ambre); }
.jauge.depasse > div { background: var(--rouge); }

.exports { display: grid; gap: .5rem; margin-bottom: 1rem; }

/* ---------------------------------------------------------------- Onglets */

.onglets {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--bord);
    padding-bottom: var(--bas);
}

.onglet {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    padding: .5rem .2rem .55rem; min-height: 54px;
    font: inherit; font-size: .68rem; font-weight: 600;
    background: none; border: 0; color: var(--tres-doux); cursor: pointer;
}
.onglet svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7;
               stroke-linecap: round; stroke-linejoin: round; }
.onglet.actif { color: var(--accent); }

/* ---------------------------------------------------------------- Modales */

.modale {
    width: min(34rem, calc(100% - 1.5rem));
    max-height: 88svh;
    padding: 0; border: 1px solid var(--bord); border-radius: 18px;
    background: var(--surface); color: var(--texte);
    box-shadow: 0 24px 60px rgba(0,0,0,.25);
    overflow: hidden;
}
.modale::backdrop { background: rgba(10,14,12,.45); backdrop-filter: blur(3px); }
.modale form { display: flex; flex-direction: column; max-height: inherit; }

.modale-entete {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1.1rem 1.1rem .9rem; border-bottom: 1px solid var(--bord);
}
.modale-corps { padding: 1.1rem; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modale-pied {
    display: flex; gap: .6rem; justify-content: flex-end;
    padding: .9rem 1.1rem calc(.9rem + var(--bas)); border-top: 1px solid var(--bord);
    background: var(--surface-2);
}
.modale-pied .bouton-danger { margin-right: auto; }

.modale-petite { width: min(24rem, calc(100% - 2rem)); }
.modale-petite .modale-corps { padding: 1.4rem 1.3rem .9rem; }
.modale-petite p { margin: 0; font-size: .98rem; line-height: 1.55; }

.bouton-danger-plein { background: var(--rouge); color: #fff; }
.bouton-danger-plein:hover { filter: brightness(.93); }
@media (prefers-color-scheme: dark) { .bouton-danger-plein { color: #1b0f0d; } }

/* Tableau de détail */
.tableau { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tableau th, .tableau td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--bord); }
.tableau th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--doux); }
.tableau td.nombre, .tableau th.nombre { text-align: right; white-space: nowrap; }
.table-enveloppe { overflow-x: auto; }

/* ------------------------------------------------------- Toast, chargement */

.toast {
    position: fixed; left: 50%; bottom: calc(5rem + var(--bas)); transform: translate(-50%, 1rem);
    z-index: 90; max-width: calc(100% - 2rem);
    padding: .7rem 1.1rem; border-radius: 999px;
    background: #16201c; color: #fff; font-size: .9rem; font-weight: 500;
    opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.erreur { background: var(--rouge); }

.chargement {
    position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
    background: var(--fond);
}
.chargement.parti { display: none; }
.rouet {
    width: 26px; height: 26px; border-radius: 50%;
    border: 2.5px solid var(--bord); border-top-color: var(--accent);
    animation: tourne .7s linear infinite;
}
@keyframes tourne { to { transform: rotate(360deg); } }

/* =================================================== Tablette et ordinateur */

@media (min-width: 700px) {
    .vignettes { grid-template-columns: repeat(4, 1fr); }
    .actions-formulaire { flex-direction: row; justify-content: flex-end; }
    .actions-formulaire .bouton-large { width: auto; min-width: 11rem; }
    .exports { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 960px) {
    .appli { display: grid; grid-template-columns: 16rem 1fr; min-height: 100svh; }

    .laterale {
        display: flex; flex-direction: column;
        padding: calc(var(--haut) + 1.5rem) 1rem 1.5rem;
        border-right: 1px solid var(--bord);
        background: var(--surface);
        position: sticky; top: 0; height: 100svh;
    }
    .laterale .marque { padding: 0 .6rem; margin-bottom: 1.75rem; }

    .nav-laterale { display: flex; flex-direction: column; gap: .15rem; }
    .nav-lien {
        text-align: left; padding: .65rem .75rem; min-height: 44px;
        font: inherit; font-size: .93rem; font-weight: 550;
        background: none; border: 0; border-radius: var(--rayon-sm);
        color: var(--doux); cursor: pointer;
    }
    .nav-lien:hover { background: var(--surface-2); color: var(--texte); }
    .nav-lien.actif { background: var(--accent-clair); color: var(--accent-fonce); font-weight: 650; }
    @media (prefers-color-scheme: dark) { .nav-lien.actif { color: var(--accent); } }

    .laterale-pied { margin-top: auto; padding: 0 .75rem; display: flex; flex-direction: column; gap: .4rem; }
    .laterale-user { font-size: .85rem; color: var(--tres-doux); overflow: hidden; text-overflow: ellipsis; }

    .onglets { display: none; }
    .contenu { padding: 2rem 2rem 4rem; max-width: 64rem; }
    .toast { bottom: 2rem; }
}

/* ============================================================== Impression */

@media print {
    .laterale, .onglets, .exports, .bouton, .bouton-icone, .mini-bouton, .puces, .barre-date { display: none !important; }
    body { background: #fff; }
    .carte, .bloc { border: 0; box-shadow: none; padding: 0; }
}
