/* ==========================================================================
   DYON — The Commitments Ledger
   Design system: calm by default, gradient accents, dark/light, full RTL.
   Red-line aligned: no red for "I owe", amber only for "needs response",
   green for fulfilled/released.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light dark;

  /* Brand gradient ramp */
  --brand-1: #6366f1;
  --brand-2: #8b5cf6;
  --brand-3: #14b8a6;
  --brand-4: #0ea5e9;
  --grad-brand: linear-gradient(135deg, var(--brand-1) 0%, var(--brand-2) 48%, var(--brand-3) 100%);
  --grad-soft: linear-gradient(135deg, rgba(99,102,241,.16), rgba(20,184,166,.14));
  --grad-warm: linear-gradient(135deg, #f59e0b, #f97316);
  --grad-green: linear-gradient(135deg, #10b981, #14b8a6);

  /* Semantic (never red for debt) */
  --owe: #6366f1;          /* I owe — indigo, calm */
  --owed: #0ea5e9;         /* Owed to me — sky */
  --needs: #d97706;        /* amber: needs response only */
  --good: #059669;         /* fulfilled / released */
  --muted-dispute: #7c3aed;/* disputes: violet, not red */

  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 26px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 20px rgba(15, 23, 42, .06);
  --shadow-2: 0 10px 40px rgba(15, 23, 42, .12);
  --ring: 0 0 0 3px rgba(99, 102, 241, .35);

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px;

  --font-sans: "Inter", "Noto Sans Arabic", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-ar: "Noto Kufi Arabic", "Noto Sans Arabic", "Inter", ui-sans-serif, system-ui, sans-serif;

  --header-h: 64px;
  --rail-w: 248px;
  --maxw: 1400px;
}

/* Light theme */
:root, [data-theme="light"] {
  --bg: #f6f7fb;
  --bg-deep: #eef0f7;
  --surface: #ffffff;
  --surface-2: #fbfbfe;
  --surface-3: #f2f3f9;
  --border: #e4e6f0;
  --border-strong: #cfd3e4;
  --text: #121629;
  --text-2: #4b5068;
  --text-3: #767c96;
  --glass: rgba(255, 255, 255, .72);
  --mesh-1: rgba(99, 102, 241, .20);
  --mesh-2: rgba(20, 184, 166, .18);
  --mesh-3: rgba(139, 92, 246, .14);
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0b1020;
  --bg-deep: #070b17;
  --surface: #141a2e;
  --surface-2: #19203a;
  --surface-3: #212a47;
  --border: #27304f;
  --border-strong: #38446b;
  --text: #eef1fa;
  --text-2: #b4bcd6;
  --text-3: #8690b0;
  --glass: rgba(20, 26, 46, .72);
  --mesh-1: rgba(99, 102, 241, .28);
  --mesh-2: rgba(20, 184, 166, .22);
  --mesh-3: rgba(139, 92, 246, .22);
  --owe: #8b90ff;
  --owed: #38bdf8;
  --needs: #f6b045;
  --good: #34d399;
  --muted-dispute: #a78bfa;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-2: 0 18px 50px rgba(0,0,0,.5);
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s ease, color .35s ease;
}
body[dir="rtl"], [dir="rtl"] { font-family: var(--font-ar); }
[dir="rtl"] { line-height: 1.75; }

/* Ambient gradient mesh */
body::before {
  content: ""; position: fixed; inset: -20% -10% auto -10%; height: 70vh; z-index: -1;
  background:
    radial-gradient(42vw 42vw at 12% 0%, var(--mesh-1), transparent 62%),
    radial-gradient(38vw 38vw at 88% 8%, var(--mesh-2), transparent 60%),
    radial-gradient(34vw 34vw at 50% 30%, var(--mesh-3), transparent 65%);
  filter: blur(8px); pointer-events: none;
  transition: opacity .4s ease;
}
body.calm::before { opacity: .35; }

h1, h2, h3, h4 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: clamp(1.4rem, 2.4vw, 1.9rem); }
h2 { font-size: clamp(1.15rem, 1.8vw, 1.4rem); }
h3 { font-size: 1.02rem; }
p { margin: 0 0 var(--space-3); color: var(--text-2); }
a { color: var(--brand-1); text-decoration: none; }
a:hover { text-decoration: underline; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 { letter-spacing: 0; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-xs); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; inset-inline-start: 8px; top: -60px; z-index: 300;
  background: var(--surface); padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); transition: top .2s;
}
.skip-link:focus { top: 8px; }

