/* ============================================================
   KARYGO — thème de l'application
   Palette issue du logo : navy #14307E / bleu #1D5BDF / #2F7DF6
   ============================================================ */
:root {
    /* L'app est conçue en thème clair : on l'indique au navigateur pour
       désactiver le « mode sombre automatique » (Chrome Android) qui
       assombrissait les fonds blancs et rendait le texte illisible. */
    color-scheme: light;

    --kg-primary: #1D5BDF;
    --kg-primary-dark: #14307E;
    --kg-accent: #2F7DF6;
    --kg-navy: #0F1E45;
    --kg-sidebar-bg: linear-gradient(180deg, #0F1E45 0%, #142C66 100%);
    --kg-sidebar-muted: #8fa0c7;
    --kg-body-bg: #f3f5fb;
    --kg-border: #e5e9f2;
}

body {
    background-color: var(--kg-body-bg);
    color: #1c2434;
}

/* Boutons principaux aux couleurs de la marque */
.btn-primary {
    --bs-btn-bg: var(--kg-primary);
    --bs-btn-border-color: var(--kg-primary);
    --bs-btn-hover-bg: var(--kg-primary-dark);
    --bs-btn-hover-border-color: var(--kg-primary-dark);
    --bs-btn-active-bg: var(--kg-primary-dark);
    --bs-btn-active-border-color: var(--kg-primary-dark);
    background-image: linear-gradient(135deg, var(--kg-accent), var(--kg-primary));
    border: none;
}

.btn-primary:hover, .btn-primary:focus {
    background-image: linear-gradient(135deg, var(--kg-primary), var(--kg-primary-dark));
}

.form-control:focus, .form-select:focus {
    border-color: var(--kg-accent);
    box-shadow: 0 0 0 .2rem rgba(47, 125, 246, .15);
}

a { color: var(--kg-primary); }

/* ---------------------------- Layout ------------------------------- */
.kg-wrapper {
    display: flex;
    min-height: 100vh;
}

.kg-sidebar {
    width: var(--kg-sidebar-w, 250px);
    background: var(--kg-sidebar-bg);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 2px 0 14px rgba(15, 30, 69, .18);
    transition: width .18s ease, left .2s ease;
    z-index: 1050;
}

.kg-brand {
    padding: 1rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    display: flex;
    align-items: center;
    gap: .6rem;
    min-height: 68px;
    position: relative;
}

.kg-brand-logo {
    height: 42px;
    width: auto;
    display: block;
}

/* Emblème seul, affiché quand le menu est réduit */
.kg-brand-mark {
    display: none;
    height: 40px;
    width: 40px;
    margin: 0 auto;
}

.kg-mobile-close {
    position: absolute;
    top: 50%;
    right: .8rem;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, .1);
    border: none;
    color: #fff;
    border-radius: .45rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kg-mobile-close:hover {
    background: rgba(255, 255, 255, .2);
}

.kg-brand-chip {
    background: #fff;
    border-radius: .55rem;
    padding: 4px;
    display: inline-flex;
    flex-shrink: 0;
}

.kg-brand-chip img {
    height: 34px;
    width: 34px;
    object-fit: contain;
}

.kg-brand-name {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kg-nav {
    padding: .75rem 0;
    flex: 1;
}

.kg-nav .nav-section {
    padding: .9rem 1.25rem .35rem;
    font-size: .67rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--kg-sidebar-muted);
}

.kg-nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    margin: .1rem .6rem;
    padding: .55rem .7rem;
    border-radius: .55rem;
    color: #cdd8f3;
    text-decoration: none;
    font-size: .93rem;
    transition: background .15s ease, color .15s ease;
}

.kg-nav a i {
    width: 20px;
    text-align: center;
    font-size: 1.05rem;
    opacity: .9;
}

.kg-nav a:hover {
    background: rgba(255, 255, 255, .07);
    color: #fff;
}

.kg-nav a.active {
    background: linear-gradient(135deg, rgba(47, 125, 246, .95), rgba(29, 91, 223, .95));
    color: #fff;
    box-shadow: 0 3px 8px rgba(29, 91, 223, .35);
}

/* « Rédiger contrat » : l'action phare, toujours visible */
.kg-nav a.kg-nav-cta {
    border: 1px dashed rgba(124, 168, 255, .55);
    color: #dbe7ff;
    background: rgba(47, 125, 246, .12);
}

