/* Design system — écran de vente (tactile, tablette en priorité)
   Identité affirmée façon Square/SumUp : indigo profond en couleur de marque,
   vert franc pour les actions de paiement, remplissages pleins sur les
   boutons plutôt que des contours, ombres colorées pour donner du relief. */

:root {
  --bg-canvas: #ECE9FB;
  --bg-panel: #ffffff;
  --bg-panel-alt: #F5F3FC;
  --ticket-bg: #F3F1FD;
  --border: #E2DEF6;
  --border-strong: #CCC5EF;

  --text-primary: #191335;
  --text-secondary: #6B6690;
  --text-inverse: #ffffff;

  --brand: #4F46E5;
  --brand-strong: #3B32B8;
  --brand-darker: #241D6B;
  --brand-soft: #E7E4FB;

  --success: #16A34A;
  --success-strong: #0F7C38;
  --success-soft: #DCFCE7;

  --danger: #E11D48;
  --danger-soft: #FFE1E9;

  --warning: #F59E0B;
  --warning-strong: #B45309;
  --warning-soft: #FEF3C7;

  --total-bg: var(--success-strong); /* vert, comme sur les TPV de référence (Openbravo) */

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 28px;

  --shadow-sm: 0 2px 6px rgba(25, 19, 53, 0.08);
  --shadow-md: 0 8px 22px rgba(25, 19, 53, 0.14);
  --shadow-lg: 0 20px 48px rgba(25, 19, 53, 0.26);
  --shadow-btn-brand: 0 6px 16px rgba(79, 70, 229, 0.35);
  --shadow-btn-success: 0 6px 18px rgba(22, 163, 74, 0.35);
  --shadow-btn-warning: 0 6px 16px rgba(245, 158, 11, 0.35);

  --entry-width: clamp(320px, 27vw, 380px);
  --touch: 60px;
  --entry-bar-height: 80px;

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* Sans ça, tout élément dont une règle CSS déclare `display` (flex/grid/...)
   ignore silencieusement l'attribut `hidden` — un piège CSS classique qui a
   causé un vrai bug (fenêtre de recherche impossible à fermer). */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  /* Empêche le scroll de la page elle-même : c'est un app-shell, tout le
     défilement doit rester confiné aux zones prévues (ticket, overlays). Sans
     ça, un dépassement vertical pousse le bouton Encaisser hors écran au lieu
     de simplement rendre le ticket scrollable. */
  overflow: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-canvas);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
}

svg {
  display: block;
}

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 1fr var(--entry-width);
  height: 100vh;
  height: 100dvh; /* tient compte de la barre d'adresse mobile, contrairement à 100vh */
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px 16px;
  padding: 14px 24px;
  background: var(--brand-darker);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.02em;
  color: var(--text-inverse);
  white-space: nowrap;
}

.topbar__brand svg {
  color: #A79CF7;
}

.topbar__history-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-inverse);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  flex: none;
  white-space: nowrap;
}

.topbar__history-btn:active {
  background: rgba(255, 255, 255, 0.22);
}

.topbar__session {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: #C9C1F9;
  white-space: nowrap;
}

#history-toggle {
  margin-left: 0;
}

#back-to-rooms-btn, #kitchen-ticket-btn, #room-logout-btn {
  margin-left: 0;
}

.topbar__table-label {
  font-weight: 800;
  font-size: 14.5px;
  color: var(--text-inverse);
  background: rgba(255, 255, 255, 0.15);
  padding: 7px 16px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- Mode Restaurant : écran salle -> table ---------- */

.room-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-canvas);
}

.room-tabs {
  display: flex;
  gap: 8px;
  padding: 16px 24px 0;
  overflow-x: auto;
}

.room-tabs .pill {
  flex: none;
}

.room-grid {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  align-content: start;
}

.table-tile {
  height: 110px;
  border-radius: var(--radius-lg);
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  color: var(--text-primary);
  background: var(--bg-panel);
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease;
}

.table-tile:active {
  transform: scale(0.96);
}

