* { box-sizing: border-box; margin: 0; }
body { font-family: -apple-system, "Segoe UI", Roboto, sans-serif; background: #fafafa; color: #1a1a1a; font-size: 14px; }

header { display: flex; align-items: center; gap: 24px; padding: 12px 20px; background: #fff; border-bottom: 1px solid #e5e5e5; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 800; letter-spacing: 1px; font-size: 16px; }
.brand span { color: #888; font-weight: 400; }
nav { display: flex; gap: 4px; }
.tab { border: none; background: none; padding: 8px 14px; cursor: pointer; font-size: 14px; color: #555; border-radius: 6px; }
.tab.active { background: #1a1a1a; color: #fff; }

.page { padding: 20px; max-width: 1280px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.muted { color: #888; font-size: 12.5px; }

.btn { border: 1px solid #d5d5d5; background: #fff; padding: 7px 13px; border-radius: 6px; cursor: pointer; font-size: 13.5px; }
.btn:hover { background: #f0f0f0; }
.btn.primary { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.btn.primary:hover { background: #333; }
.btn.danger { color: #c62828; border-color: #e5b5b5; }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Tuiles KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid #e5e5e5; border-radius: 10px; padding: 12px 14px; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #888; display: flex; align-items: center; gap: 6px; }
.kpi-num { font-size: 26px; font-weight: 800; margin: 2px 0; }
.kpi-sub { font-size: 12px; color: #999; }
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.kpi-dot.confirmee { background: #2e7d32; }
.kpi-dot.annulee { background: #9e9e9e; }
.kpi-dot.envoyee { background: #5e35b1; }
.kpi-dot.livree { background: #00897b; }
.kpi-dot.retour { background: #c62828; }

/* Recherche */
.searchbox { position: relative; display: inline-flex; align-items: center; }
.searchbox input { width: 190px; margin-top: 0; padding: 7px 28px 7px 10px; font-size: 13.5px; }
.searchbox button { position: absolute; right: 4px; border: none; background: none; font-size: 17px; color: #999; cursor: pointer; padding: 2px 6px; }
.searchbox button:hover { color: #333; }

/* Barre de période (Confirmation, Préparation, Résultats) */
.period { display: inline-flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.period select.period-preset { width: auto; margin-top: 0; padding: 7px 8px; font-size: 13.5px; }
.period input[type=date] { width: 138px; margin-top: 0; padding: 7px 8px; font-size: 13.5px; }
.period-sep { color: #999; font-size: 13px; }
/* date de commande dont l'étape en cours est datée différemment : détail au survol */
.dcell { border-bottom: 1px dotted #bbb; cursor: help; }

.pills { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.pill { border: 1px solid #ddd; background: #fff; border-radius: 20px; padding: 5px 13px; cursor: pointer; font-size: 13px; }
.pill.active { background: #1a1a1a; color: #fff; border-color: #1a1a1a; }
.pill b { margin-left: 5px; }

table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e5e5e5; border-radius: 8px; overflow: hidden; }
th, td { text-align: left; padding: 9px 11px; border-bottom: 1px solid #f0f0f0; white-space: nowrap; }
td { max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
th { background: #f7f7f7; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: #777; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8f8f8; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge.nouvelle { background: #e3f2fd; color: #1565c0; }
.badge.sans_reponse { background: #fff3e0; color: #e65100; }
.badge.confirmee { background: #e8f5e9; color: #2e7d32; }
.badge.envoyee { background: #ede7f6; color: #5e35b1; }
.badge.livree { background: #e0f2f1; color: #00695c; }
.badge.retour { background: #ffebee; color: #c62828; }
.badge.annulee { background: #eeeeee; color: #757575; }
.badge.zero_stock { background: #eceff1; color: #455a64; }
.badge.abandonnee { background: #fff8e1; color: #b26a00; }
.badge.swap { background: #e0f7fa; color: #00838f; }
.badge.reportee { background: #ede7f6; color: #4527a0; }

/* Client récurrent */
.repeat-client { color: #7b1fa2; font-weight: 700; }
.rep-chip { font-size: 11px; background: #f3e5f5; color: #7b1fa2; border-radius: 10px; padding: 1px 6px; vertical-align: middle; }
.client-history { border: 1px solid #e9d9f2; background: #faf5fd; border-radius: 8px; padding: 10px 12px; margin-top: 12px; }
.ch-title { font-size: 12.5px; font-weight: 700; color: #7b1fa2; margin-bottom: 6px; }
.ch-row { padding: 6px 0; border-top: 1px solid #f0e4f7; cursor: pointer; font-size: 13px; }
.ch-row:hover { background: #f3e9f9; }
.ch-row .badge { font-size: 11px; padding: 2px 7px; }

/* Puces d'emballage (Préparation) */
.pack-chips { display: inline-flex; gap: 4px; }
.pchip { border: 1px solid #ddd; background: #fff; border-radius: 14px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: #888; }
.pchip.on.pas_emballe { background: #fff3e0; color: #e65100; border-color: #ffcc80; font-weight: 700; }
.pchip.on.emballe { background: #e8f5e9; color: #2e7d32; border-color: #a5d6a7; font-weight: 700; }
.pchip.on.annule { background: #eeeeee; color: #616161; border-color: #bdbdbd; font-weight: 700; }

.card { background: #fff; border: 1px solid #e5e5e5; border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.card h3 { font-size: 15px; margin: 14px 0 8px; }
.card h3:first-child { margin-top: 0; }
label { display: block; margin: 10px 0; font-size: 13px; color: #555; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 7px 9px; border: 1px solid #d5d5d5; border-radius: 6px; font-size: 13.5px; font-family: inherit; }
textarea { resize: vertical; }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 50; }
.drawer-inner { position: absolute; right: 0; top: 0; bottom: 0; width: 480px; max-width: 95vw; background: #fff; padding: 22px; overflow-y: auto; box-shadow: -4px 0 20px rgba(0,0,0,.1); }
.drawer .close { position: absolute; top: 10px; right: 14px; border: none; background: none; font-size: 26px; cursor: pointer; color: #999; }
.drawer h2 { font-size: 17px; margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 12px 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.history { font-size: 12.5px; color: #777; border-top: 1px solid #eee; margin-top: 14px; padding-top: 10px; }
.history div { margin-bottom: 4px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; display: flex; align-items: center; justify-content: center; }
.modal-inner { background: #fff; border-radius: 10px; padding: 22px; width: 560px; max-width: 94vw; max-height: 90vh; overflow-y: auto; }

.variants-table th, .variants-table td { padding: 5px 8px; }
.qty-btns { display: inline-flex; gap: 4px; align-items: center; }
.qty-btns b { min-width: 30px; text-align: center; }
.low { color: #c62828; font-weight: 700; }
.zr-state { font-size: 11px; color: #5e35b1; margin-top: 3px; }

/* Vignette produit */
.numcell { display: flex; align-items: center; gap: 7px; }
.pthumb { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; flex-shrink: 0; border: 1px solid #e8e8e8; background: #f5f5f5; }
.pthumb-txt { display: inline-flex; align-items: center; justify-content: center; color: #777; font-size: 10px; font-weight: 700; }

/* Menu rapide de statut */
.badge-click { cursor: pointer; user-select: none; }
.qmenu { position: fixed; background: #fff; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.16); z-index: 200; min-width: 190px; padding: 4px; max-height: 85vh; overflow-y: auto; }
.qmenu.sheet { left: 0; right: 0; bottom: 0; top: auto; border-radius: 16px 16px 0 0; border: none; max-height: 70vh; padding: 8px 10px calc(14px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 34px rgba(0,0,0,.28); }
.qmenu.sheet button { padding: 13px 12px; font-size: 15px; }
.qmenu button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 10px 12px; font-size: 13.5px; cursor: pointer; border-radius: 6px; }
.qmenu button:hover { background: #f2f2f2; }
.qmenu-sep { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: #999; padding: 8px 12px 3px; border-top: 1px solid #eee; margin-top: 4px; }
.kpi-dot.zero_stock { background: #607d8b; }
.kpi-dot.abandonnee { background: #ef9f10; }
.kpi-dot.swap { background: #00acc1; }

#toast { margin-left: auto; font-size: 13px; color: #2e7d32; max-width: 480px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#toast.err { color: #c62828; }

/* ---------- Vue mobile (cartes) ---------- */
#orders-cards { display: none; }
#prep-cards { display: none; }
.ocard { background: #fff; border: 1px solid #e5e5e5; border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 5px; font-size: 14px; }
.ocard-top { display: flex; align-items: center; gap: 8px; }
.ocard a { color: #1565c0; text-decoration: none; }
.ocard input[type=checkbox] { width: 19px; height: 19px; }
.call-btn { display: inline-block; margin: 10px 0 0 0; text-decoration: none; color: #1565c0; border-color: #b9cfeb; }

@media (max-width: 720px) {
  body { font-size: 15px; }
  header { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  #toast { flex-basis: 100%; margin-left: 0; white-space: normal; }
  .page { padding: 12px; }
  .btn { padding: 10px 14px; }
  .pill { padding: 8px 14px; }
  /* tableau -> cartes */
  #orders-table { display: none; }
  #orders-cards { display: block; }
  /* fiche commande plein écran */
  .drawer-inner { width: 100vw; max-width: 100vw; padding: 16px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  input, select, textarea { font-size: 16px; padding: 10px; } /* évite le zoom iOS */
  .actions .btn { padding: 12px 16px; }
  .modal-inner { padding: 16px; }
  /* stock : tableau scrollable */
  .card { overflow-x: auto; }
  /* préparation : cartes au lieu du tableau */
  #prep-table { display: none; }
  #prep-cards { display: block; }
  #tab-preparation .toolbar > * { flex: 1 1 auto; }
  #prep-product { width: 100%; }
  #prep-start { width: 100% !important; }
  .pchip { padding: 9px 14px; font-size: 13.5px; }
  #prep-recap table { width: 100%; }
}

/* Tableau des tarifs : défilement horizontal sur petit écran */
#tarifs-table { overflow-x: auto; }
#tarifs-table table { min-width: 480px; }
