/**
 * LogBook — Mobile PWA · Android-native design layer
 * v1.03.09 — Expert design pass (inspiré du travail s-cloud, rebrandé Salott-IT)
 *
 * Transforme l'expérience mobile en une UI proche d'une app Android native :
 *   - Bottom-nav Material Design 3 (pastille active derrière l'icône)
 *   - Contenu edge-to-edge sur fond gris chaud, cards blanches surélevées
 *   - Cibles tactiles ≥ 44 px, rayons généreux (16 px cards, pills)
 *   - Système d'élévation Material, transitions « spring »
 *   - Modales → bottom-sheets plein écran avec poignée
 *   - Topbar immersive (safe-area en mode standalone)
 *
 * Chargé EN DERNIER — n'agit QUE sur mobile (tout est dans des @media).
 * Le bureau est totalement préservé. Couleurs : navy #0B2559 / coral #FF6B35.
 *
 * NB : on réutilise les tokens existants de logbook-theme.css
 *      (--hki-purple, --hki-coral, etc.). Aucune dépendance externe.
 */

/* ════════════════════════════════════════════════════════════════════
 *  0. TOKENS MOBILE (surfaces chaudes, ombres material)
 * ════════════════════════════════════════════════════════════════════ */
:root {
    --lbm-surface:      #F3F4F6;   /* fond appli mobile (gris chaud) */
    --lbm-card:         #FFFFFF;
    --lbm-line:         rgba(0,0,0,.06);
    --lbm-line-soft:    rgba(0,0,0,.04);
    --lbm-ink:          #111827;
    --lbm-ink-soft:     #6B7280;
    --lbm-radius:       16px;
    --lbm-radius-lg:    20px;
    --lbm-radius-sheet: 24px;
    --lbm-elev-1:       0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --lbm-elev-2:       0 6px 18px rgba(11,37,89,.10);
    --lbm-spring:       cubic-bezier(.2, 0, 0, 1);
    --lbm-sheet-ease:   cubic-bezier(.32, .72, 0, 1);
}

/* ════════════════════════════════════════════════════════════════════
 *  1. FONDATION MOBILE (< 768px)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    html {
        -webkit-tap-highlight-color: transparent;
        -webkit-text-size-adjust: 100%;
        scroll-behavior: smooth;
        overscroll-behavior-y: contain;          /* pas de bounce pull-to-refresh */
    }
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        overflow-x: hidden;
        background: var(--lbm-surface) !important;
    }

    /* Contenu edge-to-edge : le container gère le gouttière, pas le main */
    main#lb-main-content {
        background: var(--lbm-surface);
        padding-top: 10px !important;
        padding-left: 14px !important;
        padding-right: 14px !important;
    }

    /* Footer discret façon app */
    footer {
        background: transparent;
        border-top: none !important;
        font-size: .72rem;
        opacity: .65;
    }
}

/* ════════════════════════════════════════════════════════════════════
 *  2. TOPBAR — App bar immersive
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .lb-topbar {
        background: #FFFFFF !important;
        border-bottom: 1px solid var(--lbm-line) !important;
        box-shadow: 0 1px 3px rgba(0,0,0,.04);
        padding: .4rem .85rem !important;
        position: sticky;
        top: 0;
        z-index: 1035;
    }
    .lb-topbar .topbar-logo {
        height: 38px !important;
    }
    /* Boutons thème/langue : pills tactiles plus marquées */
    .lb-topbar .topbar-theme-btns,
    .lb-topbar .topbar-lang-btns {
        border-radius: 22px !important;
        background: var(--lbm-surface) !important;
        border-color: transparent !important;
    }
    .lb-topbar .topbar-icon-btn,
    .lb-topbar .topbar-lang-btn {
        height: 32px !important;
        min-width: 34px;
        font-size: .82rem !important;
    }
    .lb-topbar .topbar-entity-select {
        height: 34px !important;
        border-radius: 18px !important;
        background-color: var(--lbm-surface) !important;
        border-color: transparent !important;
    }
}

/* En mode PWA standalone : prolonger sous la barre d'état Android/iOS */
@media (max-width: 767.98px) and (display-mode: standalone) {
    .lb-topbar {
        padding-top: calc(.4rem + env(safe-area-inset-top, 0px)) !important;
    }
}

