/* Hedaya — design system. Offline, RTL-first, light & dark. */
:root {
  /* Pass 1: warmer accent, better contrast on white */
  --accent: #7a3aa0;
  --accent-soft: #f1e6f7;
  --accent-ink: #57256e;
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3ede4;
  --ink: #2b2320;
  --ink-2: #6f625b;
  --line: #e7ded2;
  --ok: #2e7d52;
  --warn: #b98214;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(43,35,32,.06), 0 6px 24px rgba(43,35,32,.07);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Cairo", system-ui, sans-serif;
}
[data-theme="dark"] {
  --accent: #9a5cc0;
  --accent-soft: #2c1838;
  --accent-ink: #d5aeee;
  --bg: #191412;
  --surface: #231d1a;
  --surface-2: #2e2622;
  --ink: #f2e9e2;
  --ink-2: #b3a49a;
  --line: #3a302a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); line-height: 1.7; font-size: 16px;
  /* Pass 1: Arabic text renders better with slight letter separation handled by font */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
/* Pass 1: clearer heading hierarchy */
h1 { font-size: 1.45em; font-weight: 800; }
h2 { font-weight: 800; letter-spacing: 0; }
/* Pass 13: visible keyboard focus everywhere */
:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 65%, white);
  outline-offset: 2px;
  border-radius: 6px;
}
/* Pass 13: skip link for keyboard users */
.skip-link {
  position: absolute; inset-inline-start: 12px; top: -60px; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 16px; border-radius: 0 0 10px 10px;
  font-weight: 700; transition: top .15s;
}
.skip-link:focus { top: 0; }
h1,h2,h3 { line-height: 1.3; margin: 0 0 .4em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
/* Pass 2: native selects & links must follow the theme (were white-on-white in dark) */
select {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
select option { background: var(--surface); color: var(--ink); }
a { color: var(--accent-ink); }
a:hover { text-decoration: none; }
[data-theme="dark"] a { color: #8fb8ff; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1060px; margin: 0 auto; padding: 12px 18px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 20px;
  box-shadow: var(--shadow);
}
.brand small { display: block; font-size: 11.5px; font-weight: 500; color: var(--ink-2); }
.topbar .spacer { flex: 1; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  width: 40px; height: 40px; display: inline-grid; place-items: center; font-size: 17px;
  transition: transform .12s ease, background .15s;
}
.icon-btn:hover { background: var(--surface-2); transform: translateY(-1px); }

.wrap { max-width: 1060px; margin: 0 auto; padding: 20px 18px 90px; }

.hero {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #42230e));
  color: #fff; border-radius: 20px; padding: 22px 24px; margin-bottom: 20px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.hero::after {
  content: "🍽️"; position: absolute; inset-inline-end: 18px; top: 50%;
  translate: 0 -50%;
  font-size: 84px; opacity: .16; transform: rotate(-8deg);
  pointer-events: none;
}
/* Pass 3: subtle dot texture over the hero gradient */
.hero::before {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.14) 1.2px, transparent 1.2px);
  background-size: 18px 18px; opacity: .5; pointer-events: none;
}
.hero > * { position: relative; }
.hero h1 { font-size: 23px; }
.hero p { margin: 0; opacity: .92; max-width: 60ch; }
.hero .stats { display: flex; gap: 26px; margin-top: 14px; flex-wrap: wrap; }
/* Pass 3: separators make the hero stats scannable */
.hero .stat { position: relative; padding-inline-start: 26px; }
.hero .stat:first-child { padding-inline-start: 0; }
.hero .stat + .stat::before {
  content: ""; position: absolute; inset-inline-start: 0; top: 15%; height: 70%;
  width: 1px; background: rgba(255,255,255,.35);
}
.hero .stat b { font-size: 22px; display: block; font-variant-numeric: tabular-nums; }
.hero .stat span { font-size: 12.5px; opacity: .88; }