/* ---------- 3. Layout ---------- */
.app-shell { min-height: 100%; }

.app-header {
  position: sticky; top: 0; z-index: 60;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-4);
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: .02em; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--grad-brand);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .95rem;
  box-shadow: 0 4px 14px rgba(99,102,241,.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b { font-size: 1.02rem; }
.brand-text span { font-size: .66rem; color: var(--text-3); font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.greeting { font-size: .9rem; color: var(--text-2); margin-inline-start: var(--space-3); }
.header-spacer { flex: 1; }
.header-tools { display: flex; align-items: center; gap: 6px; }

.app-body { display: flex; max-width: var(--maxw); margin: 0 auto; gap: var(--space-5); padding: var(--space-5) var(--space-4) 120px; }
.side-rail {
  width: var(--rail-w); flex: 0 0 var(--rail-w); position: sticky; top: calc(var(--header-h) + var(--space-5));
  align-self: flex-start; max-height: calc(100vh - var(--header-h) - 48px); overflow-y: auto;
}
.rail-group { margin-bottom: var(--space-5); }
.rail-group h4 {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-3);
  margin: 0 0 var(--space-2); padding-inline-start: 12px; font-weight: 700;
}
.rail-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 550; font-size: .92rem; min-height: 44px;
  border: 1px solid transparent; transition: background .18s, color .18s, transform .18s;
}
.rail-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.rail-link.active { background: var(--grad-soft); color: var(--text); border-color: var(--border); }
.rail-link.active .ri { color: var(--brand-1); }
.rail-link .ri { width: 20px; text-align: center; color: var(--text-3); font-size: 1rem; }
.rail-badge {
  margin-inline-start: auto; background: var(--needs); color: #fff; font-size: .68rem; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 999px; display: grid; place-items: center; padding: 0 6px;
}
.main-area { flex: 1; min-width: 0; }

/* ---------- 4. Cards & grid ---------- */
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(12, 1fr); }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; } .col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-4); box-shadow: var(--shadow-1); position: relative;
  display: flex; flex-direction: column;
  transition: box-shadow .25s ease, border-color .25s ease, transform .25s ease;
}
/* Equal-height cards within a grid row, so edges align */
.grid > .card { align-self: stretch; }
.card > .grow { flex: 1 1 auto; }
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }
/* A hairline gradient top edge gives every card the brand feel without noise */
.card::after {
  content: ""; position: absolute; inset-inline: 0; top: 0; height: 2px;
  background: var(--grad-brand); opacity: 0; transition: opacity .25s;
  border-radius: var(--radius) var(--radius) 0 0;
}
.card:hover::after { opacity: .5; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: flex-start; gap: var(--space-3); margin-bottom: var(--space-3); }
.card-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
/* Spec traceability IDs: present for auditability, de-emphasised until hover */
.card-head .wid {
  font-size: .55rem; font-weight: 700; color: var(--text-3); letter-spacing: .08em;
  padding: 1px 5px; border-radius: 5px; border: 1px solid var(--border);
  opacity: .3; transition: opacity .2s; align-self: center; flex: none;
}
.card:hover .card-head .wid { opacity: .85; }
body.hide-ids .card-head .wid { display: none; }
.card-head .spacer { flex: 1; }
.card-sub { font-size: .82rem; color: var(--text-3); margin: -6px 0 var(--space-3); }
.card-accent { padding-inline-start: calc(var(--space-4) + 4px); }
.card-accent::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px;
  background: var(--grad-brand); z-index: 1;
}
.card-hero {
  background: var(--grad-brand); color: #fff; border: none;
  box-shadow: 0 14px 40px rgba(99,102,241,.32);
}
.card-hero::after { display: none; }
/* Soft light bloom so the hero gradient reads as depth, not a flat fill */
.card-hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(60% 120% at 85% -10%, rgba(255,255,255,.3), transparent 60%);
}
.card-hero > * { position: relative; }
.card-hero h3, .card-hero p, .card-hero .card-sub { color: rgba(255,255,255,.92); }
.card-glass { background: var(--glass); backdrop-filter: blur(14px); }