.kg-nav a.kg-nav-cta:hover {
    background: rgba(47, 125, 246, .28);
    border-style: solid;
}

/* Bouton réduire/agrandir — TOUJOURS visible en haut, dans la zone marque */
.kg-collapse-btn {
    margin-left: auto;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border: none;
    border-radius: .5rem;
    background: rgba(255, 255, 255, .1);
    color: #cdd8f3;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}

.kg-collapse-btn i {
    font-size: .85rem;
    transition: transform .18s ease;
}

.kg-collapse-btn:hover {
    background: rgba(255, 255, 255, .22);
    color: #fff;
}

.kg-brand-mark,
.kg-brand-chip {
    cursor: pointer;
}

.kg-sidebar-foot {
    padding: .9rem 1.25rem;
    font-size: .78rem;
    color: var(--kg-sidebar-muted);
    border-top: 1px solid rgba(255, 255, 255, .08);
    min-height: 20px;
}

.kg-main {
    margin-left: var(--kg-sidebar-w, 250px);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left .18s ease;
}

/* Fond assombri derrière le tiroir mobile */
.kg-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 30, 69, .55);
    z-index: 1049;
    backdrop-filter: blur(2px);
}

/* ------------------- Menu réduit (desktop uniquement) --------------- */
@media (min-width: 992px) {
    html.kg-collapsed {
        --kg-sidebar-w: 76px;
    }

    html.kg-collapsed .kg-sidebar {
        overflow: visible; /* laisse sortir les infobulles */
    }

    html.kg-collapsed .kg-nav-label {
        display: none;
    }

    html.kg-collapsed .kg-brand {
        padding: .8rem .5rem;
        flex-direction: column;
        justify-content: center;
        gap: .5rem;
    }

    html.kg-collapsed .kg-collapse-btn {
        margin-left: 0;
    }

    html.kg-collapsed .kg-brand-logo {
        display: none;
    }

    html.kg-collapsed .kg-brand-mark {
        display: block;
    }

    html.kg-collapsed .kg-brand-chip {
        margin: 0 auto;
    }

    html.kg-collapsed .kg-nav a {
        justify-content: center;
        padding: .6rem 0;
        position: relative;
    }

    html.kg-collapsed .kg-nav a i {
        font-size: 1.2rem;
        width: auto;
    }

    html.kg-collapsed .kg-collapse-btn {
        position: relative;
    }

    /* Infobulle au survol (libellé du lien) */
    html.kg-collapsed .kg-nav a::after,
    html.kg-collapsed .kg-collapse-btn::after {
        content: attr(data-tip);
        position: absolute;
        left: calc(100% + 12px);
        top: 50%;
        transform: translateY(-50%);
        background: var(--kg-navy);
        color: #fff;
        padding: .3rem .65rem;
        border-radius: .45rem;
        font-size: .78rem;
        font-weight: 500;
        white-space: nowrap;
        box-shadow: 0 4px 12px rgba(15, 30, 69, .35);
        opacity: 0;
        pointer-events: none;
        transition: opacity .12s ease;
        z-index: 1060;
    }

    html.kg-collapsed .kg-nav a:hover::after,
    html.kg-collapsed .kg-collapse-btn:hover::after {
        opacity: 1;
    }

    /* Les titres de section deviennent de fins séparateurs */
    html.kg-collapsed .kg-nav .nav-section {
        padding: 0;
        margin: .55rem 1rem;
        border-top: 1px solid rgba(255, 255, 255, .12);
        height: 0;
        overflow: hidden;
    }

    /* Chevron inversé quand le menu est réduit */
    html.kg-collapsed .kg-collapse-btn i {
        transform: rotate(180deg);
    }

    html.kg-collapsed .kg-sidebar-foot {
        padding: .6rem;
        text-align: center;
    }
}

.kg-topbar {
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--kg-border);
    padding: .7rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}

.kg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--kg-accent), var(--kg-primary-dark));
    color: #fff;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
}

.kg-content {
    padding: 1.5rem;
    flex: 1;
}

/* ---------------------------- Footer ------------------------------- */
.kg-footer {
    padding: .8rem 1.5rem;
    border-top: 1px solid var(--kg-border);
    background: #fff;
    display: flex;
    flex-wrap: wrap;
    gap: .5rem 1.5rem;
    align-items: center;
    justify-content: space-between;
    font-size: .8rem;
    color: #667085;
}

