/* =====================================================================
 * ANNA RH & Paie — expérience téléphone « comme une application »
 * Chargé après app.css. Tout est limité aux écrans de 900 px et moins,
 * sauf les éléments masqués sur ordinateur.
 * ===================================================================== */

.tabbar, .drawer-backdrop, .drawer-user, .drawer-foot { display: none; }

@media (max-width: 900px) {
    :root {
        --tabbar-h: 62px;
        --topbar-h: 56px;
        --safe-top: env(safe-area-inset-top, 0px);
        --safe-bottom: env(safe-area-inset-bottom, 0px);
    }

    html, body { overscroll-behavior-y: none; -webkit-text-size-adjust: 100%; }
    body { -webkit-tap-highlight-color: transparent; background: var(--c-bg); }
    * { -webkit-tap-highlight-color: transparent; }

    /* Anciennes navigations mobiles : remplacées */
    .mobile-bottom-nav, .mobile-menu-panel, .mobile-menu-backdrop, .espace-mobile-nav, .footer, .app-footer, footer.footer { display: none !important; }

    /* ---------- Structure ---------- */
    .app-shell { display: block !important; min-height: 100dvh; }
    .app-main { margin: 0 !important; width: 100% !important; min-width: 0; }
    .main-content {
        padding: calc(var(--topbar-h) + var(--safe-top) + 12px) 12px calc(var(--tabbar-h) + var(--safe-bottom) + 18px) !important;
        max-width: 100% !important;
    }
    .page { padding: 0 !important; max-width: 100% !important; }

    /* ---------- Barre du haut ---------- */
    .topbar {
        position: fixed !important; top: 0; left: 0; right: 0; z-index: 900;
        height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) 6px 0 4px !important;
        display: flex; align-items: center; gap: 4px;
        background: var(--c-surface); border-bottom: 1px solid var(--c-border);
        box-shadow: 0 1px 0 rgba(0,0,0,.02);
    }
    .topbar-left { display: flex; align-items: center; gap: 2px; min-width: 0; flex: 1; }
    .topbar-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
    .sidebar-toggle, .page-back, .notification-bell {
        width: 44px; height: 44px; display: inline-flex !important; align-items: center; justify-content: center;
        border-radius: 12px; border: 0; background: transparent; color: var(--c-text); font-size: 18px; flex-shrink: 0;
    }
    .sidebar-toggle:active, .page-back:active, .notification-bell:active { background: var(--c-bg); }
    .page-back span { display: none; }
    .topbar-title { font-size: 17px !important; font-weight: 700; margin: 0 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
    .user-info, .user-chevron { display: none !important; }
    .user-block { padding: 0 !important; background: none !important; border: 0 !important; }
    .user-avatar { width: 34px !important; height: 34px !important; font-size: 13px !important; }
    .user-menu { right: 0 !important; left: auto !important; top: calc(100% + 6px) !important; min-width: 220px; }

    /* ---------- Tiroir de menu ---------- */
    .sidebar {
        position: fixed !important; top: 0; bottom: 0; left: 0; z-index: 1001;
        width: min(86vw, 330px) !important; height: 100dvh !important; max-height: none !important;
        display: flex !important; flex-direction: column !important; overflow-y: auto !important; overflow-x: hidden !important;
        padding: calc(var(--safe-top) + 8px) 10px calc(var(--safe-bottom) + 12px) !important;
        transform: translateX(-104%); transition: transform .26s cubic-bezier(.2,.8,.2,1); will-change: transform;
        box-shadow: 8px 0 30px rgba(0,0,0,.18); background: var(--c-surface);
        border-radius: 0 18px 18px 0;
    }
    .sidebar .menu { display: flex !important; flex-direction: column !important; gap: 2px; }
    .sidebar .menu-section { display: block !important; margin-top: 14px; }
    .sidebar .menu-item { min-height: 46px; border-radius: 12px; font-size: 15px; }
    .sidebar .menu-item:active { background: var(--c-bg); }
    .app-shell.drawer-open .sidebar { transform: translateX(0); }
    .drawer-backdrop {
        display: block; position: fixed; inset: 0; z-index: 1000; background: rgba(15, 23, 42, .45);
        opacity: 0; transition: opacity .26s; pointer-events: none;
    }
    .drawer-backdrop[hidden] { display: none; }
    .app-shell.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
    body.drawer-lock { overflow: hidden; }

    .drawer-user { display: flex; align-items: center; gap: 10px; padding: 10px 6px 14px; border-bottom: 1px solid var(--c-border); margin-bottom: 6px; flex-shrink: 0; }
    .drawer-user .user-avatar { width: 44px !important; height: 44px !important; font-size: 15px !important; flex-shrink: 0; }
    .drawer-user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
    .drawer-user-info strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .drawer-user-info span { font-size: 12px; color: var(--c-muted); }
    .drawer-close { width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--c-bg); color: var(--c-text); font-size: 18px; flex-shrink: 0; }
    .drawer-foot { display: flex; flex-direction: column; gap: 2px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--c-border); flex-shrink: 0; }
    .drawer-link { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: 12px; border: 0; background: none; color: var(--c-text); font-size: 15px; text-decoration: none; text-align: left; width: 100%; }
    .drawer-link i { width: 20px; text-align: center; color: var(--c-muted); }
    .drawer-link.danger, .drawer-link.danger i { color: var(--c-danger); }
    .drawer-link[hidden] { display: none; }
    .sidebar .brand, .sidebar .sidebar-brand { display: none; }

    /* ---------- Barre d'onglets ---------- */
    .tabbar {
        display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
        height: calc(var(--tabbar-h) + var(--safe-bottom)); padding: 4px 4px var(--safe-bottom);
        background: color-mix(in srgb, var(--c-surface) 94%, transparent);
        -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
        border-top: 1px solid var(--c-border);
    }
    .tab {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        border: 0; background: none; color: var(--c-muted); text-decoration: none; font: inherit;
        font-size: 10.5px; font-weight: 600; border-radius: 14px; min-width: 0; position: relative;
    }
    .tab i { font-size: 20px; line-height: 1; transition: transform .15s; }
    .tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .tab.active, .tab[aria-expanded="true"] { color: var(--c-primary); }
    .tab.active::before {
        content: ""; position: absolute; top: 2px; width: 34px; height: 3px; border-radius: 3px; background: var(--c-primary);
    }
    .tab:active i { transform: scale(.88); }

    /* ---------- En-têtes de page ---------- */
    .page-header, .page-header-row { display: flex !important; flex-direction: column !important; align-items: stretch !important; gap: 10px !important; margin-bottom: 14px !important; }
    .page-header h1, .page-header-row h1, .page-title { font-size: 21px !important; line-height: 1.25; margin: 0 !important; }
    .page-header p, .page-header-row p { font-size: 13px; margin: 4px 0 0; }
    .page-header-actions, .page-header-row > div:last-child:not(:first-child), .header-actions {
        display: flex !important; flex-wrap: nowrap !important; gap: 8px !important; overflow-x: auto; scrollbar-width: none;
        margin: 0 -12px !important; padding: 2px 12px 4px !important; -webkit-overflow-scrolling: touch;
    }
    .page-header-actions::-webkit-scrollbar, .header-actions::-webkit-scrollbar { display: none; }
    .page-header-actions > *, .header-actions > * { flex-shrink: 0; }
    .page-header-actions form { display: contents; }
    .bulk-download select { min-width: 150px; }
    .breadcrumb { font-size: 12.5px; white-space: nowrap; overflow-x: auto; scrollbar-width: none; }

    /* ---------- Boutons et contrôles : cibles tactiles ---------- */
    .btn { min-height: 44px; padding: 10px 16px; border-radius: 12px; font-size: 15px; }
    .btn-sm { min-height: 38px; padding: 7px 12px; font-size: 13.5px; }
    .btn:active { transform: scale(.97); }
    .btn-block, .form-actions .btn { flex: 1; }
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select, textarea {
        font-size: 16px !important;              /* évite le zoom automatique d'iOS */
        min-height: 46px; border-radius: 12px !important; max-width: 100%;
    }
    textarea { min-height: 96px; }
    input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }

    /* ---------- Grilles et cartes ---------- */
    .cards, .stats-grid, .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
    .card-stat, .stat-card { min-width: 0; padding: 12px !important; gap: 10px !important; border-radius: 16px !important; }
    .card-stat > div:last-child, .stat-card-body { min-width: 0; }
    .card-stat h3, .stat-card-label { font-size: 12px !important; white-space: normal; word-break: normal; overflow-wrap: anywhere; }
    .card-stat p, .stat-card-value { font-size: 20px !important; word-break: normal; overflow-wrap: anywhere; }
    .card-icon, .stat-card-icon { width: 38px !important; height: 38px !important; font-size: 16px !important; flex-shrink: 0; }
    .emp-grid, .grid-2, .grid-3, .dashboard-grid, .profile-layout, .anc-grid, .recap, .info-grid,
    .form-grid, .form-grid-2, .form-grid-3, [class*="-grid"]:not(.cards):not(.stats-grid):not(.kpi-grid):not(.simu):not(.pave) {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .card-block, .form-card, .card, .table-card, .data-card { border-radius: 16px !important; padding: 14px !important; margin-left: 0; margin-right: 0; }
    .card-block-header { flex-wrap: wrap; gap: 8px; }
    .form-section { padding: 0 0 14px !important; }

    /* ---------- Formulaires : barre d'enregistrement collée en bas ---------- */
    .form-card > .form-actions, form > .form-actions:last-child {
        position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px); z-index: 5;
        display: flex; gap: 8px; margin: 12px -6px 0; padding: 10px; border-radius: 16px;
        background: color-mix(in srgb, var(--c-surface) 92%, transparent);
        -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
        box-shadow: 0 6px 24px rgba(0,0,0,.12); border: 1px solid var(--c-border);
    }

    /* ---------- Filtres ---------- */
    .filter-bar { display: grid !important; grid-template-columns: minmax(0, 1fr) !important; grid-auto-flow: row !important; grid-column: auto !important; gap: 8px !important; padding: 12px !important; border-radius: 16px !important; }
    .filter-bar > *, .filter-bar select, .filter-bar input, .filter-bar .btn, .filter-search { width: 100% !important; min-width: 0 !important; }
    .filter-bar.repliee > :not(.filter-search):not(.filtre-bascule) { display: none !important; }
    .filtre-bascule { display: flex !important; align-items: center; justify-content: center; gap: 8px; }

    /* ---------- Tableaux → cartes ---------- */
    .table-wrapper, .table-wrap, .table-responsive { overflow: visible !important; border: 0 !important; box-shadow: none !important; background: none !important; padding: 0 !important; }
    table.table, table.data-table, .main-content table.cartes-mobile { display: block; width: 100% !important; min-width: 0 !important; border: 0 !important; background: none !important; }
    table.table thead, table.data-table thead, table.cartes-mobile thead { display: none; }
    table.table tbody, table.data-table tbody, table.cartes-mobile tbody { display: flex; flex-direction: column; gap: 10px; }
    table.table tr, table.data-table tr, table.cartes-mobile tr {
        display: block; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 16px;
        padding: 10px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.03);
    }
    table.table td, table.data-table td, table.cartes-mobile td {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 7px 0 !important; border: 0 !important; border-bottom: 1px dashed var(--c-border) !important;
        text-align: right !important; font-size: 14px; min-height: 0; width: auto !important; white-space: normal !important;
    }
    table.table td:last-child, table.data-table td:last-child, table.cartes-mobile td:last-child { border-bottom: 0 !important; }
    table.table td::before, table.data-table td::before, table.cartes-mobile td::before {
        content: attr(data-label); flex-shrink: 0; max-width: 45%; text-align: left;
        font-size: 12px; font-weight: 600; color: var(--c-muted); text-transform: none;
    }
    table.table td[data-label=""]::before, table.table td:not([data-label])::before { display: none; }
    /* 1re cellule = titre de la carte */
    table.table td:first-child, table.data-table td:first-child { justify-content: flex-start; text-align: left !important; font-size: 15px; padding-top: 2px !important; }
    table.table td:first-child::before, table.data-table td:first-child::before { display: none; }
    /* Cellule d'actions : boutons pleine largeur */
    table.table td.actions, table.table td:has(> .btn), table.table td:has(> .actions), table.table td:has(> form .btn) { justify-content: flex-end; flex-wrap: wrap; }
    table.table td.actions::before, table.table td:has(> .btn)::before, table.table td:has(> .actions)::before { display: none; }
    table.table tr.sous-total, table.table tr.total { background: color-mix(in srgb, var(--c-primary) 6%, var(--c-surface)); }
    table.table td[colspan] { justify-content: center; text-align: center !important; }
    table.table td[colspan]::before { display: none; }
    /* Tableaux de saisie (barèmes, paliers) : restent des tableaux */
    table.edit, table.edit thead, table.edit tbody, table.edit tr, table.edit td { display: revert !important; }

    .pagination-bar { flex-direction: column; gap: 10px; align-items: stretch; }
    .pagination { justify-content: center; flex-wrap: wrap; }

    /* ---------- Divers ---------- */
    .alert { border-radius: 14px; font-size: 14px; }
    .tabs, .tab-nav, .nav-tabs { overflow-x: auto; flex-wrap: nowrap !important; scrollbar-width: none; }
    .tabs > *, .tab-nav > *, .nav-tabs > * { flex-shrink: 0; }
    .modal-content, .modal-dialog { width: 100% !important; max-width: 100% !important; margin: auto 0 0 !important; border-radius: 20px 20px 0 0 !important; max-height: 92dvh; overflow-y: auto; }
    .profile-hero { flex-direction: column; text-align: center; padding: 18px !important; border-radius: 18px !important; }
    .profile-hero .tags, .profile-hero .badges { justify-content: center; }
    img, canvas, video, iframe { max-width: 100%; }
    .main-content > * { max-width: 100%; }
    pre, code { white-space: pre-wrap; word-break: break-word; }

    /* Transition douce entre les pages */
    .main-content { animation: entree-page .22s ease-out; }
    @keyframes entree-page { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

    /* Application installée (plein écran) */
    @media (display-mode: standalone) {
        body { user-select: none; -webkit-user-select: none; }
        input, textarea, [contenteditable], td, p, code, pre { user-select: text; -webkit-user-select: text; }
    }
}