.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row.tight { gap: var(--space-2); }
.between { justify-content: space-between; }

/* Net-position table: aligned numeric columns beat crammed inline labels */
.unit-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.unit-table th {
  text-align: end; font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3); padding: 0 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.unit-table th:first-child { text-align: start; }
.unit-table td { padding: 11px 8px; border-bottom: 1px solid var(--border); text-align: end; }
.unit-table td:first-child { text-align: start; }
.unit-table tr:last-child td { border-bottom: none; }
.unit-table tbody tr { cursor: pointer; transition: background .16s; }
.unit-table tbody tr:hover { background: var(--surface-3); }

/* ---------- 5. Buttons & controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  transition: transform .15s, box-shadow .18s, background .18s, border-color .18s;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-1); text-decoration: none; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--grad-brand); color: #fff; border-color: transparent; box-shadow: 0 6px 20px rgba(99,102,241,.35); }
.btn-primary:hover { box-shadow: 0 10px 28px rgba(99,102,241,.45); }
.btn-good { background: var(--grad-green); color: #fff; border-color: transparent; }
.btn-warn { background: var(--grad-warm); color: #fff; border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: .82rem; border-radius: 10px; }
.btn-lg { min-height: 50px; padding: 0 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 12px;
  display: inline-grid; place-items: center; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); cursor: pointer; font-size: .95rem;
  transition: background .18s, color .18s, transform .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); transform: translateY(-1px); }
.icon-btn.on { background: var(--grad-soft); color: var(--brand-1); border-color: var(--brand-1); }
.icon-btn .dot {
  position: absolute; transform: translate(14px, -12px); width: 9px; height: 9px;
  border-radius: 50%; background: var(--needs); border: 2px solid var(--surface);
}

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border); color: var(--text-2);
  font-size: .78rem; font-weight: 600; cursor: pointer; min-height: 30px;
  transition: all .16s;
}
.chip:hover { border-color: var(--border-strong); }
.chip.on { background: var(--grad-soft); border-color: var(--brand-1); color: var(--text); }
.chip.static { cursor: default; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .01em;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border);
}
.badge-owe { background: color-mix(in srgb, var(--owe) 14%, transparent); color: var(--owe); border-color: color-mix(in srgb, var(--owe) 32%, transparent); }
.badge-owed { background: color-mix(in srgb, var(--owed) 14%, transparent); color: var(--owed); border-color: color-mix(in srgb, var(--owed) 32%, transparent); }
.badge-needs { background: color-mix(in srgb, var(--needs) 16%, transparent); color: var(--needs); border-color: color-mix(in srgb, var(--needs) 34%, transparent); }
.badge-good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); border-color: color-mix(in srgb, var(--good) 32%, transparent); }
.badge-dispute { background: color-mix(in srgb, var(--muted-dispute) 15%, transparent); color: var(--muted-dispute); border-color: color-mix(in srgb, var(--muted-dispute) 32%, transparent); }

label, .label { display: block; font-size: .8rem; font-weight: 650; color: var(--text-2); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 10px 13px; min-height: 44px; transition: border-color .18s, box-shadow .18s;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-1); box-shadow: var(--ring); }
/* Validation states (§7.15: errors carried by text and icon, never colour alone) */
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--needs); background: color-mix(in srgb, var(--needs) 7%, var(--surface-2));
}
.err {
  display: flex; align-items: flex-start; gap: 6px; font-size: .76rem; font-weight: 600;
  color: var(--needs); margin-top: 6px;
}
.err:empty { display: none; }
.form-summary {
  border: 1px solid color-mix(in srgb, var(--needs) 40%, transparent);
  background: color-mix(in srgb, var(--needs) 10%, transparent);
  color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px; font-size: .84rem;
}
.form-summary:empty { display: none; }
.form-summary ul { margin: 6px 0 0; padding-inline-start: 18px; }
.form-summary button.jump {
  background: none; border: none; color: inherit; text-decoration: underline; cursor: pointer;
  font: inherit; padding: 0; text-align: start;
}
.req { color: var(--needs); font-weight: 700; }
.ok-hint { color: var(--good); font-size: .76rem; font-weight: 600; margin-top: 6px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: auto; accent-color: var(--brand-1); }
.field { margin-bottom: var(--space-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.hint { font-size: .76rem; color: var(--text-3); margin-top: 5px; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 46px; height: 26px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border-strong); position: relative; transition: background .22s, border-color .22s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-1); transition: transform .22s;
}
.switch input:checked + .track { background: var(--grad-brand); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(20px); }
[dir="rtl"] .switch input:checked + .track::after { transform: translateX(-20px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* Setting rows */
.setting {
  display: flex; align-items: center; gap: var(--space-4); padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: none; }
.setting .s-main { flex: 1; min-width: 0; }
.setting .s-main b { display: block; font-size: .92rem; font-weight: 650; }
.setting .s-main small { color: var(--text-3); font-size: .78rem; }
.setting select, .setting input[type="time"] { width: auto; min-width: 160px; }

/* Section band: groups widgets so the overview is scannable, not 18 equal cards */
.zone { grid-column: span 12; }
.zone-head {
  display: flex; align-items: center; gap: var(--space-3);
  margin: var(--space-2) 0 calc(var(--space-2) * -1); padding-inline: 2px;
}
.zone-head h2 {
  margin: 0; font-size: .74rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-3);
}
[dir="rtl"] .zone-head h2 { letter-spacing: 0; }
.zone-head .line { flex: 1; height: 1px; background: var(--border); }
.zone-toggle {
  background: none; border: none; color: var(--text-3); font: inherit; font-size: .76rem;
  font-weight: 650; cursor: pointer; padding: 6px 10px; border-radius: 8px; min-height: 32px;
  display: inline-flex; align-items: center; gap: 6px;
}
.zone-toggle:hover { background: var(--surface-3); color: var(--text); }

/* ---------- 6. Data display ---------- */
.amount { font-variant-numeric: tabular-nums; font-weight: 700; letter-spacing: -.01em; }
.amount-xl { font-size: clamp(1.5rem, 3.4vw, 2.1rem); }
.amount-lg { font-size: 1.25rem; }
.blurable.blurred { filter: blur(8px); cursor: pointer; user-select: none; }

.kv { display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr); gap: 6px var(--space-4); font-size: .88rem; }
.kv dd { overflow-wrap: anywhere; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); font-weight: 550; }