.kg-footer-credit {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    color: #667085;
    text-decoration: none;
}

.kg-footer-credit:hover {
    color: var(--kg-primary);
}

.kg-footer-credit img {
    height: 22px;
    width: auto;
    display: block;
}

/* ---------------------------- Widgets ------------------------------ */
.kg-stat {
    border: none;
    border-radius: .9rem;
    box-shadow: 0 1px 3px rgba(16, 24, 40, .08);
    transition: transform .12s ease, box-shadow .12s ease;
}

.kg-stat:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 24, 40, .1);
}

.kg-stat .kg-stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
}

.kg-stat .kg-stat-label {
    color: #667085;
    font-size: .82rem;
}

.kg-stat-icon {
    width: 46px;
    height: 46px;
    border-radius: .7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
}

.card {
    border: none;
    border-radius: .9rem;
    box-shadow: 0 1px 3px rgba(16, 24, 40, .07);
}

.card-header {
    border-bottom: 1px solid var(--kg-border);
    border-radius: .9rem .9rem 0 0 !important;
}

.table > :not(caption) > * > * {
    padding: .65rem .75rem;
}

.table thead th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #667085;
    font-weight: 600;
    background: #f8f9fd;
}

.badge {
    font-weight: 600;
}

.kg-badge-xs {
    font-size: .62rem;
    padding: .2em .5em;
}

.kg-logo-preview {
    width: 96px;
    height: 96px;
    border: 1px dashed #c6cede;
    border-radius: .75rem;
    background: #fafbfe;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    flex-shrink: 0;
}

.kg-logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ---------------------------- Connexion ---------------------------- */
.kg-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(600px 300px at 15% 10%, rgba(47, 125, 246, .25), transparent 60%),
        radial-gradient(700px 350px at 85% 90%, rgba(76, 154, 255, .18), transparent 60%),
        linear-gradient(150deg, #0F1E45 0%, #142C66 55%, #14307E 100%);
}

.kg-login-inner {
    width: 100%;
    max-width: 410px;
}

.kg-login-card {
    border-radius: 1.1rem;
    box-shadow: 0 20px 50px rgba(4, 10, 30, .45);
}

.kg-login-logo {
    width: 210px;
    max-width: 80%;
}

.kg-login-credit {
    margin-top: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    color: rgba(255, 255, 255, .75);
    font-size: .82rem;
    text-decoration: none;
}

.kg-login-credit:hover {
    color: #fff;
}

.kg-login-credit img {
    height: 24px;
    background: #fff;
    border-radius: .4rem;
    padding: 3px 7px;
}

/* ------------------------ Planning (calendrier) -------------------- */
.kg-cal-card .card-body {
    overflow: visible;
}

.kg-cal-scroll {
    overflow-x: auto;
    border: 1px solid var(--kg-border);
    border-radius: .6rem;
}

.kg-cal {
    min-width: calc(230px + var(--kg-cal-days, 31) * 40px);
}

.kg-cal-row {
    display: grid;
    grid-template-columns: 230px repeat(var(--kg-cal-days, 31), minmax(40px, 1fr));
    /* minmax : les lignes grandissent avec leur contenu — le nom du véhicule
       ne peut plus être tronqué ni chevaucher la ligne suivante. */
    grid-template-rows: repeat(var(--kg-cal-lanes, 1), minmax(50px, auto));
    border-bottom: 1px solid #eef1f7;
}

.kg-cal-row:not(.kg-cal-head):hover .kg-cal-vehicle {
    background: #f7faff;
}

.kg-cal-row:last-child {
    border-bottom: none;
}

.kg-cal-head {
    grid-template-rows: 48px;
    background: #f8f9fd;
    border-bottom: 1px solid var(--kg-border);
    position: sticky;
    top: 0;
    z-index: 4;
}

.kg-cal-head .kg-cal-vehicle {
    font-weight: 600;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #667085;
    background: #f8f9fd;
}

.kg-cal-vehicle {
    grid-column: 1;
    grid-row: 1 / -1;
    padding: .45rem .75rem;
    background: #fff;
    position: sticky;
    left: 0;
    z-index: 3;
    border-right: 1px solid var(--kg-border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .1rem;
    min-width: 0;
    line-height: 1.25;
}

.kg-cal-vehicle a {
    color: #14307E;
    font-size: .86rem;
}

.kg-cal-vehicle a:hover {
    color: var(--kg-primary);
}

.kg-cal-day-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-left: 1px solid #f1f3f8;
    line-height: 1.15;
}