.table-tile__status {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.table-tile.is-libre {
  background: var(--success-soft);
  color: var(--success-strong);
}

.table-tile.is-occupee {
  background: var(--brand);
  color: var(--text-inverse);
}

.table-tile.is-reservee {
  background: var(--warning);
  color: var(--text-inverse);
}

.room-new-table-btn {
  width: calc(100% - 48px);
  margin: 0 24px 20px;
}

.room-screen .catalogue__empty {
  margin: 32px 24px 0;
}

.topbar__clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
  color: var(--text-inverse);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.topbar__clock .clock__time {
  font-weight: 800;
  font-size: 16px;
}

.topbar__clock .clock__date {
  font-weight: 600;
  font-size: 11.5px;
  color: #C9C1F9;
  text-transform: capitalize;
}

/* ---------- Login screen ---------- */

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-canvas);
  padding: 20px;
  z-index: 500;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--brand);
  font-weight: 800;
  font-size: 22px;
  margin-bottom: 6px;
}

.login-card__brand span {
  color: var(--text-primary);
}

.login-card__links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  cursor: pointer;
  text-decoration: none;
}

.link-btn:hover {
  text-decoration: underline;
}

.forgot-password-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.field-note {
  font-size: 13px;
  color: var(--text-secondary);
}

.search-box {
  /* PAS de flex: 1 ici : .pos-left (son seul parent aujourd'hui) est en
     colonne, pas en rangée — flex: 1 y ferait grandir la barre de recherche
     pour occuper tout l'espace vertical disponible, repoussant catégories et
     favoris tout en bas de l'écran (bug constaté sur mobile). */
  position: relative;
  max-width: 640px;
}

.search-box input {
  width: 100%;
  height: var(--touch);
  padding: 0 18px 0 46px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--bg-panel-alt) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B6690' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 16px center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  transition: box-shadow .15s ease;
}

.search-box input:focus {
  outline: none;
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.categories {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.pill {
  height: 42px;
  padding: 0 20px;
  border-radius: 999px;
  border: none;
  background: var(--bg-panel-alt);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all .12s ease;
  white-space: nowrap;
}

.categories .pill {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-tabs .pill {
  flex: none;
}

.pill:active {
  transform: scale(0.96);
}

.pill.is-active {
  background: var(--brand);
  color: var(--text-inverse);
  box-shadow: var(--shadow-btn-brand);
}

/* ---------- Product grid (used inside the "browse catalogue" overlay) ---------- */

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}

.browse-grid {
  max-height: 48vh;
  overflow-y: auto;
  padding: 2px;
}

.catalogue__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  gap: 8px;
  text-align: center;
}

.catalogue__empty strong {
  color: var(--text-primary);
  font-size: 17px;
}

/* product-tile component */

product-tile {
  display: block;
}

.tile {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 132px;
  padding: 14px;
  background: var(--bg-panel);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, box-shadow .15s ease;
  user-select: none;
}

.tile:active {
  transform: scale(0.97);
}

.tile:hover {
  box-shadow: var(--shadow-md);
}

/* Retour visuel immédiat au tap : le clic seul ne suffit pas à confirmer la
   sélection tant que la grille reste affichée (l'overlay ne se ferme pas). */
.tile.is-active {
  background: var(--brand);
  transition: background-color .15s ease;
}

.tile.is-active .tile__name,
.tile.is-active .tile__price {
  color: var(--text-inverse);
}

.tile.is-active .tile__stock {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-inverse);
}

.tile.is-active .tile__stock.is-low {
  background: rgba(255, 255, 255, 0.25);
  color: var(--text-inverse);
}

.tile__name {
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.3;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile__footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}

.tile__price {
  font-weight: 800;
  font-size: 18px;
  color: var(--brand-strong);
  white-space: nowrap;
}

.tile__stock {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  background: var(--bg-panel-alt);
  padding: 2px 7px;
  border-radius: 999px;
}

.tile__stock.is-low {
  color: var(--warning-strong);
  background: var(--warning-soft);
}

/* ---------- Ticket pane (main view — "Nuevo pedido") ---------- */

