/* ============================================================
   Caisse Intermelkal — feuille de style unique
   Cible : écran tactile 1280×800+ (la caisse de la mère).
   Priorité : grosses cibles tactiles, contraste fort, zéro hover.
   ============================================================ */

:root {
  --bg:        #1a1d23;
  --bg-2:      #232730;
  --bg-3:      #2c313c;
  --fg:        #e8eaef;
  --fg-2:      #a7adba;
  --fg-3:      #6c727d;
  --accent:    #3aa6ff;
  --accent-2:  #1e5fab;
  --ok:        #3ed598;
  --warn:      #ffb84d;
  --danger:    #ff5c5c;
  --pending:   #b0b5be;

  --radius:    10px;
  --pad:       18px;
  --pad-sm:    10px;

  --h-topbar:  56px;
  --h-actions: 92px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
  font-size: 16px;
}

body {
  display: grid;
  grid-template-rows: var(--h-topbar) 1fr var(--h-actions);
  grid-template-areas: "top" "main" "actions";
  height: 100vh;
}

/* ====== TOPBAR ====== */
/* Items étalés sur toute la largeur via space-between (le gap reste comme min).
   Le logo reste calé à gauche, le dernier élément (pill écran Melkal) à droite. */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 var(--pad);
  background: var(--bg-2);
  border-bottom: 1px solid var(--bg-3);
}
#topbar .logo {
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--accent);
  font-size: 18px;
}
#topbar .clock {
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  color: var(--fg-2);
}
#topbar .health {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--fg-2);
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-ok      { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot-warn    { background: var(--warn); }
.dot-error   { background: var(--danger); }
.dot-unknown { background: var(--fg-3); }

/* ====== MAIN : TICKET ====== */
#ticket-screen {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--pad);
  gap: var(--pad-sm);
}
.ticket-header,
.ticket-line {
  display: grid;
  grid-template-columns: 40px 1fr 70px 100px 80px 120px 60px;
  align-items: center;
  gap: 10px;
}
.ticket-header {
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--fg-3);
  padding: 0 var(--pad-sm) 8px;
  border-bottom: 1px solid var(--bg-3);
}
.ticket-lines {
  flex: 1;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
}
.ticket-line {
  padding: 14px var(--pad-sm);
  border-bottom: 1px solid var(--bg-2);
  font-size: 17px;
  cursor: pointer;
  transition: background 80ms;
}
.ticket-line.selected {
  background: var(--bg-3);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.ticket-line.synced .col-status   { color: var(--ok); }
.ticket-line.pending .col-status  { color: var(--pending); }
.ticket-line.error .col-status    { color: var(--danger); }
.ticket-line.warn .col-status     { color: var(--warn); }
.ticket-line .col-status {
  font-size: 22px;
  text-align: center;
}
.ticket-line .col-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ticket-line .col-name .sub {
  display: block;
  font-size: 12px;
  color: var(--fg-3);
  font-weight: 400;
}
.ticket-line .col-qty   { text-align: center; font-variant-numeric: tabular-nums; }
.ticket-line .col-pu    { text-align: right;  font-variant-numeric: tabular-nums; color: var(--fg-2); }
.ticket-line .col-stock { text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; }
.ticket-line .col-stock.stock-ok    { color: var(--fg-2); }
.ticket-line .col-stock.stock-low   { color: var(--warn); font-weight: 600; }
.ticket-line .col-stock.stock-zero  { color: var(--danger); font-weight: 700; }
.ticket-line .col-tot   { text-align: right;  font-variant-numeric: tabular-nums; font-weight: 600; }
.ticket-line .col-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.ticket-totals {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 18px;
  padding: 14px var(--pad-sm);
  border-top: 2px solid var(--bg-3);
}
.ticket-totals .label {
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--fg-3);
}
.ticket-totals .amount {
  font-size: 36px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--fg-3);
  text-align: center;
  gap: 12px;
}
.empty-state .hint { font-size: 13px; }

/* === Pending sales button topbar === */
.pending-sales-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--bg-3);
  border-radius: 18px;
  font-size: 13px;
  cursor: pointer;
}
.pending-sales-btn:hover { background: var(--bg-3); border-color: var(--accent); }
.pending-sales-btn.has-pending { background: rgba(58, 166, 255, 0.15); border-color: var(--accent); }
.pending-sales-btn #pending-sales-count { font-weight: 700; font-variant-numeric: tabular-nums; }

