/* ============================================================================
   responsive.css — Adaptation mobile (consultation)
   Charge EN DERNIER dans base.html pour surcharger style.css / admin-ui.css.
   Ne s'active qu'en dessous de 768px : le bureau reste strictement identique.
   Perimetre : login, liste transactions (table 13 colonnes -> cartes), header.
   Aucune modif du JS metier ni des routes.
   ============================================================================ */

/* --- Bouton burger : cache par defaut, visible seulement en mobile --------- */
.mobile-burger {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1100;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 8px;
    background: #2d3748;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* Voile sombre derriere la sidebar ouverte (mobile) */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 1040;
}

/* ============================================================================
   MOBILE  (<= 768px)
   ============================================================================ */
@media (max-width: 768px) {

    /* ---- Burger visible ---------------------------------------------------- */
    .mobile-burger { display: flex; }

    /* ---- Sidebar : hors-ecran par defaut, glisse depuis la gauche ---------- */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px !important;
        max-width: 80vw;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 1050;
        overflow-y: auto;
    }
    /* Classe ajoutee par le JS burger pour ouvrir le menu */
    .sidebar.mobile-open { transform: translateX(0); }
    .mobile-overlay.show { display: block; }

    /* Le bouton "reduire" du bureau n'a pas de sens en mobile */
    .toggle-btn { display: none !important; }

    /* Les libelles texte du menu sont utiles en mobile (on annule un eventuel
       mode "collapse" herite du bureau) */
    .sidebar .sidebar-menu span { display: inline !important; }
    #small_logo_aro { display: none !important; }
    #logo_aro { display: inline !important; }

    /* ---- Contenu principal : pleine largeur -------------------------------- */
    .main-content,
    #mainContent,
    .not_authenticated,
    #mainContent2 {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .content {
        padding: 12px !important;
        /* laisse la place au burger en haut a gauche */
        padding-top: 60px !important;
    }

    /* ---- Header : compact, on laisse la place au burger -------------------- */
    .header {
        padding-left: 60px !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .header-user span {
        max-width: 55vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* ---- Toolbar transactions : passe en colonne, boutons pleine largeur --- */
    .tx-toolbar {
        flex-wrap: wrap;
        gap: 8px;
    }
    .tx-toolbar-btn {
        flex: 1 1 auto;
        justify-content: center;
    }
    .tx-toolbar-sep { display: none; }

    /* ========================================================================
       TABLEAU 13 COLONNES -> CARTES EMPILEES
       Technique : on passe chaque <tr> en "carte" et chaque <td> en ligne
       libelle/valeur. Le libelle vient de l'attribut data-label (ajoute dans
       le template) ; a defaut, la cellule s'affiche sans libelle.
       ======================================================================== */
    .item-table thead {
        /* en-tetes masques visuellement mais accessibles */
        position: absolute;
        width: 1px; height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .item-table,
    .item-table tbody,
    .item-table tr,
    .item-table td {
        display: block;
        width: 100% !important;
    }

    .item-table tr {
        margin: 0 0 12px 0;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        padding: 8px 12px;
        background: #fff;
        box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
    }

    .item-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 7px 0 !important;
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        text-align: right;
        min-height: 34px;
        white-space: normal;
        word-break: break-word;
    }
    .item-table td:last-child { border-bottom: none !important; }

    /* Libelle de colonne, injecte via data-label */
    .item-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #4a5568;
        text-align: left;
        flex: 0 0 42%;
        white-space: nowrap;
    }
    /* Cellule sans libelle (ex: checkbox) : pas de pseudo-element vide gourmand */
    .item-table td[data-label=""]::before,
    .item-table td:not([data-label])::before { content: ""; flex: 0; }

    /* La cellule des sous-documents (colspan) reprend toute la largeur en bloc */
    .item-table td[colspan] {
        text-align: left;
    }
    .item-table td[colspan]::before { content: ""; }

    /* Sous-tableau des documents : meme traitement carte */
    .docs-table thead { display: none; }
    .docs-table, .docs-table tbody, .docs-table tr, .docs-table td { display: block; width: 100%; }
    .docs-table tr {
        border: 1px dashed #cbd5e0;
        border-radius: 8px;
        margin: 8px 0;
        padding: 6px 10px;
    }
    .docs-table td {
        display: flex;
        justify-content: space-between;
        gap: 10px;
        padding: 5px 0;
        text-align: right;
        word-break: break-word;
    }
    .docs-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #4a5568;
        text-align: left;
    }

    /* Actions : boutons accessibles au doigt */
    .doc-actions, td[id^="actions_"] {
        flex-wrap: wrap;
        justify-content: flex-end !important;
        gap: 6px;
    }
    .btn-row { flex-wrap: wrap; gap: 6px; }

    /* ---- Login / pages auth : carte centree, marges confortables ----------- */
    .login-wrap { padding: 16px; }
    .login-card { width: 100%; max-width: 420px; }

    /* ---- Modale QR : tient dans l'ecran ------------------------------------ */
    .modal-content { max-width: 92vw !important; }
}

/* ============================================================================
   TRES PETITS ECRANS (<= 420px) : libelles au-dessus des valeurs
   ============================================================================ */
@media (max-width: 420px) {
    .item-table td,
    .docs-table td {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        gap: 2px;
    }
    .item-table td::before { flex: none; }
    .header-user span { max-width: 70vw; }
}