.ticket-pane {
  display: flex;
  flex-direction: column;
  background: var(--ticket-bg);
  height: 100%;
  min-height: 0; /* item de grille : sans ça, il refuse de se réduire et pousse le reste hors écran */
  overflow: hidden;
}

.ticket-pane__header {
  flex-shrink: 0;
  padding: 20px 22px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ticket-pane__title {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.cart__count {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-inverse);
  background: var(--brand);
  padding: 4px 12px;
  border-radius: 999px;
}

.customer-bar {
  flex-shrink: 0;
  margin: 0 22px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  text-align: left;
}

.customer-bar:hover {
  border-color: var(--brand);
}

.customer-bar svg:first-child {
  color: var(--brand);
  flex-shrink: 0;
}

.customer-bar span:not(.customer-bar__chevron) {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.customer-bar__chevron {
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* ---------- Overlay de sélection / création client ---------- */

.customer-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 50px;
  padding: 0 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  text-align: left;
}

.customer-option:hover {
  border-color: var(--brand);
}

.customer-option--anon {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand-strong);
}

.customer-option__meta {
  margin-left: auto;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12.5px;
}

.customer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.customer-new-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 4px;
}

.ticket-pane__lines {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ticket-pane__empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-secondary);
  padding: 20px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
}

.ticket-pane__empty svg {
  opacity: .35;
  color: var(--brand);
}

/* cart-line component */

cart-line {
  display: block;
}

.line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  border-left: 5px solid var(--brand);
  box-shadow: var(--shadow-sm);
  animation: line-flash .7s ease-out;
}

/* Flash bleu marqué à chaque ajout/màj de la ligne (pas juste un fondu discret) :
   confirmation visuelle sans ambiguïté que l'article a bien été pris en compte. */
@keyframes line-flash {
  0% { background: var(--brand-soft); border-left-color: var(--brand-strong); transform: scale(1.015); }
  100% { background: var(--bg-panel); border-left-color: var(--brand); transform: scale(1); }
}

.line__name {
  font-weight: 700;
  font-size: 16px;
  grid-column: 1 / -1;
  line-height: 1.3;
  color: var(--text-primary);
}

.line__controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-panel-alt);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.stepper button {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg-panel);
  font-size: 19px;
  font-weight: 800;
  color: var(--brand);
  cursor: pointer;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.stepper button:active {
  background: var(--brand-soft);
}

.stepper__qty {
  min-width: 26px;
  text-align: center;
  font-weight: 800;
  font-size: 15px;
}

.line__remove {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.line__price {
  display: flex;
  align-items: baseline;
  gap: 6px;
  justify-self: end;
}

.line__unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.line__total {
  font-weight: 800;
  font-size: 18px;
  color: var(--text-primary);
}

.line__discount-toggle {
  height: 36px;
  padding: 0 12px;
  border: none;
  background: var(--bg-panel-alt);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.line__discount-input {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.line__discount-input input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  font-size: 14px;
}

.line__discount-input button {
  height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--text-inverse);
  font-weight: 700;
  cursor: pointer;
}

.line__comment-toggle {
  height: 36px;
  padding: 0 12px;
  border: none;
  background: var(--bg-panel-alt);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}

.line__comment-toggle.has-comment {
  background: var(--warning-soft);
  color: var(--warning-strong, var(--warning));
}

.line__comment-display {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 600;
  color: var(--warning-strong, var(--warning));
  background: var(--warning-soft);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.line__comment-input {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.line__comment-input input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  font-size: 14px;
}

.line__comment-input button {
  height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--text-inverse);
  font-weight: 700;
  cursor: pointer;
}

/* ---------- Total + checkout ---------- */

.ticket-pane__summary {
  flex-shrink: 0;
  padding: 16px 20px 20px;
  background: var(--ticket-bg);
}

.total-bar {
  background: var(--total-bg);
  border-radius: var(--radius-xl);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  box-shadow: var(--shadow-md);
}

.total-bar__label {
  color: #B7AEF5;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.total-bar__amount {
  color: var(--text-inverse);
  font-weight: 900;
  font-size: 38px;
  letter-spacing: -0.02em;
}

.btn {
  height: var(--touch);
  border-radius: var(--radius-md);
  border: none;
  font-weight: 800;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .1s ease, opacity .15s ease, box-shadow .15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  box-shadow: none !important;
}

.btn-block {
  width: 100%;
}

.btn-success {
  background: var(--success);
  color: var(--text-inverse);
  box-shadow: var(--shadow-btn-success);
}

.btn-success:not(:disabled):hover {
  background: var(--success-strong);
}

/* Le bouton d'encaissement est LE point de sortie du panier vers le paiement :
   volontairement plus grand et plus voyant que les autres boutons. */
#checkout-btn {
  height: 72px;
  font-size: 19px;
  letter-spacing: .01em;
}

