/* Shared design tokens — light/dark, safe areas, sticky header */
:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #f0ede4;
  --ink: #14212b;
  --ink-2: #4b5a63;
  --ink-3: #7c8a92;
  --line: #e2ddd0;
  --brand: #0f3d4c;
  --brand-ink: #ffffff;
  --gold: #b88a35;
  --gold-soft: #f4e8cf;
  --ok: #1f7a4d;
  --ok-soft: #dcf1e5;
  --warn: #b26b00;
  --warn-soft: #fbecd2;
  --bad: #b3261e;
  --bad-soft: #f9dedc;
  --info: #2357a6;
  --info-soft: #dfe9f8;
  --focus: #2b6cb0;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 33, 43, .06), 0 6px 20px rgba(20, 33, 43, .06);
  --font-en: 'Noto Sans', 'Noto Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-ar: 'Noto Sans Arabic', 'Noto Sans', 'Segoe UI', Tahoma, system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1821; --surface: #15232d; --surface-2: #1b2c37; --ink: #f3f0e8; --ink-2: #b9c6cc; --ink-3: #8a9aa2;
    --line: #2a3d49; --brand: #e6b96a; --brand-ink: #0d1821; --gold: #e6b96a; --gold-soft: #3a3020;
    --ok: #5fd39a; --ok-soft: #173a2a; --warn: #f2b45a; --warn-soft: #3b2c15; --bad: #ff8a80; --bad-soft: #3d1c1a;
    --info: #8ab4f8; --info-soft: #1b2b45; --focus: #8ab4f8; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1821; --surface: #15232d; --surface-2: #1b2c37; --ink: #f3f0e8; --ink-2: #b9c6cc; --ink-3: #8a9aa2;
  --line: #2a3d49; --brand: #e6b96a; --brand-ink: #0d1821; --gold: #e6b96a; --gold-soft: #3a3020;
  --ok: #5fd39a; --ok-soft: #173a2a; --warn: #f2b45a; --warn-soft: #3b2c15; --bad: #ff8a80; --bad-soft: #3d1c1a;
  --info: #8ab4f8; --info-soft: #1b2b45; --focus: #8ab4f8; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--font-en);
  padding-left: var(--safe-l); padding-right: var(--safe-r);
  -webkit-font-smoothing: antialiased;
}
html[lang="ar"] body, [dir="rtl"] body { font-family: var(--font-ar); }
.ar { font-family: var(--font-ar); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
a { color: var(--info); }
[hidden] { display: none !important; }
svg.ic { width: 1.1em; height: 1.1em; vertical-align: -.2em; flex: none; stroke-width: 2.2; }
.big-ic { display: grid; place-items: center; }
.big-ic svg.ic { width: 52px; height: 52px; }
.big-ic.ok { color: var(--ok); } .big-ic.warn { color: var(--warn); }

/* Sticky header honoring the notch */
.topbar {
  position: sticky; top: 0; z-index: 50;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.bottombar {
  position: sticky; bottom: 0; z-index: 40;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}

.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(--ink); font-weight: 600; cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.gold { background: var(--gold); color: #1a1406; border-color: var(--gold); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

.toast-wrap { position: fixed; z-index: 200; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); display: grid; gap: 8px; width: min(92vw, 460px); pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; animation: toastIn .2s ease-out; }
.toast.warn { background: var(--warn); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.modal-back { position: fixed; inset: 0; z-index: 150; background: rgba(8, 14, 20, .55); display: grid; place-items: center; padding: 16px; }
.modal { width: min(560px, 100%); max-height: 88vh; overflow: auto; padding: 22px; }
.modal h3 { margin: 0 0 8px; }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition: none !important; } }
