/* =====================================================================
   responsive.css — Kpadjalé Doctor
   Menu burger + adaptation à tous les écrans. À charger APRÈS style.css.

   Points de rupture :
     > 992px  : ordinateur — barre latérale fixe, repliable (icônes seules)
     ≤ 992px  : tablette — la barre latérale devient un tiroir coulissant
     ≤ 768px  : mobile — formulaires et grilles sur une colonne
     ≤ 640px  : téléphone — les tableaux s'affichent en cartes empilées
     ≤ 400px  : petit téléphone
   ===================================================================== */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, video, canvas, iframe { max-width: 100%; }
img { height: auto; }
.layout { overflow-x: clip; }
.main { min-width: 0; }
.badge { white-space: nowrap; }

/* =====================================================================
   BOUTON BURGER
   ===================================================================== */
.burger-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 42px;
    height: 42px;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
    background: transparent;
    border: 1px solid #d5dfe0;
    border-radius: 10px;
    color: var(--primary-dark, #093f48);
    cursor: pointer;
    font-size: 0;
    line-height: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background .2s, border-color .2s;
}
.burger-btn:hover { background: #e6f2f2; border-color: #b9d3d5; }
.burger-btn:focus-visible { outline: 2px solid var(--primary, #0e6b7a); outline-offset: 2px; }
.burger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    transition: transform .28s ease, opacity .2s ease;
}
body.menu-open .burger-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.menu-open .burger-btn span:nth-child(2) { opacity: 0; }
body.menu-open .burger-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.sidebar-overlay { display: none; }
.sidebar-close { display: none; }

/* Barre du haut */
.topbar { gap: 12px; }
.topbar h2 { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { flex-shrink: 0; }
.btn-logout { display: inline-flex; align-items: center; gap: 4px; }
.btn-logout .logout-ico { display: none; }

/* Marque et liens du menu */
.sidebar-brand { display: flex; align-items: center; gap: 10px; line-height: 1.2; }
.sidebar-brand .brand-logo { height: 34px; width: auto; flex-shrink: 0; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; }
.sidebar nav a .nav-ico { width: 20px; text-align: center; flex-shrink: 0; }

/* Tableaux enveloppés automatiquement par responsive.js */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* =====================================================================
   ORDINATEUR (> 992px) : barre latérale collée à l'écran, repliable
   ===================================================================== */
@media (min-width: 993px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        align-self: flex-start;
        transition: width .25s ease;
        overflow-x: hidden;
    }
    body.sidebar-collapsed .sidebar { width: 72px; }
    body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 18px 0; }
    body.sidebar-collapsed .sidebar-brand .brand-text,
    body.sidebar-collapsed .sidebar .nav-txt { display: none; }
    body.sidebar-collapsed .nav-section { font-size: 0; padding: 8px 0 4px; margin: 0 14px; border-top: 1px solid rgba(255,255,255,.1); }
    body.sidebar-collapsed .sidebar nav a { justify-content: center; padding: 11px 0; gap: 0; }
    body.sidebar-collapsed .sidebar nav a .nav-ico { width: auto; font-size: 18px; }
}

/* =====================================================================
   TABLETTE ET MOBILE (≤ 992px) : barre latérale en tiroir
   ===================================================================== */
@media (max-width: 992px) {
    .sidebar {
        position: fixed !important;
        top: 0; left: 0; bottom: 0;
        height: 100%;
        height: 100dvh;
        width: 280px !important;
        max-width: 85vw;
        margin-left: 0 !important;
        transform: translateX(-105%);
        transition: transform .28s ease, box-shadow .28s ease;
        z-index: 1001;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    body.menu-open .sidebar { transform: translateX(0); box-shadow: 6px 0 28px rgba(0, 0, 0, .35); }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(5, 25, 30, .5);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: opacity .28s ease, visibility .28s ease;
        -webkit-tap-highlight-color: transparent;
    }
    body.menu-open .sidebar-overlay { opacity: 1; visibility: visible; }
    body.menu-open { overflow: hidden; }

    .sidebar-close {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 14px;
        right: 12px;
        width: 34px;
        height: 34px;
        border: none;
        border-radius: 50%;
        background: rgba(255, 255, 255, .14);
        color: #fff;
        font-size: 24px;
        line-height: 1;
        cursor: pointer;
        z-index: 2;
    }
    .sidebar-close:hover { background: rgba(255, 255, 255, .25); }
    .sidebar-brand { padding-right: 56px !important; }
    .sidebar nav a { min-height: 46px; font-size: 14.5px; }

    .topbar { position: sticky; top: 0; z-index: 50; padding: 12px 18px; }
    .content { padding: 18px; }
}

/* =====================================================================
   MOBILE (≤ 768px)
   ===================================================================== */
@media (max-width: 768px) {
    .topbar { padding: 10px 12px; gap: 10px; }
    .topbar h2 { font-size: 16px; }
    .topbar-right { gap: 8px; }
    .topbar .user-chip .user-name { display: none; }
    .topbar .user-chip { font-size: 18px; }
    .btn-logout { padding: 7px 10px !important; font-size: 0 !important; }
    .btn-logout .logout-ico { display: inline; font-size: 16px; }

    .content { padding: 14px 12px; }
    .licence-banner { padding: 8px 14px; }

    /* Cartes de statistiques : 2 par ligne */
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; margin-bottom: 16px; }
    .card { padding: 12px 14px; min-width: 0; }
    .card .value { font-size: 20px; word-break: break-word; }

    .panel { padding: 14px; margin-bottom: 16px; }
    .panel h3 { font-size: 16px; }

    /* Formulaires : une colonne */
    .form-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 12px; }
    .form-grid [style*="grid-column"] { grid-column: auto !important; }
    input, select, textarea { font-size: 16px !important; max-width: 100%; min-width: 0; } /* pas de zoom auto sur iPhone */

    .toolbar { align-items: stretch; }
    .toolbar input[type=search] { min-width: 0; width: 100%; flex: 1 1 100%; }
    .toolbar > form { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 8px; }
    .toolbar > form > * { flex: 1 1 auto; }

    /* Styles écrits directement dans les pages */
    [style*="grid-template-columns"]:not([style*="auto-fit"]):not([style*="auto-fill"]) { grid-template-columns: minmax(0, 1fr) !important; }
    [style*="display:flex"], [style*="display: flex"] { flex-wrap: wrap; }
    [style*="min-width"] { min-width: 0 !important; }
    [style*="width:220px"], [style*="width:140px"] { width: 100% !important; }

    .pub-grid { grid-template-columns: minmax(0, 1fr); }
    .pub-card img { height: 180px; }
    .recu { margin: 10px auto; padding: 16px; }
    .thumb-lg { max-width: 160px; }

    /* Tableaux qui défilent : cellules sur une ligne, textes longs repliés */
    table { font-size: 13px; }
    th, td { white-space: nowrap; padding: 9px 10px; }
    td.td-long { white-space: normal; min-width: 200px; max-width: 320px; }

    /* Pages de connexion / mot de passe / installation */
    .page-auth { padding: 16px; align-items: flex-start; padding-top: max(24px, 6vh); }
    .auth-box { width: 100% !important; max-width: 420px; padding: 28px 22px !important; }

    .alert, .alert-warn { word-break: break-word; }
}