.btn-brand {
  background: var(--brand);
  color: var(--text-inverse);
  box-shadow: var(--shadow-btn-brand);
}

.btn-brand:not(:disabled):hover {
  background: var(--brand-strong);
}

.btn-ghost {
  background: var(--bg-panel-alt);
  color: var(--text-primary);
  border: none;
}

.btn-danger-ghost {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse);
  box-shadow: 0 6px 16px rgba(225, 29, 72, 0.35);
}

/* ---------- Historique des ventes / duplicata / avoir ---------- */

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 14px 16px;
  background: var(--bg-panel-alt);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background .12s ease;
}

.history-row:active {
  background: var(--brand-soft);
}

.history-row__main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-row__id {
  font-weight: 800;
  font-size: 15px;
}

.history-row__date {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.history-row__total {
  grid-row: 1 / 3;
  grid-column: 2;
  align-self: center;
  font-weight: 800;
  font-size: 17px;
  color: var(--text-primary);
}

.history-row__total.is-negative {
  color: var(--danger);
}

.history-badge {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success-strong);
}

.history-badge--avoir {
  background: var(--danger-soft);
  color: var(--danger);
}

.history-detail__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.history-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 14.5px;
  font-weight: 600;
}

.history-item:last-child {
  border-bottom: none;
}