/* ════════════════════════════════════════════════════════════════════
 *  3. NAVBAR DESKTOP — masquée sur mobile (la bottom-nav prend le relais)
 *     (la navbar Bootstrap collapse déjà ; on évite juste le double-emploi
 *      visuel en la rendant plus compacte si affichée)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {
    .navbar-custom {
        border-bottom-width: 2px;
    }
}

/* ════════════════════════════════════════════════════════════════════
 *  4. BOTTOM-NAV — Material Design 3 (sur la base .lb-mobile-nav existante)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .lb-mobile-nav {
        left: 10px;
        right: 10px;
        bottom: 10px;
        height: 64px;
        border-radius: 22px;
        background: rgba(255,255,255,.97);
        border: 1px solid var(--lbm-line);
        box-shadow: 0 -2px 16px rgba(11,37,89,.10), 0 6px 20px rgba(0,0,0,.06);
    }

    .lb-mobile-nav-item {
        gap: 3px;
        font-weight: 600;
        color: var(--lbm-ink-soft);
        border-radius: 14px;
        position: relative;
        overflow: visible;
    }
    .lb-mobile-nav-item .lb-nav-icon {
        font-size: 1.3rem;
        transition: transform .2s var(--lbm-spring);
        position: relative;
        z-index: 1;
    }

    /* Pastille MD3 derrière l'icône de l'onglet actif */
    .lb-mobile-nav-item.active { color: var(--hki-purple); }
    .lb-mobile-nav-item.active::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 46px;
        height: 30px;
        background: var(--hki-purple-lt);
        border-radius: 16px;
        z-index: 0;
        animation: lbmPill .28s var(--lbm-spring) forwards;
    }
    .lb-mobile-nav-item.active .lb-nav-icon {
        transform: translateY(-1px);
    }
    /* le bouton "Plus" ne doit pas afficher la pastille active permanente */
    .lb-mobile-nav button.lb-mobile-nav-item.active::before {
        animation: none;
    }
    @keyframes lbmPill {
        from { width: 0;    opacity: 0; }
        to   { width: 46px; opacity: 1; }
    }

    /* le dot devient inutile (remplacé par la pastille) */
    .lb-mobile-nav-item.active .lb-mnav-dot { display: none; }

    .lb-mobile-nav-item:active { transform: scale(.94); }

    /* FAB : carré arrondi MD3 + dégradé navy → coral subtil */
    .lb-mobile-nav-fab {
        width: 58px;
        height: 58px;
        flex-basis: 58px;
        border-radius: 18px;
        background: linear-gradient(135deg, var(--hki-purple) 0%, #15407f 100%);
        box-shadow:
            0 6px 16px rgba(11,37,89,.40),
            0 0 0 4px rgba(255,255,255,.97);
    }
    .lb-mobile-nav-fab:active {
        transform: translateY(-8px) scale(.9);
    }

    /* Badge alertes : anneau blanc cohérent */
    .lb-mnav-badge {
        background: var(--hki-coral);
        box-shadow: 0 1px 4px rgba(255,107,53,.45);
    }
}

/* ════════════════════════════════════════════════════════════════════
 *  5. MENU « PLUS » — bottom-sheet plein largeur
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .lb-mobile-more-menu {
        left: 10px;
        right: 10px;
        bottom: 84px;
        min-width: 0;
        border-radius: var(--lbm-radius-lg);
        border: 1px solid var(--lbm-line);
        box-shadow: 0 12px 36px rgba(11,37,89,.20), 0 4px 12px rgba(0,0,0,.10);
        padding: 8px;
    }
    .lb-mobile-more-item {
        padding: 12px 14px;
        border-radius: 12px;
        font-size: .92rem;
        min-height: 48px;
    }
    .lb-mobile-more-item:active { transform: scale(.98); }
    .lb-mobile-more-item i { font-size: 1.2rem; }
}

/* ════════════════════════════════════════════════════════════════════
 *  6. CARDS — élévation Material, coins arrondis
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    main#lb-main-content .card {
        border-radius: var(--lbm-radius) !important;
        border: 1px solid var(--lbm-line-soft) !important;
        box-shadow: var(--lbm-elev-1) !important;
        background: var(--lbm-card) !important;
        overflow: hidden;
        margin-bottom: 14px;
    }
    main#lb-main-content .card > .card-body { padding: 16px !important; }
    main#lb-main-content .card > .card-header {
        background: transparent !important;
        border-bottom: 1px solid var(--lbm-line-soft) !important;
        padding: 14px 16px !important;
        font-weight: 700;
    }
    main#lb-main-content .card > .card-footer {
        background: transparent !important;
        border-top: 1px solid var(--lbm-line-soft) !important;
        padding: 12px 16px !important;
    }

    /* lb-card (design system maison) → même traitement tactile */
    main#lb-main-content .lb-card {
        border-radius: var(--lbm-radius) !important;
        box-shadow: var(--lbm-elev-1) !important;
        margin-bottom: 14px;
    }

    /* stat-cards → plus respirantes, valeur plus grosse */
    .lb-stat-card { padding: 1rem !important; border-radius: var(--lbm-radius) !important; }
    .lb-stat-value { font-size: 1.7rem !important; }
}

