:root {
  /* Palette sobre inspirée d'Archeodunum (terracotta désaturé + brun terre) */
  --bg: #f5f4f2;
  --surface: #ffffff;
  --border: #e5e1dc;
  --text: #2e2a26;
  --muted: #7a736c;
  --primary: #8c5a43;          /* terracotta-brun sobre */
  --primary-dark: #70452f;
  --primary-soft: #f1eae5;
  --brand-brown: #4e3629;      /* brun terre */
  --brand-brown-soft: #efeae6;
  --success: #4b7a52;
  --warning: #b07d3a;
  --danger: #b04a3f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(46, 42, 38, 0.08), 0 1px 2px rgba(46, 42, 38, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--primary); }

/* ---------- Header ---------- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.app-header .inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--brand-brown));
  display: grid; place-items: center; color: #fff; font-size: 18px;
}
.brand-logo { height: 26px; width: auto; display: block; cursor: default; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; }
.header-spacer { flex: 1; }
.header-user { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.role-badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary);
}
.role-badge.admin { background: var(--brand-brown-soft); color: var(--brand-brown); }

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.page-title { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 24px; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 9px 16px; border-radius: 10px; font-size: 14px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tabs / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 20px; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented button {
  border: none; background: transparent; padding: 7px 14px; border-radius: 7px;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.segmented button.active { background: var(--primary); color: #fff; }
.search-input {
  flex: 1; min-width: 200px; padding: 9px 14px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; background: var(--surface);
}
.search-input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

/* ---------- Grid of articles ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.card .thumb {
  height: 140px; background: #f8fafc; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 40px; border-bottom: 1px solid var(--border); overflow: hidden;
}
.card .thumb img { max-width: 100%; max-height: 100%; object-fit: contain; padding: 12px; }
.card .body { padding: 14px; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.card .cat {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted);
}
.card .cat.informatique { color: var(--primary); }
.card .cat.bureautique { color: var(--brand-brown); }
.card h3 { margin: 0; font-size: 15px; }
.card .desc { font-size: 13px; color: var(--muted); flex: 1; }
.card .ref { font-size: 12px; color: var(--muted); }
.card .actions { padding: 8px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.card .controls { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; min-height: 37px; }
.field-mini { display: flex; flex-direction: column; align-items: stretch; gap: 1px; flex: 0 0 auto; min-width: 0; }
.field-mini > label { font-size: 9px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.field-mini select { padding: 2px 5px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; background: #fff; height: 22px; }
.qty { display: inline-flex; align-items: stretch; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; height: 22px; }
.qty button { border: none; background: #f8fafc; width: 22px; cursor: pointer; font-size: 14px; line-height: 1; flex: 0 0 auto; }
.qty input { width: 30px; border: none; text-align: center; font-size: 13px; min-width: 0; height: 100%; box-sizing: border-box; -webkit-appearance: none; -moz-appearance: textfield; appearance: none; margin: 0; }
.field-mini .qty input { flex: 1 1 auto; }
.qty input::-webkit-outer-spin-button,
.qty input::-webkit-inner-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }
.card .actions .btn { width: 100%; justify-content: center; }
.card .actions .hint-1max { font-size: 12px; color: var(--muted); text-align: center; min-height: 37px; display: flex; align-items: center; justify-content: center; }

/* ---------- Cart drawer ---------- */
.cart-btn { position: relative; }
.cart-count {
  position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 999px;
  display: grid; place-items: center; padding: 0 5px;
}
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.4); z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 400px; max-width: 92vw;
  background: var(--surface); z-index: 50; transform: translateX(100%);
  transition: transform .25s ease; display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(15,23,42,.12);
}
.drawer.open { transform: translateX(0); }
.drawer header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.drawer header h2 { margin: 0; font-size: 18px; }
.drawer .items-wrap { flex: 1; min-height: 0; position: relative; display: flex; }
.drawer .items { flex: 1; overflow-y: auto; padding: 12px 20px; }
/* Fondus haut/bas indiquant qu'on peut faire défiler la liste */
.drawer .items-wrap::before,
.drawer .items-wrap::after {
  content: ''; position: absolute; left: 0; right: 0; height: 34px;
  pointer-events: none; opacity: 0; transition: opacity .2s; z-index: 1;
}
.drawer .items-wrap::before { top: 0; background: linear-gradient(to bottom, var(--surface), transparent); }
.drawer .items-wrap::after { bottom: 0; background: linear-gradient(to top, var(--surface), transparent); }
.drawer .items-wrap.can-up::before { opacity: 1; }
.drawer .items-wrap.can-down::after { opacity: 1; }
.drawer .scroll-cue {
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%);
  z-index: 2; color: var(--muted); font-size: 20px; line-height: 1;
  opacity: 0; transition: opacity .2s; pointer-events: none;
  animation: cueBounce 1.4s ease-in-out infinite;
}
.drawer .items-wrap.can-down .scroll-cue { opacity: .75; }
@keyframes cueBounce { 0%, 100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, 4px); } }
.drawer footer { border-top: 1px solid var(--border); padding: 16px 20px; }
.cart-line { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.cart-line .ci-thumb { width: 46px; height: 46px; border-radius: 8px; background: #f8fafc; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; overflow: hidden; }
.cart-line .ci-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cart-line .ci-info { flex: 1; min-width: 0; }
.cart-line .ci-info h4 { margin: 0 0 2px; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.status {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; display: inline-block;
}
.status.pending { background: #f3ecd9; color: #8a6d2f; }
.status.validated { background: #e4ebe8; color: #3f6b57; }
.status.available { background: #e7eef3; color: #3f5c73; }
.status.partial { background: #f6ecdc; color: #9a6a1c; }
.status.delivered { background: #e3ede4; color: #3f6b45; }
.status.cancelled { background: #f2e4e2; color: #99453b; }

/* ---------- Modal / forms ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 60; display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(15,23,42,.25); }
.modal header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal header h2 { margin: 0; font-size: 18px; }
.modal .content { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 70px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s ease; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.close-x { margin-left: auto; border: none; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.muted { color: var(--muted); }
.section-title { font-size: 18px; font-weight: 700; margin: 32px 0 14px; }
.mini { font-size: 13px; color: var(--muted); }
.thumb-mini { width: 40px; height: 40px; border-radius: 8px; background: #f8fafc; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.thumb-mini img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(135deg, #fff1ec, #f2ece9); }
.login-card { background: var(--surface); border-radius: 18px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(15,23,42,.12); text-align: center; }
.login-card .logo-lg { width: 60px; height: 60px; border-radius: 16px; background: linear-gradient(135deg, var(--primary), var(--brand-brown)); display: grid; place-items: center; color: #fff; font-size: 30px; margin: 0 auto 18px; }
.login-card h1 { font-size: 22px; margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 26px; }
.btn-ms { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.dev-note { margin-top: 22px; padding-top: 22px; border-top: 1px dashed var(--border); }

/* ---------- Onglets défilables (utile sur petit écran) ---------- */
.segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented button { white-space: nowrap; }

/* ---------- Responsive / téléphones ---------- */
@media (max-width: 680px) {
  .row-2 { grid-template-columns: 1fr; }
  .container { padding: 16px 14px 48px; }
  .page-title { font-size: 20px; }
  .page-sub { margin-bottom: 18px; }

  /* Header compact : on garde l'avatar et les actions, on masque le nom */
  .app-header .inner { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .brand { font-size: 16px; }
  .brand .logo { width: 30px; height: 30px; font-size: 16px; }
  .header-user { gap: 6px; }
  .header-user > div:not(.avatar) { display: none; }
  .btn { padding: 8px 12px; font-size: 13px; }
  .btn.small { padding: 6px 9px; font-size: 12px; }

  /* Grille catalogue : une carte par ligne, confortable au doigt */
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card .thumb { height: 120px; }

  /* Panier : plein écran */
  .drawer { width: 100%; max-width: 100%; }

  /* Modales : marges réduites */
  .modal-overlay { padding: 16px 10px; }
  .toolbar { gap: 8px; }

  /* Zones tactiles un peu plus grandes */
  .qty button { width: 34px; height: 36px; }

  /* Écran de connexion */
  .login-wrap { padding: 14px; }
  .login-card { padding: 28px 20px; }
  .login-card h1 { font-size: 20px; }
}

/* Très petits écrans : brand sans le mot, plus d'espace pour les actions */
@media (max-width: 380px) {
  .brand { font-size: 0; gap: 0; }
  .brand .logo { font-size: 16px; }
  .role-badge { font-size: 10px; }
}
