:root {
  --bg: oklch(97.3% 0.006 235);
  --surface: oklch(100% 0 0);
  --border: oklch(89% 0.012 235);
  --text: oklch(23% 0.02 235);
  --text-muted: oklch(48% 0.018 235);
  --text-faint: oklch(63% 0.014 235);
  --primary: oklch(52% 0.11 224);
  --primary-dark: oklch(41% 0.1 224);
  --primary-soft: oklch(93% 0.028 224);
  --success: oklch(52% 0.13 155);
  --success-soft: oklch(93% 0.05 155);
  --warning: oklch(58% 0.15 55);
  --warning-soft: oklch(93% 0.06 75);
  --danger: oklch(55% 0.17 25);
  --danger-soft: oklch(93% 0.05 25);
  --font-display: "Manrope", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Public Sans", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::placeholder { color: var(--text-faint); }

.boot-loading {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; color: var(--text-faint); font-size: 14px;
}

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px; min-width: 260px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 22px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 26px 8px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: #fff;
}
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 14.5px; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text-faint); }

.nav-group-label {
  font-family: var(--font-display); font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em;
  color: var(--text-faint); text-transform: uppercase; padding: 0 12px; margin-bottom: 6px;
}
.nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 18px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--text-muted); font-weight: 500; font-size: 13.5px; border: none; background: transparent;
  text-align: left; width: 100%;
}
.nav-item svg { flex-shrink: 0; }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-item:hover:not(.active) { background: var(--bg); }

.sidebar-user {
  margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 11px;
  border-radius: 12px; background: var(--bg);
}
.avatar {
  width: 33px; height: 33px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-display);
  font-weight: 700; font-size: 12.5px; flex-shrink: 0;
}
.sidebar-user-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--text-faint); }
.logout-btn { border: none; background: transparent; color: var(--text-faint); padding: 6px; border-radius: 8px; }
.logout-btn:hover { background: var(--surface); color: var(--danger); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 72px; min-height: 72px; border-bottom: 1px solid var(--border); display: flex;
  align-items: center; justify-content: space-between; padding: 0 32px; background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar-title { font-family: var(--font-display); font-weight: 800; font-size: 20px; letter-spacing: -0.01em; }
.topbar-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 18px; }
.topbar-clock { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.topbar-divider { width: 1px; height: 24px; background: var(--border); }
.icon-btn {
  position: relative; width: 38px; height: 38px; border-radius: 10px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted); border: none;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary-dark); }
.badge-count {
  position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 8px; background: var(--danger); color: #fff; font-size: 9.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.content { flex: 1; overflow: auto; padding: 26px 32px 40px 32px; display: flex; flex-direction: column; gap: 20px; }

/* Bouton hamburger (ouvre le menu latéral) et bouton fermer dans le menu :
   masqués par défaut, affichés uniquement sur petit écran (voir media queries
   plus bas). Le fond assombri ("backdrop") derrière le menu ouvert est
   masqué tant que le menu n'est pas ouvert. */
.menu-toggle-btn { display: none; }
.sidebar-close-btn { display: none; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15, 23, 31, 0.45); z-index: 39;
}
.sidebar-backdrop.visible { display: block; }

/* ---------- Cards / KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; }
.card-title { font-family: var(--font-display); font-weight: 700; font-size: 14px; margin-bottom: 14px; }
.kpi-row { display: flex; gap: 16px; flex-wrap: wrap; }
.kpi-card { flex: 1; min-width: 190px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; }
.kpi-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kpi-label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.kpi-icon { width: 30px; height: 30px; border-radius: 9px; background: var(--primary-soft); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; }
.kpi-value { font-family: var(--font-display); font-weight: 800; font-size: 25px; letter-spacing: -0.01em; }
.kpi-foot { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.kpi-foot.up { color: var(--success); font-weight: 600; }

/* ---------- Tabs / pills ---------- */
.tabs { display: flex; gap: 3px; background: var(--surface); padding: 4px; border-radius: 10px; border: 1px solid var(--border); }
.tab-btn { padding: 7px 14px; border: none; border-radius: 7px; font-size: 12.5px; font-weight: 600; background: transparent; color: var(--text-faint); }
.tab-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(20,30,40,0.08); }
.tabs.inset { background: var(--bg); }
.tabs.inset .tab-btn.active { background: var(--surface); }

.chip { padding: 8px 14px; border: 1px solid var(--border); border-radius: 9px; font-size: 12.5px; font-weight: 600; background: var(--surface); color: var(--text-muted); }
.chip.active { background: var(--primary-soft); color: var(--primary-dark); border-color: var(--primary-soft); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px;
  border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text);
  font-size: 13px; font-weight: 600;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); color: #fff; border: none; font-family: var(--font-display); font-weight: 700; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 13px;
  background: var(--surface); color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search-box input { width: 100%; padding: 12px 14px 12px 40px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); font-size: 13.5px; outline: none; }

