/* === NextGescom - Gestion commerciale / Achats / Stock === */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
#print-area { display: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: #1f2937; background: #f3f4f6;
  -webkit-font-smoothing: antialiased;
}

/* === Layout === */
#app-shell { display: flex; height: 100vh; }
.sidebar {
  width: 224px;
  background: linear-gradient(180deg, #0c4a6e 0%, #082f49 100%);
  color: #e5e7eb; display: flex; flex-direction: column; flex-shrink: 0;
}
.brand { padding: 16px 16px 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.brand-text-logo { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; line-height: 1; }
.brand-next   { color: #F5922E; }
.brand-gescom { color: #ffffff; }
.brand-sub { font-size: 11px; color: #7dd3fc; margin-top: 4px; }

.nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-section {
  font-size: 10px; letter-spacing: 0.8px; text-transform: uppercase;
  color: #38bdf8; opacity: 0.7; padding: 14px 16px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; color: #cbd5e1; text-decoration: none;
  font-size: 13.5px; border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: white; }
.nav-item.active { background: rgba(14, 165, 233, 0.18); color: white; border-left-color: #0ea5e9; }
.nav-item.nav-danger { color: #fca5a5; }
.nav-item.nav-danger:hover { background: rgba(239, 68, 68, 0.12); color: #fecaca; }
.nav-item .ic { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { padding: 12px 16px; font-size: 11px; color: #64748b; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-user { color: #e5e7eb; font-size: 12px; margin-bottom: 6px; font-weight: 500; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 54px; background: white; border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0;
}
.topbar-title { font-size: 17px; font-weight: 600; color: #0f172a; }
.topbar-actions { display: flex; gap: 8px; }
.content { flex: 1; overflow-y: auto; padding: 20px; }

/* === Boutons === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid #d1d5db; background: white; color: #1f2937;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
  font-weight: 500; transition: all 0.15s; text-decoration: none;
  white-space: nowrap; font-family: inherit;
}
.btn:hover { background: #f9fafb; border-color: #9ca3af; }
.btn-primary { background: #0ea5e9; color: white; border-color: #0ea5e9; }
.btn-primary:hover { background: #0284c7; border-color: #0284c7; }
.btn-success { background: #10b981; color: white; border-color: #10b981; }
.btn-success:hover { background: #059669; border-color: #059669; }
.btn-danger  { background: #ef4444; color: white; border-color: #ef4444; }
.btn-danger:hover  { background: #dc2626; border-color: #dc2626; }
.btn-warning { background: #f59e0b; color: white; border-color: #f59e0b; }
.btn-warning:hover { background: #d97706; border-color: #d97706; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Cartes === */
.card {
  background: white; border-radius: 8px; border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04); padding: 18px; margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; margin: 0 0 12px; color: #0f172a; }

/* === KPI === */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: white; border-radius: 10px; border: 1px solid #e5e7eb; border-left: 4px solid #e5e7eb;
  padding: 16px 18px; display: flex; align-items: center; gap: 14px; cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}
.kpi:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); transform: translateY(-1px); }
.kpi.blue { border-left-color: #3b82f6; } .kpi.green { border-left-color: #10b981; }
.kpi.orange { border-left-color: #f97316; } .kpi.red { border-left-color: #ef4444; }
.kpi.purple { border-left-color: #8b5cf6; }
.kpi-ic { width: 46px; height: 46px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.kpi-ic.blue { background: #dbeafe; color: #1d4ed8; } .kpi-ic.green { background: #d1fae5; color: #047857; }
.kpi-ic.orange { background: #fed7aa; color: #c2410c; } .kpi-ic.red { background: #fee2e2; color: #b91c1c; }
.kpi-ic.purple { background: #ede9fe; color: #6d28d9; }
.kpi-label { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.kpi-value { font-size: 23px; font-weight: 700; color: #0f172a; margin-top: 2px; line-height: 1.1; white-space: nowrap; }
.kpi-sub { font-size: 12px; color: #6b7280; margin-top: 3px; font-weight: 500; }

.dash-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 900px) { .dash-row { grid-template-columns: 1fr; } }

/* === Portail d'accueil (modules) === */
.welcome { margin-bottom: 20px; }
.welcome-t { font-size: 22px; font-weight: 800; color: #0f172a; }
.modules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.module-tile { background: white; border: 1px solid #e5e7eb; border-radius: 14px; padding: 24px 18px; cursor: pointer; text-align: center; transition: transform 0.12s, box-shadow 0.12s; border-top: 4px solid #0ea5e9; }
.module-tile:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0,0,0,0.1); }
.module-tile.blue { border-top-color: #3b82f6; } .module-tile.green { border-top-color: #10b981; }
.module-tile.purple { border-top-color: #8b5cf6; } .module-tile.orange { border-top-color: #f97316; }
.module-tile .mt-ic { font-size: 42px; line-height: 1; }
.module-tile .mt-t { font-size: 16px; font-weight: 700; color: #0f172a; margin-top: 10px; }
.module-tile .mt-s { font-size: 12.5px; color: #6b7280; margin-top: 4px; }

/* === Formulaires === */
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label { font-size: 12px; font-weight: 600; color: #374151; }
.form-row input, .form-row select, .form-row textarea {
  border: 1px solid #d1d5db; border-radius: 6px; padding: 8px 10px;
  font-size: 13.5px; font-family: inherit; background: white; color: #1f2937; width: 100%;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none; border-color: #0ea5e9; box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}
.form-row textarea { resize: vertical; min-height: 60px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field-hint { font-size: 11.5px; color: #6b7280; margin-top: 2px; }

/* === Tableaux === */
.table-wrap { background: white; border-radius: 8px; border: 1px solid #e5e7eb; overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th {
  text-align: left; padding: 10px 12px; background: #f9fafb; border-bottom: 1px solid #e5e7eb;
  font-weight: 600; font-size: 12px; color: #374151; text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap;
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover td { background: #f8fafc; }
table.tbl td.actions { text-align: right; white-space: nowrap; }
table.tbl td .btn { margin-left: 4px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: #6b7280; }
.empty-state { text-align: center; padding: 40px 20px; color: #6b7280; }
.empty-state .ic { font-size: 36px; margin-bottom: 8px; opacity: 0.5; }

/* === Badges === */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.badge-ok, .badge-paye, .badge-valide, .badge-recu, .badge-livre { background: #d1fae5; color: #047857; }
.badge-attente, .badge-partiel, .badge-brouillon, .badge-ouverte { background: #fef3c7; color: #92400e; }
.badge-annule, .badge-refuse { background: #f3f4f6; color: #4b5563; }
.badge-impaye, .badge-bas, .badge-rupture { background: #fee2e2; color: #b91c1c; }
.badge-info, .badge-envoye { background: #dbeafe; color: #1d4ed8; }

/* === Filtres === */
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { border: 1px solid #d1d5db; border-radius: 6px; padding: 7px 10px; font-size: 13px; background: white; font-family: inherit; }
.filters .grow { flex: 1; min-width: 200px; }

/* === Modal === */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal { background: white; border-radius: 10px; width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal-lg { max-width: 980px; }
.modal-header { padding: 14px 18px; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; color: #6b7280; cursor: pointer; line-height: 1; }
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 18px; border-top: 1px solid #e5e7eb; display: flex; justify-content: flex-end; gap: 8px; }

/* === Toast === */
#toast-root { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: white; border-left: 4px solid #0ea5e9; border-radius: 6px; padding: 10px 16px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); min-width: 260px; font-size: 13.5px; animation: slideIn 0.2s; }
.toast.success { border-left-color: #10b981; } .toast.error { border-left-color: #ef4444; } .toast.warning { border-left-color: #f59e0b; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === Login === */
.login-screen { position: fixed; inset: 0; background: linear-gradient(135deg, #0c4a6e 0%, #082f49 100%); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 5000; }
.login-card { background: white; border-radius: 12px; padding: 32px 30px; width: 100%; max-width: 380px; box-shadow: 0 25px 50px rgba(0,0,0,0.3); }
.login-logo-txt { text-align: center; font-size: 30px; font-weight: 800; letter-spacing: -1px; margin-bottom: 6px; }
.login-logo-txt .brand-gescom { color: #0c4a6e; }
.login-sub { text-align: center; color: #6b7280; margin: 0 0 22px; font-size: 13px; }
.login-error { color: #b91c1c; background: #fee2e2; border-radius: 6px; padding: 8px 10px; margin: 0 0 10px; font-size: 12.5px; }
.login-error:empty { display: none; }
.login-footer { text-align: center; margin-top: 18px; font-size: 11.5px; color: #94a3b8; }

/* === Documents (lignes saisie) === */
.doc-head-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
@media (max-width: 800px) { .doc-head-grid { grid-template-columns: 1fr; } }
.lines-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.lines-table th { background: #f1f5f9; padding: 7px 8px; text-align: left; font-size: 11.5px; text-transform: uppercase; color: #475569; border-bottom: 1px solid #e5e7eb; }
.lines-table td { padding: 5px 6px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.lines-table input, .lines-table select { width: 100%; border: 1px solid #d1d5db; border-radius: 5px; padding: 6px 7px; font-size: 13px; font-family: inherit; }
.lines-table .num { width: 90px; }
.lines-table .num input { text-align: right; }
.lines-table td.ltot { text-align: right; font-weight: 700; white-space: nowrap; }
.lines-table .ldel { background: none; border: none; color: #cbd5e1; cursor: pointer; font-size: 16px; }
.lines-table .ldel:hover { color: #ef4444; }
.doc-totaux { margin-top: 14px; margin-left: auto; max-width: 320px; }
.doc-totaux .tot-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; border-bottom: 1px solid #f1f5f9; }
.doc-totaux .tot-ttc { display: flex; justify-content: space-between; padding: 10px; background: #0c4a6e; color: white; font-size: 17px; font-weight: 800; border-radius: 6px; margin-top: 6px; }

.scan-add { display: flex; align-items: center; gap: 8px; background: #ecfeff; border: 1px solid #a5f3fc; border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.scan-add .si { font-size: 18px; }
.scan-add input { flex: 1; border: 2px solid #0ea5e9; border-radius: 7px; padding: 9px 12px; font-size: 15px; font-weight: 600; font-family: inherit; }
.scan-add input:focus { outline: none; box-shadow: 0 0 0 3px rgba(14,165,233,0.3); }

/* === Etiquettes code-barres === */
.etq-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.etq {
  border: 1px dashed #94a3b8; border-radius: 6px; padding: 8px; text-align: center;
  background: white; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.etq .etq-rs { font-size: 10px; color: #64748b; }
.etq .etq-nom { font-size: 12px; font-weight: 700; line-height: 1.2; }
.etq .etq-prix { font-size: 13px; font-weight: 800; color: #0c4a6e; }
.etq svg { max-width: 100%; }

/* === Facture / document A4 (apercu) === */
.facture-page { background: white; max-width: 800px; margin: 0 auto; padding: 24px 30px; font-size: 12px; color: #1f2937; border: 1px solid #e5e7eb; border-radius: 8px; }
.fac-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.fac-rs { font-size: 16px; font-weight: 800; color: #0c4a6e; }
.fac-societe div { line-height: 1.45; }
.fac-titrebox { text-align: right; }
.fac-titre { font-size: 19px; font-weight: 800; color: #0c4a6e; letter-spacing: 1px; }
.fac-num { font-size: 14px; font-weight: 700; margin-top: 4px; }
.fac-client { border: 1px solid #e5e7eb; border-radius: 8px; padding: 9px 13px; margin-bottom: 16px; background: #f8fafc; max-width: 360px; margin-left: auto; }
.fac-client-lbl { font-size: 9px; font-weight: 700; color: #64748b; letter-spacing: 1px; }
.fac-client-nom { font-size: 14px; font-weight: 700; }
.fac-tbl { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.fac-tbl th { background: #0c4a6e; color: white; padding: 6px 8px; text-align: left; font-size: 11px; }
.fac-tbl td { padding: 5px 8px; border-bottom: 1px solid #e5e7eb; }
.fac-tbl .r { text-align: right; }
.fac-bottom { display: flex; justify-content: flex-end; gap: 20px; margin-top: 8px; }
.fac-totaux { min-width: 280px; }
.fac-tot-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid #f1f5f9; }
.fac-tot-ttc { display: flex; justify-content: space-between; padding: 8px 10px; background: #0c4a6e; color: white; font-size: 15px; font-weight: 800; border-radius: 6px; margin-top: 6px; }
.fac-legal { margin-top: 18px; padding-top: 8px; border-top: 1px solid #e5e7eb; font-size: 9px; color: #64748b; text-align: center; }
/* Applique le temps de la capture PDF (html2canvas) : page A4 pleine hauteur,
   pied de page colle en bas — meme rendu qu'a l'impression. 1131px = 297mm a l'echelle 800px/210mm. */
.facture-page.pdf-a4 { min-height: 1131px; box-sizing: border-box; display: flex; flex-direction: column; }
.facture-page.pdf-a4 .fac-legal { margin-top: auto; }
/* Documents multi-pages : numero de page repete en bas de chaque feuille */
.fac-pagenum { text-align: right; font-size: 9px; color: #64748b; margin-top: 4px; }
.facture-page.doc-mp { max-width: none; }

/* Apercu plein ecran avant impression */
.apercu-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .8); z-index: 1200; display: flex; flex-direction: column; }
.apercu-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; background: #0f2748; color: #fff; flex-wrap: wrap; }
.apercu-info { font-weight: 600; }
.apercu-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.apercu-scroll { flex: 1; overflow: auto; padding: 20px; }
.apercu-stage { transform-origin: top center; display: flex; flex-direction: column; align-items: center; gap: 16px; width: 800px; margin: 0 auto; }
.apercu-page { box-shadow: 0 4px 24px rgba(0, 0, 0, .45); background: #fff; flex: 0 0 auto; }

/* ============================================================
   ECRAN CAISSE (POS)
   ============================================================ */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 14px; height: calc(100vh - 54px); padding: 14px; }
.pos-left { display: flex; flex-direction: column; min-height: 0; }
.scan-bar { display: flex; align-items: center; gap: 8px; background: #0f172a; border-radius: 10px; padding: 6px 10px 6px 14px; margin-bottom: 10px; }
.scan-bar .scan-ic { font-size: 18px; }
.scan-bar .scan-input { flex: 1; border: 2px solid #0ea5e9 !important; border-radius: 8px; padding: 12px 14px; font-size: 16px; font-weight: 600; }
.scan-bar .scan-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(14,165,233,0.4); }
.scan-bar .scan-last { color: #38bdf8; font-size: 12.5px; font-weight: 600; min-width: 90px; max-width: 180px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; overflow-y: auto; align-content: start; flex: 1; padding-right: 4px; }
.prod-tile { background: white; border: 1px solid #e5e7eb; border-top: 4px solid #0ea5e9; border-radius: 10px; padding: 12px 10px; cursor: pointer; display: flex; flex-direction: column; min-height: 86px; justify-content: space-between; transition: transform 0.1s, box-shadow 0.1s; }
.prod-tile:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); transform: translateY(-1px); }
.prod-tile:active { transform: scale(0.97); }
.prod-tile .pname { font-size: 13px; font-weight: 600; color: #0f172a; line-height: 1.25; }
.prod-tile .pprice { font-size: 15px; font-weight: 700; color: #0369a1; margin-top: 6px; }
.prod-tile .pstock { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.prod-tile.rupture { opacity: 0.55; }
.prod-tile .pstock.bas { color: #dc2626; font-weight: 600; }

.pos-right { background: white; border: 1px solid #e5e7eb; border-radius: 12px; display: flex; flex-direction: column; min-height: 0; }
.cart-head { padding: 12px 14px; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; }
.cart-head .ctitle { font-weight: 700; font-size: 15px; }
.cart-items { flex: 1; overflow-y: auto; padding: 8px 10px; }
.cart-line { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid #f1f5f9; }
.cart-line .cl-name { flex: 1; min-width: 0; }
.cart-line .cl-name .n { font-size: 13px; font-weight: 600; color: #0f172a; }
.cart-line .cl-name .u { font-size: 11.5px; color: #6b7280; }
.cart-qty { display: flex; align-items: center; gap: 4px; }
.cart-qty button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid #d1d5db; background: #f8fafc; font-size: 16px; font-weight: 700; cursor: pointer; line-height: 1; color: #334155; }
.cart-qty .q { width: 30px; text-align: center; font-weight: 700; font-size: 14px; }
.cart-line .cl-total { width: 78px; text-align: right; font-weight: 700; font-size: 13.5px; color: #0f172a; }
.cart-line .cl-del { background: none; border: none; color: #cbd5e1; cursor: pointer; font-size: 16px; }
.cart-line .cl-del:hover { color: #ef4444; }
.cart-empty { text-align: center; color: #9ca3af; padding: 40px 10px; }
.cart-foot { border-top: 1px solid #e5e7eb; padding: 12px 14px; }
.cart-totline { display: flex; justify-content: space-between; font-size: 13px; color: #475569; margin-bottom: 4px; }
.cart-total { display: flex; justify-content: space-between; font-size: 22px; font-weight: 800; color: #0f172a; margin: 8px 0 12px; }
.cart-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cart-actions .btn { justify-content: center; }
.cart-pay { grid-column: 1 / -1; padding: 14px; font-size: 16px; }
@media (max-width: 1100px) { .pos { grid-template-columns: 1fr 320px; } }