/* =====================================================================
   TÉLÉPHONE (≤ 640px) : tableaux en cartes empilées
   (responsive.js ajoute .table-cards et les attributs data-label)
   ===================================================================== */
@media (max-width: 640px) {
    .table-wrap { background: transparent; box-shadow: none; overflow: visible; }
    table.table-cards,
    table.table-cards tbody,
    table.table-cards thead,
    table.table-cards tr,
    table.table-cards td { display: block; width: 100%; }
    table.table-cards tr.row-header { display: none; }
    /* Ligne de titre du tableau (th en colspan) : affichée comme un intitulé */
    table.table-cards tr.row-caption { background: transparent; border: none; box-shadow: none; padding: 0; margin: 0 0 8px; }
    table.table-cards tr.row-caption th { display: block; background: transparent; padding: 4px 2px; font-size: 13px; color: var(--primary-dark, #093f48); }

    table.table-cards tr {
        background: #fff;
        border: 1px solid #e2e9ea;
        border-radius: 10px;
        margin-bottom: 10px;
        padding: 4px 12px;
        box-shadow: 0 1px 3px rgba(0,0,0,.05);
    }
    table.table-cards tr:hover td { background: transparent; }
    table.table-cards td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 8px 0 !important;
        border-bottom: 1px dashed #e2e9ea;
        white-space: normal !important;
        text-align: right !important;
        min-width: 0 !important;
        max-width: none !important;
        word-break: break-word;
    }
    table.table-cards td:last-child { border-bottom: none; }
    table.table-cards td::before {
        content: attr(data-label);
        flex: 0 0 38%;
        text-align: left;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--primary-dark, #093f48);
        opacity: .75;
    }
    table.table-cards td.cell-title { font-weight: 700; font-size: 14.5px; }
    table.table-cards td.cell-nolabel { justify-content: flex-end; }
    table.table-cards td.cell-nolabel::before { display: none; }
    table.table-cards td[colspan] { justify-content: center; text-align: center !important; }
    table.table-cards td[colspan]::before { display: none; }
    table.table-cards td:empty { display: none; }

    /* Cellules d'actions : boutons alignés à droite, passage à la ligne sans écrasement */
    table.table-cards td.cell-actions { flex-wrap: wrap; justify-content: flex-end; gap: 6px; word-break: normal; }
    table.table-cards td.cell-actions::before { margin-right: auto; }
    table.table-cards td.cell-actions > * { flex: 0 0 auto; margin: 0 !important; }
    table.table-cards td.cell-actions .btn { white-space: nowrap; }
    table.table-cards td.cell-actions > form { display: inline-flex !important; gap: 6px; flex-wrap: wrap; align-items: center; }
    /* Formulaire dépliable (details) : pleine largeur une fois ouvert */
    table.table-cards td details { display: inline-block; text-align: left; }
    table.table-cards td details[open] { flex: 1 1 100% !important; order: 10; background: #f4f9f9; border-radius: 8px; padding: 8px; }
    table.table-cards td details form { display: block !important; }
    table.table-cards td details input, table.table-cards td details select, table.table-cards td details textarea { width: 100% !important; margin-bottom: 6px; }
}

/* =====================================================================
   PETIT TÉLÉPHONE
   ===================================================================== */
@media (max-width: 480px) {
    .burger-btn { width: 40px; height: 40px; }
    .topbar h2 { font-size: 15px; }
    .btn { padding: 9px 13px; }
    .toolbar > .btn, .toolbar > a.btn, .form-grid + .btn, .panel form > .btn[type=submit], .panel form > button.btn { width: 100%; text-align: center; }
}
@media (max-width: 400px) {
    table.table-cards td::before { flex-basis: 45%; }
}
@media (max-width: 340px) {
    .cards { grid-template-columns: minmax(0, 1fr) !important; }
}

/* =====================================================================
   GRANDS ÉCRANS
   ===================================================================== */
@media (min-width: 1600px) {
    .content { padding: 28px 40px; }
    .topbar { padding: 14px 40px; }
}

/* =====================================================================
   PORTAIL PATIENT : menu horizontal -> menu burger
   ===================================================================== */
.portal-topbar { position: relative; display: flex; align-items: center; flex-wrap: nowrap; }
.portal-topbar .burger-btn { display: none; order: 3; }
.portal-topbar .topnav-menu a.active { font-weight: 700; color: var(--primary-dark, #093f48); }
@media (max-width: 768px) {
    .portal-topbar { padding: 10px 12px !important; }
    .portal-topbar h2 { font-size: 16px; }
    .portal-topbar .burger-btn { display: inline-flex; }
    .portal-topbar .topnav-menu {
        display: none !important;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 0 !important;
        background: #fff;
        border-bottom: 1px solid #e2e6e3;
        box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
        z-index: 1001;
        padding: 6px 0;
    }
    body.menu-open .portal-topbar .topnav-menu { display: flex !important; }
    .portal-topbar .topnav-menu a { padding: 14px 20px; border-bottom: 1px solid #f0f2f1; font-size: 15px; }
    .portal-topbar .topnav-menu a.btn { margin: 10px 16px 6px; text-align: center; border: 1px solid #ccc; }
    body.portal-page.menu-open { overflow: auto; }
    body.portal-page .sidebar-overlay { top: 0; }
    main.content[style*="max-width:900px"] { padding: 14px 12px; }
}

/* ---------- Réduction des animations ---------- */
@media (prefers-reduced-motion: reduce) {
    .sidebar, .sidebar-overlay, .burger-btn span { transition: none !important; }
}

/* ---------- Impression : jamais de menu ni de burger ---------- */
@media print {
    .burger-btn, .sidebar, .sidebar-overlay, .sidebar-close { display: none !important; }
    .table-scroll { overflow: visible !important; }
}