.listy { list-style: none; margin: 0; padding: 0; }
.listy > li { border-bottom: 1px solid var(--border); }
.listy > li:last-child { border-bottom: none; }

.item-row {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3);
  width: 100%; text-align: start; background: none; border: none; color: inherit; font: inherit;
  cursor: pointer; border-radius: var(--radius-sm); transition: background .16s;
}
.item-row:hover { background: var(--surface-3); }
.item-main { flex: 1; min-width: 0; }
.item-main b { display: block; font-weight: 620; font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-main small { color: var(--text-3); font-size: .78rem; display: block; }
.item-end { text-align: end; flex: none; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--grad-brand); color: #fff; font-weight: 700; font-size: .85rem;
  text-transform: uppercase;
}
.avatar.sm { width: 30px; height: 30px; font-size: .72rem; }
.avatar.lg { width: 60px; height: 60px; font-size: 1.2rem; }
.avatar.k1 { background: linear-gradient(135deg,#6366f1,#8b5cf6); }
.avatar.k2 { background: linear-gradient(135deg,#0ea5e9,#14b8a6); }
.avatar.k3 { background: linear-gradient(135deg,#8b5cf6,#ec4899); }
.avatar.k4 { background: linear-gradient(135deg,#14b8a6,#84cc16); }
.avatar.k5 { background: linear-gradient(135deg,#f59e0b,#f97316); }

.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--grad-brand); border-radius: 999px; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.progress.good > i { background: var(--grad-green); }

.meter-ring { display: grid; place-items: center; position: relative; width: 104px; height: 104px; flex: none; }
.meter-ring svg { transform: rotate(-90deg); }
[dir="rtl"] .meter-ring svg { transform: rotate(-90deg) scaleY(-1); }
.meter-ring .mval { position: absolute; font-weight: 750; font-size: 1.3rem; font-variant-numeric: tabular-nums; }

.timeline { position: relative; padding-inline-start: 26px; }
.timeline::before { content: ""; position: absolute; inset-inline-start: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: var(--space-4); }
.tl-item::before {
  content: ""; position: absolute; inset-inline-start: -24px; top: 6px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--brand-1);
}
.tl-item.done::before { background: var(--good); border-color: var(--good); }
.tl-item.warn::before { background: var(--needs); border-color: var(--needs); }
.tl-item b { font-size: .9rem; }
.tl-item small { display: block; color: var(--text-3); font-size: .76rem; }

.empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--text-3); }
.empty .ei { font-size: 2.2rem; background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; margin-bottom: var(--space-3); }
.empty h3 { color: var(--text); }

.notice {
  font-size: .78rem; color: var(--text-3); background: var(--surface-3); border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm); padding: 10px 12px; line-height: 1.55;
}
.notice.islamic { border-style: solid; background: var(--grad-soft); color: var(--text-2); }
.ayah { font-family: var(--font-ar); font-size: 1.05rem; line-height: 2.1; color: var(--text); direction: rtl; text-align: center; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: var(--space-4); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 14px; border: none; background: none; color: var(--text-3); font: inherit; font-weight: 600;
  font-size: .88rem; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; min-height: 44px;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--brand-1); border-bottom-color: var(--brand-1); }

.scroller { display: flex; gap: var(--space-3); overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.scroller > * { scroll-snap-align: start; flex: none; }
.scroller::-webkit-scrollbar { height: 6px; }
.scroller::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }

.person-card {
  width: 184px; min-width: 184px; padding: var(--space-3); border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
  text-align: start; font: inherit; color: inherit; overflow: hidden;
  transition: transform .18s, box-shadow .18s, border-color .18s;
}
.person-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-1); border-color: var(--brand-1); }
.person-card b, .person-card small {
  display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Fade the scroller edge so a clipped card reads as "more to scroll", not broken */
.scroller-wrap { position: relative; }
.scroller-wrap::after {
  content: ""; position: absolute; inset-block: 0; inset-inline-end: 0; width: 28px;
  background: linear-gradient(to left, var(--surface), transparent); pointer-events: none;
}
[dir="rtl"] .scroller-wrap::after { background: linear-gradient(to right, var(--surface), transparent); }

.stars { display: inline-flex; gap: 2px; }
.stars button { background: none; border: none; cursor: pointer; color: var(--text-3); padding: 2px; font-size: .9rem; min-height: 28px; }
.stars button.on { color: #f59e0b; }

.spark { display: flex; align-items: flex-end; gap: 4px; height: 44px; }
.spark i { flex: 1; background: var(--grad-brand); border-radius: 3px 3px 0 0; min-height: 3px; opacity: .85; }

/* ---------- 7. Overlays ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(8, 11, 22, .55); backdrop-filter: blur(3px);
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; z-index: 110; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-2); display: flex; flex-direction: column;
  inset-inline-end: 0; top: 0; bottom: 0; width: min(560px, 100%);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  transform: translateX(104%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
[dir="rtl"] .sheet { border-radius: 0 var(--radius-lg) var(--radius-lg) 0; transform: translateX(-104%); }
.sheet.open { transform: translateX(0); }
.sheet-head {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4);
  border-bottom: 1px solid var(--border); flex: none;
}
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.sheet-body { padding: var(--space-4); overflow-y: auto; flex: 1; }
.sheet-foot {
  padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); flex: none;
  display: flex; gap: var(--space-2); background: var(--surface-2);
}
.sheet-foot .btn { flex: 1; }

.toast-wrap {
  position: fixed; inset-block-end: 24px; inset-inline-end: 24px; inset-inline-start: auto; z-index: 200;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none;
  max-width: min(460px, calc(100vw - 32px));
}
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: 12px 16px; display: flex; align-items: center; gap: 12px;
  max-width: 460px; pointer-events: auto; animation: toastIn .3s cubic-bezier(.2,.8,.2,1);
  font-size: .88rem;
}
.toast.good { border-inline-start: 4px solid var(--good); }
.toast.warn { border-inline-start: 4px solid var(--needs); }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }

/* ---------- 8. Mobile ---------- */
.mobile-bar {
  display: none; position: fixed; inset-inline: 0; bottom: 0; z-index: 70;
  background: var(--glass); backdrop-filter: blur(18px); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.mobile-bar nav { display: flex; max-width: 560px; margin: 0 auto; }
.mb-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px;
  color: var(--text-3); font-size: .64rem; font-weight: 600; min-height: 50px; position: relative;
}
.mb-item:hover { text-decoration: none; }
.mb-item i { font-size: 1.12rem; }
.mb-item.active { color: var(--brand-1); }
.mb-fab {
  width: 50px; height: 50px; border-radius: 16px; background: var(--grad-brand); color: #fff;
  display: grid; place-items: center; font-size: 1.3rem; border: none; cursor: pointer; margin-top: -14px;
  box-shadow: 0 8px 22px rgba(99,102,241,.45);
}
.mb-item .mb-dot { position: absolute; top: 4px; inset-inline-end: 26%; width: 8px; height: 8px; border-radius: 50%; background: var(--needs); }

@media (max-width: 1100px) {
  .col-8, .col-6, .col-4, .col-3 { grid-column: span 12; }
  .col-m6 { grid-column: span 6; }
}
@media (max-width: 960px) {
  .side-rail { display: none; }
  .mobile-bar { display: block; }
  .app-body { padding: var(--space-4) var(--space-3) 110px; }
  .greeting { display: none; }
  .col-m6 { grid-column: span 12; }
  .sheet { inset: auto 0 0 0; width: 100%; max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; transform: translateY(104%); }
  [dir="rtl"] .sheet { border-radius: var(--radius-lg) var(--radius-lg) 0 0; transform: translateY(104%); }
  .sheet.open { transform: translateY(0); }
  .field-row { grid-template-columns: 1fr; }
  .toast-wrap { inset-block-end: 96px; inset-inline: 12px; align-items: stretch; max-width: none; }
}
@media (max-width: 420px) {
  .brand-text span { display: none; }
}

/* ---------- 9. Calm mode & motion ---------- */
body.calm .card { box-shadow: none; }
body.calm .card-hero { background: var(--grad-soft); color: var(--text); border: 1px solid var(--border); }
body.calm .card-hero h3, body.calm .card-hero p { color: var(--text); }
body.calm .badge, body.calm .chip { filter: saturate(.75); }
body.calm .btn-primary { box-shadow: none; }
body.calm .grid { gap: var(--space-5); }
body.calm .rail-badge { background: var(--text-3); }

.celebrate { animation: pop .6s cubic-bezier(.2,.9,.3,1.4); }
@keyframes pop { 0% { transform: scale(.9); opacity: 0 } 60% { transform: scale(1.03) } 100% { transform: scale(1); opacity: 1 } }
.fade-in { animation: fadeIn .32s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

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

/* ---------- 9b. Beginner guide ---------- */
.guide-defs { display: grid; grid-template-columns: 1fr; gap: 0; margin: 0; }
.guide-defs dt {
  font-weight: 700; font-size: .92rem; color: var(--text);
  padding: 14px 0 4px; border-top: 1px solid var(--border);
}
.guide-defs dt:first-child { border-top: none; padding-top: 0; }
.guide-defs dd {
  margin: 0 0 4px; color: var(--text-2); font-size: .88rem; line-height: 1.65;
  overflow-wrap: anywhere;
}
@media (min-width: 760px) {
  .guide-defs { grid-template-columns: minmax(150px, 230px) 1fr; column-gap: var(--space-5); }
  .guide-defs dt { padding: 14px 0 14px; }
  .guide-defs dd { padding: 14px 0; border-top: 1px solid var(--border); }
  .guide-defs dt:first-child, .guide-defs dt:first-child + dd { border-top: none; padding-top: 0; }
}

.guide-num {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 750; font-size: .82rem;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border);
}
.guide-num.done { background: var(--grad-green); color: #fff; border-color: transparent; }

.guide-nav { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin-top: var(--space-3); }
.guide-nav-card {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  padding: var(--space-4); border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: inherit; font: inherit; text-align: start; cursor: pointer;
  min-height: 84px; transition: transform .18s, box-shadow .18s, border-color .18s;
}
.guide-nav-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-1); border-color: var(--brand-1); }
.guide-nav-card.next { align-items: flex-end; text-align: end; }
.guide-nav-card small { color: var(--text-3); font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; }
[dir="rtl"] .guide-nav-card small { letter-spacing: 0; }
.guide-nav-card b { font-size: .95rem; font-weight: 650; }
.guide-nav-card.ghost { cursor: default; opacity: .55; }
.guide-nav-card.ghost:hover { transform: none; box-shadow: none; border-color: var(--border); }
.guide-nav-card.done { background: var(--grad-soft); border-color: var(--brand-1); align-items: flex-end; text-align: end; }
@media (max-width: 620px) {
  .guide-nav { grid-template-columns: 1fr; }
  .guide-nav-card, .guide-nav-card.next, .guide-nav-card.done { align-items: flex-start; text-align: start; }
}

/* ---------- 9c. Coach-mark tour ---------- */
.tour-scrim {
  position: fixed; inset: 0; z-index: 300; background: rgba(8, 11, 22, .62);
  backdrop-filter: blur(2px); animation: fadeIn .25s ease both;
}
.tour-ring {
  position: fixed; z-index: 301; pointer-events: none; border-radius: 14px;
  border: 2px solid var(--brand-2);
  box-shadow: 0 0 0 9999px rgba(8, 11, 22, .62), 0 0 0 4px rgba(139, 92, 246, .35);
  transition: top .28s cubic-bezier(.2,.8,.2,1), left .28s cubic-bezier(.2,.8,.2,1),
              width .28s cubic-bezier(.2,.8,.2,1), height .28s cubic-bezier(.2,.8,.2,1);
}
.tour-bubble {
  position: fixed; z-index: 302; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-2); padding: var(--space-4);
  animation: fadeIn .22s ease both;
}
.tour-bubble h3 { font-size: 1rem; }
.tour-bubble p { color: var(--text-2); }

/* ---------- 10. Print (estate export) ---------- */
@media print {
  .app-header, .side-rail, .mobile-bar, .no-print, .scrim, .sheet { display: none !important; }
  body { background: #fff; color: #000; }
  body::before { display: none; }
  .card { break-inside: avoid; border: 1px solid #ccc; box-shadow: none; }
}
