:root {
    --accent: #194180;
    --accent-deep: #122F5E;
    --cta-1: #E33622;
    --cta-2: #FFAA00;
    --bg: #F4F6FA;
    --surface: #FFFFFF;
    --text: #1A2233;
    --text-muted: #6B7488;
    --border: #E3E7EF;
    --rail-width: 260px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
    }
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.rail {
    width: var(--rail-width);
    background: var(--accent-deep);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    flex-shrink: 0;
}

.rail .brand {
    font-family: "Montserrat", sans-serif;
    font-weight: 700;
    font-size: 20px;
    margin-bottom: 32px;
    padding: 0 8px;
}

.rail nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rail nav a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
}

.rail nav a:hover {
    background: rgba(255, 255, 255, 0.08);
}

.rail nav a.active {
    background: var(--accent);
    color: #fff;
}

.rail .rail-footer {
    margin-top: auto;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    padding: 0 8px;
}

.main {
    flex: 1;
    padding: 32px 40px;
}

.main h1 {
    font-family: "Montserrat", sans-serif;
    margin-top: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
}

.badge {
    display: inline-block;
    background: var(--cta-2);
    color: #3a2900;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 6px;
    margin-left: 8px;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 340px;
}

.login-box h1 {
    font-family: "Montserrat", sans-serif;
    color: var(--accent-deep);
    font-size: 22px;
    margin-top: 0;
}

.login-box label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin: 16px 0 6px;
}

.login-box input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
}

.login-box button {
    width: 100%;
    margin-top: 24px;
    padding: 12px;
    background: var(--cta-1);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

.error {
    background: #FDEDEB;
    color: var(--cta-1);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-top: 16px;
}

/* ------------------------------------------------------------------ */
/* Mobile / tablette (commerciaux terrain) — le rail passe en barre   */
/* horizontale en haut de l'écran au lieu d'une colonne fixe de 260px. */
/* ------------------------------------------------------------------ */
@media (max-width: 768px) {
    .app-shell {
        flex-direction: column;
        height: 100vh;
        min-height: 100vh;
    }

    .rail {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 14px 16px;
        gap: 6px 14px;
    }

    .rail .brand {
        margin-bottom: 0;
        font-size: 17px;
        flex: 1 1 auto;
        padding: 0 4px;
    }

    .rail nav {
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        gap: 6px;
        order: 3;
    }

    .rail nav a {
        padding: 8px 12px;
        font-size: 13px;
    }

    .rail .rail-footer {
        margin-top: 0;
        order: 2;
        font-size: 11px;
        text-align: right;
        white-space: nowrap;
        padding: 0 4px;
    }

    .main {
        padding: 16px;
        min-height: 0;
    }

    .main.main--full-bleed {
        padding: 0;
        min-height: 0;
    }

    .login-box {
        width: calc(100% - 32px);
        max-width: 386px;
        box-sizing: border-box;
        padding: 28px 22px;
    }
}

@media (max-width: 480px) {
    .rail .brand {
        font-size: 15px;
    }

    .rail nav a {
        padding: 7px 10px;
        font-size: 12.5px;
    }

    .main {
        padding: 12px;
    }
}

/* ------------------------------------------------------------------ */
/* Phase 16 — Refonte de l'en-tête mobile + correctifs responsive     */
/* (bloc ajouté en fin de fichier : il complète les règles ci-dessus) */
/* ------------------------------------------------------------------ */
html, body {
    margin: 0;
}

body {
    font-family: "Lexend", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

.rail nav a.btn-cta svg {
    display: none; /* le libellé contient déjà « + » : évite le double « + + » */
}

@media (max-width: 768px) {
    /* La largeur de la barre inclut désormais son padding : plus de débordement horizontal */
    .rail {
        box-sizing: border-box;
        max-width: 100%;
        padding: 12px 14px 12px;
        gap: 10px 12px;
    }

    .rail .brand {
        flex: 1 1 auto;
        min-width: 0;
    }

    .rail .rail-footer {
        white-space: normal;
        line-height: 1.35;
        max-width: 50%;
    }

    /* Navigation : grille propre (CTA pleine largeur puis 5 onglets alignés) */
    .rail nav {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr)) 44px;
        gap: 6px;
        width: 100%;
    }

    .rail nav > div {
        display: none; /* légendes d'aide : utiles sur desktop seulement */
    }

    .rail nav a {
        box-sizing: border-box;
        text-align: center;
        padding: 9px 4px;
        font-size: 13px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        background: rgba(255, 255, 255, 0.06);
        border-radius: 8px;
        min-width: 0;
    }

    .rail nav a.active {
        background: var(--accent);
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
    }

    .rail nav a.btn-cta {
        order: -1;
        grid-column: 1 / -1;
        margin: 0 !important;
        padding: 12px 14px;
        font-size: 15px;
        font-weight: 600;
        background: linear-gradient(90deg, #e33622 0%, #e33622 65%, #ffaa00 100%);
        box-shadow: none;
    }

    /* Libellés courts des onglets sur mobile */
    .rail nav a[href*="air-eau"],
    .rail nav a[href*="air-air"],
    .rail nav a[href*="parametres"] {
        font-size: 0;
    }

    .rail nav a[href*="air-eau"]::after { content: "Air Eau"; font-size: 13px; }
    .rail nav a[href*="air-air"]::after { content: "Air Air"; font-size: 13px; }
    .rail nav a[href*="parametres"]::after { content: "\2699"; font-size: 17px; line-height: 1; }

    .main h1 {
        font-size: 24px;
        margin-bottom: 12px;
    }

    /* Fiche client : les 3 cartes coordonnées s'empilent, l'email revient à la ligne */
    #client-fiche div:has(> .fiche-coord-card) {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .fiche-coord-card {
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: break-word;
    }
}

