/* Responsive (session H) : téléphone ≤ 600, tablette ≤ 900/1024, ordinateur au-delà (inchangé).
   Chargé APRÈS style.css. N'agit que sous les seuils ci-dessous : l'affichage ordinateur n'est pas touché. */

/* Jamais de défilement horizontal de la page */
html { overflow-x: hidden; }
body { max-width: 100%; }
main { min-width: 0; }
img, video, canvas { max-width: 100%; }

/* ---------- Écran Ventes : colonnes en onglets (≤ 900 px) ---------- */
#vcol-tabs { display: none; }
@media (max-width: 900px) {
  #vcol-tabs { flex: none; display: flex; gap: 6px; padding: 4px 2px 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #vcol-tabs::-webkit-scrollbar { display: none; }
  #vcol-tabs button { flex: 1 0 auto; min-height: 44px; min-width: 44px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-weight: 700; font-size: .78em; white-space: nowrap; }
  #vcol-tabs button.on { background: var(--accent); color: var(--accent-fg, #fff); border-color: transparent; }

  #ventes-panels.vtabs-on { flex-direction: column !important; flex-wrap: nowrap !important; overflow: hidden !important; }
  #ventes-panels.vtabs-on > .resize-handle { display: none !important; }
  /* Une seule colonne affichée. La colonne active garde son propre display : une colonne
     masquée par la personnalisation (display:none en ligne) n'est jamais réaffichée. */
  #ventes-panels.vtabs-on > .ventes-col:not(.vtab-active) { display: none !important; }
  #ventes-panels.vtabs-on > .ventes-col { width: 100% !important; max-height: none !important; min-height: 0 !important; flex: 1 1 0 !important; }
}

/* ---------- Mise en page générale ≤ 900 px ---------- */
@media (max-width: 900px) {
  .header { gap: 6px; }
  .global-search { display: none; }
  .tabs { justify-content: flex-start; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  main { padding: 6px; }
  .modal { max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  table { max-width: 100%; }
}

/* ---------- Cibles tactiles ≥ 44 px (écran étroit ou tactile) ---------- */
@media (max-width: 900px), (pointer: coarse) {
  .btn, .btn-sm, .tab-btn, .qty-btn, .btn-outline, .btn-primary, #btn-login, .tabs button,
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select { min-height: 44px; }
  .btn, .btn-sm, .btn-outline, .btn-primary { min-width: 44px; }
  .qty-btn { min-width: 44px; }
  .tab-btn { padding-left: 10px; padding-right: 10px; }
  input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; }
  #user-badge { width: 44px !important; height: 44px !important; }
  .stock-card, .sidebar-item, .art-card, .cart-line { min-height: 44px; }
}

/* ---------- Téléphone ---------- */
@media (max-width: 600px) {
  :root { --font-base: 16px; }
  .header { padding: 4px 6px; }
  /* les écrans à plusieurs colonnes (Stock, Commandes, Historique…) défilent verticalement */
  .panel-row { overflow-y: auto !important; overflow-x: hidden !important; }
  .panel-row > .card { max-height: none !important; min-height: 220px; }
}

/* ---------- Super-admin (public/superadmin) ≤ 700 px : navigation en barre d'onglets, colonnes empilées ---------- */
@media (max-width: 700px) {
  .app-body { flex-direction: column; }
  .app-body > .sidebar { display: flex !important; flex-direction: row; width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .app-body > .sidebar .sidebar-head, .app-body > .sidebar .sidebar-footer { display: none; }
  .app-body > .sidebar .nav-item { flex: 1; justify-content: center; width: auto; min-height: 44px; border-bottom: 3px solid transparent; border-left: 0; padding: 8px 10px; }
  .app-body > .sidebar .nav-item.active { border-bottom-color: var(--accent); border-left: 0; padding-left: 10px; }
  .page.active { padding: 10px; }
  .page.active table { display: block; max-width: 100%; overflow-x: auto; }
  .boutique-split { flex-direction: column; overflow-y: auto; }
  .blist-col { width: 100%; max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--border); flex: none; }
  .bdetail-col { flex: none; overflow: visible; }
  .bdetail-inner { flex-direction: column; overflow: visible; }
  .bdet-id { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .bdet-users { min-width: 0; border-right: 0; overflow: visible; }
  .nav-item, .user-menu-item, .btn-close { min-height: 44px; }
}

/* ---------- Catalogue public : barre « mode édition » (administrateur connecté) sur petit écran ---------- */
@media (max-width: 640px) {
  #edit-bar { overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
  #edit-bar > * { flex: none; }
  #edit-bar::-webkit-scrollbar { display: none; }
}

/* ---------- Usage tactile (tablette, téléphone) : l'application doit se manier comme une vraie application ---------- */
@media (pointer: coarse) {
  html, body { overscroll-behavior: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; } /* pas de « tirer pour recharger » ni de rebond de la page */
  button, a, select, label, summary, .btn, .tab-btn, .chip, .card-head, th, .sidebar-item, .art-card, .cart-line, .ot-sm-btn, .ot-sm-chip, .ot-sm-stat, #otchino-statusbar {
    touch-action: manipulation; -webkit-tap-highlight-color: transparent; /* pas d'attente de double-tap, pas de halo gris */
  }
  button, .btn, .tab-btn, .chip, .card-head, th, .sidebar-item, .art-card, .ot-sm-btn, .ot-sm-chip, .ot-sm-stat, #otchino-statusbar, .header {
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; /* un appui long ne sélectionne pas les menus et boutons */
  }
  input, select, textarea { font-size: max(16px, 1em); } /* iPad / iPhone : en dessous de 16 px, l'écran zoome tout seul à la saisie */
  /* Texte jamais minuscule (les tailles en « em » se cumulaient jusqu'à 8 px) */
  button, .btn, .btn-sm, .chip, .tab-btn, select, label { font-size: max(13px, 1em); }
  small, .small, .muted, .ps-hint, .badge-muted, .small-title { font-size: max(11.5px, .8em); }
  /* Cibles de 44 px : pastilles, filtres, boutons compacts, champs de recherche */
  .chip, .btn-sm, .input-sm, .vcl-q, #caisse-search, #global-search { min-height: 40px !important; }
  .chip { display: inline-flex; align-items: center; padding-left: 14px; padding-right: 14px; }
  .sidebar-item, .art-card, .cart-line, .vo-row, .cmdp-row, .cmdp-item { min-height: 44px; }
  .hv-day, #grid-articles .sidebar-item, #cal-grid button, #vcv-modes button { min-height: 40px !important; }
  [class*="vcl-"] small, .vcl-nm { font-size: max(11px, .8em) !important; }
  .vcl-av, .vcl-letter { font-size: max(11px, 1em) !important; }
  #grid-articles .sidebar-item { padding-top: 6px !important; padding-bottom: 6px !important; }
  html body .header .tab-btn { font-size: max(11.5px, .72em) !important; }
  @media (max-width: 600px) { html body .header .tab-btn { white-space: normal; line-height: 1.12; text-align: center; justify-content: center; overflow: hidden; padding-left: 2px !important; padding-right: 2px !important; min-height: 44px; } } /* onglets du téléphone : jamais plus petits que 11,5 px */
  /* Encoches / coins arrondis : rien sous l'encoche en application installée */
  .header { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); padding-top: max(6px, env(safe-area-inset-top)); }
  main { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  /* Défilement doux dans les listes et colonnes */
  .col-body, .panel-row, #ventes-panels, .modal, .tabs { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
}

