:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e3e5ea;
  --text: #0f1b2e;
  --text-muted: #6b7280;

  --brand: #d9a441;
  --brand-dark: #b4822f;

  --nav-bg: #0f1b2e;
  --nav-bg-hover: #16223a;
  --nav-item-active-bg: #1a2740;
  --nav-text: #9aa3b5;
  --nav-text-active: #f3f5f8;

  --pole-stock: #1d9e75;
  --pole-import: #378add;
  --pole-ventes: #ba7517;
  --pole-finance: #7f77dd;
  --pole-admin: #5f5e5a;

  --success-bg: #e1f5ee; --success-text: #0f6e56;
  --danger-bg: #fcebeb; --danger-text: #a32d2d;
  --warning-bg: #faeeda; --warning-text: #854f0b;
  --muted-bg: #eef0f3; --muted-text: #6b7280;

  --radius: 10px;
  --font-head: 'Plus Jakarta Sans', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
}

h1, h2, h3, .brand-name { font-family: var(--font-head); font-weight: 600; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
}
.login-card .brand-name { font-size: 20px; color: var(--text); margin: 0 0 4px; }
.login-card .brand-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 28px; }
.login-card label { display: block; font-size: 13px; margin: 16px 0 6px; color: var(--text-muted); }
.login-card input {
  width: 100%; padding: 11px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px;
}
.login-card input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn-primary {
  width: 100%; margin-top: 24px; padding: 11px; border: none; border-radius: 8px;
  background: var(--brand); color: #1a1305; font-weight: 600; font-size: 14px; cursor: pointer;
}
.btn-primary:hover { background: var(--brand-dark); }
.login-error { color: var(--danger-text); font-size: 13px; margin-top: 14px; min-height: 16px; }

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

.rail {
  width: 56px; background: var(--nav-bg); flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 10px;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 2;
}
.rail-brand {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #1a1305;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; margin-bottom: 6px;
}
.rail-hamburger {
  width: 30px; height: 30px; border-radius: 8px; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; margin-bottom: 8px;
}
.rail-hamburger span { display: block; width: 16px; height: 2px; background: var(--nav-text); border-radius: 1px; }

.rail-dot {
  width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; cursor: pointer; border: 1.5px solid transparent; flex-shrink: 0;
}
.rail-dot--active { border-color: rgba(255,255,255,0.55); }

.drawer-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15,27,46,0.35); z-index: 10;
}
.drawer-backdrop--open { display: block; }

.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 240px; background: var(--nav-bg);
  z-index: 11; transform: translateX(-100%); transition: transform 0.2s ease;
  padding: 16px 14px; overflow-y: auto; display: flex; flex-direction: column;
}
.drawer--open { transform: translateX(0); }

.drawer-header { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.drawer-header .brand-name { font-size: 13px; color: var(--nav-text-active); margin: 0; }

.drawer-group-label { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; margin: 14px 0 6px 4px; }

.drawer-item {
  font-size: 12.5px; color: var(--nav-text); padding: 8px; border-radius: 7px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px;
}
.drawer-item:hover { background: var(--nav-bg-hover); }
.drawer-item--active { background: var(--nav-item-active-bg); color: var(--nav-text-active); font-weight: 600; }
.drawer-item--soon { cursor: default; opacity: 0.6; }
.drawer-item--soon:hover { background: none; }
.drawer-soon-badge { font-size: 9px; background: var(--nav-item-active-bg); border-radius: 9px; padding: 1px 6px; color: var(--nav-text); }

.drawer-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.08); display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #1a1305;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
#user-name { display: block; font-size: 12.5px; font-weight: 600; color: var(--nav-text-active); }
#user-role { display: block; font-size: 11px; color: var(--nav-text); }
.btn-logout { background: none; border: none; color: var(--nav-text); cursor: pointer; font-size: 12px; }
.btn-logout:hover { color: var(--danger-text); }

.main { flex: 1; margin-left: 56px; padding: 20px; }

.view { display: none; }
.view--active { display: block; }

.view-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.view-header h1 { font-size: 19px; margin: 0 0 4px; }
.view-header p { color: var(--text-muted); margin: 0; font-size: 12.5px; }

/* ---------- Cartes de liste ---------- */
.item-list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; border-left: 3px solid var(--pole-import);
}
.item-card__top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.item-card__title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.item-card__ref { font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.item-card__bottom {
  display: flex; justify-content: space-between; align-items: center; margin-top: 10px;
  border-top: 1px solid var(--border); padding-top: 8px; font-size: 12.5px; color: var(--text-muted);
}
.item-card__amount { font-weight: 600; color: var(--text); }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger-text); }
.empty-state { text-align: center; color: var(--text-muted); padding: 30px 10px; font-size: 13px; }