.kg-cal-dow {
    font-size: .6rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #98a2b3;
}

.kg-cal-num {
    font-weight: 600;
    font-size: .85rem;
    color: #344054;
}

.kg-cal-day-head.is-weekend {
    background: #f1f4fa;
}

.kg-cal-day-head.is-today .kg-cal-num {
    background: var(--kg-primary);
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kg-cal-cell {
    grid-row: 1 / -1;
    border-left: 1px solid #f1f3f8;
    display: block;
}

.kg-cal-cell.is-weekend {
    background: #f8fafd;
}

.kg-cal-cell.is-today {
    background: rgba(29, 91, 223, .05);
}

.kg-cal-cell:hover {
    background: rgba(29, 91, 223, .1);
    box-shadow: inset 0 0 0 1px rgba(29, 91, 223, .4);
}

.kg-cal-bar {
    margin: 7px 3px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    padding: 0 .55rem;
    font-size: .76rem;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
    z-index: 2;
    overflow: hidden;
    white-space: nowrap;
    box-shadow: 0 2px 5px rgba(15, 30, 69, .28);
    transition: transform .1s ease, box-shadow .1s ease;
}

.kg-cal-bar:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(15, 30, 69, .35);
}

.kg-cal-bar:hover {
    filter: brightness(1.1);
    color: #fff;
}

.kg-cal-draft {
    background: #fff;
    color: #475467;
    border: 1.5px dashed #98a2b3;
    box-shadow: none;
}

.kg-cal-draft:hover {
    color: #1c2434;
}