/* ════════════════════════════════════════════════════════════════════
 *  7. BOUTONS — cibles tactiles Android
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .btn {
        min-height: 44px;
        border-radius: 12px;
        padding: 10px 18px;
        font-weight: 600;
        transition: transform .1s var(--lbm-spring), background .15s, box-shadow .15s;
    }
    .btn:active { transform: scale(.97); }
    .btn-sm {
        min-height: 38px;
        border-radius: 10px;
        padding: 7px 14px;
    }
    .btn-lg { min-height: 50px; border-radius: 14px; }
    .btn.rounded-pill { border-radius: 50px; }

    /* Boutons pleine largeur dans les barres d'actions de formulaire */
    .lb-form-actions .btn,
    .d-grid .btn { width: 100%; }

    /* lb-btn (design system) : garder l'esprit pill mais cible ≥ 44px */
    .lb-btn { min-height: 44px; }
    .lb-btn-sm { min-height: 38px; }
}

/* ════════════════════════════════════════════════════════════════════
 *  8. FORMULAIRES — style Material
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .form-control,
    .form-select {
        min-height: 48px;
        border-radius: 12px !important;
        padding: 12px 14px !important;
        /* 16px déjà imposé ailleurs pour empêcher le zoom iOS */
        border: 1.5px solid #E5E7EB !important;
        background: #FFFFFF !important;
        transition: border-color .2s, box-shadow .2s !important;
    }
    .form-control:focus,
    .form-select:focus {
        border-color: var(--hki-purple) !important;
        box-shadow: 0 0 0 3px rgba(11,37,89,.12) !important;
    }
    textarea.form-control { min-height: 100px; }

    .form-label {
        font-size: .82rem;
        font-weight: 600;
        color: #374151;
        margin-bottom: 6px;
    }
    .input-group-text {
        border-radius: 12px;
        border: 1.5px solid #E5E7EB;
    }
    .form-check { min-height: 40px; display: flex; align-items: center; }
    .form-check-input { width: 20px; height: 20px; }
    .form-check-input:checked {
        background-color: var(--hki-purple);
        border-color: var(--hki-purple);
    }
}

/* ════════════════════════════════════════════════════════════════════
 *  9. MODALES — bottom-sheets (téléphones < 576px)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 575.98px) {

    .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        position: fixed !important;
        bottom: 0; left: 0; right: 0;
        transform: translateY(100%) !important;
        transition: transform .3s var(--lbm-sheet-ease) !important;
    }
    .modal.show .modal-dialog { transform: translateY(0) !important; }
    .modal-dialog.modal-dialog-centered { align-items: flex-end !important; }

    .modal-content {
        border-radius: var(--lbm-radius-sheet) var(--lbm-radius-sheet) 0 0 !important;
        border: none !important;
        box-shadow: 0 -4px 24px rgba(0,0,0,.16) !important;
        max-height: 92vh;
    }
    /* Poignée de drag en haut du sheet */
    .modal-content::before {
        content: '';
        display: block;
        width: 38px; height: 4px;
        background: #D1D5DB;
        border-radius: 2px;
        margin: 9px auto 0;
    }
    /* Si le header a déjà un fond coloré (modales custom), on garde la poignée lisible */
    .modal-content.lb-sheet-dark::before { background: rgba(255,255,255,.5); }

    .modal-header { border-bottom: 1px solid var(--lbm-line) !important; padding: 12px 18px 14px !important; }
    .modal-body   { padding: 16px 18px !important; max-height: 68vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .modal-footer {
        padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        border-top: 1px solid var(--lbm-line) !important;
    }
    .modal-footer .btn { flex: 1 1 auto; }

    .modal-backdrop.show { opacity: .4 !important; }
}