/* ---------- Tablette en largeur (≤ 1180 px) : on réduit l'affichage au nécessaire ---------- */
@media (max-width: 1180px) and (pointer: coarse) {
  .global-search { display: none; }
  .header .shop-name { max-width: 14vw; }
}

/* ---------- Menu du bas sur téléphone (≤ 600 px) : public/bottom-nav.js ----------
   Barre : 2 raccourcis, bouton central rond surélevé (logo) qui ouvre la feuille « Menu », 2 raccourcis.
   Feuille : grille de pastilles colorées par sections. */
#bottom-nav, #bottom-nav-sheet { display: none; }
@media (max-width: 600px) {
  :root { --bn-h: 62px; }
  body.has-bottom-nav .header #main-tabs { display: none !important; }
  body.has-bottom-nav { padding-bottom: calc(var(--bn-h) + env(safe-area-inset-bottom, 0px)); }
  #bottom-nav { display: flex; align-items: stretch; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10001; height: calc(var(--bn-h) + env(safe-area-inset-bottom, 0px)); padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); background: var(--panel, #fff); border-top: 1px solid var(--border); box-shadow: 0 -2px 12px rgba(0, 0, 0, .07); }
  #bottom-nav .bn-item, #bottom-nav .bn-center { flex: 1 1 0; min-width: 0; min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 2px; border: 0; background: transparent; color: var(--muted); font-size: 11.5px; font-weight: 700; line-height: 1.1; cursor: pointer; }
  #bottom-nav .bn-pill { display: flex; align-items: center; justify-content: center; width: 52px; height: 30px; border-radius: 999px; transition: background .15s; }
  #bottom-nav .bn-item.on { color: var(--accent); }
  #bottom-nav .bn-item.on .bn-pill { background: color-mix(in srgb, var(--accent) 16%, transparent); }
  #bottom-nav .bn-lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* bouton central : rond, surélevé, anneau de la couleur d'accent */
  #bottom-nav .bn-center { position: relative; justify-content: flex-end; padding-bottom: 6px; color: var(--text); }
  #bottom-nav .bn-logo { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); width: 58px; height: 58px; border-radius: 50%; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #1c1c20; color: #fff; font-weight: 800; font-size: 22px; border: 3px solid var(--panel, #fff); box-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(0, 0, 0, .25); }
  #bottom-nav .bn-logo img { width: 70%; height: 70%; object-fit: contain; }
  #bottom-nav .bn-center.open .bn-logo { box-shadow: 0 0 0 3px var(--accent), 0 4px 12px rgba(0, 0, 0, .25); }
  #bottom-nav .bn-center .bn-lbl { color: var(--accent); }
  #bottom-nav-sheet:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 10000; }
  #bottom-nav-sheet .bn-backdrop { position: absolute; inset: 0; background: rgba(15, 20, 30, .45); }
  #bottom-nav-sheet .bn-sheet { position: absolute; left: 0; right: 0; bottom: calc(var(--bn-h) + env(safe-area-inset-bottom, 0px)); max-height: 68vh; overflow-y: auto; background: var(--panel, #fff); border-radius: 22px 22px 0 0; padding: 8px 14px 36px; box-shadow: 0 -6px 24px rgba(0, 0, 0, .2); overscroll-behavior: contain; }
  #bottom-nav-sheet .bn-grip { width: 44px; height: 5px; border-radius: 5px; background: var(--border); margin: 2px auto 10px; }
  #bottom-nav-sheet .bn-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 4px 12px; font-size: 18px; }
  #bottom-nav-sheet .bn-link { min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: transparent; color: var(--accent); font-weight: 700; font-size: 14px; }
  #bottom-nav-sheet .bn-reset { display: block; margin: 14px auto 0; color: var(--muted); }
  #bottom-nav-sheet .bn-hint, #bottom-nav-sheet .bn-empty { margin: 0 4px 12px; color: var(--muted); font-size: 13px; }
  #bottom-nav-sheet .bn-tico { position: relative; }
  #bottom-nav-sheet .bn-tile:not(.sel):not(.on) .bn-tico { }
  #bottom-nav-sheet .bn-check { position: absolute; top: -5px; right: -5px; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; }
  #bottom-nav-sheet .bn-tile.sel .bn-tico { box-shadow: 0 0 0 2px var(--accent); }
  #bottom-nav-sheet .bn-sec { margin: 8px 4px 8px; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
  #bottom-nav-sheet .bn-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 4px; }
  #bottom-nav-sheet .bn-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 44px; padding: 2px 0; border: 0; background: transparent; color: var(--text); font-size: 13px; font-weight: 700; text-align: center; line-height: 1.15; }
  #bottom-nav-sheet .bn-tico { width: 56px; height: 56px; border-radius: 16px; display: flex; align-items: center; justify-content: center; color: hsl(var(--h) 70% 45%); background: hsl(var(--h) 85% 50% / .12); border: 1px solid hsl(var(--h) 70% 50% / .25); }
  #bottom-nav-sheet .bn-tico svg { width: 26px; height: 26px; }
  #bottom-nav-sheet .bn-tile.on .bn-tico { box-shadow: 0 0 0 2px var(--accent); }
  #bottom-nav-sheet .bn-tlbl { max-width: 100%; overflow-wrap: anywhere; }
  body.has-bottom-nav #otchino-statusbar { min-height: 30px; align-items: flex-start; padding-top: 4px; } /* le texte reste au-dessus du bouton R */
}

/* ---------- Téléphone : cibles tactiles confortables hors tableaux (audit) ---------- */
@media (max-width: 600px) {
  main button:not(table button):not(.qty-btn):not(.ag-ib):not(.sh-act):not(.ac-ib):not(.resize-handle),
  main a.btn, main .chip, #ot-submenu button, #ot-submenu a { min-height: 40px; }
  main select, main input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]) { min-height: 42px; }
  #ot-submenu .ot-sm-row > * { flex: none; }            /* les puces du sous-menu défilent au lieu de se comprimer */
  #ot-submenu .ot-sm-row { padding-top: 6px; padding-bottom: 6px; }
  .ag-ib, .ac-ib, .sh-act { min-height: 36px; min-width: 36px; }
  .page.active .col-body, .page.active .panel-row { padding-bottom: 8px; }
  #tip-btn { min-width: 40px; min-height: 40px; }
  th > button[data-xf] { min-height: 34px !important; font-size: 13px !important; } /* filtre ▾ des en-têtes de tableaux (style en ligne) */
}
