@font-face {
  font-family: 'Jakarta';
  src: url('/fonts/jakarta-latin.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Jakarta';
  src: url('/fonts/jakarta-latin-ext.woff2') format('woff2');
  font-weight: 200 800;
  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;
}

:root {
  --font: 'Jakarta', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --brand-50: #ecf8f3;
  --brand-100: #d0eee2;
  --brand-200: #a3dcc6;
  --brand-400: #3fae86;
  --brand-500: #179068;
  --brand-600: #0f7555;
  --brand-700: #0b5a41;
  --brand-800: #083f2e;
  --brand-900: #052a1f;
  --gold-300: #f3d77a;
  --gold-400: #e2b94a;
  --gold-500: #c9a227;
  --gold-600: #a67f13;

  --bg: #f6f4ee;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f2f0e8;
  --surface-3: #e9e6dc;
  --border: #e3dfd3;
  --border-strong: #cfc9b8;
  --text: #17231e;
  --text-2: #4b5a53;
  --text-3: #7c877f;
  --primary: var(--brand-600);
  --primary-strong: var(--brand-700);
  --primary-soft: var(--brand-50);
  --on-primary: #ffffff;
  --accent: var(--gold-500);
  --danger: #c2410c;
  --danger-soft: #fdeee6;
  --warning: #b7791f;
  --warning-soft: #fdf3dc;
  --success: #15803d;
  --success-soft: #e5f6ea;
  --info: #1d6fb8;
  --info-soft: #e6f0fa;
  --focus: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent);
  --shadow-sm: 0 1px 2px rgba(23, 35, 30, .06), 0 1px 1px rgba(23, 35, 30, .04);
  --shadow: 0 6px 20px -8px rgba(23, 35, 30, .18), 0 2px 6px rgba(23, 35, 30, .06);
  --shadow-lg: 0 24px 60px -20px rgba(5, 42, 31, .35);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --pattern-color: rgba(15, 117, 85, .07);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1310;
    --bg-elev: #111b17;
    --surface: #131f1a;
    --surface-2: #192822;
    --surface-3: #21332b;
    --border: #243630;
    --border-strong: #345046;
    --text: #e8efe9;
    --text-2: #a9b8b0;
    --text-3: #7a8a82;
    --primary: var(--brand-400);
    --primary-strong: #5cc29b;
    --primary-soft: rgba(63, 174, 134, .12);
    --on-primary: #04150f;
    --danger: #f08a5d;
    --danger-soft: rgba(240, 138, 93, .12);
    --warning: #e8b34c;
    --warning-soft: rgba(232, 179, 76, .12);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, .12);
    --info: #6cb4f0;
    --info-soft: rgba(108, 180, 240, .12);
    --shadow: 0 8px 24px -10px rgba(0, 0, 0, .6);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
    --pattern-color: rgba(63, 174, 134, .06);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1310;
  --bg-elev: #111b17;
  --surface: #131f1a;
  --surface-2: #192822;
  --surface-3: #21332b;
  --border: #243630;
  --border-strong: #345046;
  --text: #e8efe9;
  --text-2: #a9b8b0;
  --text-3: #7a8a82;
  --primary: var(--brand-400);
  --primary-strong: #5cc29b;
  --primary-soft: rgba(63, 174, 134, .12);
  --on-primary: #04150f;
  --danger: #f08a5d;
  --danger-soft: rgba(240, 138, 93, .12);
  --warning: #e8b34c;
  --warning-soft: rgba(232, 179, 76, .12);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, .12);
  --info: #6cb4f0;
  --info-soft: rgba(108, 180, 240, .12);
  --shadow: 0 8px 24px -10px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
  --pattern-color: rgba(63, 174, 134, .06);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ar { font-family: 'Noto Naskh Arabic', 'Amiri', 'Geeza Pro', 'Traditional Arabic', serif; direction: rtl; }
.muted { color: var(--text-2); }
.tiny { font-size: 12px; color: var(--text-3); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* Motif géométrique (étoile à huit branches) */
.pattern {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.2'%3E%3Crect x='22' y='22' width='36' height='36'/%3E%3Crect x='22' y='22' width='36' height='36' transform='rotate(45 40 40)'/%3E%3Ccircle cx='40' cy='40' r='9'/%3E%3Cpath d='M0 0l22 22M80 0L58 22M0 80l22-22M80 80L58 58'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 80px 80px;
}

/* ----- Boutons ----- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid var(--btn-border); border-radius: 11px;
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-border: transparent; box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--primary) 80%, transparent); }
.btn-primary:hover { --btn-bg: var(--primary-strong); border-color: transparent; }
.btn-gold { --btn-bg: linear-gradient(135deg, var(--gold-300), var(--gold-500)); --btn-fg: #3b2c00; --btn-border: transparent; background: linear-gradient(135deg, var(--gold-300), var(--gold-500)); }
.btn-ghost { --btn-bg: transparent; --btn-border: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-border: transparent; }
.btn-danger-ghost { --btn-bg: transparent; --btn-fg: var(--danger); --btn-border: transparent; }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: transparent; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-icon { width: 40px; padding: 0; }
.btn-sm.btn-icon { width: 34px; }
.btn-block { width: 100%; }

/* ----- Champs ----- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .req { color: var(--danger); margin-left: 2px; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 11px;
  transition: border-color .15s, box-shadow .15s;
  font-size: 15px;
}
.textarea { min-height: 88px; resize: vertical; }
.select {
  appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%237c877f'%3E%3Cpath d='M5.3 7.3a1 1 0 011.4 0L10 10.6l3.3-3.3a1 1 0 111.4 1.4l-4 4a1 1 0 01-1.4 0l-4-4a1 1 0 010-1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
}
.select:disabled { opacity: .6; cursor: not-allowed; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); }
.field-error { font-size: 12.5px; color: var(--danger); font-weight: 500; }
.field-hint { font-size: 12.5px; color: var(--text-3); }
.input-group { display: flex; align-items: stretch; }
.input-group .addon {
  display: flex; align-items: center; padding: 0 12px; font-weight: 600; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border); border-right: 0; border-radius: 11px 0 0 11px;
}
.input-group .input { border-radius: 0 11px 11px 0; }

.check { display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }

.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; border: 1px solid var(--border); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--text-2); transition: .15s; }
.segmented input:checked + span { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 40px; height: 24px; border-radius: 99px; background: var(--surface-3); position: relative; transition: .2s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: .2s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

/* ----- Divers ----- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.tone-green { background: var(--success-soft); color: var(--success); }
.tone-amber { background: var(--warning-soft); color: var(--warning); }
.tone-red { background: var(--danger-soft); color: var(--danger); }
.tone-gray { background: var(--surface-2); color: var(--text-2); }
.tone-blue { background: var(--info-soft); color: var(--info); }
.tone-brand { background: var(--primary-soft); color: var(--primary); }

.spinner { width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toasts */
.toasts { position: fixed; z-index: 1000; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500; animation: toast-in .25s ease-out; }
.toast.ok { background: var(--brand-700); color: #fff; }
.toast.err { background: #9a330b; color: #fff; }
.toast svg { width: 20px; height: 20px; flex: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

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