@media (max-width: 480px) {
    .rail nav a {
        font-size: 12.5px;
        padding: 9px 2px;
    }

    .rail nav a[href*="air-eau"]::after,
    .rail nav a[href*="air-air"]::after {
        font-size: 12.5px;
    }
}

/* Accueil : le tableau des dossiers devient une liste de cartes sur téléphone */
@media (max-width: 600px) {
    .dossiers-table thead {
        display: none;
    }

    .dossiers-table,
    .dossiers-table tbody {
        display: block;
        width: 100%;
    }

    .dossiers-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 4px 12px;
        padding: 12px 2px;
        border-bottom: 1px solid var(--border);
    }

    .dossiers-table td {
        display: block;
        padding: 0 !important;
        border: 0 !important;
        min-width: 0;
    }

    .dossiers-table td:nth-child(1) { grid-column: 1; grid-row: 1; font-weight: 600; }
    .dossiers-table td:nth-child(2) { grid-column: 2; grid-row: 1; justify-self: end; }
    .dossiers-table td:nth-child(3) { grid-column: 1; grid-row: 2; font-size: 12.5px; color: var(--text-muted); }
    .dossiers-table td:nth-child(4) { grid-column: 1; grid-row: 3; font-size: 12.5px; color: var(--text-muted); }
    .dossiers-table td:nth-child(5) { grid-column: 2; grid-row: 2 / span 2; justify-self: end; }
}

/* ------------------------------------------------------------------ */
/* Phase 22 — Logo Econolia dans le rail et sur l'écran de connexion   */
/* ------------------------------------------------------------------ */
.rail .brand-logo {
    display: block;
    width: 180px;
    max-width: 100%;
    height: auto;
}

.rail .brand-sub {
    display: block;
    margin-top: 6px;
    font-family: "Montserrat", sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.6);
}

.login-logo {
    display: block;
    width: 220px;
    max-width: 80%;
    height: auto;
    margin: 0 auto 22px;
}

@media (max-width: 768px) {
    .rail .brand-logo {
        width: auto;
        height: 34px;
    }

    .rail .brand-sub {
        display: none;
    }
}

@media (max-width: 480px) {
    .rail .brand-logo {
        height: 30px;
    }
}

/* ------------------------------------------------------------------ */
/* Phase 22 bis — Logo aux couleurs d'origine sur carte blanche (option A) */
/* ------------------------------------------------------------------ */
.rail .brand {
    padding: 0;
}

.rail .brand-card {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #ffffff;
    border-radius: 12px;
    padding: 14px 16px;
}

.rail .brand-card .brand-logo {
    width: 190px;
    max-width: 100%;
    height: auto;
}

@media (max-width: 768px) {
    .rail .brand-card {
        display: inline-flex;
        border-radius: 8px;
        padding: 6px 10px;
    }

    .rail .brand-card .brand-logo {
        width: auto;
        height: 30px;
    }
}

/* ------------------------------------------------------------------ */
/* Sous-menu Paramètres visible sur téléphone (pastilles sous les      */
/* onglets) — le sous-menu des simulateurs reste masqué sur mobile.    */
/* ------------------------------------------------------------------ */
@media (max-width: 768px) {
    .rail nav > .subnav:not(#crm-subnav) {
        display: flex !important;
        order: 10;
        grid-column: 1 / -1;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        margin: 2px 0 0;
        padding: 2px 0 2px;
    }

    .rail nav > .subnav:not(#crm-subnav) .subnav-item,
    .rail nav > .subnav:not(#crm-subnav) .subnav-item--nested {
        flex: 0 0 auto;
        padding: 7px 12px;
        font-size: 12.5px;
        line-height: 1.2;
        white-space: nowrap;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.08);
        opacity: 0.9;
    }

    .rail nav > .subnav:not(#crm-subnav) .subnav-item.active {
        background: #ffffff;
        color: #122F5E;
        opacity: 1;
        font-weight: 700;
    }

    /* les liens du sous-menu contiennent "parametres" : on annule l'icône engrenage des onglets */
    .rail nav > .subnav:not(#crm-subnav) .subnav-item::after {
        content: none;
    }

    .rail nav > .subnav:not(#crm-subnav) .subnav-item.active {
        box-shadow: none;
    }

    .rail nav > .subnav:not(#crm-subnav) .subnav-group {
        display: none;
    }
}