/* Selfa — système visuel « Aurora », commun au portail, au back-office et au simulateur USSD.
   Les couleurs sont des jetons : le thème sombre redéfinit les mêmes noms. */

@font-face {
  font-family: "Inter";
  src: url("fonts/inter-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/inter-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face { font-family: "Cairo"; src: url("fonts/cairo-400.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Cairo"; src: url("fonts/cairo-700.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  color-scheme: light;
  --brand: #5B4BF5;
  --brand-strong: #4436D9;
  --brand-soft: rgba(91, 75, 245, 0.10);
  --brand-ink: #4436D9;
  --accent: #0EA5A0;
  --accent-soft: rgba(14, 165, 160, 0.12);
  --gold: #F5A524;
  --gold-soft: rgba(245, 165, 36, 0.16);
  --gold-ink: #8A5A00;
  --bg: #F6F7FB;
  --surface: #FFFFFF;
  --surface-2: #F1F2F9;
  --surface-3: #E9EBF5;
  --border: #E4E6F0;
  --border-strong: #D3D6E6;
  --text: #0D1023;
  --text-2: #474B65;
  --text-3: #7B7F98;
  --grid: #EDEEF5;
  --axis: #D3D6E6;
  --aurora: linear-gradient(135deg, #2E25C9 0%, #5B4BF5 45%, #0EA5A0 125%);
  --aurora-soft: linear-gradient(135deg, rgba(46, 37, 201, 0.10) 0%, rgba(91, 75, 245, 0.08) 45%, rgba(14, 165, 160, 0.10) 125%);
  /* Statuts : sémantiques, jamais réutilisés comme couleur de série. */
  --good: #0CA30C; --good-soft: rgba(12, 163, 12, 0.10); --good-ink: #067A06;
  --warning: #FAB219; --warning-soft: rgba(250, 178, 25, 0.16); --warning-ink: #8A5A00;
  --serious: #EC835A; --serious-soft: rgba(236, 131, 90, 0.14); --serious-ink: #A8441C;
  --critical: #D03B3B; --critical-soft: rgba(208, 59, 59, 0.10); --critical-ink: #B42828;
  --info: #2F7FE0; --info-soft: rgba(47, 127, 224, 0.10); --info-ink: #1F63B8;
  /* Séries catégorielles, ordre validé (validate_palette.js, mode clair, surface #FFFFFF). */
  --s1: #5B4BF5; --s2: #0E9F9A; --s3: #DB8A00; --s4: #D63E70;
  --neutral-mark: #C3C6D8;
  /* Classes de risque, du meilleur au moins bon. */
  --band-A: #047857; --band-B: #22A35A; --band-C: #D49B00; --band-D: #E5672F; --band-E: #D33A3A;
  --shadow-sm: 0 1px 2px rgba(13, 16, 35, 0.05);
  --shadow: 0 1px 2px rgba(13, 16, 35, 0.04), 0 10px 30px -12px rgba(13, 16, 35, 0.12);
  --shadow-lg: 0 24px 60px -20px rgba(36, 28, 140, 0.35);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-ar: "Cairo", "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --brand: #8D80FF; --brand-strong: #B3AAFF; --brand-soft: rgba(141, 128, 255, 0.14); --brand-ink: #B3AAFF;
    --accent: #2DD4BF; --accent-soft: rgba(45, 212, 191, 0.12);
    --gold: #FBBF24; --gold-soft: rgba(251, 191, 36, 0.14); --gold-ink: #FBBF24;
    --bg: #090B16; --surface: #111427; --surface-2: #181C35; --surface-3: #20254A;
    --border: #252A47; --border-strong: #323862;
    --text: #EDEFFF; --text-2: #B5B9D6; --text-3: #8288A8;
    --grid: #1D2140; --axis: #323862;
    --aurora-soft: linear-gradient(135deg, rgba(91, 75, 245, 0.22) 0%, rgba(91, 75, 245, 0.10) 45%, rgba(14, 165, 160, 0.16) 125%);
    --good-soft: rgba(12, 163, 12, 0.16); --good-ink: #4ADE80;
    --warning-soft: rgba(250, 178, 25, 0.16); --warning-ink: #FBBF24;
    --serious-soft: rgba(236, 131, 90, 0.16); --serious-ink: #F4A07F;
    --critical-soft: rgba(208, 59, 59, 0.18); --critical-ink: #F28B8B;
    --info-soft: rgba(47, 127, 224, 0.18); --info-ink: #8DBBF5;
    --s1: #7C6EF7; --s2: #16A394; --s3: #C98500; --s4: #D6528A;
    --neutral-mark: #3A4070;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 32px -14px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #8D80FF; --brand-strong: #B3AAFF; --brand-soft: rgba(141, 128, 255, 0.14); --brand-ink: #B3AAFF;
  --accent: #2DD4BF; --accent-soft: rgba(45, 212, 191, 0.12);
  --gold: #FBBF24; --gold-soft: rgba(251, 191, 36, 0.14); --gold-ink: #FBBF24;
  --bg: #090B16; --surface: #111427; --surface-2: #181C35; --surface-3: #20254A;
  --border: #252A47; --border-strong: #323862;
  --text: #EDEFFF; --text-2: #B5B9D6; --text-3: #8288A8;
  --grid: #1D2140; --axis: #323862;
  --aurora-soft: linear-gradient(135deg, rgba(91, 75, 245, 0.22) 0%, rgba(91, 75, 245, 0.10) 45%, rgba(14, 165, 160, 0.16) 125%);
  --good-soft: rgba(12, 163, 12, 0.16); --good-ink: #4ADE80;
  --warning-soft: rgba(250, 178, 25, 0.16); --warning-ink: #FBBF24;
  --serious-soft: rgba(236, 131, 90, 0.16); --serious-ink: #F4A07F;
  --critical-soft: rgba(208, 59, 59, 0.18); --critical-ink: #F28B8B;
  --info-soft: rgba(47, 127, 224, 0.18); --info-ink: #8DBBF5;
  --s1: #7C6EF7; --s2: #16A394; --s3: #C98500; --s4: #D6528A;
  --neutral-mark: #3A4070;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 32px -14px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-feature-settings: "cv11", "ss01";
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[lang="ar"], .ar { font-family: var(--font-ar); }
a { color: var(--brand-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; }
button { font: inherit; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.tnum { font-variant-numeric: tabular-nums; }
::selection { background: var(--brand-soft); }

/* --- Marque --- */
.mark { display: inline-flex; align-items: center; gap: 11px; }
.mark-badge {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  background: var(--aurora); position: relative; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px; font-family: var(--font-ar);
  box-shadow: 0 8px 20px -6px rgba(46, 37, 201, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.mark-badge::after { content: ""; position: absolute; inset: 0; background: radial-gradient(60% 60% at 25% 15%, rgba(255, 255, 255, 0.35), transparent 60%); }
.mark-name { font-weight: 800; font-size: 18px; letter-spacing: -0.03em; }
.mark-name .ar { font-weight: 700; color: var(--accent); margin-inline-start: 7px; }

/* --- Pastilles, statuts, classes --- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 11px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border); white-space: nowrap;
}
.pill svg { width: 14px; height: 14px; }
.pill.sim { background: var(--gold-soft); color: var(--gold-ink); border-color: transparent; }
.pill.brand { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.ghost { background: transparent; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.chip.ACTIVE { color: var(--info-ink); background: var(--info-soft); }
.chip.REPAID, .chip.APPROVED, .chip.GRANTED, .chip.OK { color: var(--good-ink); background: var(--good-soft); }
.chip.LATE { color: var(--warning-ink); background: var(--warning-soft); }
.chip.DEFAULTED, .chip.DECLINED, .chip.REVOKED, .chip.KO { color: var(--critical-ink); background: var(--critical-soft); }
.chip.NEUTRAL { color: var(--text-2); background: var(--surface-2); }
.band { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; font-weight: 800; font-size: 13px; color: #fff; flex: none; }
.band.A { background: var(--band-A); } .band.B { background: var(--band-B); } .band.C { background: var(--band-C); color: #1D1600; }
.band.D { background: var(--band-D); } .band.E { background: var(--band-E); }
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.tag i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.tag.INTEREST i { background: var(--s1); } .tag.MOURABAHA i { background: var(--s2); }

/* --- Cartes, grilles --- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card-title { font-size: 13px; font-weight: 650; color: var(--text); margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; letter-spacing: -0.005em; }
.card-title .hint { font-size: 12px; font-weight: 500; color: var(--text-3); }
.eyebrow { font-size: 11.5px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.08em; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.muted { color: var(--text-3); }
.soft { color: var(--text-2); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap-row { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 12px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; border: none; }

/* --- Boutons, champs --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:focus-visible, .seg button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn.primary { background: var(--brand); border-color: transparent; color: #fff; box-shadow: 0 8px 20px -8px rgba(91, 75, 245, 0.7); }
:root[data-theme="dark"] .btn.primary { color: #0D1023; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .btn.primary { color: #0D1023; } }
.btn.primary:hover { background: var(--brand-strong); }
.btn.aurora { background: var(--aurora); border-color: transparent; color: #fff; box-shadow: 0 10px 24px -10px rgba(46, 37, 201, 0.8); }
.btn.aurora:hover { filter: brightness(1.06); }
.btn.danger { color: var(--critical-ink); border-color: var(--critical-soft); }
.btn.danger:hover { background: var(--critical-soft); }
.btn.sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.btn.icon { width: 38px; padding: 0; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
input, select {
  height: 40px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
label.field { display: grid; gap: 6px; align-content: start; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
label.field .hint { font-weight: 400; color: var(--text-3); font-size: 12px; }
.input-affix { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); overflow: hidden; transition: border-color .15s ease, box-shadow .15s ease; }
.input-affix:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.input-affix input { border: none; box-shadow: none !important; flex: 1; min-width: 0; border-radius: 0; font-variant-numeric: tabular-nums; }
.input-affix span { display: grid; place-items: center; padding: 0 12px; color: var(--text-3); font-weight: 600; font-size: 12.5px; background: var(--surface-2); border-inline-start: 1px solid var(--border); }

/* Contrôle segmenté */
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); gap: 2px; }
.seg button { height: 30px; padding: 0 13px; border: none; border-radius: 9px; background: transparent; color: var(--text-2); font-weight: 600; font-size: 12.5px; cursor: pointer; transition: background .15s ease, color .15s ease; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

/* --- Tableaux --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th { text-align: start; font-size: 11.5px; font-weight: 650; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); position: sticky; top: 0; z-index: 1; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s ease; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* --- Barre de progression --- */
.meter { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--brand); }
.meter.good > i { background: var(--good); } .meter.warn > i { background: var(--warning); } .meter.bad > i { background: var(--critical); }

/* --- Infobulle, toast, voile, tiroir, modale --- */
#tooltip {
  position: fixed; pointer-events: none; z-index: 1000; padding: 9px 11px; border-radius: 10px; font-size: 12px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow);
  opacity: 0; transition: opacity .1s ease; max-width: 280px;
}
#tooltip.on { opacity: 1; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--surface); padding: 12px 18px; border-radius: 14px; font-weight: 600; opacity: 0; transition: all .25s ease; z-index: 90; box-shadow: var(--shadow-lg); max-width: calc(100vw - 32px); pointer-events: none; }
.toast.on { opacity: 1; transform: translateX(-50%); }
.scrim { position: fixed; inset: 0; background: rgba(7, 8, 20, 0.5); backdrop-filter: blur(3px); z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.scrim.on { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(900px, 100vw); background: var(--bg); z-index: 60; transform: translateX(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .28s; visibility: hidden; overflow-y: auto; box-shadow: -24px 0 60px rgba(7, 8, 20, 0.25); border-inline-start: 1px solid var(--border); }
.drawer.on { transform: none; visibility: visible; transition: transform .28s cubic-bezier(.2, .8, .2, 1); }
.drawer header { position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); padding: 18px 26px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 5; }
.drawer header h3 { font-size: 18px; }
.drawer .body { padding: 22px 26px 48px; }
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 70; pointer-events: none; }
.modal .card { width: min(440px, calc(100vw - 32px)); pointer-events: none; visibility: hidden; transform: translateY(10px) scale(0.98); opacity: 0; transition: transform .22s ease, opacity .22s ease, visibility 0s linear .22s; }
.modal.on .card { pointer-events: auto; visibility: visible; transform: none; opacity: 1; transition: transform .22s ease, opacity .22s ease; }

/* --- Raisons d'une décision --- */
.reason { display: flex; gap: 12px; padding: 11px 13px; border-radius: 12px; margin-top: 8px; font-size: 13px; border: 1px solid transparent; }
.reason .ic { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; flex: none; font-size: 12px; font-weight: 800; }
.reason.NEGATIVE { background: var(--critical-soft); } .reason.NEGATIVE .ic { background: var(--critical); color: #fff; }
.reason.POSITIVE { background: var(--good-soft); } .reason.POSITIVE .ic { background: var(--good); color: #fff; }
.reason.LIMIT { background: var(--brand-soft); } .reason.LIMIT .ic { background: var(--brand); color: #fff; }
.reason.POLICY { background: var(--serious-soft); } .reason.POLICY .ic { background: var(--serious); color: #fff; }
.reason.EDUCATION { background: var(--gold-soft); } .reason.EDUCATION .ic { background: var(--gold); color: #1D1600; }
.reason > div { flex: 1; min-width: 0; }
.reason .ar { direction: rtl; display: block; color: var(--text-2); margin-top: 4px; }

/* --- Bascule de thème --- */
.theme-toggle .sun { display: none; } .theme-toggle .moon { display: block; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; } :root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .theme-toggle .sun { display: block; }
  :root:where(:not([data-theme="light"])) .theme-toggle .moon { display: none; }
}

/* --- QR (portail) --- */
.access { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.qr { padding: 10px; background: #fff; border-radius: 14px; border: 1px solid var(--border); line-height: 0; }
.qr img, .qr canvas { display: block; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
