/* ================================================================
   MOBILE.CSS — Expérience app-like pour Order-POS Admin
   Chargé en complément de styles.css, ne modifie rien d'existant.
   ================================================================ */

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --bottom-nav-h: 62px;
}

/* ──────────────────────────────────────────
   BOTTOM NAV — caché par défaut (desktop)
   ────────────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
}

/* ──────────────────────────────────────────
   SIDEBAR BACKDROP — caché par défaut
   ────────────────────────────────────────── */
.sidebar-backdrop {
  display: none;
}

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

  /* ── Safe areas & layout global ── */
  body {
    padding-top: var(--safe-top);
  }

  /* Espace pour la bottom nav */
  .content {
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px);
  }

  /* ── Topbar sticky ── */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 9980;
    background: var(--panel) !important;
    border-bottom: 1px solid var(--border);
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    padding: 10px 12px !important;
  }

  /* Cacher les éléments non essentiels sur mobile */
  #clock,
  #auth-status {
    display: none !important;
  }

  /* Hamburger inutile si on a la bottom nav */
  #sidebar-toggle-mobile {
    display: none !important;
  }

  /* Search prend tout l'espace dispo */
  .search {
    flex: 1;
    min-width: 0;
  }

  /* Topbar actions compactes */
  .topbar-actions {
    flex-wrap: nowrap;
    gap: 4px;
    padding-bottom: 0 !important;
    overflow: visible;
    justify-content: flex-end;
  }

  /* ── Sidebar backdrop overlay ── */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 9985;
    pointer-events: none;
    transition: background 0.25s ease;
  }

  body:not(.sidebar-hidden) .sidebar-backdrop {
    background: rgba(0, 0, 0, 0.55);
    pointer-events: all;
    cursor: pointer;
  }

  /* ── Sidebar slide-in améliorée ── */
  .sidebar {
    z-index: 9990 !important;
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1) !important;
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.35);
  }

  /* ── Bottom Tab Navigation ── */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--panel);
    border-top: 1px solid var(--border);
    z-index: 9982;
    box-shadow: 0 -2px 24px rgba(0, 0, 0, 0.18);
    /* Forcer la remontée sur son propre calque de rendu */
    will-change: transform;
    transform: translateZ(0);
  }

  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.02em;
    position: relative;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: color 0.15s ease, transform 0.1s ease;
    touch-action: manipulation;
  }

  .mobile-tab svg {
    width: 21px;
    height: 21px;
    flex-shrink: 0;
    stroke-width: 1.8;
  }

  /* Indicateur actif — barre en haut */
  .mobile-tab::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 28px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .mobile-tab.active {
    color: var(--primary);
  }

  .mobile-tab.active::before {
    transform: translateX(-50%) scaleX(1);
  }

  /* Feedback tactile */
  .mobile-tab:active {
    transform: scale(0.88);
    transition: transform 0.08s ease;
  }

  /* Badge commandes en attente */
  .mobile-tab-badge {
    position: absolute;
    top: 5px;
    right: calc(50% - 18px);
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    min-width: 15px;
    height: 15px;
    border-radius: 99px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    pointer-events: none;
    border: 1.5px solid var(--panel);
  }

  /* ── Cibles tactiles minimum 44px ── */
  .btn {
    min-height: 40px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .nav-item,
  .nav-sub-item {
    min-height: 44px;
    touch-action: manipulation;
  }

  .icon-btn {
    min-width: 36px;
    min-height: 36px;
  }

  /* ── Indicateurs de scroll sur les tables ── */
  /* Box-shadow interne : ne chevauche PAS le contenu du tableau */
  .table-wrap,
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    transition: box-shadow 0.2s ease;
    box-shadow: inset -8px 0 10px -8px rgba(0, 0, 0, 0.5);
  }

  /* Plus de shadow quand on est au bout ou quand pas de scroll */
  .table-wrap.scroll-end,
  .table-responsive.scroll-end,
  .table-wrap.no-scroll,
  .table-responsive.no-scroll {
    box-shadow: none;
  }

  /* ── Modals : z-index au-dessus de la topbar (9980) ── */
  .modal-overlay,
  .order-detail-modal-overlay {
    z-index: 9995 !important;
  }

  /* ── Modals → Bottom sheet ── */
  /* Classe ajoutée via mobile.js */
  .modal-overlay.mobile-sheet {
    align-items: flex-end !important;
    padding: 0 !important;
    justify-content: stretch !important;
  }

  .modal-overlay.mobile-sheet > .card,
  .modal-overlay.mobile-sheet > [class*="card"] {
    border-radius: 20px 20px 0 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(20px + var(--safe-bottom)) !important;
    margin: 0 !important;
    animation: slideUpSheet 0.3s cubic-bezier(0.32, 0.72, 0, 1) !important;
  }

  /* Handle bar visuelle */
  .modal-overlay.mobile-sheet > .card::before,
  .modal-overlay.mobile-sheet > [class*="card"]::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 14px auto 4px;
    flex-shrink: 0;
  }

  @keyframes slideUpSheet {
    from {
      transform: translateY(60px);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }

  /* Modal ordre de détail → gardée en plein écran mais améliorée */
  .order-detail-modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  .order-detail-shell {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 96vh !important;
    border-radius: 20px 20px 0 0 !important;
    animation: slideUpSheet 0.3s cubic-bezier(0.32, 0.72, 0, 1) !important;
  }

  /* ── Layout principal ── */
  .main {
    overscroll-behavior-y: contain;
    isolation: isolate;
    /* Pas de overflow-x: hidden ici — ça bloque le scroll vertical */
  }

  /* ── Cards ── */
  .card {
    border-radius: 14px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* ── Grilles : min-width 0 pour éviter le débordement ── */
  .grid-2,
  .grid-3,
  .form-grid,
  .kpi-grid {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* ── Tous les inputs/selects : s'adaptent au conteneur ── */
  input,
  select,
  textarea {
    font-size: 16px !important;
    touch-action: manipulation;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* ── Boutons dans .actions : toujours pleine largeur ── */
  .actions {
    flex-direction: column;
  }

  .actions .btn {
    width: 100% !important;
    justify-content: center !important;
    box-sizing: border-box;
  }

  /* ── Notification toast repositionné ── */
  .notification-toast {
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 12px);
    top: auto !important;
    right: 12px !important;
    left: 12px !important;
    width: auto !important;
    max-width: 100% !important;
  }

  /* ── form-grid toujours 1 colonne sur mobile ── */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── card-head : titre + badge/chip wrappent proprement ── */
  .card-head {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
  }

  .card-title {
    flex: 1;
    min-width: 0;
    word-break: break-word;
  }

  /* ── actions : sélects pleine largeur comme les boutons ── */
  .actions select {
    width: 100%;
    min-width: 0;
  }

  /* ── Page Support : filtre (select + select + btn) en colonne ── */
  #support-filter-customer,
  #support-filter-status {
    width: 100%;
    min-width: 0;
  }

  /* Messages list : hauteur adaptée, pas fixée à 500px ── */
  #support-messages-list {
    max-height: 60vh !important;
  }

  /* ── Page Promos : historiques scrollables sur mobile ── */
  #coupons-list,
  #newsletters-list,
  #promo-history-list {
    max-height: 50vh;
    overflow-y: auto;
  }
}

/* ================================================================
   MOBILE TRÈS PETIT ≤ 480px
   ================================================================ */
@media (max-width: 480px) {
  .mobile-tab span {
    display: none; /* icône seule sur très petits écrans */
  }

  .mobile-tab {
    gap: 0;
  }

  .mobile-tab::before {
    width: 20px;
  }

  .mobile-bottom-nav {
    --bottom-nav-h: 54px;
  }
}
