:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1c2430; --muted: #6b7684; --line: #e1e5ea; --soft: #f0f3f6;
  --brand: #0f5b8f; --brand-ink: #ffffff; --brand-soft: #e6f0f7;
  --error: #b3261e; --error-soft: #fbeaea; --ok: #1e7a3c; --ok-soft: #e7f4ea; --warn: #8a5a00; --warn-soft: #fdf3e0;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161c; --card: #1b2129; --text: #e6e9ee; --muted: #98a2b0; --line: #2c3440; --soft: #222a33;
          --brand: #4ea3dc; --brand-ink: #0b1016; --brand-soft: #1d3342;
          --error: #ff8a80; --error-soft: #3a2222; --ok: #6fd18f; --ok-soft: #1d3326; --warn: #f0c060; --warn-soft: #3a3020; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 "Segoe UI", Tahoma, "Noto Sans Arabic", Arial, sans-serif; }
.boot { text-align: center; color: var(--muted); padding: 40px; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; direction: ltr; unicode-bidi: isolate; }

/* --- connexion --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 28px 24px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.logo { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--brand); color: var(--brand-ink); font-weight: 700; flex: none; }

/* --- structure --- */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--card); border-inline-end: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.side .brand { margin: 4px 6px 18px; }
.side .brand b { display: block; font-size: 14px; }
.nav a, .nav span { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--soft); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav span.soon { color: var(--muted); font-size: 14px; }
.nav span.soon small { margin-inline-start: auto; font-size: 11px; background: var(--soft); padding: 1px 6px; border-radius: 6px; }
.nav h3 { font-size: 11px; font-weight: 600; color: var(--muted); margin: 14px 10px 6px; letter-spacing: .3px; }
.main { padding: 22px 26px 40px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.menu-btn { display: none; }

/* --- composants --- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 20px; font-weight: 600; margin-top: 4px; }
.stat .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1; min-width: 180px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; background: var(--soft); }
td.r, th.r { text-align: end; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.table-wrap table th:first-child { border-start-start-radius: var(--radius); }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--error-soft); color: var(--error); }
.pos { color: var(--ok); } .neg { color: var(--error); }

label { display: block; font-size: 13.5px; color: var(--muted); }
label > span { display: block; margin-bottom: 5px; }
input, select, textarea {
  display: block; width: 100%; padding: 9px 11px; font: inherit; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
input[dir="ltr"] { text-align: left; }
.form { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.form .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }
.actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 14px; flex-wrap: wrap; }
button, .btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; font: inherit; font-weight: 600; border: 0;
  border-radius: 8px; background: var(--brand); color: var(--brand-ink); cursor: pointer; white-space: nowrap;
}
button.secondary, .btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.small { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: wait; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 14px; margin: 10px 0 0; }
.alert.err { background: var(--error-soft); color: var(--error); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); } dl.kv dd { margin: 0; }
.cols { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.back { font-size: 14px; display: inline-block; margin-bottom: 8px; }

/* --- reçu --- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.receipt { background: #fff; color: #111; width: 100%; max-width: 560px; border-radius: 10px; padding: 26px 28px; max-height: 92vh; overflow: auto; }
.receipt .head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #111; padding-bottom: 12px; margin-bottom: 14px; }
.receipt h2 { font-size: 18px; margin: 0; }
.receipt table td { border-bottom: 1px solid #ddd; padding: 7px 4px; }
.receipt .total td { font-weight: 700; }
.receipt .sign { display: flex; justify-content: space-between; margin-top: 34px; font-size: 13px; color: #444; }
.receipt .sign > div { border-top: 1px dashed #999; padding-top: 6px; width: 42%; text-align: center; }
.receipt .sign { break-inside: avoid; page-break-inside: avoid; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 0 0 auto; width: 250px; z-index: 5; transform: translateX(110%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px; }
  .cols { grid-template-columns: 1fr; }
}
@media print {
  /* marge 0 : le navigateur n'imprime plus la date, l'heure et l'adresse de la page */
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  #app > *:not(.overlay), .no-print { display: none !important; }
  .overlay { position: static; background: none; padding: 0; display: block; }
  .receipt { max-width: none; max-height: none; border-radius: 0; padding: 10mm 12mm 8mm; }
  .invoice .inv-stamp img { height: 165px; }
  .invoice .inv-stamp { min-height: 0; }
  .invoice .sign { margin-top: 16px; }
}

