:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e3e7ef;
  --text: #1c2333;
  --muted: #6b7489;
  --primary: #2f5bea;
  --primary-soft: #e8eeff;
  --success: #12965a;
  --success-soft: #e3f6ec;
  --warning: #c27a06;
  --warning-soft: #fdf3e0;
  --danger: #d23c3c;
  --danger-soft: #fdeaea;
  --sidebar: #141a2b;
  --sidebar-text: #aab2c8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 26, 43, .05), 0 2px 8px rgba(20, 26, 43, .04);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--sidebar); color: var(--sidebar-text);
  padding: 20px 12px; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 22px; display: flex; gap: 10px; align-items: center; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; font-size: 15px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); margin-bottom: 2px; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav .ico { width: 18px; text-align: center; }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #5f6880; padding: 16px 12px 6px; }
.nav .badge-count { margin-left: auto; background: var(--warning); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.main { margin-left: 230px; flex: 1; padding: 26px 30px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.btn.menu-btn { display: none; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 700; margin: 6px 0 4px; letter-spacing: -.01em; }
.kpi .hint { font-size: 12px; color: var(--muted); }
.kpi .hint.up { color: var(--success); } .kpi .hint.down { color: var(--danger); }
.kpi.accent { border-left: 3px solid var(--primary); }
.kpi.warn { border-left: 3px solid var(--warning); }
.kpi.ok { border-left: 3px solid var(--success); }
.kpi.bad { border-left: 3px solid var(--danger); }
.cols-2 { grid-template-columns: 2fr 1fr; }
.cols-2b { grid-template-columns: 1fr 1fr; }
.chart-box { position: relative; height: 260px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 10px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.mini-list li:last-child { border-bottom: none; }
.mini-list .t { font-weight: 500; } .mini-list .s { color: var(--muted); font-size: 12px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-payee, .b-encaisse, .b-entree, .b-annulation { background: var(--success-soft); color: var(--success); }
.b-partielle, .b-en_attente, .b-ajustement { background: var(--warning-soft); color: var(--warning); }
.b-impayee, .b-rejete, .b-sortie { background: var(--danger-soft); color: var(--danger); }
.b-annulee { background: #eceef3; color: var(--muted); text-decoration: line-through; }
.b-vente, .b-especes, .b-cheque { background: var(--primary-soft); color: var(--primary); }
.stock-low { color: var(--danger); font-weight: 700; }

/* ---------- Forms ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px;
  font: inherit; font-weight: 550; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 12px 20px; font-size: 15px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ico { border: none; background: none; cursor: pointer; padding: 5px 7px; border-radius: 6px; font-size: 14px; color: var(--muted); }
.btn-ico:hover { background: var(--surface-2); color: var(--text); }
label { display: block; font-size: 12.5px; font-weight: 550; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font: inherit; color: var(--text); background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }
.toolbar .grow { flex: 1; min-width: 200px; }

/* Payment mode switch */
.pay-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.pay-mode { border: 2px solid var(--border); border-radius: 10px; padding: 14px; cursor: pointer; text-align: center; font-weight: 600; background: var(--surface); }
.pay-mode .ic { font-size: 22px; display: block; margin-bottom: 4px; }
.pay-mode.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone { border: 2px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; background: var(--surface-2); }
.dropzone:hover, .dropzone.over { border-color: var(--primary); color: var(--primary); }
.dropzone img { max-width: 100%; max-height: 160px; border-radius: 6px; margin-top: 8px; }
.file-chosen { color: var(--text); font-weight: 550; }

/* POS */
.pos { display: grid; grid-template-columns: 1fr 430px; gap: 16px; align-items: start; }
.cart-line { display: grid; grid-template-columns: minmax(0,1fr) 62px 82px 86px 26px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cart-line input { padding: 6px 8px; }
.cart-line .name { font-weight: 550; } .cart-line .name small { display: block; color: var(--muted); font-weight: 400; }
.totals { margin-top: 10px; }
.totals .row { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .grand { font-size: 20px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; }
.search-results { position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.1); z-index: 10; max-height: 320px; overflow: auto; }
.search-results div { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.search-results div:hover, .search-results div.hl { background: var(--primary-soft); }
.search-results .out { color: var(--muted); cursor: not-allowed; }
.product-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.tile { border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; background: var(--surface); }
.tile:hover { border-color: var(--primary); }
.tile .n { font-weight: 600; margin-bottom: 4px; } .tile .p { color: var(--primary); font-weight: 700; } .tile .s { font-size: 12px; color: var(--muted); }
.tile.disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 20, 35, .45); display: none; align-items: flex-start; justify-content: center; z-index: 100; padding: 50px 16px; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.detail-grid .k { font-size: 12px; color: var(--muted); } .detail-grid .v { font-weight: 600; }
.proof-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); vertical-align: middle; }

/* ---------- Toast ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; animation: in .2s ease; }
.toast.err { background: var(--danger); } .toast.ok { background: var(--success); }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }

.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 16px; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .pos, .cols-2 { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; padding: 16px; }
  .btn.menu-btn { display: inline-flex; }
  .cols-2b, .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .cart-line { grid-template-columns: 1fr 70px 90px 30px; }
  .cart-line .lt { display: none; }
}

/* ---------- Utilisateur connecté ---------- */
.user-box { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding: 14px 6px 0; }
.user-box .who { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.user-box .avatar { width: 34px; height: 34px; border-radius: 50%; background: #2b3550; color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.user-box .n { color: #fff; font-weight: 600; }
.user-box .r { font-size: 12px; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.12); color: var(--sidebar-text); flex: 1; justify-content: center; padding: 6px 6px; font-size: 12px; }
.btn.ghost:hover { background: rgba(255,255,255,.06); color: #fff; }
.b-admin { background: #efe8ff; color: #6a3fd1; } .b-vendeur { background: var(--primary-soft); color: var(--primary); }
.b-actif { background: var(--success-soft); color: var(--success); } .b-inactif { background: #eceef3; color: var(--muted); }
.sidebar { overflow-y: auto; }
[hidden] { display: none !important; }

/* ---------- Icônes SVG ---------- */
svg.i { flex-shrink: 0; vertical-align: middle; }
.nav .ico { display: inline-flex; width: 20px; justify-content: center; opacity: .85; }
.nav a.active .ico, .nav a:hover .ico { opacity: 1; }
.brand .logo { color: #fff; }
.pay-mode .ic { display: flex; justify-content: center; margin-bottom: 6px; }
.dropzone svg { margin-bottom: 4px; }
.file-chosen { display: inline-flex; align-items: center; gap: 6px; color: var(--success); }
svg.warn, .stock-low svg { color: var(--warning); }
.stock-low svg { color: var(--danger); }
.btn-ico { display: inline-flex; align-items: center; justify-content: center; }
.user-box .btn.ghost { gap: 5px; }
input.search {
  padding-left: 36px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7489' stroke-width='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 12px center;
}
.user-box > .flex { flex-direction: column; align-items: stretch; gap: 6px; }
.user-box .btn.ghost { justify-content: flex-start; padding: 7px 10px; }

/* ---------- Logo ---------- */
.brand-logo { max-width: 170px; max-height: 34px; filter: brightness(0) invert(1); display: block; }
.brand:has(.brand-logo) { padding: 8px 10px 24px; }
.logo-setting { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.logo-preview { width: 260px; height: 80px; border: 1px dashed var(--border); border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); padding: 10px; }
.logo-preview img { max-width: 100%; max-height: 100%; }

.cart-head { padding: 0 0 6px; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cart-head .num { text-align: right; }
.cart-line .lt { text-align: right; }