/* ---------- Tables ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); padding: 12px 18px; border-bottom: 1px solid var(--border); background: var(--surface);
}
table.data td { padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--bg); }

/* ---------- Badges / status ---------- */
.badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.bg-warning { background: var(--warning-soft); color: var(--warning); }
.badge.bg-danger { background: var(--danger-soft); color: var(--danger); }
.badge.bg-success { background: var(--success-soft); color: var(--success); }
.badge.bg-primary { background: var(--primary-soft); color: var(--primary-dark); }
.badge.bg-muted { background: var(--bg); color: var(--text-muted); }

.banner { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-radius: 10px; }
.banner.success { background: var(--success-soft); color: var(--success); }
.banner.warning { background: var(--warning-soft); color: var(--warning); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner-content { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; }
.banner-close { border: none; background: transparent; cursor: pointer; font-size: 12px; font-weight: 600; color: inherit; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--text-faint); padding: 40px 0; text-align: center; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,30,40,0.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { width: 460px; max-width: 100%; max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(20,30,40,0.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-family: var(--font-display); font-weight: 800; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; margin-top: 6px; }

/* ---------- Comptoir ---------- */
.comptoir-layout { flex: 1; min-height: 0; display: flex; margin: -26px -32px -40px -32px; }
.comptoir-catalog { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 24px 24px 24px 32px; gap: 16px; overflow: auto; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.product-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.product-card:hover { border-color: var(--primary); }
.product-cat { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.product-add { width: 26px; height: 26px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.product-name { font-size: 13.5px; font-weight: 600; line-height: 1.3; min-height: 35px; }
.product-price { font-family: var(--font-display); font-weight: 800; font-size: 15px; }
.product-stock { font-size: 11px; color: var(--text-faint); }

.panier { width: 400px; min-width: 400px; border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.panier-head { padding: 20px 20px 0 20px; display: flex; flex-direction: column; gap: 14px; }
.panier-items { flex: 1; min-height: 0; overflow: auto; padding: 14px 20px; display: flex; flex-direction: column; }
.panier-item { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.qty-control { display: flex; align-items: center; gap: 4px; background: var(--bg); border-radius: 8px; padding: 3px; }
.qty-control button { width: 20px; height: 20px; border: none; border-radius: 6px; background: var(--surface); color: var(--text-muted); font-weight: 700; font-size: 13px; }
.panier-foot { padding: 16px 20px 20px 20px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; }
.line-row { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-muted); }
.total-row { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Chat ---------- */
.chat-fab {
  position: fixed; bottom: 24px; right: 24px; width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(20,30,40,0.25); z-index: 40;
}
.chat-panel {
  position: fixed; bottom: 92px; right: 24px; width: 360px; max-width: calc(100vw - 32px); height: 480px;
  max-height: calc(100vh - 130px); background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 50px rgba(20,30,40,0.25); display: flex; flex-direction: column; overflow: hidden; z-index: 41;
}
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.chat-tabs { display: flex; border-bottom: 1px solid var(--border); }
.chat-tab { flex: 1; padding: 9px; border: none; background: transparent; font-size: 12px; font-weight: 600; color: var(--text-faint); border-bottom: 2px solid transparent; }
.chat-tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.chat-warning { padding: 8px 12px; background: var(--warning-soft); color: var(--warning); font-size: 10.5px; font-weight: 600; text-align: center; }
.chat-messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 85%; padding: 8px 11px; border-radius: 12px; background: var(--bg); font-size: 12.5px; }
.chat-msg.mine { align-self: flex-end; background: var(--primary-soft); }
.chat-msg-meta { font-size: 10px; color: var(--text-faint); margin-bottom: 3px; display: flex; gap: 6px; align-items: center; }
.chat-msg-del { border: none; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 10px; }
.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-input-row input { flex: 1; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 12.5px; outline: none; }
.chat-dm-list { overflow: auto; }
.chat-dm-item { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); width: 100%; border: none; background: transparent; text-align: left; }
.chat-dm-item:hover { background: var(--bg); }

/* ---------- Login ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-card { width: 380px; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px; display: flex; flex-direction: column; gap: 18px; box-shadow: 0 20px 50px rgba(20,30,40,0.08); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.login-error { font-size: 12.5px; color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 10px; }
.login-hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; background: var(--bg); border-radius: 10px; padding: 10px 12px; }

/* ---------- Utility ---------- */
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.gap-8 { gap: 8px; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }
.mt-0 { margin-top: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); } .comptoir-layout { flex-direction: column; } .panier { width: 100%; min-width: 0; border-left: none; border-top: 1px solid var(--border); } }

/* Smartphones et tablettes en portrait : le menu latéral devient un tiroir
   qui s'ouvre par-dessus le contenu (au lieu d'être simplement invisible,
   comme c'était le cas auparavant — bug signalé) via le bouton hamburger
   dans la barre du haut. */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 40; box-shadow: 0 12px 40px rgba(15, 23, 31, 0.25);
    transform: translateX(-100%); transition: transform 0.2s ease; height: 100dvh;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .menu-toggle-btn { display: flex; }
  .sidebar-close-btn { display: flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 18px 16px 32px 16px; }
  .table-card { overflow-x: auto; }
}

@media (max-width: 720px) {
  .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-clock { display: none; }
}