.grid { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.panel > h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.panel > h2 .count {
  background: var(--accent-soft); color: var(--accent-ink); border-radius: 20px;
  font-size: 12px; padding: 1px 10px; font-weight: 700;
}
.panel .panel-actions { margin-inline-start: auto; }

.btn {
  border: none; background: var(--accent); color: #fff; font-weight: 700;
  padding: 9px 16px; border-radius: 10px; font-size: 14.5px;
  transition: filter .15s, transform .12s;
}
.btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn.ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.danger { background: var(--danger); }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 180px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 8px 12px;
}
.search input { border: none; outline: none; background: none; flex: 1; font-size: 15px; }
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 30px; padding: 5px 13px; font-size: 13px; font-weight: 600;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: flex-start;
}
.card .avatar {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  background: var(--accent-soft); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 20px; font-weight: 800;
}
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card .meta { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.card .actions { display: flex; gap: 6px; flex: none; }
.badge {
  font-size: 11.5px; font-weight: 700; border-radius: 20px; padding: 2px 10px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge.s-idea { background: #e8e4fb; color: #4f44a8; }
.badge.s-planned { background: #fdf3d7; color: #8a6410; }
.badge.s-bought { background: #dcefe4; color: var(--ok); }
.badge.s-given { background: var(--surface-2); color: var(--ink-2); text-decoration: line-through; }
[data-theme="dark"] .badge.s-idea { background: #2c2745; color: #b6abf0; }
[data-theme="dark"] .badge.s-planned { background: #3a3116; color: #e3c46b; }
[data-theme="dark"] .badge.s-bought { background: #17352a; color: #7fd0a5; }
.badge.soon { background: #fde8e6; color: var(--danger); }
[data-theme="dark"] .badge.soon { background: #3d1c1a; color: #f0958d; }
.price { font-weight: 800; color: var(--accent-ink); white-space: nowrap; }

.empty {
  text-align: center; padding: 34px 16px; color: var(--ink-2);
}
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }

/* modal */
dialog {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 18px; padding: 0; width: min(480px, 92vw); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20,14,10,.45); backdrop-filter: blur(3px); }
dialog form { padding: 20px; }
dialog h3 { font-size: 17px; margin-bottom: 14px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 5px; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; background: var(--bg); font-size: 15px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
dialog .form-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 18px; }
.err { color: var(--danger); font-size: 13px; margin-top: 6px; min-height: 1.2em; font-weight: 600; }

/* toast */
.toasts { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%); z-index: 50; display: grid; gap: 8px; }
[dir="rtl"] .toasts { transform: translateX(50%); }
.toast {
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

footer { text-align: center; color: var(--ink-2); font-size: 12.5px; padding: 20px 0 30px; }

/* Pass 8: budget progress on person cards */
.budget { margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.budget .bar { flex: 1; max-width: 180px; height: 7px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.budget .fill { height: 100%; border-radius: 6px; background: var(--ok); transition: width .3s ease; }
.budget .fill.over { background: var(--danger); }
.budget span { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Pass 9: occasions strip */
.occasions-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 14px; margin-top: -6px;
  scrollbar-width: thin;
}
.occ-chip {
  flex: none; background: var(--surface); border: 1px solid var(--line); border-radius: 30px;
  padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--ink-2); box-shadow: var(--shadow);
}
.occ-chip.soon { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }

/* Pass 5: occasion editor rows */
.occ-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.occ-row input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--bg); font-size: 14px; min-width: 0; }
.occ-row .icon-btn { width: 34px; height: 34px; flex: none; }

/* Pass 18: print stylesheet — clean gift list */
@media print {
  .topbar, .toolbar, .chips, .card .actions, .btn, dialog, .toasts, footer, #occasions-strip { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .hero { color: #000; background: none; border: 1px solid #ccc; box-shadow: none; }
  .hero::before, .hero::after { display: none; }
  .grid { grid-template-columns: 1fr; }
  .panel, .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

/* Pass 4: mobile pass — single column earlier, bigger touch targets */
@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 15.5px; }
  .wrap { padding: 14px 12px 90px; }
  .topbar-inner { padding: 10px 12px; }
  .brand { font-size: 18px; }
  .hero { padding: 18px; border-radius: 16px; }
  .hero h1 { font-size: 20px; }
  .hero::after { font-size: 60px; }
  .hero .stats { gap: 18px; }
  .hero .stat { padding-inline-start: 18px; }
  .toolbar { flex-direction: column; }
  .toolbar select { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
  .card { padding: 12px; flex-wrap: wrap; }
  .card .actions { width: 100%; justify-content: flex-end; }
  .card .actions .icon-btn { width: 44px; height: 44px; }
  dialog { width: 94vw; }
  .field-row { flex-direction: column; gap: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Masroof extras */
/* Pass 13: avatar radio picker */
.avatar-row { display: flex; gap: 8px; flex-wrap: wrap; }
.avatar-pick {
  width: 46px; height: 46px; border-radius: 12px; font-size: 24px;
  border: 2px solid var(--line); background: var(--bg);
}
.avatar-pick.on { border-color: var(--accent); background: var(--accent-soft); }
/* Pass 6: undo button inside toasts */
.toast-undo {
  background: none; border: none; color: #ffd27a; font-weight: 800;
  margin-inline-start: 10px; padding: 0 4px; text-decoration: underline;
}
/* chore rows are slimmer than kid rows */
.chore-row { padding: 10px 16px; }

/* Wasfa extras */
.recipe-detail { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.recipe-detail h4 { margin: 10px 0 6px; font-size: 14px; }
.ings, .steps { margin: 0; padding-inline-start: 22px; }
.ings li, .steps li { margin-bottom: 4px; font-size: 14.5px; }
.serving-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; }
.serving-row .icon-btn { width: 34px; height: 34px; }
.serving-row b { min-width: 2ch; text-align: center; font-size: 17px; }
.shop-item .price { margin-inline-start: 8px; }
.card.recipe { align-items: flex-start; }

/* Aklak extras */
.pantry-group h3 { font-size: 14px; color: var(--ink-2); margin: 12px 0 6px; }
.pantry-group:first-child h3 { margin-top: 0; }
.group-h { font-size: 15px; color: var(--ink-2); margin: 16px 0 8px; }
.recipe-detail { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.recipe-detail h4 { margin: 10px 0 6px; font-size: 14px; }
.steps { margin: 0; padding-inline-start: 22px; }
.steps li { margin-bottom: 4px; font-size: 14.5px; }