.kg-cal-confirmed {
    background: linear-gradient(135deg, #2F7DF6, #1D5BDF);
}

.kg-cal-ongoing {
    background: linear-gradient(135deg, #22b357, #14883f);
}

.kg-cal-completed {
    background: #9aa6bb;
}

.kg-cal-maintenance {
    background: repeating-linear-gradient(45deg, #f59e0b, #f59e0b 8px, #dd8b00 8px, #dd8b00 16px);
}

.kg-cal-bar.cont-left {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    margin-left: 0;
}

.kg-cal-bar.cont-right {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    margin-right: 0;
}

.kg-dot {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    display: inline-block;
    vertical-align: -1px;
    margin-right: .25rem;
}

.kg-cal-legend .kg-cal-draft {
    border-width: 1px;
}

/* --------------- Aperçu « papier » du contrat (wizard) -------------- */
.kg-paper {
    background: #fff;
    border: 1px solid #d8dfec;
    border-radius: .5rem;
    box-shadow: 0 6px 24px rgba(15, 30, 69, .12);
    padding: 18px 20px;
    font-size: .72rem;
    color: #111;
    line-height: 1.35;
    max-width: 860px;
    margin: 0 auto;
}

.kg-paper .p-band {
    background: #EDF1FB;
    border: 1px solid #333;
    padding: 3px 8px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.kg-paper .p-title {
    border: 1.5px solid #B3261E;
    color: #B3261E;
    background: #EDF1FB;
    font-weight: 700;
    padding: 2px 10px;
    display: inline-block;
}

.kg-paper .p-box {
    border: 1px solid #333;
    margin-top: 6px;
}

.kg-paper .p-box-title {
    background: #DCE4F5;
    border-bottom: 1px solid #333;
    padding: 2px 8px;
    font-weight: 700;
    color: #14307E;
    display: flex;
    justify-content: space-between;
}

.kg-paper .p-row {
    display: flex;
    gap: .5rem;
    padding: 2.5px 8px;
    align-items: baseline;
}

.kg-paper .p-row .l { color: #333; min-width: 38%; }
.kg-paper .p-row .v {
    flex: 1;
    border-bottom: 1px dotted #999;
    font-weight: 700;
    color: #14307E;
    min-height: 1em;
}
.kg-paper .p-row .a { color: #333; direction: rtl; }

.kg-paper table.p-enc { width: 100%; border-collapse: collapse; }
.kg-paper table.p-enc td { border: 1px solid #999; padding: 2.5px 8px; }
.kg-paper table.p-enc .num { text-align: right; font-weight: 700; }
.kg-paper table.p-enc tr.strong td { background: #14307E; color: #fff; font-weight: 700; }

.kg-paper .p-brand { color: #B3261E; font-weight: 800; font-size: 1.05rem; }
.kg-paper .p-muted { color: #667085; font-size: .66rem; }

/* ------------------------- Responsive (mobile) --------------------- */
@media (max-width: 991.98px) {
    /* Tiroir hors écran ; l'état « réduit » desktop est ignoré ici */
    .kg-sidebar {
        width: 280px;
        max-width: 85vw;
        left: -290px;
        box-shadow: none;
    }

    body.kg-nav-open .kg-sidebar {
        left: 0;
        box-shadow: 4px 0 24px rgba(15, 30, 69, .35);
    }

    body.kg-nav-open .kg-backdrop {
        display: block;
    }

    body.kg-nav-open {
        overflow: hidden; /* fige la page derrière le tiroir */
    }

    .kg-main {
        margin-left: 0;
    }

    .kg-content {
        padding: 1rem;
    }

    .kg-topbar {
        padding: .6rem 1rem;
    }
}

/* ======================================================================
   Éditeur de contrat — colonnes hautes sur desktop, fluides sur mobile
   ====================================================================== */
.kg-editor-form { max-height: calc(100vh - 210px); overflow-y: auto; }
.kg-editor-preview { height: calc(100vh - 250px); min-height: 500px; }

/* ======================================================================
   Affinages MOBILE (≤ 991px) — corrige les problèmes d'interface constatés
   ====================================================================== */
@media (max-width: 991.98px) {
    /* Éditeur de contrat : fin du double-scroll, tout s'écoule naturellement */
    .kg-editor-form { max-height: none; overflow: visible; }
    .kg-editor-preview { height: 78vh; min-height: 320px; }

    /* Aperçu papier du contrat (wizard) : réduit et jamais débordant */
    .kg-paper { font-size: .68rem; padding: 12px 14px; overflow-x: auto; }

    /* Titre de la barre supérieure : tronqué au lieu de casser la mise en page */
    .kg-topbar h5 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* Cartes un peu plus compactes sur petit écran */
    .kg-content .card-body { padding: 1rem; }

    /* Boutons d'action en pied de formulaire : pleine largeur, empilés */
    .kg-actions-mobile { flex-direction: column; }
    .kg-actions-mobile > .btn, .kg-actions-mobile > form > .btn { width: 100%; }
}

/* Téléphone étroit : réduit encore les gouttières des grilles serrées */
@media (max-width: 575.98px) {
    .kg-content .row.g-2 { --bs-gutter-x: .5rem; }
    .kg-stat .kg-stat-value { font-size: 1.5rem; }
}

/* ==========================================================================
   ADAPTATION MOBILE GLOBALE — palette de classes réutilisables
   Appliquée écran par écran. Cible ≤ 767px (téléphone) sauf mention.
   ========================================================================== */

/* 1) En-tête de page (titre + action) : passe à la ligne au lieu de déborder.
      Usage : <div class="kg-page-head mb-3"> <h4>Titre</h4> <a class="btn">Action</a> </div> */
.kg-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem .75rem;
}
.kg-page-head > h1, .kg-page-head > h2, .kg-page-head > h3,
.kg-page-head > h4, .kg-page-head > h5 { margin-bottom: 0; min-width: 0; }

@media (max-width: 575.98px) {
    /* Très petit écran : l'action principale prend toute la largeur (facile à toucher). */
    .kg-page-head > .btn,
    .kg-page-head > .kg-page-head-actions { width: 100%; }
    .kg-page-head-actions { display: flex; gap: .5rem; }
    .kg-page-head-actions > .btn { flex: 1; }
}

/* 2) Barre d'actions en pied de formulaire : empilée, pleine largeur, action
      principale en haut. Usage : <div class="d-flex ... kg-form-actions"> … </div> */
@media (max-width: 767.98px) {
    .kg-form-actions { flex-direction: column-reverse; align-items: stretch !important; }
    .kg-form-actions > .btn,
    .kg-form-actions > form,
    .kg-form-actions > form > .btn,
    .kg-form-actions > a.btn { width: 100%; }
}

/* 3) Tableaux de données → CARTES empilées sur téléphone (fin du scroll horizontal).
      Usage : <table class="table kg-cards"> + data-label="Entête" sur chaque <td>.
      - ligne d'état vide : <tr class="kg-cards-empty">
      - cellule d'actions (boutons) : <td class="kg-cards-actions"> (sans data-label) */
@media (max-width: 767.98px) {
    .kg-cards thead { display: none; }
    .kg-cards, .kg-cards tbody, .kg-cards tfoot, .kg-cards tr, .kg-cards td, .kg-cards th {
        display: block;
        width: auto;
    }
    .kg-cards > tbody > tr {
        border: 1px solid var(--kg-border);
        border-radius: .7rem;
        padding: .25rem .1rem;
        margin-bottom: .6rem;
        background: #fff;
        box-shadow: 0 1px 2px rgba(16, 24, 40, .05);
    }
    .kg-cards > tbody > tr > td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        text-align: right;
        border: 0;
        padding: .3rem .8rem !important;
        min-height: 0;
    }
    /* Le libellé n'apparaît QUE sur les cellules porteuses d'un data-label :
       une cellule sans libellé (visuel, titre, barre) s'affiche pleine largeur,
       sans « trou » — dégradation propre même si une conversion est partielle. */
    .kg-cards > tbody > tr > td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: .7rem;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: #667085;
        text-align: left;
        flex: 0 0 40%;
    }
    /* Un progress/badge/valeur riche occupe l'espace restant */
    .kg-cards > tbody > tr > td > .progress { flex: 1; }
    /* Cellule d'actions : boutons alignés à droite (pas de libellé) */
    .kg-cards > tbody > tr > td.kg-cards-actions {
        justify-content: flex-end;
        gap: .4rem;
        border-top: 1px solid var(--kg-border);
        margin-top: .15rem;
        padding-top: .55rem !important;
    }
    /* Ligne « aucune donnée » : centrée, sans cadre de carte */
    .kg-cards > tbody > tr.kg-cards-empty {
        border: 0; box-shadow: none; background: transparent; margin-bottom: 0;
    }
    .kg-cards > tbody > tr.kg-cards-empty > td { justify-content: center; text-align: center; }
    /* Pied de tableau (totaux) : carte accentuée (th ET td).
       Pas de fond forcé : on respecte les variantes Bootstrap (table-dark/-light)
       pour garder un contraste texte correct. */
    .kg-cards > tfoot > tr {
        border: 1px solid var(--kg-border);
        border-radius: .7rem;
        overflow: hidden;
        padding: .1rem;
        margin-bottom: .6rem;
    }
    .kg-cards > tfoot > tr > th,
    .kg-cards > tfoot > tr > td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        border: 0;
        padding: .35rem .8rem;
    }
    .kg-cards > tfoot > tr > th[data-label]::before,
    .kg-cards > tfoot > tr > td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        color: #667085;
    }
}

/* 4) Cibles tactiles confortables au doigt (téléphone) */
@media (max-width: 767.98px) {
    .btn { min-height: 40px; }
    .btn-group-sm > .btn, .btn-sm { min-height: 36px; }
    .kg-cards .btn-sm, .table .btn-sm { min-height: 34px; }
    .form-control, .form-select { min-height: 44px; }
    .form-control-sm, .form-select-sm { min-height: 38px; }
    /* Empêche le zoom auto iOS au focus (police ≥ 16px sur les champs) */
    .form-control, .form-select { font-size: 16px; }
    .form-control-sm, .form-select-sm { font-size: .95rem; }
}

/* ==========================================================================
   Planning (calendrier) — optimisation MOBILE / tactile
   ========================================================================== */
@media (max-width: 991.98px) {
    /* Colonne véhicule plus étroite → plus de jours visibles à l'écran */
    .kg-cal-row {
        grid-template-columns: 118px repeat(var(--kg-cal-days, 31), minmax(42px, 1fr));
    }
    .kg-cal { min-width: calc(118px + var(--kg-cal-days, 31) * 42px); }
    .kg-cal-vehicle { padding: .4rem .5rem; }
    .kg-cal-vehicle a { font-size: .78rem; }
    .kg-cal-vehicle .small { font-size: .66rem; }
    .kg-cal-vehicle .kg-badge-xs { display: none; } /* gagne de la place */
    /* Scroll horizontal fluide + inertie tactile, avec repère visuel */
    .kg-cal-scroll {
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scrollbar-width: thin;
    }
    .kg-cal-day-head { scroll-snap-align: start; }
    /* Barres de réservation un peu plus hautes = plus faciles à toucher */
    .kg-cal-bar { min-height: 30px; font-size: .72rem; }
}