.history-receipt {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* ---------- Modal overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(25, 19, 53, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal--wide {
  max-width: 760px;
}

.modal__header {
  padding: 16px 22px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__title {
  font-weight: 800;
  font-size: 20px;
}

.modal__close {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: none;
  background: var(--bg-panel-alt);
  font-size: 18px;
  color: var(--text-secondary);
  cursor: pointer;
}

.modal__body {
  padding: 10px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field input, .field textarea {
  width: 100%;
  height: var(--touch);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--bg-panel-alt);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.field input:focus, .field textarea:focus {
  outline: none;
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.field input:disabled {
  color: var(--text-secondary);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.error-banner {
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
  font-size: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
}

/* ---------- Payment modal — deux zones nettes (recap à gauche, action
   tintée à droite), à l'image d'un vrai terminal de caisse professionnel. ---------- */

.modal--payment {
  max-width: 860px;
}

.pay-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  min-height: 0;
}

.pay-recap {
  padding: 6px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-right: 1.5px solid var(--border);
  overflow-y: auto;
  max-height: 72vh;
}

.pay-recap__title {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.pay-recap__items {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.pay-recap__item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.pay-recap__item-qty {
  color: var(--text-secondary);
  font-weight: 800;
  margin-right: 4px;
}

.pay-recap__item-total {
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pay-recap__total {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1.5px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 800;
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.pay-recap__total span:last-child {
  font-size: 19px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.pay-action {
  background: var(--bg-panel-alt);
  padding: 6px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: 72vh;
}

/* Le bouton d'encaissement ne doit JAMAIS nécessiter de défiler pour être
   atteint, quelle que soit la hauteur du récapitulatif/pavé numérique
   au-dessus — collé en bas du panneau plutôt qu'en flux normal. */
.pay-action > [data-action="submit-payment"],
.pay-action > [data-action="confirm"],
.pay-action > [data-action="confirm-exact"] {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  box-shadow: 0 -8px 12px -4px var(--bg-panel-alt);
}

/* Le focal point de tout l'écran : ce que la vendeuse doit lire en un coup
   d'œil avant toute autre information. */
.pay-focal {
  text-align: center;
  padding: 4px 0 2px;
}

.pay-focal__label {
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.pay-focal__amount {
  font-size: 42px;
  font-weight: 900;
  color: var(--brand-darker);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.pay-focal__amount.is-settled {
  color: var(--success-strong);
}

.pay-note {
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 700;
  font-size: 12.5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.method-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.method-btn {
  height: 78px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.method-btn svg {
  width: 26px;
  height: 26px;
  color: var(--brand);
}

.method-btn.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--text-inverse);
  box-shadow: var(--shadow-btn-brand);
}

.method-btn.is-active svg {
  color: var(--text-inverse);
}

.amount-display-label {
  text-align: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: -6px;
}

.amount-display {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  padding: 10px;
  background: var(--bg-panel);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  letter-spacing: .01em;
}

/* "À rendre au client" — le seul chiffre que la vendeuse doit lire d'un coup
   d'œil pendant qu'elle compte les billets : gros, plein, sans ambiguïté. */
.pay-change {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px;
  background: var(--success);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-btn-success);
}

.pay-change__label {
  font-weight: 700;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: rgba(255, 255, 255, 0.85);
}

.pay-change__value {
  color: var(--text-inverse);
  font-size: 38px;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.payment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.payment-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--success-soft);
  color: var(--success-strong);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 14px;
}

.payment-list__item button {
  border: none;
  background: transparent;
  color: var(--success-strong);
  font-weight: 700;
  cursor: pointer;
  font-size: 16px;
}

/* numeric-keypad component */

numeric-keypad {
  display: block;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.keypad button {
  height: 46px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--bg-panel-alt);
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  cursor: pointer;
}

.keypad button:active {
  background: var(--brand-soft);
}

.keypad button.keypad__backspace {
  color: var(--danger);
  background: var(--danger-soft);
}

.keypad button.keypad__primary {
  background: var(--success);
  color: var(--text-inverse);
  box-shadow: var(--shadow-btn-success);
  font-size: 15px;
}

/* Pavé numérique du paiement : volontairement différent du pavé "quantité"
   (touches plus grandes, fond blanc cerné) pour signaler qu'on manipule de
   l'argent — une étape plus sensible qu'une simple quantité d'articles. */
numeric-keypad.keypad--payment .keypad {
  gap: 10px;
}

numeric-keypad.keypad--payment .keypad button {
  height: 56px;
  font-size: 21px;
  background: var(--bg-panel);
  border: 1.5px solid var(--border-strong);
}

numeric-keypad.keypad--payment .keypad button:active {
  background: var(--brand-soft);
  border-color: var(--brand);
}

numeric-keypad.keypad--payment .keypad button.keypad__backspace {
  background: var(--danger-soft);
  border-color: transparent;
}

@media (max-width: 700px) {
  .pay-grid {
    grid-template-columns: 1fr;
  }

  .pay-recap {
    border-right: none;
    border-bottom: 1.5px solid var(--border);
    max-height: none;
    padding: 6px 20px 16px;
  }

  .pay-action {
    max-height: none;
    padding: 16px 20px 20px;
  }
}

/* ---------- Entry pane (scan + quantity — the fast input zone) ---------- */

.entry-pane {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: var(--bg-panel);
  overflow-y: auto;
}

.entry-pane__row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.scan-box {
  flex: 1;
  min-width: 0; /* sans ça, un <input> dans un conteneur flex refuse de rétrécir et déborde */
  position: relative;
}

.scan-box input {
  width: 100%;
  height: 68px;
  padding: 0 90px 0 20px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--brand-soft);
  font-size: 17px;
  font-weight: 700;
  color: var(--brand-darker);
  box-shadow: inset 0 0 0 2.5px var(--brand);
}

.scan-box input::placeholder {
  color: var(--brand);
  opacity: .65;
  font-weight: 600;
  font-size: 14.5px;
}

.scan-box input:focus {
  outline: none;
  box-shadow: inset 0 0 0 2.5px var(--brand), 0 0 0 4px var(--brand-soft);
}

.pending-qty-badge {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--brand-darker);
  color: var(--text-inverse);
  font-weight: 800;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.scan-suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 300px;
  overflow-y: auto;
  z-index: 30;
}

.scan-suggestion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.scan-suggestion:last-child {
  border-bottom: none;
}

.scan-suggestion:hover,
.scan-suggestion:active {
  background: var(--brand-soft);
}

.scan-suggestion__price {
  color: var(--brand-strong);
  font-weight: 800;
  white-space: nowrap;
}

.scan-suggestion__stock {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.scan-suggestions__empty {
  padding: 16px 18px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
}

.icon-btn {
  flex: none;
  width: 80px;
  height: 68px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-inverse);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn span {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.icon-btn:active {
  transform: scale(0.96);
}

#qty-toggle {
  background: var(--brand);
  box-shadow: var(--shadow-btn-brand);
}

#browse-toggle-compact {
  background: var(--warning);
  box-shadow: var(--shadow-btn-warning);
}

/* Masqué par défaut à toutes les largeurs : seul le bouton "Qté" le révèle.
   Avant ce correctif, la règle mobile (display:none + .is-open) était la
   seule à gater l'affichage — au-delà de 700px le pavé restait affiché en
   permanence et le bouton "Qté" n'avait plus aucun effet visible. */
.entry-pane__keypad {
  display: none;
  flex-direction: column;
  gap: 14px;
  background: var(--bg-panel-alt);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.entry-pane__keypad.is-open {
  display: flex;
}

#qty-toggle.is-active {
  background: var(--brand-strong);
  box-shadow: none;
}

.qty-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px;
}

.qty-preview__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.qty-preview__value {
  font-size: 32px;
  font-weight: 900;
  color: var(--brand);
}

.btn-ghost.btn-browse {
  background: var(--warning-soft);
  color: var(--warning-strong);
  font-weight: 800;
}

.btn-ghost.btn-browse svg {
  color: var(--warning-strong);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand-darker);
  color: var(--text-inverse);
  padding: 15px 24px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 14.5px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in .2s ease;
}

.toast.is-success { background: var(--success-strong); }
.toast.is-error { background: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ==========================================================================
   Responsive — deux axes indépendants, volontairement séparés :

   1) LARGEUR → décide de la STRUCTURE (1 colonne empilée vs 2 colonnes
      côte à côte). Breakpoint à 700px, choisi pour que le format tablette
      (768–1024px, priorité absolue) obtienne TOUJOURS la disposition large
      à 2 colonnes, y compris en portrait. Seuls les téléphones (~360–430px
      en portrait) passent sous ce seuil et reçoivent la disposition
      empilée avec barre de saisie compacte en bas.

   2) HAUTEUR → décide du GABARIT (paddings/tailles confortables vs
      compacts), indépendamment de la largeur. C'est ce qui manquait et
      causait le bug : un téléphone en paysage a une largeur "moyenne" mais
      une hauteur très réduite (~360–430px) ; sans règle dédiée à la
      hauteur, les paddings/tailles fixes du ticket ne s'adaptaient pas et
      le bouton Encaisser pouvait être coupé. Ce bloc s'applique à TOUTE
      disposition (1 ou 2 colonnes) dès que la hauteur est courte.

   Breakpoints résultants :
   - Mobile portrait   (large. < 700px, haut. ≥ 500px) → structure empilée, gabarit confortable
   - Mobile paysage     (large. variable, haut. < 500px) → structure empilée OU large selon la largeur, gabarit compact
   - Tablette portrait (large. 768–1024px)              → structure large (2 colonnes), gabarit confortable
   - Tablette paysage  (large. > 1024px)                → structure large (2 colonnes), gabarit confortable
   ========================================================================== */

@media (max-width: 700px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .ticket-pane {
    grid-row: 2;
  }

  .entry-pane {
    grid-row: 3;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    box-shadow: 0 -4px 16px rgba(25, 19, 53, 0.1);
    overflow: visible;
  }

  .entry-pane__row {
    flex: 1;
  }

  .scan-box input {
    height: var(--touch);
    font-size: 16px;
  }

  .icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .entry-pane__keypad {
    display: none;
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(var(--entry-bar-height) + env(safe-area-inset-bottom, 0));
    z-index: 70;
    box-shadow: var(--shadow-lg);
  }

  .entry-pane__keypad.is-open {
    display: flex;
  }

  #browse-toggle {
    display: none;
  }
}

@media (max-width: 480px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  /* Sur très petit écran, les deux boutons icône laissent trop peu de place
     au champ de scan (le plus important des trois) : on les resserre. */
  .icon-btn {
    width: 60px;
  }

  .icon-btn span {
    font-size: 9.5px;
  }
}

/* ---------- Gabarit compact : viewport bas (mobile en paysage, ~320–500px
   de haut). Indépendant de la largeur — s'applique que le layout soit
   empilé ou à 2 colonnes, pour garantir que le total + Encaisser restent
   TOUJOURS visibles sans scroll, quelle que soit l'orientation. ---------- */

@media (max-height: 500px) {
  .topbar {
    padding: 8px 20px;
  }

  .ticket-pane__header {
    padding: 10px 20px 8px;
  }

  .ticket-pane__title {
    font-size: 16px;
  }

  .ticket-pane__lines {
    padding: 4px 20px 8px;
    gap: 6px;
  }

  .line {
    padding: 10px 14px;
  }

  .ticket-pane__summary {
    padding: 8px 16px 10px;
  }

  .total-bar {
    padding: 10px 18px;
    margin-bottom: 8px;
  }

  .total-bar__amount {
    font-size: 26px;
  }

  #checkout-btn {
    height: 48px;
    font-size: 16px;
  }

  .entry-pane {
    padding: 10px 16px;
    gap: 10px;
  }

  .scan-box input,
  .icon-btn {
    height: 48px;
  }

  .entry-pane__keypad {
    padding: 8px;
    gap: 8px;
  }

  .keypad button {
    height: 40px;
  }
}

/* ---------- Écran de confirmation (avant impression / nouvelle vente) ---------- */

.sale-confirm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0 14px;
}

.sale-confirm__check {
  color: var(--success);
  margin-bottom: 4px;
}

.sale-confirm__title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
}

.sale-confirm__ticket {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
}

/* ---------- Ticket imprimable (receipt-modal) ---------- */

.receipt-print {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-panel-alt);
  border-radius: var(--radius-md);
  padding: 18px;
  margin-bottom: 4px;
}