@media (max-width: 380px) {
    .tab span { font-size: 9.5px; }
    .cards, .stats-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar, .drawer-backdrop, .main-content { transition: none !important; animation: none !important; }
}

@media (max-width: 900px) {
    /* Les éléments des en-têtes ne dépassent jamais l'écran */
    .page-header > *, .page-header-row > * { min-width: 0; max-width: 100%; }
    .page-header-actions, .page-header-row > div:last-child:not(:first-child), .header-actions { width: auto; max-width: none; }
    .page-header-row > div:first-child, .page-header > div:first-child { overflow-wrap: anywhere; }
    /* Garde-fou : aucune page ne défile en largeur */
    .main-content { overflow-x: clip; }
    .main-content .btn { max-width: 100%; white-space: normal; text-align: center; }
    .page-header-actions .btn, .header-actions .btn, .tabbar .tab { white-space: nowrap; }
    .main-content [style*="display:flex"], .main-content [style*="display: flex"] { flex-wrap: wrap; }
}
@media (max-width: 900px) {
    .main-content > *, .page > *, .page-header-row, .page-header { min-width: 0 !important; max-width: 100% !important; }
    .page-header-actions, .header-actions { max-width: calc(100% + 24px) !important; }
    .photo-block { max-width: 100%; }
}
@media (max-width: 900px) { .form-photo-row { grid-template-columns: minmax(0, 1fr) !important; } }
@media (max-width: 900px) { .filter-bar > * { grid-column: 1 / -1 !important; } }
.select-source { width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; }