/* ════════════════════════════════════════════════════════════════════
 * 10. TABLES — lignes confortables au doigt
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .table-responsive {
        border-radius: var(--lbm-radius);
        border: 1px solid var(--lbm-line-soft);
        background: #FFFFFF;
    }
    /* Ne s'applique pas aux tables transformées en cards (.lb-table-cards) */
    .table:not(.lb-table-cards) td,
    .table:not(.lb-table-cards) th {
        padding: 13px 12px !important;
        vertical-align: middle !important;
    }
    .table:not(.lb-table-cards) thead th {
        font-size: .72rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--lbm-ink-soft);
        white-space: nowrap;
    }
}

/* ════════════════════════════════════════════════════════════════════
 * 11. LIST GROUPS — style liste native
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    main#lb-main-content .list-group {
        border-radius: var(--lbm-radius);
        overflow: hidden;
    }
    main#lb-main-content .list-group-item {
        padding: 14px 16px;
        min-height: 50px;
        border-color: var(--lbm-line-soft);
    }
    main#lb-main-content .list-group-item:active { background: rgba(0,0,0,.035); }
}

/* ════════════════════════════════════════════════════════════════════
 * 12. TYPOGRAPHIE — hiérarchie mobile
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    main#lb-main-content h1, main#lb-main-content .h1,
    main#lb-main-content .page-title {
        font-size: 1.45rem !important;
        font-weight: 800 !important;
        line-height: 1.25 !important;
        letter-spacing: -.01em;
    }
    main#lb-main-content h2, main#lb-main-content .h2 {
        font-size: 1.3rem !important;
        font-weight: 700 !important;
        line-height: 1.3 !important;
    }
    main#lb-main-content h3, main#lb-main-content .h3 { font-size: 1.12rem !important; font-weight: 700 !important; }
    .lb-section-header h2 { font-size: 1.3rem !important; }
}

/* ════════════════════════════════════════════════════════════════════
 * 13. BADGES / CHIPS — pills arrondis
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {
    .badge { border-radius: 8px; padding: 5px 9px; font-size: .72rem; font-weight: 600; }
    .badge.rounded-pill { border-radius: 50px; }
}

/* ════════════════════════════════════════════════════════════════════
 * 14. NAV-TABS & SOUS-MENUS MODULES — scroll horizontal pills
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .nav-tabs,
    .dash-nav .nav, .loc-nav .nav, .gen-nav .nav, .mnt-nav .nav,
    .tcv-nav .nav, .rep-nav .nav, .adm-nav .nav, .dep-nav .nav {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .nav-tabs::-webkit-scrollbar { display: none; }
    .nav-tabs .nav-link {
        white-space: nowrap;
        padding: 10px 15px !important;
        font-size: .82rem;
        font-weight: 600;
        min-height: 40px;
    }
    .nav-tabs .nav-link.active {
        border-bottom: 3px solid var(--hki-purple) !important;
        color: var(--hki-purple) !important;
    }
}

/* ════════════════════════════════════════════════════════════════════
 * 15. ALERTES (bootstrap) — arrondies
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {
    .alert { border-radius: 14px; padding: 13px 15px; }
}

/* ════════════════════════════════════════════════════════════════════
 * 16. DROPDOWNS — surface élevée tactile
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .dropdown-menu {
        border-radius: var(--lbm-radius) !important;
        border: 1px solid var(--lbm-line) !important;
        box-shadow: 0 8px 24px rgba(0,0,0,.12) !important;
        padding: 8px !important;
    }
    .dropdown-item {
        border-radius: 10px;
        padding: 11px 14px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* ════════════════════════════════════════════════════════════════════
 * 17. PAGINATION — boutons tactiles
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .pagination { gap: 4px; flex-wrap: wrap; }
    .page-link {
        min-width: 40px; min-height: 40px;
        border-radius: 10px !important;
        display: flex; align-items: center; justify-content: center;
        font-weight: 600;
    }
    .page-item:first-child .page-link,
    .page-item:last-child .page-link { border-radius: 10px !important; }
}

/* ════════════════════════════════════════════════════════════════════
 * 18. DATATABLES — polish mobile
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    .dataTables_wrapper { overflow: hidden; }
    .dataTables_filter input {
        min-height: 42px;
        border-radius: 12px !important;
        padding: 8px 14px !important;
        border: 1.5px solid #E5E7EB !important;
    }
    .dataTables_filter input:focus {
        border-color: var(--hki-purple) !important;
        box-shadow: 0 0 0 3px rgba(11,37,89,.1) !important;
    }
    .dataTables_length select { min-height: 40px; border-radius: 10px !important; }
    .dataTables_info { font-size: .76rem; color: var(--lbm-ink-soft); }
    .dataTables_paginate .paginate_button {
        min-width: 38px; min-height: 38px;
        border-radius: 9px !important;
    }
}

/* ════════════════════════════════════════════════════════════════════
 * 19. EMPTY STATES — généreux et centrés
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {
    .lb-empty-state { padding: 2.5rem 1rem; }
    .lb-empty-state .lb-empty-icon { font-size: 3.4rem; }
}

/* ════════════════════════════════════════════════════════════════════
 * 20. ESPACEMENTS — rythme mobile respirant + place pour la bottom-nav
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    main#lb-main-content {
        padding-bottom: calc(94px + env(safe-area-inset-bottom, 0px)) !important;
    }
    main#lb-main-content .row { --bs-gutter-x: 12px; }
}

/* ════════════════════════════════════════════════════════════════════
 * 21. SCROLLBARS masquées sur mobile (feel natif)
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {
    main#lb-main-content::-webkit-scrollbar,
    .modal-body::-webkit-scrollbar { display: none; }
    main#lb-main-content, .modal-body { scrollbar-width: none; }
}

/* ════════════════════════════════════════════════════════════════════
 * 22. PETITS TÉLÉPHONES (< 576px) — compaction
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 575.98px) {
    main#lb-main-content {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    .lb-stat-value { font-size: 1.5rem !important; }
}

/* ════════════════════════════════════════════════════════════════════
 * 23. PAYSAGE COURT — bottom-nav compacte
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) and (orientation: landscape) and (max-height: 480px) {
    .lb-mobile-nav { height: 54px; }
    .lb-mobile-nav-item { min-height: 46px; font-size: .6rem; }
    .lb-mobile-nav-fab { width: 46px; height: 46px; flex-basis: 46px; border-radius: 14px; }
    main#lb-main-content {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ════════════════════════════════════════════════════════════════════
 * 24. THÈME SOMBRE — surfaces mobiles cohérentes
 * ════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {

    [data-bs-theme="dark"] body { background: #0f0f1e !important; }
    [data-bs-theme="dark"] main#lb-main-content { background: #0f0f1e; }

    [data-bs-theme="dark"] .lb-topbar {
        background: #0d0d1c !important;
        border-bottom-color: rgba(255,255,255,.06) !important;
    }
    [data-bs-theme="dark"] .lb-topbar .topbar-theme-btns,
    [data-bs-theme="dark"] .lb-topbar .topbar-lang-btns,
    [data-bs-theme="dark"] .lb-topbar .topbar-entity-select {
        background: rgba(255,255,255,.05) !important;
    }

    [data-bs-theme="dark"] main#lb-main-content .card,
    [data-bs-theme="dark"] main#lb-main-content .lb-card {
        background: #1a1a30 !important;
        border-color: rgba(255,255,255,.07) !important;
        box-shadow: 0 2px 10px rgba(0,0,0,.4) !important;
    }
    [data-bs-theme="dark"] .form-control,
    [data-bs-theme="dark"] .form-select,
    [data-bs-theme="dark"] .dataTables_filter input {
        background: #13132a !important;
        border-color: rgba(255,255,255,.12) !important;
        color: #dde0f0 !important;
    }
    [data-bs-theme="dark"] .form-control:focus,
    [data-bs-theme="dark"] .form-select:focus {
        border-color: #c084fc !important;
        box-shadow: 0 0 0 3px rgba(192,132,252,.18) !important;
    }
    [data-bs-theme="dark"] .table-responsive { background: #1a1a30; border-color: rgba(255,255,255,.07); }
    [data-bs-theme="dark"] .modal-content::before { background: rgba(255,255,255,.25); }

    /* pastille MD3 active en sombre */
    [data-bs-theme="dark"] .lb-mobile-nav-item.active { color: #c084fc; }
    [data-bs-theme="dark"] .lb-mobile-nav-item.active::before { background: rgba(192,132,252,.18); }
}

/* ════════════════════════════════════════════════════════════════════
 * 25. ACCESSIBILITÉ — respect du « reduce motion »
 * ════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    .lb-mobile-nav-item.active::before { animation: none !important; }
    .modal-dialog { transition: none !important; }
    .btn, .lb-mobile-nav-item, .dropdown-item, .list-group-item { transition: none !important; }
}
