/* ═════════════════════════════════════════════════════════════════════════
   RESPONSIVE FOUNDATION — Appezy CRM
   Sprint A : safe-area + lisibilité + touch targets (v2 — corrections iPhone)
   ═════════════════════════════════════════════════════════════════════════ */

/* ─── 1. SAFE-AREA TOP : SEULEMENT la navbar principale (dark) ─── */
/* Important : on ne touche PAS aux navbars internes (fiche client, etc.)
   qui utilisent bg-gradient et vivent dans le body. Sinon ça décale le
   contenu des pages. */
nav.navbar.navbar-dark.bg-dark {
    padding-top: calc(.5rem + env(safe-area-inset-top, 0px)) !important;
    padding-left: calc(1rem + env(safe-area-inset-left, 0px));
    padding-right: calc(1rem + env(safe-area-inset-right, 0px));
}

/* ─── 2. SAFE-AREA BOTTOM : pagination + chat bubble ─── */
/* On garde la pagination fixée en bas avec une légère marge pour le
   Home Indicator, sans excès. */
.fixed-table-pagination {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 1030 !important;
}
#chatWidget {
    bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
}
@media (max-width: 575px) {
    #chatWidget {
        bottom: calc(58px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ─── 2b. BANNER "Version ordi / mobile" : masqué sur petit écran ─── */
/* Le banner flottait par-dessus la pagination et doublait les bars fixes.
   On le cache sur mobile — les users peuvent toujours passer en desktop via
   le menu utilisateur si besoin. Visible uniquement sur écrans larges. */
@media (max-width: 991px) {
    #view-switch-banner {
        display: none !important;
    }
}

/* ─── 3. INPUTS : 16px min sur mobile → bloque l'auto-zoom iOS Safari ─── */
@media (max-width: 991px) {
    input.form-control,
    input[type="text"].form-control,
    input[type="search"].form-control,
    input[type="email"].form-control,
    input[type="tel"].form-control,
    input[type="number"].form-control,
    input[type="password"].form-control,
    input[type="date"].form-control,
    input[type="datetime-local"].form-control,
    textarea.form-control,
    select.form-control {
        font-size: 16px !important;
    }
    .form-control-sm {
        font-size: 16px !important;
        padding: 6px 10px !important;
    }
}

/* ─── 4. INLINE-EDIT PILLS : touch target confortable sur mobile ─── */
@media (max-width: 991px) {
    .inline-edit-pill {
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        padding: 8px 12px !important;
        font-size: 13px !important;
    }
    .inline-edit-wrap {
        min-width: 140px !important;
    }
}

/* ─── 5. COMMENTAIRES : desktop tronqué / mobile en entier ─── */
/* Desktop : chaque ligne tronquée à 180px avec ellipsis (comportement initial) */
.comment-line {
    width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    cursor: default;
}
/* Mobile : on vire les contraintes, le commentaire s'affiche en entier */
@media (max-width: 767px) {
    .comment-line {
        width: auto !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        line-height: 1.45 !important;
        padding: 3px 0 !important;
    }
    #table tbody td:nth-child(10) {
        font-size: 13px !important;
        color: #334155 !important;
        cursor: default !important;
        padding: 8px !important;
    }
    #table tbody td:nth-child(10)::before {
        font-size: 11px !important;
        color: #64748b !important;
    }
}

/* ─── 6. TOUCH TARGETS : boutons fiche client + tabs ─── */
@media (max-width: 767px) {
    .navbar.bg-gradient.rounded-top .btn {
        min-height: 40px;
        font-size: 12px !important;
        padding: 6px 10px !important;
    }
    #nav-tab-client .nav-link {
        min-height: 40px;
        font-size: 12px !important;
        padding: 8px 12px !important;
        display: flex;
        align-items: center;
    }
    .btn-sm {
        min-height: 34px;
    }
}

/* ─── 7. MODALES mobile : bouton close accessible ─── */
@media (max-width: 767px) {
    .modal-content .close {
        font-size: 28px;
        padding: 10px 14px;
        min-width: 44px;
        min-height: 44px;
    }
}

/* ─── 7b. MODALE fiche client (#staticBackdrop) : plein largeur mobile ─── */
/* Desktop : 95% du viewport (comportement historique). Mobile : prend la
   quasi-totalité de l'écran via la règle .modal-dialog existante de
   mobile.css (calc(100% - 1rem)). L'inline style max-width: 95% qui
   bloquait ça a été retiré du HTML. */
@media (min-width: 576px) {
    #staticBackdrop .modal-dialog {
        max-width: 95% !important;
    }
}

/* ─── 8. BADGES : lisibilité minimum ─── */
@media (max-width: 767px) {
    .badge {
        font-size: 11px !important;
        padding: 3px 8px;
    }
}

/* ─── 8b. TABLE ROWS : kill transitions pour éviter flicker au refresh ─── */
/* Les rows ont un background-color dérivé du statut (via rowStyle JS).
   Bootstrap applique transition: background-color .15s sur les TR par défaut.
   Combiné avec le refresTable() toutes les 60s, on voyait un "sautillement"
   coloré visible. On désactive la transition sur les rows : le background
   s'applique instantanément sans animation. */
#table tbody tr,
#table tbody tr td {
    transition: none !important;
}