/* ---------- Badges & stepper ---------- */
.badge { padding: 3px 9px; border-radius: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
.badge--success { background: var(--success-bg); color: var(--success-text); }
.badge--danger { background: var(--danger-bg); color: var(--danger-text); }
.badge--warning { background: var(--warning-bg); color: var(--warning-text); }
.badge--muted { background: var(--muted-bg); color: var(--muted-text); }

.stepper { display: flex; align-items: center; gap: 3px; margin-top: 8px; }
.stepper__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
.stepper__dot--done { background: var(--pole-import); }

/* ---------- Buttons ---------- */
.btn { padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn-accent { background: var(--brand); color: #1a1305; border: none; font-weight: 600; }
.btn-accent:hover { background: var(--brand-dark); }
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 6px; }
.btn-icon:hover { color: var(--danger-text); }

/* ---------- Modale (bottom sheet mobile) ---------- */
.modal {
  display: none; position: fixed; inset: 0; background: rgba(15, 27, 46, 0.45);
  align-items: flex-end; justify-content: center; z-index: 50;
}
.modal--open { display: flex; }
.modal-card {
  background: var(--surface); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; padding: 22px 20px 28px;
}
.modal-card h2 { margin: 0 0 18px; font-size: 16px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 10px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 16px; font-family: var(--font-body);
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.ligne-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }
.ligne-row input {
  padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px;
}

.ligne-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: var(--bg); }
.ligne-card input, .ligne-card select {
  padding: 8px 9px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 16px;
}
.ligne-card__row1 { margin-bottom: 6px; }
.ligne-card__row1 input { width: 100%; }
.ligne-card__row2 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.ligne-card__row3 { display: flex; gap: 6px; align-items: center; }
.ligne-card__row3 select { flex: 1; }
.ligne-card__row3 input { flex: 1; }

/* ---------- Vue détail commande ---------- */
.detail-back { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 0; margin-bottom: 10px; }
.detail-back:hover { color: var(--text); }

.detail-stepper { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.detail-stepper__step {
  font-size: 11px; padding: 5px 10px; border-radius: 20px; background: var(--muted-bg); color: var(--muted-text);
}
.detail-stepper__step--done { background: var(--pole-import); color: #fff; }

.detail-section { margin-top: 22px; }
.detail-section__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.detail-section__header h3 { font-size: 14px; margin: 0; }

.nested-card { border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.nested-card__title { font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.nested-sub { margin-left: 12px; margin-top: 8px; padding-left: 10px; border-left: 2px solid var(--border); }

.frais-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.frais-row:last-child { border-bottom: none; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (min-width: 720px) {
  .main { padding: 32px 40px; }
}

/* ---------- Lightbox photo plein écran ---------- */
.lightbox {
  display: none; position: fixed; inset: 0; background: rgba(5, 8, 15, 0.92);
  align-items: center; justify-content: center; padding: 24px; z-index: 60;
}
.lightbox--open { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.lightbox-close {
  position: absolute; top: 18px; right: 18px; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); border: none; color: #fff; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- Impression (compte-rendu de commande) ---------- */
@page { margin: 0; }

#zone-impression { display: none; }

@media print {
  .app-shell, .drawer, .drawer-backdrop, .modal, .lightbox { display: none !important; }
  #zone-impression { display: block !important; }
}

/* ---------- Barre de filtres ---------- */
.filtres-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}
.filtres-bar .form-row { margin-bottom: 10px; }
.filtres-bar .form-grid-2 { margin-bottom: 0; }

.recherche-wrap { position: relative; }
.recherche-wrap input { padding-left: 32px !important; }
.recherche-wrap::before {
  content: "🔍";
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 12px; opacity: 0.5; pointer-events: none;
}

.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: 2px solid var(--brand); outline-offset: 1px;
}

/* ---------- Interactions de survol (desktop) ---------- */
.item-card { transition: box-shadow 0.15s ease, border-color 0.15s ease; }
.item-card:hover { box-shadow: 0 2px 10px rgba(15, 27, 46, 0.07); border-color: #c7cdd6; }

/* ---------- Mise en page desktop plus lisible ---------- */
@media (min-width: 900px) {
  .main { max-width: 980px; margin: 0 auto; }
}
