:root {
  --bg: #f3f5f7;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --line: #e7eaee;
  --text: #3b4656;
  --head: #253858;
  --muted: #9aa5b5;
  --primary: #74c4d6;      /* teal / sky (actif, boutons primaires) */
  --primary-d: #5bb2c6;
  --green: #8cbf4e;        /* ajouter / valider / rechercher */
  --green-d: #7aad3f;
  --gold: #d7b63f;         /* boutons "Ajouter un ..." */
  --gold-d: #c7a52f;
  --blue: #5bbcd1;         /* action éditer */
  --orange: #e8693f;       /* action supprimer/désactiver */
  --purple: #6b63d6;       /* action voir */
  --ok: #7aad3f;
  --ko: #e8693f;
  --radius: 14px;
  --shadow: 0 6px 18px rgba(37, 56, 88, .06);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5; font-size: 14px;
}
a { color: inherit; }

/* ===== Connexion ===== */
.auth-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, #e9f4f7, #f3f5f7);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.auth-logo { font-weight: 800; letter-spacing: 2px; color: var(--head); font-size: 24px; margin-bottom: 8px; }
.auth-card h1 { font-size: 18px; margin: 0 0 18px; font-weight: 600; color: var(--head); }
.auth-card label { display: block; text-align: left; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.auth-card input {
  width: 100%; padding: 11px 12px; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; color: var(--text); font-size: 14px;
}
.auth-card input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.alert { background: #fdecec; color: #c0392b; border: 1px solid #f5c6c6; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin: 0 0 6px; }
.flash { background: #eef7e6; color: #5a8a2c; border: 1px solid #cfe6b5; padding: 10px 12px; border-radius: 10px; font-size: 13px; margin: 0 0 16px; }

/* ===== Boutons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 600; text-decoration: none; color: #fff; background: var(--primary); }
.btn:hover { filter: brightness(.96); }
.btn-primary { background: var(--primary); }
.btn-green { background: var(--green); }
.btn-gold { background: var(--gold); }
.btn-block { width: 100%; justify-content: center; margin-top: 18px; }
.btn-ghost { background: #fff; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { color: var(--text); border-color: var(--primary); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-danger { background: var(--orange); }
.icon-btn { width: 34px; height: 34px; padding: 0; justify-content: center; border-radius: 8px; }
.ib-blue { background: var(--blue); } .ib-gold { background: var(--gold); }
.ib-orange { background: var(--orange); } .ib-purple { background: var(--purple); }
.ib-green { background: var(--green); }

/* ===== Application : layout ===== */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; }
.brand { font-weight: 800; letter-spacing: 2px; color: var(--head); font-size: 22px; padding: 0 10px 2px; }
.company-name { font-weight: 800; color: var(--primary); font-size: 15px; letter-spacing: .5px; padding: 0 10px 12px; }
.role-badge { display: inline-block; background: #e5f3f7; color: #5aa9bd; font-size: 11px; font-weight: 700; letter-spacing: .5px; padding: 5px 12px; border-radius: 8px; margin: 0 8px 10px; }
.switch-co { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 8px 14px; padding: 9px 10px; border-radius: 10px; background: #fff3e0; color: #c15c00; border: 1px solid #ffd8a8; font-size: 13px; font-weight: 700; text-decoration: none; }
.switch-co:hover { background: #ffe8cc; }
.switch-co svg { width: 16px; height: 16px; fill: none; stroke: #c15c00; stroke-width: 2; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a, .nav summary { display: flex; align-items: center; gap: 11px; color: #51607a; text-decoration: none; padding: 11px 12px; border-radius: 10px; font-size: 14px; cursor: pointer; }
.nav a:hover, .nav summary:hover { background: #f1f4f6; }
.nav a.active { background: var(--primary); color: #fff; }
.nav a.active svg { stroke: #fff; }
.nav svg { width: 18px; height: 18px; stroke: #6b7890; flex: none; fill: none; stroke-width: 2; }
.nav details > summary { list-style: none; justify-content: space-between; }
.nav details > summary::-webkit-details-marker { display: none; }
.nav details > summary .grp { display: flex; align-items: center; gap: 11px; }
.nav details > summary::after { content: "+"; color: #9aa5b5; font-weight: 700; }
.nav details[open] > summary::after { content: "–"; }
.nav details[open] > summary { background: var(--primary); color: #fff; }
.nav details[open] > summary svg { stroke: #fff; }
.submenu { display: flex; flex-direction: column; margin: 2px 0 6px 14px; padding-left: 10px; border-left: 2px solid var(--line); }
.submenu a { padding: 8px 12px; font-size: 13.5px; color: #6b7890; }
.submenu a.active { background: transparent; color: var(--primary-d); font-weight: 600; }
.submenu a.active::before { content: "•"; margin-right: 6px; color: var(--primary); }

.side-foot { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.logout .btn { width: 100%; justify-content: center; }

/* ===== Contenu ===== */
.content { padding: 22px 26px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.topbar h1 { font-size: 22px; margin: 0; color: var(--head); font-weight: 800; }
.breadcrumb { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.breadcrumb a { color: var(--primary-d); text-decoration: none; }
.whoami { color: var(--muted); font-size: 13px; }
.whoami span { color: var(--text); }

/* Cartes statistiques (dégradés) */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { border-radius: var(--radius); padding: 22px; color: #fff; position: relative; overflow: hidden; box-shadow: var(--shadow); min-height: 120px; display: flex; flex-direction: column; justify-content: flex-end; }
.stat .ic { position: absolute; top: 18px; left: 18px; width: 42px; height: 42px; background: rgba(255,255,255,.25); border-radius: 10px; display: grid; place-items: center; }
.stat .ic svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2; }
.stat .v { font-size: 26px; font-weight: 800; }
.stat .l { font-size: 13px; opacity: .95; }
.g-green { background: linear-gradient(135deg, #a7cf5b, #8cbf4e); }
.g-gold { background: linear-gradient(135deg, #e0c355, #d2ad38); }
.g-blue { background: linear-gradient(135deg, #7fd0e0, #66bdd1); }
.g-teal { background: linear-gradient(135deg, #5bc0b8, #46a9a1); }
.g-gray { background: linear-gradient(135deg, #9aa3a0, #7f8a86); }
.g-orange { background: linear-gradient(135deg, #f0a85a, #e08a3c); }

/* Grille des permissions (restrictions d'accès) */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; }
.perm-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.perm-item input { width: auto; margin: 0; }

/* Pagination */
.pager { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 12px 0; }
.pager .btn { min-width: 36px; justify-content: center; }
.pager .is-disabled { opacity: .45; pointer-events: none; }
.pager-gap { padding: 0 4px; color: var(--muted); }

/* Panneaux & tableaux */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.panel h2 { font-size: 16px; margin: 0 0 14px; color: var(--head); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 700; font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
tbody tr:hover { background: #fafbfc; }
.r { text-align: right; }
.muted { color: var(--muted); }
.sm { font-size: 12.5px; }
.link { color: var(--primary-d); text-decoration: none; font-weight: 600; }
.link:hover { text-decoration: underline; }
.tag { background: #eef2f5; color: #5c6b82; padding: 2px 10px; border-radius: 20px; font-size: 12px; }
.badge { background: #eef2f5; padding: 2px 10px; border-radius: 20px; }
.badge.low { background: #fdecc8; color: #b5791f; }
.state-ok { color: var(--ok); font-weight: 600; }
.state-ko { color: var(--ko); font-weight: 600; }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* Formulaires */
.row-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-form input, .row-form select { flex: 1; min-width: 150px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.row-form .chk { display: inline-flex; align-items: center; gap: 7px; color: var(--text); font-size: 14px; white-space: nowrap; }
.row-form .chk input { flex: 0 0 auto; min-width: 0; width: 16px; height: 16px; }
.grid-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea { padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; color: var(--text); width: 100%; }
input, select, textarea { font-family: inherit; font-size: 14px; }
.panel input:focus, .panel select:focus, .panel textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
table input, table select { padding: 8px 10px; background: #fff; border: 1px solid var(--line); border-radius: 8px; color: var(--text); width: 100%; }
.w-sm { max-width: 120px; }
.search, .filters { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.search input, .filters input, .filters select { padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.search input { min-width: 220px; }
.filters .field { gap: 4px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.total-chip { font-size: 13px; color: var(--muted); } .total-chip strong { color: var(--green-d); }

.narrow { max-width: 460px; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.stack label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.stack input { padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; color: var(--text); }
.role-pill { font-size: 11px; padding: 1px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .5px; background: #e5f3f7; color: #5aa9bd; }
.whoami-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--text); text-decoration: none; font-size: 13px; padding: 8px 12px; border-radius: 9px; }
.whoami-link:hover { background: #f1f4f6; }

/* Point de vente */
.pos-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.pos-side label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.pos-side select { width: 100%; }
.pos-total { display: flex; justify-content: space-between; align-items: center; margin: 20px 0 14px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 15px; }
.pos-total strong { font-size: 22px; color: var(--green-d); }

/* Reçu */
.receipt-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.receipt-head h2 { margin: 0; } .receipt-head p { margin: 2px 0; font-size: 13px; }
tfoot td { border-top: 2px solid var(--line); border-bottom: none; font-size: 15px; }

/* Graphiques / pie */
.chart-wrap { position: relative; height: 320px; }
.chart-wrap.sm { height: 260px; }

/* Barres rapports */
.bar-row { display: grid; grid-template-columns: 110px 1fr 120px; gap: 10px; align-items: center; margin: 8px 0; font-size: 13px; }
.bar-label { color: var(--muted); } .bar-val { text-align: right; }
.bar { background: #eef2f5; border-radius: 20px; height: 12px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 20px; }
.bar-fill.alt { background: var(--green); }
.bar-cell { width: 40%; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .pos-grid, .grid-form { grid-template-columns: 1fr; }
}

/* Impression A4 des documents (bon de commande, bon de livraison, proforma, facture) */
@page { size: A4 portrait; margin: 14mm 15mm; }
@media print {
  body { background: #fff; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sidebar, .topbar, .no-print, .flash { display: none !important; }
  .app { display: block; } .content { padding: 0; margin: 0; }
  .panel { border: none; box-shadow: none; padding: 0; margin: 0; background: #fff; }

  /* Le pied de page est fixé tout en bas de la page (et non au milieu) ;
     on réserve la hauteur du pied pour que le contenu ne passe pas dessous. */
  .receipt { display: block; max-width: none; margin: 0; padding-bottom: 42mm; }
  .doc-foot { position: fixed; left: 0; right: 0; bottom: 0; margin: 0;
    background: #fff; border-top: 1px solid #000; padding-top: 8px; }

  /* En-tête de tableau répété et éléments non coupés entre deux pages */
  table { page-break-inside: auto; width: 100%; }
  thead { display: table-header-group; }
  tr, .signatures, .doc-head { break-inside: avoid; }

  .doc-head { border-color: #000; }
  .doc-logo { color: #000; }
  a { color: #000; text-decoration: none; }
}

/* Aperçu écran des documents imprimables : allure « feuille A4 » */
.receipt { max-width: 820px; margin: 0 auto; }

/* Édition sur demande : lignes en lecture seule par défaut, édition via « Modifier » */
.ed { display: none !important; }
.ro { display: inline; }
tr.editing .ed { display: inline-block !important; }
tr.editing .ro { display: none; }
.btn-save, .btn-cancel { display: none; }
tr.editing .btn-save, tr.editing .btn-cancel { display: inline-flex; }
tr.editing .btn-modif { display: none; }

/* En-tête / pied de page des documents imprimables */
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px;
  border-bottom: 2px solid var(--primary); padding-bottom: 12px; margin-bottom: 16px; }
.doc-logo { font-size: 26px; font-weight: 800; letter-spacing: 1px; color: var(--primary); }
.doc-soc p { margin: 2px 0; }
.doc-meta h2 { margin: 0 0 6px; }
.doc-meta p { margin: 2px 0; }
.sm { font-size: 12px; }
.doc-foot { margin-top: 22px; border-top: 1px solid #e2e8f0; padding-top: 12px; }
.doc-foot p { margin: 4px 0; }
.signatures { display: flex; justify-content: space-between; gap: 20px; margin-top: 34px; }
.signatures p { margin: 2px 0; }

/* Logo et mentions légales des documents */
.doc-logo-img { max-width: 220px; height: auto; display: block; margin-bottom: 6px; }
.doc-activite { max-width: 420px; }
.doc-legal { margin-top: 16px; padding-top: 8px; border-top: 1px solid #e2e8f0;
  font-size: 10.5px; color: #64748b; text-align: center; }