/* ─── 9. NOTIFICATIONS PANEL : safe-area sur drawer fullscreen ─── */
@media (max-width: 575px) {
    #notifPanel {
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   SPRINT B — Layout fluide
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── B.1 Admin dropdown : safe-area-top + max-height ajustée ─── */
/* Le dropdown était top:56px fixe — avec navbar padded pour safe-area,
   il se retrouvait par-dessus le contenu. On calcule top dynamique. */
@media (max-width: 575px) {
    #navbarDropdown + .dropdown-menu {
        top: calc(56px + env(safe-area-inset-top, 0px)) !important;
        max-height: calc(100vh - 56px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px) !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }
}

/* ─── B.2 Tables hors bootstrap-table : wrapper scroll horizontal ─── */
@media (max-width: 767px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    /* Toute table bare (sans wrapper responsive) → min-width: 100% et wrap possible */
    table:not(.fixed-table-body table):not(.bootstrap-table *) {
        max-width: 100%;
        word-break: break-word;
    }
}

/* ─── B.3 Touch targets : 44×44 minimum (Apple HIG / Material) ─── */
/* Règle globale sur mobile : tous les boutons/liens cliquables ≥ 44pt.
   Exceptions : icônes de décor (FA dans <i>), boutons déjà gérés par
   leur contexte (btn-sm, dropdown-item). */
@media (max-width: 767px) {
    button:not(.close):not(.btn-sm):not(.dropdown-item):not(.page-link):not(.navbar-toggler),
    .btn:not(.btn-sm):not(.dropdown-item):not(.close):not(.page-link) {
        min-height: 44px;
    }
    /* Boutons de page (pagination) plus cliquables */
    .page-link {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    /* Icônes de ligne dans les tables (actions) → 32×32 mini */
    .table .btn-sm i.fa,
    td .btn-link i.fa {
        font-size: 15px;
    }
}

/* ─── B.4 Fiche client : onglets scrollables + tap target ─── */
@media (max-width: 767px) {
    #nav-tab-client {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }
    #nav-tab-client .nav-link {
        min-width: 60px;
        text-align: center;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   SPRINT C — Polish + PWA
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── C.1 Landscape : modales avec body scrollable + footer sticky ─── */
/* Sur landscape (typ. 390×844px réduit à 390×390 visible keyboard),
   les formulaires dans des modales devenaient inatteignables.
   On fait : header non-scrollable en haut, body scrollable au milieu,
   boutons sticky en bas. */
@media (max-width: 991px) and (orientation: landscape) {
    .modal-dialog {
        max-height: 100vh;
        margin: 0 !important;
        max-width: 100% !important;
    }
    .modal-content {
        max-height: 100vh;
        display: flex;
        flex-direction: column;
        border-radius: 0 !important;
    }
    .modal-header {
        flex-shrink: 0;
    }
    .modal-body {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-footer {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        background: #fff;
        z-index: 10;
    }
}

/* ─── C.2 Typo + spacing harmonisés (design tokens mobile) ─── */
@media (max-width: 767px) {
    /* Base type scale mobile */
    body {
        font-size: 14px;
        line-height: 1.5;
    }
    h1 { font-size: 22px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    h5 { font-size: 15px !important; }
    h6 { font-size: 13px !important; }
    small {
        font-size: 12px !important;
    }
}

/* ─── C.3 Chat widget mobile : z-index + safe-area harmonisés ─── */
@media (max-width: 575px) {
    #chatBubble {
        width: 52px !important;
        height: 52px !important;
        font-size: 22px !important;
    }
}

/* ─── C.3b POLISH liste client : TOUT à gauche sur mobile ─── */
/* Reset défensif : toutes les cellules col 2 et col 3 + leurs descendants
   commencent au même x (padding-left 0, text-align left, margin-left 0).
   Sur cards mobile, les lignes nom / adresse / ID / tags / CP / ABF / tel
   doivent toutes partir du bord gauche interne de la card. */
@media (max-width: 767px) {
    #table tbody td:nth-child(2),
    #table tbody td:nth-child(3) {
        text-align: left !important;
        padding-left: 0 !important;
    }
    /* Force TOUT le contenu de col 2 et col 3 à démarrer à gauche */
    #table tbody td:nth-child(2) *,
    #table tbody td:nth-child(3) * {
        text-align: left !important;
    }
    /* Le wrapper <span> de col 2 (eligibiliteFormatter) doit s'afficher
       en block pour que ses enfants s'empilent proprement à gauche */
    #table tbody td:nth-child(2) > span {
        display: block !important;
        margin-left: 0 !important;
        padding-left: 0 !important;
    }
    /* Div flex des tags : flex-start + pas de marge auto */
    #table tbody td:nth-child(2) div[style*="flex"] {
        justify-content: flex-start !important;
        margin: 0 !important;
        max-width: 100% !important;
    }

    /* CP h5 : compact, pas de marge gauche */
    #table tbody td:nth-child(3) h5 {
        font-size: 12px !important;
        margin: 6px 0 0 !important;
        padding: 0 !important;
        font-weight: 600 !important;
    }
    /* Badge vert CP : compact */
    #table tbody td:nth-child(3) h5 .badge,
    #table tbody td:nth-child(3) h5 .badge-success,
    #table tbody td:nth-child(3) h5 span.badge {
        font-size: 10px !important;
        font-weight: 600 !important;
        padding: 2px 9px !important;
        border-radius: 10px !important;
        line-height: 1.3 !important;
        display: inline-block !important;
    }
    /* abfLine : bien collée à gauche sous le CP */
    #table tbody td:nth-child(3) h5 + div {
        margin: 4px 0 0 !important;
        padding: 0 !important;
    }
}
@media (max-width: 767px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    ::-webkit-scrollbar-thumb {
        background: rgba(100,116,139,.4);
        border-radius: 4px;
    }
}