.receipt__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.receipt__logo {
  max-width: 120px;
  max-height: 64px;
  object-fit: contain;
}

.receipt__shop {
  text-align: center;
  font-weight: 800;
  font-size: 16px;
  margin-bottom: 4px;
}

.receipt__meta {
  text-align: center;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 10px;
}

.receipt__divider {
  border-top: 1px dashed var(--border-strong);
  margin: 10px 0;
}

.receipt__item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
}

.receipt__total {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 15px;
  padding: 4px 0;
}

.receipt__vat {
  margin-bottom: 6px;
}

.receipt__vat-line {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.receipt__payments {
  margin-top: 6px;
}

.receipt__payment {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
  padding: 2px 0;
}

.receipt__hash {
  margin-top: 10px;
  font-size: 10.5px;
  color: var(--text-secondary);
  word-break: break-all;
}

.receipt__thanks {
  text-align: center;
  margin-top: 14px;
  font-weight: 700;
}

/* Impression : seul le ticket est visible, le reste de l'écran (sidebar,
   boutons, overlay sombre) disparaît. Fallback PDF/imprimante système faute
   d'intégration ESC/POS matérielle testable (cf. CLAUDE.md §2 — impression). */
@media print {
  body * {
    visibility: hidden;
  }

  .receipt-print, .receipt-print * {
    visibility: visible;
  }

  .receipt-print {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: #fff;
    box-shadow: none;
  }
}

/* ---------- Blocage abonnement expiré ---------- */

.subscription-blocker {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-canvas);
  padding: 20px;
}

.subscription-blocker__card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.subscription-blocker__card svg {
  color: var(--danger);
}

.subscription-blocker__card h1 {
  font-size: 20px;
  margin: 0;
}

.subscription-blocker__card p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.subscription-blocker__card .btn {
  margin-top: 6px;
}