/* === Pending sales overlay === */
.overlay-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.overlay-footer {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
.pending-sales-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  overflow-x: hidden;
  min-height: 200px;
  max-height: 60vh;
  overflow-y: auto;
}
.pending-sales-list .loading,
.pending-sales-list .empty { grid-column: 1 / -1; text-align: center; color: var(--fg-3); padding: 40px 20px; }
.pending-sale-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 20px;
  background: var(--bg-2);
  border: 2px solid var(--bg-3);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s, background-color .12s;
}
.pending-sale-card:hover {
  border-color: var(--accent);
  background-color: rgba(58, 166, 255, 0.08);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.pending-sale-card.current { border-color: var(--ok); background: rgba(62, 213, 152, 0.1); }
.pending-sale-card .vendeur { font-weight: 600; font-size: 16px; }
.pending-sale-card .heure { color: var(--fg-3); font-size: 13px; }
.pending-sale-card .montant {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
}

/* === Scanner debug badge === */
.scanner-debug {
  font-family: monospace;
  font-size: 12px;
  padding: 4px 10px;
  background: rgba(255, 200, 0, 0.15);
  border: 1px solid rgba(255, 200, 0, 0.4);
  border-radius: 6px;
  color: #ffc107;
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scanner-debug.hidden { display: none; }
.scanner-debug.committed { background: rgba(62, 213, 152, 0.15); border-color: var(--ok); color: var(--ok); }
.scanner-debug.rejected  { background: rgba(255, 71, 87, 0.15);  border-color: var(--danger); color: var(--danger); }

/* === Cross-sell suggestions (bandeau plus visible : header lisible, chips gros) === */
.crosssell {
  padding: 14px var(--pad-sm) 14px 90px;
  border-top: 2px solid var(--accent);
  background: linear-gradient(180deg, rgba(58,166,255,0.08), rgba(58,166,255,0.03));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.crosssell.hidden { display: none; }
.crosssell-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 1.5px;
  font-weight: 600;
}
.crosssell-label { text-transform: uppercase; }
.crosssell-source {
  color: var(--fg);
  font-size: 15px;
  letter-spacing: 0;
  font-weight: 500;
}
.crosssell-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.crosssell-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1.5px solid var(--bg-3);
  border-radius: 20px;
  background: var(--bg-2);
  font-size: 15px;
  cursor: pointer;
  transition: border-color .12s, background .12s, transform .08s;
}
.crosssell-item:hover { border-color: var(--accent); background: var(--bg-1); transform: scale(1.03); }
.crosssell-item .nom { color: var(--fg); }
.crosssell-item .pct {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
}
.empty-state kbd {
  background: var(--bg-3);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: monospace;
  font-size: 12px;
  color: var(--fg);
}
.hidden { display: none !important; }

/* ====== FOOTER ACTIONS ====== */
#actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.8fr 1fr 1.4fr;
  gap: 10px;
  padding: 12px var(--pad);
  background: var(--bg-2);
  border-top: 1px solid var(--bg-3);
}
.btn {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 1px;
  border: none;
  border-radius: var(--radius);
  background: var(--bg-3);
  color: var(--fg);
  cursor: pointer;
  transition: transform 80ms, background 80ms;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) {
  transform: scale(0.96);
}
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.btn.big        { font-size: 22px; }
.btn-primary    { background: var(--accent-2); color: white; }
.btn-success    { background: var(--ok); color: #0a3320; }
.btn-warn       { background: var(--warn); color: #3a2400; }
.btn-danger     { background: var(--danger); color: white; }
.btn-ghost      { background: transparent; color: var(--fg-2); border: 1px solid var(--bg-3); }

/* ====== OVERLAYS (search + qty) ====== */
.overlay {
  border: none;
  background: rgba(15, 18, 24, 0.85);
  backdrop-filter: blur(8px);
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  padding: 0;
  margin: 0;
  color: var(--fg);
}
.overlay::backdrop { background: rgba(0, 0, 0, 0.6); }
.overlay[open] {
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.overlay-inner {
  background: var(--bg);
  border-radius: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.overlay-small .overlay-inner {
  width: 360px;
  height: auto;
  margin: auto;
  border-radius: var(--radius);
  padding: var(--pad);
  align-items: stretch;
}

/* ----- search overlay ----- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px var(--pad);
  border-bottom: 1px solid var(--bg-3);
  background: var(--bg-2);
}
#search-input {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--bg-3);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 22px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
.meta {
  font-size: 13px;
  color: var(--fg-3);
  min-width: 100px;
  text-align: right;
}

.results-grid {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: var(--pad);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  align-content: start;
}
.result-card {
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 80ms, background 80ms, border-color 80ms;
}
.result-card:active {
  transform: scale(0.97);
  background: var(--accent-2);
  border-color: var(--accent);
}
.result-card .card-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.result-card .avatar {
  flex: 0 0 36px;
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: rgba(255,255,255,.92);
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.result-card .name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-card .meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-3);
}
.result-card .price {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.result-card .stock {
  font-size: 13px;
  color: var(--fg-2);
}
.result-card .stock.zero  { color: var(--danger); }
.result-card .stock.low   { color: var(--warn); }
.result-card .barcode {
  font-family: monospace;
  font-size: 11px;
  color: var(--fg-3);
}
.result-card .supplier-prices {
  font-size: 11px;
  color: var(--warn);
  border-top: 1px dashed var(--bg-3);
  padding-top: 4px;
  margin-top: 2px;
  letter-spacing: 0.3px;
}

/* ====== Chip benchmark même jour an dernier ====== */
.header-stat {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--bg-2);
  color: var(--fg-2);
  border: 1px solid var(--bg-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.header-stat:empty { display: none; }

/* ====== Mini-vue Melkal (screenshot polled 1 FPS) ====== */
.melkal-mini {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 380px;
  background: var(--bg-2);
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  overflow: hidden;
  font-size: 12px;
}
.melkal-mini.hidden { display: none; }
.melkal-mini-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--bg-3);
  font-weight: 600;
}
.melkal-mini-head button {
  background: transparent;
  border: none;
  color: var(--fg);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}
.melkal-mini-head button:hover { color: var(--danger); }
.melkal-mini img {
  display: block;
  width: 100%;
  height: auto;
  background: #111;
  cursor: pointer;
}
.melkal-mini-status {
  padding: 4px 10px;
  color: var(--fg-3);
  font-size: 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ====== Pill écran Melkal (synchro temps réel) ====== */
.melkal-screen-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-2);
  color: var(--fg-3);
  border: 1px solid var(--bg-3);
}
.melkal-screen-vente    { background: rgba(62, 213, 152, 0.18); color: var(--ok); border-color: var(--ok); }
.melkal-screen-accueil  { background: rgba(58, 166, 255, 0.18); color: var(--accent); border-color: var(--accent); }
.melkal-screen-results  { background: rgba(255, 184, 28, 0.18); color: var(--warn); border-color: var(--warn); }
.melkal-screen-articles { background: rgba(255, 184, 28, 0.10); color: var(--warn); }
.melkal-screen-ventes-en-cours { background: rgba(180, 130, 255, 0.18); color: #b482ff; border-color: #b482ff; }
.melkal-screen-bo       { background: rgba(120, 200, 200, 0.18); color: #78c8c8; border-color: #78c8c8; }
.melkal-screen-stocks,
.melkal-screen-clients,
.melkal-screen-plannings,
.melkal-screen-fournisseurs,
.melkal-screen-vendeurs,
.melkal-screen-reglages,
.melkal-screen-graphiques,
.melkal-screen-archives,
.melkal-screen-caisse-du-jour,
.melkal-screen-personnaliser { background: rgba(150, 150, 150, 0.15); color: var(--fg-2); border-color: var(--bg-3); }
.melkal-screen-login    { background: rgba(255, 100, 100, 0.20); color: #ff6464; border-color: #ff6464; }
.melkal-screen-unknown  { background: var(--bg-2); color: var(--fg-3); }

/* ====== INVOICE BUTTON + OVERLAY ====== */
.invoice-btn {
  background: var(--accent-2);
  color: white;
  border: none;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 18px;
  cursor: pointer;
  transition: transform 80ms;
}
.invoice-btn:active { transform: scale(0.96); }

.dashboard-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--bg-3);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 18px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 80ms, background 120ms;
}
.dashboard-link:hover { background: var(--bg-3); border-color: var(--accent); }
.dashboard-link:active { transform: scale(0.96); }

.invoice-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px var(--pad);
  background: var(--bg-2);
  border-bottom: 1px solid var(--bg-3);
}
.invoice-header h2 { flex: 0 0 auto; font-size: 20px; margin: 0; letter-spacing: 1px; }

.invoice-drop {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: var(--pad);
  border: 2px dashed var(--bg-3);
  border-radius: 14px;
  background: var(--bg-2);
  padding: 60px 30px;
  cursor: pointer;
  transition: all 0.2s;
  gap: 16px;
  text-align: center;
}
.invoice-drop:hover, .invoice-drop.dragover {
  border-color: var(--accent);
  background: rgba(58, 166, 255, 0.08);
}
.invoice-drop p { font-size: 18px; color: var(--fg); margin: 0; }
.invoice-formats { display: flex; gap: 10px; }
.badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
}
.badge-dod  { background: rgba(58, 166, 255, 0.2); color: var(--accent); }
.badge-desa { background: rgba(255, 184, 77, 0.2); color: var(--warn); }

/* ===== Inputs PDF fournisseurs (modale facture) =====
   3 tuiles cliquables : COUDERC stylisée texte, BRUNEL/ECODIS avec logo. */
.supplier-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  margin: 0 var(--pad) var(--pad);
}
.supplier-card {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-3);
  border-radius: 12px;
  padding: 24px 12px;
  min-height: 110px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .08s;
  background: var(--bg-2);
  overflow: hidden;
}
.supplier-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transform: translateY(-2px);
}
.supplier-card.is-loading { opacity: 0.6; pointer-events: none; }
.supplier-logo {
  max-height: 70px;
  max-width: 100%;
  object-fit: contain;
}
/* Rangée scrape auto (DOD + FINDIS, pas d'upload nécessaire) */
.supplier-scrape {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 0 var(--pad) var(--pad);
}
.supplier-scrape .supplier-card {
  flex-direction: column;
  gap: 4px;
  border: none;
  color: white;
}
.supplier-scrape-label {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  font-size: 28px;
  letter-spacing: 2px;
}
.supplier-scrape-sub { font-size: 12px; opacity: 0.85; letter-spacing: 0.5px; }
.supplier-dod    { background: linear-gradient(135deg, #d62828 0%, #a32020 100%); }
.supplier-dod:hover    { background: linear-gradient(135deg, #ef3535 0%, #c32424 100%); }
.supplier-findis { background: linear-gradient(135deg, #1e6091 0%, #144a70 100%); }
.supplier-findis:hover { background: linear-gradient(135deg, #2a78b0 0%, #1a5f8e 100%); }

/* COUDERC : fond bleu clair, texte jaune or, Arial majuscule (pas de logo officiel) */
.supplier-couderc {
  background: #87CEEB; /* bleu clair (skyblue) */
  border-color: #5fb4dc;
}
.supplier-couderc:hover {
  background: #6fc1e0;
  border-color: #d4af00;
}
.supplier-couderc .supplier-label {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 900;
  font-size: 32px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #FFD700; /* jaune or */
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.35);
}

.invoice-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--pad);
  gap: 12px;
}
.invoice-preview.hidden { display: none; }
.invoice-controls { display: flex; gap: 10px; align-items: center; }
.invoice-controls .btn { padding: 10px 18px; font-size: 14px; }
.invoice-table-wrap {
  flex: 1;
  overflow: auto;
  background: var(--bg-2);
  border-radius: 8px;
  border: 1px solid var(--bg-3);
}
.invoice-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.invoice-table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg-3); color: var(--fg-2);
  text-align: left; padding: 10px 8px;
  font-size: 11px; letter-spacing: 0.5px; font-weight: 600;
}
.invoice-table td {
  padding: 8px;
  border-bottom: 1px solid var(--bg-3);
  font-variant-numeric: tabular-nums;
}
.invoice-table tr.new-article { background: rgba(255, 184, 77, 0.06); }
.invoice-table tr.price-up    { background: rgba(255, 92, 92, 0.04); }
.invoice-table tr.price-down  { background: rgba(62, 213, 152, 0.04); }
.invoice-table .ean { font-family: monospace; font-size: 11px; color: var(--fg-3); }
.invoice-table .pa-old { color: var(--fg-3); }
.invoice-table .pa-old.delta-up   { color: var(--danger); }
.invoice-table .pa-old.delta-down { color: var(--ok); }
.invoice-table .nouveau-pv input[type="number"] {
  width: 70px; padding: 4px 6px;
  background: var(--bg); color: var(--accent);
  border: 1px solid var(--bg-3); border-radius: 4px;
  font-variant-numeric: tabular-nums;
  font-size: 13px; font-weight: 600;
}
/* PV actuel : rouge si < nouveauPv (à augmenter), vert si >= (déjà OK) */
.invoice-table .pv-low { color: var(--danger); font-weight: 600; }
.invoice-table .pv-ok  { color: var(--ok); font-weight: 600; }
.invoice-table input[type="number"] {
  width: 70px; padding: 4px 6px;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--bg-3); border-radius: 4px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.invoice-table .state-new { color: var(--warn); font-size: 11px; font-weight: 600; }
.invoice-table .state-ok  { color: var(--ok); font-size: 11px; }

.invoice-bo-status {
  margin-top: 8px;
  padding: 12px 16px;
  background: var(--bg-2);
  border-radius: 8px;
  border: 1px solid var(--bg-3);
  font-size: 13px;
  line-height: 1.5;
}
.invoice-bo-status.ok { border-left: 4px solid var(--ok); }
.invoice-bo-status.error { border-left: 4px solid var(--danger); }
.invoice-bo-status.dry { border-left: 4px solid var(--warn); }
.invoice-bo-status .steps {
  margin-top: 8px;
  font-family: monospace;
  font-size: 11px;
  color: var(--fg-3);
  white-space: pre-wrap;
}

/* ====== RESTOCK BADGE + OVERLAY ====== */
.restock-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--warn);
  color: #3a2400;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 18px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  transition: transform 80ms;
}
.restock-badge:active { transform: scale(0.96); }
.restock-badge .restock-icon { font-size: 14px; }
.restock-badge .restock-label { font-size: 11px; opacity: 0.85; letter-spacing: 0.5px; }

/* ====== PENDING INVOICES BADGES (1 par fournisseur en attente de réception) ====== */
.pending-invoices-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.pending-invoice-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  background: rgba(255, 184, 77, 0.18);
  color: var(--warn);
  border: 1px solid var(--warn);
  border-radius: 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: transform 80ms, background 120ms;
}
.pending-invoice-badge:hover { background: rgba(255, 184, 77, 0.32); }
.pending-invoice-badge:active { transform: scale(0.96); }
.pending-invoice-logo {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
}
.pending-invoice-name {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px;
  padding: 0 8px;
  border-radius: 14px;
  background: var(--bg-3);
  color: var(--fg);
  font-size: 11px;
  letter-spacing: 0.5px;
}
.pending-invoice-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  background: var(--warn);
  color: #3a2400;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 12px;
}

