/* GesComptoir — mobile et tablette « comme une application » : barre d'onglets en bas, en-tête compact, comptoir en deux onglets
   (Articles | Panier), fenêtres plein écran, tableaux défilants, zones tactiles de 48 px, zones de sécurité (encoche, barre
   de gestes). Aucun style en ligne (CSP) ; tout est piloté ici. Ordre de chargement : après theme.css. */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
button, .btn, a, summary, input, select { touch-action: manipulation; }
.tabbar { display: none; }
.c-mtabs, .c-gocart { display: none; }

/* ---------------------------------------------------------------- tablette et téléphones, jusqu'à 1100 px (menu en bas) */
@media (max-width: 1100px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  body.page-counter { padding-bottom: 0; }

  /* En-tête compact : marque + thème ; langue et déconnexion passent dans « Plus ». */
  header.top { padding: calc(.4rem + env(safe-area-inset-top)) calc(.75rem + env(safe-area-inset-right)) .4rem calc(.75rem + env(safe-area-inset-left)); gap: .5rem; flex-wrap: nowrap; }
  header.top nav { display: none; }
  header.top .right { margin-inline-start: auto; gap: .4rem; }
  header.top .right > form { display: none; }
  header.top .theme-menu > summary { padding: .5rem .7rem; min-height: 44px; }
  header.top .theme-menu .nav-menu { position: fixed; inset-inline: .75rem; top: 56px; min-width: 0; z-index: 60; }

  /* Barre d'onglets */
  .tabbar { display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 50; background: var(--head-bg, var(--card)); color: var(--head-fg, var(--text)); border-top: 1px solid var(--head-line, var(--line)); padding-bottom: env(safe-area-inset-bottom); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: 0 -4px 18px rgba(0, 0, 0, .12); }
  body.page-counter .tabbar { display: none; }
  .tabbar > a, .tabbar > details > summary { flex: 1 1 0; min-width: 0; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; font-size: .72rem; font-weight: 600; text-decoration: none; color: inherit; list-style: none; cursor: pointer; padding: .25rem .1rem; border-radius: 12px; }
  .tabbar > details { flex: 1 1 0; min-width: 0; }
  .tabbar .ico { font-size: 1.35rem; line-height: 1; }
  .tabbar a.on, .tabbar details[open] > summary { color: var(--brand); background: var(--card-2); }
  :root[data-theme=marine] .tabbar a.on, :root[data-theme=marine] .tabbar details[open] > summary { color: #ffb347; background: rgba(255, 255, 255, .12); }
  .tabbar .sheet { position: fixed; inset-inline: 0; bottom: calc(60px + env(safe-area-inset-bottom)); max-height: 78vh; overflow-y: auto; background: var(--card); color: var(--text); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 1rem; box-shadow: 0 -10px 30px rgba(0, 0, 0, .25); z-index: 70; }
  .tabbar .sheet h3 { margin: .9rem 0 .4rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
  .tabbar .sheet h3:first-child { margin-top: 0; }
  .tabbar .sheet .grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .tabbar .sheet .grid a, .tabbar .sheet .grid button { min-height: 52px; display: flex; align-items: center; gap: .5rem; padding: .5rem .8rem; border-radius: 14px; background: var(--card-2); color: var(--text); border: 1px solid var(--line); text-decoration: none; font-weight: 600; font-size: .95rem; box-shadow: none; text-align: start; }
  .tabbar .sheet form { display: contents; }

  main { margin: .75rem auto; padding-inline: calc(.75rem + env(safe-area-inset-left)) calc(.75rem + env(safe-area-inset-right)); }
  :root[data-layout=side] body { padding-inline-start: 0; }
}

/* ---------------------------------------------------------------- téléphone */
@media (max-width: 700px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 1rem; border-radius: 16px; margin-bottom: 1rem; }
  .row > * { flex: 1 1 100%; }
  /* 16 px minimum : évite le zoom automatique d'iOS dans les champs. */
  input, select, textarea, button { font-size: 16px; }
  .actions { gap: .4rem; }
  .actions .btn, .actions button { flex: 1 1 auto; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .kpi { padding: .8rem; }
  .kpi .kpi-value { font-size: 1.4rem; }
  .dash { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .tile { min-height: 84px; font-size: 1rem; }

  /* Tableaux : défilement horizontal doux plutôt que du texte écrasé. */
  main table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  main table th, main table td { padding: .55rem .6rem; }
  .filters .row { gap: .5rem; }

  /* Fenêtres (paiement, accord du gérant, vente terminée) : plein écran, comme une feuille d'application. */
  #counter dialog { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; padding: 1rem calc(1rem + env(safe-area-inset-right)) calc(1rem + env(safe-area-inset-bottom)) calc(1rem + env(safe-area-inset-left)); overflow-y: auto; }
  .c-pay-row { flex-direction: column; align-items: stretch; }
  .c-pay-row input { flex: 1 1 auto; width: 100%; }
  .c-modes button { flex: 1 1 45%; }

  /* ---- Comptoir : deux onglets Articles | Panier ---- */
  main.counter { padding-inline: .5rem; margin-top: .5rem; }
  #counter .c-top { flex-direction: column; gap: .5rem; margin-bottom: .6rem; }
  #counter .c-top input { min-height: 52px; }
  .c-mtabs { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .6rem; position: sticky; top: 52px; z-index: 20; }
  .c-mtabs button { min-height: 52px; font-size: 1rem; display: flex; align-items: center; justify-content: center; gap: .5rem; }
  .c-mtabs button:not(.on) { background: var(--card-2); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
  .c-mtabs .badge-count { min-width: 1.6rem; height: 1.6rem; border-radius: 999px; background: var(--bad); color: #fff; font-size: .85rem; display: inline-flex; align-items: center; justify-content: center; padding: 0 .4rem; }
  .c-mtabs .badge-count[data-n="0"] { display: none; }
  .c-main { grid-template-columns: 1fr; }
  .c-main .card { min-height: 0; }
  #counter[data-ctab=panier] .c-results, #counter:not([data-ctab]) .c-cart { display: none; }
  #counter[data-ctab=articles] .c-cart { display: none; }
  #counter[data-ctab=articles] .c-buttons, #counter:not([data-ctab]) .c-buttons { display: none; }
  .c-tiles { grid-template-columns: repeat(2, 1fr); }
  .c-tile { min-height: 96px; }
  .c-line { grid-template-columns: 1fr auto; row-gap: .4rem; }
  .c-line-name { grid-column: 1 / -1; }
  .c-line-total { grid-column: 1 / -1; text-align: start; }
  .c-totals-table .grand th, .c-totals-table .grand td { font-size: 1.6rem; }
  .c-paystate button { min-height: 56px; font-size: 1rem; padding-inline: .4rem; }
  .c-buttons { position: static; display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; padding: .5rem 0 calc(.5rem + env(safe-area-inset-bottom)); background: var(--bg); }
  .c-buttons button, .c-buttons .btn { min-height: 48px; padding: .3rem .2rem; font-size: .9rem; flex: none; }
  .c-buttons [data-doc=TK] { grid-column: 1 / -1; min-height: 56px; font-size: 1.15rem; }
  .c-buttons kbd { display: none; }

  /* Bouton flottant « Voir le panier » depuis l'onglet Articles */
  .c-gocart { display: flex; position: fixed; inset-inline: .75rem; bottom: calc(.75rem + env(safe-area-inset-bottom)); z-index: 40; min-height: 60px; font-size: 1.05rem; justify-content: space-between; align-items: center; box-shadow: 0 8px 24px var(--glow); }
  #counter[data-ctab=panier] .c-gocart { display: none !important; }
  body.page-counter { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* ---------------------------------------------------------------- tablette (portrait et paysage) : comptoir à deux colonnes */
@media (min-width: 701px) and (max-width: 1100px) {
  main.counter { max-width: none; padding-inline: .75rem; }
  .c-main { grid-template-columns: 1fr 1fr; }
  .c-line { grid-template-columns: 1fr auto; row-gap: .4rem; }
  .c-line-name { grid-column: 1 / -1; }
  .c-line-total { grid-column: 1 / -1; text-align: end; }
  .c-tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .c-buttons { position: sticky; bottom: 0; padding-bottom: calc(.5rem + env(safe-area-inset-bottom)); }
  body.page-counter { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
  main table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* Affichage « application installée » : plus de marges inutiles, pas de sélection de texte sur les boutons. */
@media (display-mode: standalone) {
  button, .btn, .tabbar a, summary { -webkit-user-select: none; user-select: none; }
  body { overscroll-behavior-y: contain; }
}

@media print { .tabbar, .c-mtabs, .c-gocart { display: none !important; } body { padding-bottom: 0 !important; } }

[hidden] { display: none !important; }

/* Les cartes du comptoir ne doivent jamais élargir la page. */
.c-main > *, #counter .c-top > *, .c-results, .c-cart { min-width: 0; max-width: 100%; }
.c-tabs { max-width: 100%; }

@media (max-width: 700px) { .c-sum.big { font-size: 1.35rem; } .c-sum.change { font-size: 1.8rem; } }

/* Les tableaux du comptoir (totaux) ne défilent pas : ils tiennent dans la colonne. */
@media (max-width: 1100px) {
  main.counter table, .c-totals-table { display: table; overflow: visible; white-space: normal; width: 100%; }
  .c-totals-table .grand th, .c-totals-table .grand td { font-size: 1.5rem; }
}
