/* ============================================================
   OK CUISINE — Mobile CSS
   Styles ciblés mobile/tablette (< 768px)
   N'affecte AUCUN style desktop — ajouts purs
   ============================================================ */

@media (max-width: 768px) {

    /* ── 1. Layout général ─────────────────────────────────── */

    .content {
        margin-left: 0 !important;
        padding: 0.75rem !important;
    }

    .top-bar {
        padding: 0 0.75rem;
    }

    /* Mini-espace entre la loupe (fin du groupe gauche) et le « ? » (début du groupe droit),
       qui se touchaient sur mobile. Juste de quoi les séparer, rien d'autre ne bouge. */
    .help-btn {
        margin-left: 8px;
    }

    /* ── 2. Textes & débordements globaux ──────────────────── */

    /* On garde overflow-wrap (coupe un mot SEULEMENT s'il déborde vraiment), mais on RETIRE
       la coupure agressive qui cassait le texte caractère par caractère → texte "vertical"
       dans les zones flex serrées (ex. cartes d'inventaire). */
    * {
        overflow-wrap: break-word;
    }

    .section-title {
        font-size: 1.1rem;
    }

    /* ── 3. Section headers & actions ─────────────────────── */

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.65rem;
        margin-bottom: 1rem;
    }

    .section-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
        width: 100%;
    }

    .section-actions .btn {
        flex: 1 1 auto;
        min-width: 120px;
        font-size: 0.82rem;
        padding: 0.5rem 0.65rem;
        white-space: nowrap;
    }

    /* ── 4. Stats grid ─────────────────────────────────────── */

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.6rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* ── 5. Cards ──────────────────────────────────────────── */

    .card {
        padding: 0.85rem;
        border-radius: 10px;
        margin-bottom: 0.75rem;
    }

    .card-header {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .card-title {
        font-size: 0.95rem;
    }

    /* ── 6. Toutes les tables : scroll horizontal ──────────── */

    .table-container,
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    /* Ajouter scroll sur toute table sans wrapper explicite */
    table:not(.no-mobile-scroll) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    /* Cellules sur UNE ligne → la table DÉFILE horizontalement au lieu de s'empiler
       (corrige inventaire / stock-entretien : tableaux SANS classe .table qui n'avaient
       pas le nowrap). Les cas spéciaux (ex. #page-secteurs td:last-child) gardent la main
       grâce à leur spécificité par #id. */
    table:not(.no-mobile-scroll) td,
    table:not(.no-mobile-scroll) th {
        white-space: nowrap;
    }

    .table th,
    .table td {
        padding: 0.45rem 0.55rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* ── 7. Formulaires ────────────────────────────────────── */

    .form-control,
    .form-select,
    select.form-control,
    input.form-control,
    textarea.form-control {
        width: 100% !important;
        min-width: 0 !important;
        font-size: 1rem; /* évite le zoom auto iOS */
    }

    .form-group {
        margin-bottom: 0.9rem;
    }

    .add-row {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .add-row .btn {
        width: 100%;
        margin-top: 0.25rem;
    }

    /* ── 8. Boutons ────────────────────────────────────────── */

    .btn {
        min-height: 42px;
        font-size: 0.88rem;
    }

    .btn-sm {
        min-height: 32px;
        padding: 0.3rem 0.55rem;
        font-size: 0.78rem;
    }

    .btn-lg {
        min-height: 52px;
        font-size: 1rem;
    }

    /* Boutons .btn-kitchen trop grands sur mobile */
    .btn-kitchen {
        padding: 0.65rem 1rem !important;
        font-size: 0.9rem !important;
        min-height: 48px !important;
        min-width: 0 !important;
    }

    /* ── 9. Modales ────────────────────────────────────────── */

    .modal-container {
        width: 100vw !important;
        max-width: 100vw !important;
        margin: 0;
        border-radius: 16px 16px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 92vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-overlay {
        align-items: flex-end;
    }

    .modal-body {
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 0.9rem;
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 110px;
    }

    /* ── 10. Quick actions dashboard ───────────────────────── */

    .quick-actions {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem;
    }

    .quick-action-btn {
        padding: 0.75rem 0.5rem;
        font-size: 0.82rem;
    }

    /* ── 11. Bouton micro vocal mobile ─────────────────────── */

    #mobile-mic-btn {
        position: fixed;
        bottom: calc(1.5rem + env(safe-area-inset-bottom));
        right: 1.25rem;
        width: 64px;
        height: 64px;
        border-radius: 50%;
        background: var(--accent);
        color: #fff;
        border: none;
        font-size: 1.6rem;
        box-shadow: 0 4px 20px rgba(0,0,0,0.45);
        z-index: 200;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: transform 0.15s, background 0.2s;
        -webkit-tap-highlight-color: transparent;
    }

    #mobile-mic-btn.listening {
        background: var(--danger);
        animation: mobile-mic-pulse 1.2s ease-in-out infinite;
    }

    #mobile-mic-btn.processing {
        background: var(--warning);
    }

    @keyframes mobile-mic-pulse {
        0%, 100% { transform: scale(1); box-shadow: 0 4px 20px rgba(0,0,0,0.45); }
        50% { transform: scale(1.1); box-shadow: 0 4px 30px rgba(220,53,69,0.6); }
    }

    /* (Ancien décalage retiré : #mobile-mic-btn n'existe pas — le vrai micro est #fab-mic,
       qui garde sa position normale. On ajoute juste la marge « safe-area » iPhone.) */
    .fab-mic {
        bottom: calc(2rem + env(safe-area-inset-bottom)) !important;
        right: 1.25rem !important;
    }

    /* ── 12. Module Journal ─────────────────────────────────── */

    /* NB : le rendu "cartes" mobile (.journal-mobile-card) n'existe PAS dans le code
       (journal.js ne le génère pas). On NE cache donc PAS le tableau — il défile
       horizontalement comme les autres (règle table:not(.no-mobile-scroll) plus haut).
       Les styles .journal-mobile-* ci-dessous restent inertes (aucun élément). */

    .journal-mobile-list {
        display: flex !important;
        flex-direction: column;
        gap: 0.6rem;
    }

    .journal-mobile-card {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 0.75rem;
    }

    .journal-mobile-card .jm-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.3rem;
        gap: 0.5rem;
    }

    .journal-mobile-card .jm-module {
        font-size: 0.72rem;
        padding: 0.15rem 0.45rem;
        border-radius: 20px;
        background: var(--bg-alt);
        color: var(--text-muted);
        white-space: nowrap;
    }

    .journal-mobile-card .jm-date {
        font-size: 0.72rem;
        color: var(--text-muted);
        white-space: nowrap;
    }

    .journal-mobile-card .jm-action {
        font-size: 0.88rem;
        font-weight: 600;
        color: var(--text);
        margin-bottom: 0.2rem;
    }

    .journal-mobile-card .jm-user {
        font-size: 0.78rem;
        color: var(--text-muted);
    }

    /* ── 13. Module Gestion Secteurs ───────────────────────── */

    #page-secteurs .table-container {
        overflow-x: auto;
    }

    #page-secteurs td,
    #page-secteurs th {
        max-width: 160px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #page-secteurs td:last-child,
    #page-secteurs th:last-child {
        max-width: none;
        white-space: normal;
    }

    /* Colonnes secondaires masquées sur très petit écran */
    #page-secteurs .col-secondary {
        display: none;
    }

    /* ── 14. Module Inventaire ──────────────────────────────── */

    #page-inventaire .section-actions {
        flex-direction: column;
    }

    #page-inventaire .section-actions .btn {
        width: 100%;
    }

    /* Carte produit inventaire : EMPILEMENT vertical sur mobile.
       Sinon les 3 enfants flex (bandeau expiré · nom/quantité · boutons) écrasent le nom
       à ~1 caractère → texte vertical. En colonne, chaque bloc prend toute la largeur. */
    .inv-item {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.6rem;
    }
    .inv-item-info {
        width: 100% !important;
        min-width: 0;
    }
    .inv-item-row1 {
        flex-wrap: wrap;
    }
    /* Le nom garde toute sa largeur et ne se coupe JAMAIS caractère par caractère */
    .inv-item-name {
        flex: 1 1 auto;
        min-width: 0;
        overflow-wrap: anywhere;
        word-break: keep-all;
    }
    .inv-item-actions {
        align-self: flex-end;
    }

    /* (Colonnes inventaire NON masquées : par précaution on ne cache aucune donnée sur mobile.
       Le tableau défile horizontalement comme les autres — aucune info perdue.) */

    /* ── 15. Module Menus ───────────────────────────────────── */

    #page-menus .menu-grid,
    #page-menus [class*="week"],
    #page-menus [class*="semaine"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
    }

    #page-menus table {
        min-width: 600px;
    }

    #page-menus .section-actions {
        flex-wrap: wrap;
    }

    /* ── 16. Dashboard mobile ───────────────────────────────── */

    .widget-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.6rem;
    }

    .widget-card {
        padding: 0.75rem;
    }

    .widget-value {
        font-size: 1.4rem;
    }

    /* ── 17. Voice panel mobile ────────────────────────────── */

    /* Feuille du bas : on ANNULE le tiroir latéral droit du desktop (translateX)
       qui, sous width:100vw, créait 100vw de débordement horizontal à droite. */
    .voice-panel {
        top: auto !important;
        width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        max-height: 75vh;
        overflow-y: auto;
        transform: translateY(100%) !important;   /* caché sous l'écran (plus de débordement à droite) */
    }
    .voice-panel.open {
        transform: translateY(0) !important;        /* glisse depuis le bas */
    }

    /* ── 18. Planning absences ─────────────────────────────── */

    #page-planning-absences table {
        min-width: 480px;
    }

    /* ── 19. Chips & badges ────────────────────────────────── */

    .chip-list {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .chip {
        font-size: 0.8rem;
        padding: 0.3rem 0.6rem;
    }

    /* ── 20. Barre de filtre / recherche ───────────────────── */

    .filter-bar,
    [style*="display:flex"][style*="gap"] {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    /* ── 21. Padding bas (safe area iPhone) ────────────────── */

    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ── Extra petit écran < 380px ──────────────────────────────── */
@media (max-width: 380px) {

    .content {
        padding: 0.5rem !important;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.4rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .card {
        padding: 0.65rem;
    }

    .btn {
        font-size: 0.82rem;
        padding: 0.45rem 0.6rem;
    }

    .section-title {
        font-size: 1rem;
    }

    #mobile-mic-btn {
        width: 56px;
        height: 56px;
        font-size: 1.4rem;
    }
}

/* ============================================================
   WCAG 2.1 AA — Tap targets & accessibilité (tous écrans)
   Réf. : WCAG 2.5.5 (Level AA) — cible min 44×44 CSS px
   ============================================================ */

/* Focus ring visible sur tous les éléments interactifs */
:focus-visible {
    outline: 3px solid #4fc3f7;
    outline-offset: 2px;
    border-radius: 3px;
}

/* Désactiver l'outline navigateur par défaut uniquement si :focus-visible actif */
:focus:not(:focus-visible) {
    outline: none;
}

@media (max-width: 768px) {

    /* ── Tap targets min 44×44px (WCAG 2.5.5) ─────────────── */

    .btn,
    button:not(.pin-btn),
    [role="button"],
    select,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Pin pad : boutons carrés 56px */
    .pin-btn {
        min-height: 56px;
        min-width: 56px;
    }

    /* Cellules de table cliquables */
    td[onclick],
    td[role="button"],
    tr[onclick],
    tr[role="button"] {
        min-height: 44px;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(79, 195, 247, 0.15);
    }

    /* Inputs : hauteur min 44px + font-size 16px (évite zoom iOS) */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="search"],
    textarea,
    select {
        min-height: 44px;
        font-size: 16px !important;
    }

    /* ── Espacement entre éléments cliquables ──────────────── */

    .section-actions .btn + .btn {
        margin-top: 0;
    }

    /* Icônes nav sidebar : agrandir zone de tap */
    .nav-item {
        padding: 0.65rem 0.5rem;
    }

    /* ── Skip-link accessibilité ───────────────────────────── */

    .skip-link {
        position: absolute;
        top: -60px;
        left: 1rem;
        padding: 0.5rem 1rem;
        background: #1a1a2e;
        color: #fff;
        border-radius: 0 0 6px 6px;
        font-size: 0.9rem;
        z-index: 10000;
        transition: top 0.2s;
    }

    .skip-link:focus {
        top: 0;
    }
}
