/* ───────────── Tokens ───────────── */
:root {
  --brand: #C8873A;
  --brand-2: #2F5D50;
  --font-body: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
  --font-sign: 'Lalezar', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --space: 16px;
  color-scheme: dark;
  --bg: #1E1915;
  --bg-2: #241E19;
  --surface: #2A231D;
  --surface-2: #342B24;
  --line: #43382F;
  --text: #F3EBDD;
  --muted: #B5A895;
  --faint: #8B7F6E;
  --on-brand: #1E1915;
  --danger: #E5806B;
  --ok: #7FC4A4;
  --warn: #E7B85C;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, .6);
  --focus: 0 0 0 3px color-mix(in srgb, var(--brand) 55%, transparent);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #EEF0EB;
  --bg-2: #E6E9E2;
  --surface: #FFFFFF;
  --surface-2: #F4F6F2;
  --line: #D6DBD2;
  --text: #1F2420;
  --muted: #5D665E;
  --faint: #879088;
  --on-brand: #FFFFFF;
  --danger: #B5402B;
  --ok: #2E7D5B;
  --warn: #9A6A12;
  --shadow: 0 18px 40px -22px rgba(30, 40, 30, .35);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
:lang(en) body, body:lang(en) { line-height: 1.5; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0; font-weight: 600; }
p { margin: 0; }
.ic { flex-shrink: 0; }
[dir="rtl"] .ic-flip { transform: scaleX(-1); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ───────────── Buttons ───────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--faint); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { border-color: var(--brand); filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn-block { width: 100%; }
.btn .spinner { width: 16px; height: 16px; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── Forms ───────────── */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 14px; font-weight: 600; color: var(--text); }
.field .hint { font-size: 13px; color: var(--muted); }
.field .err { font-size: 13px; color: var(--danger); }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 9px 13px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input[type="number"] { direction: ltr; text-align: end; }
[dir="rtl"] .input[type="number"] { text-align: start; }
.input-ltr { direction: ltr; }
[dir="rtl"] .input-ltr { text-align: right; }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); flex-shrink: 0; margin: 0; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 42px; height: 24px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; flex-shrink: 0; }
.switch .track::after { content: ''; position: absolute; inset-block-start: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); }
.switch input:checked + .track { background: var(--brand); }
[dir="ltr"] .switch input:checked + .track::after { transform: translateX(18px); }
[dir="rtl"] .switch input:checked + .track::after { transform: translateX(-18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

/* ───────────── Toasts ───────────── */
.toasts { position: fixed; inset-inline: 0; bottom: 18px; display: grid; justify-items: center; gap: 8px; z-index: 200; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: center; max-width: 480px;
  padding: 11px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  box-shadow: var(--shadow); font-size: 15px; animation: toast-in .25s var(--ease);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.ok .ic { color: var(--ok); }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* ───────────── States ───────────── */
.state { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 48px 20px; color: var(--muted); }
.state .ic { color: var(--faint); }
.state h3 { color: var(--text); font-size: 18px; }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge.brand { background: color-mix(in srgb, var(--brand) 20%, transparent); color: var(--brand); }

/* ───────────── Dialog / bottom sheet ───────────── */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(10, 8, 6, .55); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--surface); color: var(--text); border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow); animation: sheet-up .32s var(--ease); overflow: hidden;
}
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; flex: 1; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 16px; flex: 1; }
.sheet-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
@media (min-width: 700px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: var(--r-lg); max-height: 88dvh; animation: pop .22s var(--ease); }
  .sheet.wide { max-width: 860px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } }
@keyframes pop { from { transform: scale(.97); opacity: 0; } }

.center-page { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.notfound { text-align: center; display: grid; gap: 14px; justify-items: center; }
.notfound h1 { font-family: var(--font-sign); font-size: 72px; color: var(--brand); font-weight: 400; }

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

/* Shared small pieces */
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.form-grid { display: grid; gap: 16px; }
.form-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); border-radius: var(--r-sm); padding: 10px 12px; font-size: 14.5px; display: flex; gap: 8px; align-items: flex-start; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--bg-2); border-radius: 99px; border: 1px solid var(--line); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: grid; place-items: center; min-height: 38px; padding: 0 10px; border-radius: 99px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); text-align: center; line-height: 1.2; }
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px -3px rgba(0,0,0,.35); }
.seg input:focus-visible + span { box-shadow: var(--focus); }