/* === Overlay pending invoices === */
.pending-invoices-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.pending-invoice-card {
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  border-radius: var(--radius);
  overflow: hidden;
}
.pending-invoice-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-3);
}
.pending-invoice-card-meta { flex: 1; }
.pending-invoice-card-supplier {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1px;
  color: var(--warn);
}
.pending-invoice-no {
  font-family: monospace;
  font-size: 13px;
  color: var(--accent);
  font-weight: 700;
}
.pending-invoice-card-meta {
  color: var(--fg-2);
  font-size: 12px;
}
.pending-invoice-filename {
  font-family: monospace;
  color: var(--fg-3);
}
.pending-invoice-mark {
  white-space: nowrap;
}
.pending-invoice-lines {
  list-style: none;
  padding: 4px 0;
  max-height: 320px;
  overflow-y: auto;
}
.pending-invoice-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--bg-3);
  font-size: 13px;
}
.pending-invoice-line:last-child { border-bottom: none; }
.pending-invoice-line-nom {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pending-invoice-line-ean {
  font-family: monospace;
  color: var(--fg-3);
  font-size: 12px;
}

.restock-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px var(--pad);
  background: var(--bg-2);
  border-bottom: 1px solid var(--bg-3);
}
.restock-header h2 { flex: 0 0 auto; font-size: 20px; margin: 0; letter-spacing: 1px; }
.restock-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--pad);
}
.restock-group-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 14px;
  margin: 16px 0 4px;
  background: var(--bg-3);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
}
.restock-group-header:first-child { margin-top: 0; }
.restock-group-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1px;
  color: var(--accent);
}
.restock-group-name.unknown { color: var(--fg-3); }
.restock-group-count {
  font-size: 12px;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
}
.restock-row {
  display: grid;
  grid-template-columns: 36px 1fr 80px 90px 1fr 90px;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--bg-2);
  font-size: 14px;
}
.restock-row .stock-pill {
  background: var(--danger);
  color: white;
  border-radius: 50%;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.restock-row .stock-pill.warn { background: var(--warn); color: #3a2400; }
.restock-row .name { font-weight: 500; }
.restock-row .name .sub { display: block; font-size: 11px; color: var(--fg-3); }
.restock-row .pv { text-align: right; color: var(--fg-2); font-variant-numeric: tabular-nums; }
.restock-row .pa { text-align: right; color: var(--fg-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.restock-row .best-supplier { font-size: 12px; color: var(--ok); }
.restock-row .best-supplier strong { color: var(--fg); }
.restock-row .scrape-now {
  font-size: 12px;
  background: var(--bg-3);
  border: 1px solid var(--bg-3);
  color: var(--fg-2);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
.restock-row .scrape-now.scraping { background: var(--accent-2); color: white; }
.restock-row.queued { background: rgba(58, 166, 255, 0.04); }
.restock-row.queued .scrape-now { background: var(--accent-2); color: white; opacity: 0.6; cursor: not-allowed; }

/* ----- qty overlay ----- */
.qty-display {
  background: var(--bg-2);
  border-radius: var(--radius);
  text-align: center;
  padding: 18px;
  font-size: 56px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 12px 0;
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.key {
  font-size: 26px;
  padding: 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--bg-3);
  color: var(--fg);
  cursor: pointer;
}
.key:active { transform: scale(0.96); }
.key-ok { background: var(--ok); color: #0a3320; }

/* ====== TOASTS ====== */
.toasts {
  position: fixed;
  bottom: calc(var(--h-actions) + 12px);
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: var(--bg-2);
  border-left: 4px solid var(--accent);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  min-width: 280px;
  max-width: 420px;
  animation: toast-in 200ms ease-out;
}
.toast.toast-ok    { border-left-color: var(--ok); }
.toast.toast-warn  { border-left-color: var(--warn); }
.toast.toast-error { border-left-color: var(--danger); }
.toast .title { font-weight: 600; margin-bottom: 2px; }
.toast .body  { font-size: 12px; color: var(--fg-2); }
@keyframes toast-in {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ====== PAIEMENT OVERLAY ====== */
.pay-inner {
  display: flex;
  flex-direction: column;
  padding: 0;
}
.pay-header {
  display: flex;
  align-items: center;
  padding: 14px var(--pad);
  background: var(--bg-2);
  border-bottom: 1px solid var(--bg-3);
}
.pay-header h2 {
  flex: 1;
  font-size: 22px;
  letter-spacing: 2px;
  font-weight: 600;
  margin: 0;
}
.pay-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 18px;
  padding: 18px;
  min-height: 0;
}
.pay-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-content: start;
}
.pay-mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 1px;
  border: 2px solid var(--bg-3);
  background: var(--bg-2);
  color: var(--fg);
  border-radius: 14px;
  padding: 26px 10px;
  cursor: pointer;
  transition: transform 80ms, background 80ms, border-color 80ms;
  -webkit-tap-highlight-color: transparent;
}
.pay-mode:active {
  transform: scale(0.96);
  background: var(--accent-2);
  border-color: var(--accent);
}
.pay-mode.is-active {
  background: var(--accent-2);
  border-color: var(--accent);
}
.pay-mode.is-loading {
  opacity: 0.5;
  cursor: wait;
}
.pay-icon {
  font-size: 38px;
  line-height: 1;
}
.pay-amounts {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pay-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 16px;
  background: var(--bg-2);
  border-radius: 10px;
  border: 1px solid var(--bg-3);
}
.pay-row .lbl { font-size: 13px; letter-spacing: 1.5px; color: var(--fg-3); }
.pay-row .amt { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pay-row-input .amt { color: var(--accent); }
.pay-row-change {
  background: var(--bg-3);
}
.pay-row-change .amt { color: var(--ok); }
.pay-row-change.negative .amt { color: var(--danger); }
.pay-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.pay-keypad .key {
  font-size: 24px;
  padding: 14px;
}
.pay-quick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.pay-quick .quick {
  font-size: 14px;
  padding: 12px 4px;
  border: 1px solid var(--bg-3);
  background: var(--bg-2);
  color: var(--fg);
  border-radius: 8px;
  cursor: pointer;
}
.pay-quick .quick:active { transform: scale(0.96); }
.pay-footer {
  padding: 14px var(--pad);
  background: var(--bg-2);
  border-top: 1px solid var(--bg-3);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
}
.pay-status {
  font-size: 14px;
  color: var(--fg-2);
}
.pay-status.ok    { color: var(--ok); font-weight: 600; }
.pay-status.error { color: var(--danger); font-weight: 600; }

/* ====== AI CHAT ====== */
.ai-fab {
  position: fixed;
  left: 18px;
  bottom: calc(var(--h-actions) + 14px);
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #6a5cf8, #3aa6ff);
  color: white;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.4), 0 0 0 0 rgba(58, 166, 255, 0.5);
  z-index: 1000;
  transition: transform 100ms, box-shadow 100ms;
}
.ai-fab:hover { transform: scale(1.06); }
.ai-fab:active { transform: scale(0.94); }
.overlay-chat .overlay-inner {
  max-width: 720px;
  margin: auto;
  width: 100%;
  height: auto;
  max-height: 88vh;
  border-radius: var(--radius);
  border: 1px solid var(--bg-3);
  overflow: hidden;
}
.ai-inner { display: flex; flex-direction: column; }
.ai-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px var(--pad);
  background: var(--bg-2);
  border-bottom: 1px solid var(--bg-3);
}
.ai-header h2 { flex: 1; font-size: 18px; letter-spacing: 1.5px; margin: 0; }
.ai-model { font-size: 11px; color: var(--fg-3); font-family: monospace; }
.ai-conversation {
  flex: 1;
  overflow-y: auto;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 200px;
  max-height: 60vh;
}
.ai-suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.ai-hint { font-size: 13px; color: var(--fg-3); margin-bottom: 4px; }
.ai-sug {
  text-align: left;
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--fg-2);
  cursor: pointer;
  transition: background 80ms;
}
.ai-sug:hover { background: var(--bg-3); color: var(--fg); }
.ai-msg {
  padding: 10px 14px;
  border-radius: 10px;
  max-width: 85%;
  line-height: 1.4;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ai-msg-user {
  align-self: flex-end;
  background: var(--accent-2);
  color: white;
}
.ai-msg-ai {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--bg-3);
}
.ai-msg-tool {
  align-self: flex-start;
  background: var(--bg-3);
  font-family: monospace;
  font-size: 11px;
  color: var(--fg-3);
  max-width: 95%;
  padding: 6px 10px;
}
.ai-msg-tool summary { cursor: pointer; }
.ai-msg-tool pre { margin: 4px 0 0; overflow-x: auto; }
.ai-input-row {
  display: flex;
  gap: 8px;
  padding: 12px var(--pad);
  border-top: 1px solid var(--bg-3);
  background: var(--bg-2);
}
#ai-input {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 2px solid var(--bg-3);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 15px;
  resize: none;
  font-family: inherit;
  outline: none;
}
#ai-input:focus { border-color: var(--accent); }
#ai-send { padding: 0 22px; }

/* spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--bg-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
  vertical-align: -3px;
}