/* --- téléphone : chaque ligne de tableau devient une carte (aucun montant coupé) --- */
@media (max-width: 640px) {
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 12px; }
  .table-wrap td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); padding: 7px 0; text-align: start; }
  .table-wrap td:last-child { border-bottom: 0; }
  .table-wrap td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; flex: none; }
  .table-wrap td.r { text-align: end; }
  .table-wrap td:empty { display: none; }
  tr.click:hover td { background: transparent; }
  .top h1 { font-size: 18px; }
}

/* --- évolutions : modale, client, pièces jointes, notifications, facture --- */
.modal { background: var(--card); color: var(--text); width: 100%; max-width: 620px; border-radius: 12px; padding: 18px 20px; max-height: 92vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.sugg-wrap { position: relative; }
.sugg { position: absolute; inset-inline: 0; top: 100%; z-index: 4; background: var(--card); border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; box-shadow: 0 6px 20px rgba(0,0,0,.12); overflow: hidden; }
.sugg-item { display: flex; width: 100%; gap: 8px; justify-content: space-between; background: transparent; color: var(--text); border-radius: 0; font-weight: 400; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.sugg-item:hover { background: var(--soft); }
details.adv { border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; }
details.adv summary, details.help summary { cursor: pointer; color: var(--brand); font-weight: 600; }
details.help p { margin: 8px 0 0; line-height: 1.7; }
.files { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.file { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-height: 92px; background: var(--card); }
.file-open { background: var(--soft); color: var(--text); flex-direction: column; align-items: flex-start; font-weight: 400; padding: 8px; white-space: normal; text-align: start; }
.file-ico { font-size: 11px; font-weight: 700; color: var(--brand); }
.file-name { font-size: 12.5px; word-break: break-all; }
.file.empty-slot { border-style: dashed; color: var(--muted); background: transparent; justify-content: center; align-items: center; font-size: 22px; cursor: pointer; }
.bell { position: relative; font-size: 18px; text-decoration: none; padding: 2px 6px; }
.bell-count { position: absolute; top: -6px; inset-inline-end: -8px; background: var(--error); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 5px; line-height: 17px; min-width: 17px; text-align: center; }
.notifs { display: flex; flex-direction: column; gap: 8px; }
.notif { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; color: var(--text); }
.notif.unread { border-inline-start: 4px solid var(--brand); background: var(--brand-soft); }
.hist { border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.hist ul { margin: 4px 0 0; padding-inline-start: 20px; }
.invoice { max-width: 760px; font-family: Arial, "Segoe UI", sans-serif; }
.invoice .small { font-size: 12.5px; color: #444; }
.invoice .inv-client { display: flex; justify-content: space-between; gap: 16px; border: 1px solid #ccc; border-radius: 6px; padding: 10px 12px; margin-bottom: 14px; }
.invoice table.inv-lines th { background: #f0f0f0; color: #222; }
.invoice table.inv-lines td, .invoice table.inv-lines th { border-bottom: 1px solid #ddd; padding: 7px 6px; }
.invoice table.inv-totals { width: auto; margin-inline-start: auto; margin-top: 12px; min-width: 320px; }
.invoice table.inv-totals td { padding: 6px 8px; border-bottom: 1px solid #ddd; }
.invoice .inv-terms { border-top: 1px solid #ccc; margin-top: 14px; padding-top: 8px; font-size: 12.5px; }
.invoice .r { text-align: right; }
@media (max-width: 640px) {
  .invoice .inv-client { flex-direction: column; }
  .invoice table.inv-totals { min-width: 0; width: 100%; }
  .receipt { padding: 18px 14px; }
}
@media print {
  .invoice table.inv-lines, .invoice table.inv-lines tr, .invoice table.inv-lines td { display: revert; }
}
.invoice .inv-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: start; border-bottom: 2px solid #5b2a4a; padding-bottom: 10px; margin-bottom: 12px; }
.invoice .inv-logo { text-align: center; } .invoice .inv-logo img { max-height: 90px; max-width: 170px; }
.invoice .inv-title { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 12px; }
.invoice .inv-words { border: 1px dashed #999; border-radius: 6px; padding: 8px 10px; font-size: 13.5px; }
.logo-prev { min-height: 70px; display: flex; align-items: center; } .logo-prev img { max-height: 80px; max-width: 200px; }
@media (max-width: 640px) { .invoice .inv-head { grid-template-columns: 1fr; } .invoice .inv-head > div { text-align: left !important; } }

.invoice .inv-stamp { position: relative; min-height: 200px; text-align: center; }
.invoice .inv-stamp img { display: block; margin: 4px auto 0; height: 200px; max-width: 100%; object-fit: contain; }

.invoice .inv-scope { background: #f3eef2; border-inline-start: 4px solid #5b2a4a; padding: 6px 10px; margin-bottom: 12px; font-size: 14px; }
.invoice .inv-notva { border: 1px solid #c9a227; background: #fdf7e3; color: #5a4600; border-radius: 6px; padding: 8px 10px; font-size: 12.5px; margin: 10px 0; }

/* =====================================================================
   Thème « Rabah Sourcing » v2 — couleurs du logo (prune + bleu), cartes douces, menu sombre
   ===================================================================== */
:root {
  --bg: #f5f3f8; --card: #ffffff; --text: #1f1a2b; --muted: #6f6880; --line: #e8e3ef; --soft: #f3eff8;
  --brand: #6b2c66; --brand-2: #1f6fb8; --brand-ink: #ffffff; --brand-soft: #f1e6f0;
  --side-bg: linear-gradient(180deg, #3b1739 0%, #5a2556 55%, #2a3f7a 100%); --side-text: #efe6f1; --side-muted: #b9a7c0;
  --shadow: 0 1px 2px rgba(40, 20, 50, .05), 0 6px 18px rgba(40, 20, 50, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15121b; --card: #1e1a26; --text: #ece7f2; --muted: #a59cb3; --line: #2f2939; --soft: #262030;
          --brand: #d48fcd; --brand-2: #6fb0f0; --brand-ink: #1a1020; --brand-soft: #35233a;
          --side-bg: linear-gradient(180deg, #1c0f1f 0%, #2b1530 60%, #142140 100%);
          --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25); }
}
body { font-family: "Segoe UI", "Noto Sans Arabic", Tahoma, system-ui, Arial, sans-serif; }

/* menu latéral */
.side { background: var(--side-bg); border: 0; color: var(--side-text); box-shadow: 2px 0 18px rgba(30, 10, 40, .15); }
.side .brand b { color: #fff; font-size: 15px; letter-spacing: .2px; }
.side .brand .muted { color: var(--side-muted); }
.side .logo, .login .logo { background: linear-gradient(135deg, #8e3a86, #1f6fb8); color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.2); border-radius: 12px; }
.nav h3 { color: var(--side-muted); text-transform: uppercase; font-size: 10.5px; letter-spacing: .8px; margin-top: 18px; }
.nav a { color: var(--side-text); border-radius: 10px; padding: 9px 12px; transition: background .15s, transform .15s; }
.nav a:hover { background: rgba(255, 255, 255, .09); }
.nav a.active { background: rgba(255, 255, 255, .16); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #f0b3e8; }
[dir="rtl"] .nav a.active { box-shadow: inset -3px 0 0 #f0b3e8; }

/* barre du haut */
.main { padding: 18px 26px 40px; }
.top { background: transparent; }
.main > .top:first-child { background: var(--card); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
h1 { font-size: 22px; font-weight: 700; letter-spacing: .1px; }
h2 { font-size: 16px; font-weight: 700; color: var(--brand); }
.bell { background: var(--soft); border-radius: 10px; padding: 4px 9px; }

/* cartes et chiffres */
.card { border: 0; box-shadow: var(--shadow); border-radius: var(--radius); padding: 18px 20px; }
.stat { border: 0; box-shadow: var(--shadow); border-radius: var(--radius); position: relative; overflow: hidden; padding: 16px 18px; }
.stat::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: linear-gradient(180deg, var(--brand), var(--brand-2)); }
.stat .v { font-size: 22px; font-weight: 700; }
.grid { gap: 14px; }

/* tableaux */
.table-wrap { border: 0; box-shadow: var(--shadow); border-radius: var(--radius); }
th { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
td { border-bottom-color: var(--line); }
tr.click:hover td { background: var(--soft); }
tbody tr:last-child td { border-bottom: 0; }

/* champs et boutons */
input, select, textarea { border-radius: 10px; border-color: var(--line); background: var(--card); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
button, .btn { border-radius: 10px; background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 55%, var(--brand-2)));
  box-shadow: 0 3px 10px color-mix(in srgb, var(--brand) 28%, transparent); transition: transform .12s, box-shadow .12s, filter .12s; }
button:hover:not(:disabled), .btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
button.secondary, .btn.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
button.secondary:hover, .btn.secondary:hover { border-color: var(--brand); color: var(--brand); }
.badge { border-radius: 999px; padding: 2px 10px; font-weight: 600; }
.alert { border-radius: 10px; }
details.help, details.adv { border-radius: var(--radius); }
details.help summary, details.adv summary { color: var(--brand); }
.notif { border: 0; box-shadow: var(--shadow); border-radius: 12px; }
.notif.unread { background: var(--brand-soft); box-shadow: var(--shadow), inset 4px 0 0 var(--brand); border: 0; }
[dir="rtl"] .notif.unread { box-shadow: var(--shadow), inset -4px 0 0 var(--brand); }
.file { border-radius: 12px; border-color: var(--line); }
.file.empty-slot:hover { border-color: var(--brand); color: var(--brand); }

/* connexion */
.login-wrap { background: radial-gradient(1200px 600px at 85% -10%, #8e3a8655, transparent), radial-gradient(900px 500px at -10% 110%, #1f6fb855, transparent), var(--bg); }
.login { border: 0; box-shadow: 0 20px 50px rgba(50, 20, 60, .18); border-radius: 20px; padding: 32px 28px; }
.login h1 { color: var(--brand); }

/* téléphone */
@media (max-width: 860px) {
  .side { box-shadow: none; }
}
@media (max-width: 640px) {
  .table-wrap tr { border: 0; box-shadow: var(--shadow); border-radius: 12px; }
  .main { padding: 12px; }
}
/* impression : aucun effet de couleur sur les documents */
@media print { button, .btn { box-shadow: none; } }

/* cases vides des pièces jointes : plus discrètes */
.file.empty-slot { min-height: 56px; box-shadow: none; background: transparent; }
.files { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }

.kind-sel { padding: 4px 6px; font-size: 12px; }
.file .small { font-size: 12px; padding: 5px 8px; white-space: normal; }
.files { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.file.empty-slot { align-self: start; height: 56px; min-height: 0; }

.table-wrap.lines td { vertical-align: middle; } .table-wrap.lines input { min-width: 0; }
.table-wrap.lines td:first-child { width: 45%; }
@media (max-width: 640px) { .table-wrap.lines td { display: flex; } .table-wrap.lines td input { flex: 1; max-width: none !important; } }
/* impression : facture tenue sur une seule page A4 */
@media print {
  .invoice { font-size: 12px; }
  .invoice .inv-head { padding-bottom: 6px; margin-bottom: 8px; }
  .invoice .inv-title, .invoice .inv-scope, .invoice .inv-client { margin-bottom: 8px; }
  .invoice .inv-client { padding: 6px 10px; }
  .invoice table.inv-lines td, .invoice table.inv-lines th, .invoice table.inv-totals td { padding: 4px 6px; }
  .invoice table.inv-totals { margin-top: 6px; }
  .invoice .inv-notva, .invoice .inv-words { margin: 6px 0; padding: 5px 8px; font-size: 11px; }
  .invoice p { margin: 5px 0; }
  .invoice .sign { margin-top: 10px; }
  .invoice .inv-stamp img { height: 135px; }
}
/* cachet en taille réelle (≈ 6 cm) sous « Cachet et signature » */
.invoice .inv-stamp { min-height: 0; }
.invoice .inv-stamp img { display: block; margin: 6px auto 0; height: 230px; width: auto; max-width: 100%; object-fit: contain; }
@media print {
  .invoice, .receipt.invoice { overflow: visible; }
  .invoice .inv-stamp img { height: 230px; }
}
