/* ============================================================
   مصاريف العيلة والفواتير — فيرجن 1
   Material 3 — أزرق هادي #5B8DC9 / أزرق فاتح #D9E6F2
   أبيض #FFFFFF / نص #3A4552 — الألوان المعتمدة فقط
   ============================================================ */

:root {
  --blue: #5B8DC9;
  --blue-dark: #4A7AB5;
  --blue-light: #D9E6F2;
  --blue-soft: #EAF2F9;
  --white: #FFFFFF;
  --ink: #3A4552;
  --ink-soft: #5B6B7C;
  --mint: #D9F2E4;
  --mint-ink: #1E7A4C;
  /* --coral / --coral-ink: حالة «متأخر» فقط (الدليل) — تظهر على
     الصفوف المتأخرة مع نص صريح «اتأخر N يوم»، لا باللون وحده */
  --coral: #FBE3D8;
  --coral-ink: #A03E1B; /* أغمق من #B4451F ليمر تباين نص «متأخر» (5.36:1) */
  --card-border: #E3EDF6;
  --shadow: 0 2px 12px rgba(58, 69, 82, 0.08);
  --shadow-lg: 0 8px 24px rgba(58, 69, 82, 0.12);
  --radius-card: 24px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #F4F8FC;
  color: var(--ink);
  font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* الأرقام: بطل الشاشة — أكبر بدرجة، عريض، واتجاه ثابت LTR */
.num {
  direction: ltr;
  unicode-bidi: isolate;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  white-space: nowrap;
}

.app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--white);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 40px rgba(58, 69, 82, 0.10);
}

main {
  flex: 1;
  padding: 8px 20px 110px;
  overflow-x: hidden;
}

.screen { display: none; }
.screen.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- الهيدر ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 4px;
}
.app-header h1 {
  font-size: 28px;
  line-height: 1.25;
  margin: 0;
  font-weight: 800;
  color: var(--ink);
}
.app-header .sub {
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.app-header .title-block { flex: 1; min-width: 0; }
.icon-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  border: none;
  background: var(--blue-light);
  color: var(--blue-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:focus-visible, .btn:focus-visible, .chip:focus-visible, .nav-btn:focus-visible, input:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}
.icon-btn .dot {
  position: absolute;
  top: 10px;
  inset-inline-start: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid var(--white);
}
.icon-btn { position: relative; }

/* ---------- الكروت ---------- */
.card {
  background: var(--white);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card.soft { background: var(--blue-soft); border-color: transparent; }
.card.blue-light { background: var(--blue-light); border-color: transparent; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 22px 2px 12px;
}
.section-title h2 { font-size: 18px; margin: 0; font-weight: 800; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue-light);
  color: var(--ink);
  border: none;
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  min-height: 36px;
}
.chip.mint { background: var(--mint); color: var(--mint-ink); }
.chip.coral { background: var(--coral); color: var(--coral-ink); } /* حالة «متأخر» فقط — حسب الدليل */
.chip.ghost { background: var(--white); border: 1.5px solid var(--card-border); color: var(--ink-soft); }
.chip[aria-pressed="true"] { background: var(--blue-light); color: var(--ink); border: 2px solid var(--blue); }

/* ---------- لوحة الشهر ---------- */
.hero-remaining { text-align: center; padding: 22px 18px 18px; }
.hero-remaining .label { font-size: 16px; color: var(--ink-soft); }
.hero-remaining .big { font-size: 52px; line-height: 1.15; color: var(--ink); }
.hero-remaining .big .unit { font-size: 20px; font-weight: 700; color: var(--ink-soft); }
.hero-remaining .weekly {
  margin-top: 10px;
  display: inline-block;
  background: var(--blue-light);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 700;
}
.money-row {
  display: flex;
  gap: 12px;
  margin-top: 14px;
}
.money-box {
  flex: 1;
  background: var(--white);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 12px 10px;
  text-align: center;
}
.money-box .label { font-size: 13.5px; color: var(--ink-soft); }
.money-box .value { font-size: 21px; }

/* قوائم الالتزامات */
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--card-border);
}
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .name { font-weight: 700; font-size: 16px; }
.list-row .due { font-size: 13.5px; color: var(--ink-soft); }
.list-row .amount { font-size: 18px; text-align: end; }
.list-row .end { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.icon-tile {
  width: 52px;
  height: 52px;
  min-width: 52px;
  border-radius: 16px;
  background: var(--blue-light);
  color: var(--blue-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-tile svg { width: 26px; height: 26px; }
.icon-tile.round { border-radius: 50%; }
.icon-tile.mint { background: var(--mint); color: var(--mint-ink); }

/* ---------- الأقساط ---------- */
.summary-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 6px;
}
.summary-box {
  background: var(--white);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 16px 14px;
  text-align: center;
}
.summary-box .label { font-size: 14px; color: var(--ink-soft); line-height: 1.5; }
.summary-box .value { font-size: 30px; margin-top: 4px; }
.summary-box .unit { font-size: 15px; font-weight: 700; color: var(--ink-soft); }

.plan { padding: 16px 18px; }
.plan-top { display: flex; align-items: flex-start; gap: 12px; }
.plan-top .grow { flex: 1; min-width: 0; }
.plan-top .name { font-size: 18px; font-weight: 800; }
.plan-top .meta { font-size: 14.5px; color: var(--ink-soft); margin-top: 2px; }
.plan-top .meta .num { font-size: 15px; }
.plan-progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.plan-pct { font-size: 20px; font-weight: 800; }
.bar {
  flex: 1;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--blue-light);
  overflow: hidden;
}
.bar > span { display: block; height: 100%; background: var(--blue-dark); border-radius: inherit; }
.bar.over > span { background: var(--coral-ink); }
.budget-state-over { color: var(--coral-ink); font-weight: 700; }
.lock-overlay { position: fixed; inset: 0; z-index: 50; background: var(--blue-soft); padding: 32px 16px; overflow-y: auto; }

/* تقويم مواعيد الدفع (P2-25) — السبت أول أيام الأسبوع */
.cal-nav { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cal-title { flex: 1; text-align: center; font-size: 20px; font-weight: 800; color: var(--ink); }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.cal-weekday { text-align: center; font-size: 12px; font-weight: 700; color: var(--ink-soft); padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell { position: relative; min-height: 52px; padding: 6px 2px; border: 1px solid var(--hatch-widget-border, #dbe4ee); border-radius: 10px; background: var(--hatch-widget-surface, #fff); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px; }
.cal-cell.empty { border-color: transparent; background: transparent; cursor: default; }
.cal-cell.today { border: 2px solid var(--blue-dark); }
.cal-cell.selected { background: var(--blue-light); }
.cal-num { font-size: 15px; font-weight: 700; color: var(--ink); }
.cal-badge { font-size: 11px; font-weight: 800; color: var(--blue-dark); background: var(--blue-light); border-radius: 999px; min-width: 20px; height: 20px; line-height: 20px; text-align: center; padding: 0 4px; }
.cal-over { font-size: 10px; font-weight: 800; color: var(--coral-ink); }
.budget-state-near { color: var(--blue-dark); font-weight: 700; }
.plan .remaining-line { font-size: 14.5px; color: var(--ink-soft); margin-top: 8px; }
.plan .remaining-line .num { font-size: 15.5px; color: var(--ink); }

/* ---------- الفواتير ---------- */
.bills-summary { text-align: center; }
.bills-summary .total-label { font-size: 17px; font-weight: 700; }
.bills-summary .total-value { font-size: 34px; }
.bills-summary .total-value .unit { font-size: 16px; font-weight: 700; color: var(--ink-soft); }
.pills { display: flex; gap: 12px; margin-top: 14px; }
.pill {
  flex: 1;
  border-radius: var(--radius-pill);
  padding: 12px 10px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.5;
}
.pill.mint { background: var(--mint); color: var(--mint-ink); }
.pill.blue { background: var(--blue-light); color: var(--ink); }
.pill .num { font-size: 19px; }

/* ---------- الإضافة السريعة ---------- */
.info-bar {
  background: var(--blue-light);
  border-radius: 18px;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.info-bar .icon-tile { width: 40px; height: 40px; min-width: 40px; background: var(--blue); color: var(--white); }
.info-bar .icon-tile svg { width: 20px; height: 20px; }

.voice-card {
  background: var(--blue-light);
  border: none;
  text-align: center;
  padding: 26px 18px 20px;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  color: var(--ink);
}
.voice-card .mic {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--blue);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(91, 141, 201, 0.45);
}
.voice-card .mic svg { width: 36px; height: 36px; }
.voice-card h3 { font-size: 20px; margin: 14px 0 4px; }
.voice-card p { margin: 0; color: var(--ink); font-size: 15px; }
.wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 44px;
  margin-top: 14px;
}
.wave span {
  width: 4px;
  border-radius: 4px;
  background: var(--blue);
  opacity: 0.75;
  animation: wave 1.1s ease-in-out infinite;
}
@keyframes wave { 0%, 100% { height: 10px; } 50% { height: 34px; } }
@media (prefers-reduced-motion: reduce) { .wave span { animation: none; height: 16px; } }

.field-label { font-size: 16px; font-weight: 800; margin: 20px 2px 8px; }
.amount-input {
  width: 100%;
  border: 2px solid var(--blue);
  border-radius: 18px;
  padding: 16px 18px;
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
  background: var(--white);
  font-family: inherit;
}
.amount-input::placeholder { color: #5B6B7C; }
.amount-wrap { position: relative; }
.amount-wrap .unit {
  position: absolute;
  top: 50%;
  inset-inline-start: 18px;
  transform: translateY(-50%);
  color: var(--ink-soft);
  font-weight: 700;
  pointer-events: none;
}
.chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: none;
}
.chips-row::-webkit-scrollbar { display: none; }

.wallet-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 2px;
}
.wallet-row .grow { flex: 1; }
.wallet-row .name { font-weight: 800; font-size: 16px; }
.wallet-row .note { font-size: 13.5px; color: var(--ink-soft); }

/* ---------- الأزرار ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--blue);
  color: var(--white);
  font-size: 19px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  padding: 12px 20px;
  box-shadow: 0 6px 16px rgba(91, 141, 201, 0.35);
}
.btn:active { background: var(--blue-dark); }
.btn.secondary {
  background: var(--white);
  color: var(--blue-dark);
  border: 2px solid var(--blue-light);
  box-shadow: none;
}
.btn-row { display: flex; gap: 12px; margin-top: 16px; }
.btn-row .btn { flex: 1; }
/* صفوف فيها ٣ أزرار أو أكتر: زرّين في السطر والتالت تحت — بدل ما النص يتقص */
.btn-row.wrap { flex-wrap: wrap; }
.btn-row.wrap .btn { flex: 1 1 calc(50% - 6px); min-width: 0; font-size: 16px; padding: 0 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--white);
  padding: 14px 20px;
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  max-width: calc(430px - 40px);
  width: max-content;
  max-width: 90vw;
  text-align: center;
  z-index: 50;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- لافتة المزامنة (أوفلاين / تغييرات معلّقة) ---------- */
.cloud-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  margin: 0 12px;
  padding: 10px 16px;
  border-radius: 0 0 18px 18px;
  background: var(--blue-soft);
  color: var(--ink);
  border: 1px solid var(--card-border);
  border-top: none;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.cloud-banner[hidden] { display: none; }

.version-note {
  text-align: center;
  font-size: 13px;
  color: var(--ink-soft);
  margin: 26px 0 0;
}

/* ---------- التنقل السفلي ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  background: var(--white);
  border-top: 1px solid var(--card-border);
  display: flex;
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
}
.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: 18px;
  font-size: 13px;
  font-weight: 700;
  min-height: 56px;
}
.nav-btn svg { width: 26px; height: 26px; }
.nav-btn.active { background: var(--blue-light); color: var(--ink); }
.nav-btn.active svg { color: var(--blue-dark); }
.nav-btn.active .plus-dot svg { color: var(--white); }
.nav-btn .plus-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--blue);
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-btn.active .plus-dot { box-shadow: 0 4px 12px rgba(91, 141, 201, 0.45); }

@media (min-width: 500px) {
  body { padding: 24px 0; }
  .app { border-radius: 32px; overflow: hidden; min-height: calc(100vh - 48px); min-height: calc(100dvh - 48px); }
  .bottom-nav { border-radius: 0 0 32px 32px; }
}

/* ---------- أدوات لوحة الشهر (بطاقات تنقل للشاشات الجديدة) ---------- */
.hub-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 16px; }
.hub-card { display: flex; align-items: center; gap: 12px; padding: 14px; text-decoration: none; color: var(--ink); min-width: 0; }
.hub-card > div { min-width: 0; }
.hub-card .name, .hub-card .due { overflow-wrap: anywhere; }
.hub-card .name { font-size: 15px; font-weight: 700; }
.hub-card .due { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; line-height: 1.5; }

/* ---------- إدارة الالتزامات ---------- */
.manage-row { padding: 10px 0; border-bottom: 1px solid var(--card-border); }
.manage-row:last-child { border-bottom: none; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; padding-right: 52px; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.btn.danger { background: var(--coral-ink); color: var(--white); }
.form-card { margin-top: 16px; }
.form-card h2 { font-size: 17px; font-weight: 800; margin-bottom: 12px; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.field-input { width: 100%; min-height: 48px; border: 1.5px solid var(--card-border); border-radius: 12px; padding: 10px 14px; font-family: inherit; font-size: 16px; color: var(--ink); background: var(--white); }
.field-input:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.check-row { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; margin-bottom: 12px; min-height: 48px; }
.check-row input { width: 22px; height: 22px; accent-color: var(--blue); }

/* ---------- التذكيرات ---------- */
.rem-card { margin-bottom: 12px; }
.rem-dates { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.rem-date { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--blue-soft); border-radius: 10px; padding: 8px 4px; font-size: 12.5px; text-align: center; min-width: 0; overflow-wrap: anywhere; }
.rem-date .rem-label { color: var(--ink-soft); font-size: 11.5px; }
.rem-date .rem-state { color: var(--ink-soft); font-size: 11.5px; }
.rem-date.today { background: var(--blue-light); border: 1.5px solid var(--blue); }
.rem-date.today .rem-state { color: var(--blue-dark); font-weight: 700; }
.rem-date.past { opacity: 0.55; }

/* ---------- الإضافة السريعة: بطاقة الصوت ---------- */
.voice-card.disabled { cursor: default; opacity: 0.8; }
.voice-card.disabled .mic { background: var(--blue-light); color: var(--ink-soft); }

/* ---------- أدوار العائلة ---------- */
.role-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.role-btn { min-height: 48px; border-radius: 14px; border: 1.5px solid var(--card-border); background: var(--white); font-family: inherit; font-size: 16px; font-weight: 700; color: var(--ink); cursor: pointer; }
.role-btn.active { background: var(--blue-light); border: 2px solid var(--blue); }
.role-note { font-size: 14px; color: var(--ink-soft); line-height: 1.6; margin-bottom: 16px; }

/* ---------- التسجيل الصوتي: حالة الاستماع ---------- */
.voice-card.listening { border: 2px solid var(--blue); }
.voice-card.listening .mic { animation: micpulse 1s ease-in-out infinite; }
@keyframes micpulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* ---------- قراءة الإيصال ---------- */
.receipt-card { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.receipt-top { display: flex; gap: 12px; align-items: center; }
.receipt-top h3 { font-size: 16px; font-weight: 800; }
.receipt-top p { font-size: 13.5px; color: var(--ink-soft); line-height: 1.6; margin-top: 2px; }
.receipt-preview { max-height: 120px; overflow: auto; background: var(--blue-soft); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; line-height: 1.7; white-space: pre-wrap; color: var(--ink); }

/* ---------- الدفع من التذكير (رابط فقط) ---------- */
a.btn { text-decoration: none; }

/* ---------- تصدير PDF: تنسيق الطباعة (P2-8) ---------- */
/* رأس التقرير يظهر في الطباعة فقط. */
.print-head { display: none; }

@media print {
  body { background: #fff; }
  .bottom-nav, .btn-row, #toast, .icon-btn { display: none !important; }
  .print-head { display: block; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 2px solid #5B8DC9; }
  .print-head-title { font-size: 20px; font-weight: 800; color: #3A4552; }
  .print-head-sub { font-size: 13px; color: #5B6B7C; margin-top: 4px; }
  .card, .list-row { break-inside: avoid; }
  .screen { padding: 0; }
}

/* بانر وضع التجريبي — أزرق هادئ فقط (#5B8DC9 / #D9E6F2 / #3A4552)، بلا موف. */
.demo-banner { background: var(--blue-light); color: var(--ink); border: 1px solid var(--blue); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 700; }

/* شاشات ضيقة جداً (٣٢٠px): شرائح التذكير أربعة في سطر بيتزنقوا، فبنخليها اتنين */
@media (max-width: 360px) {
  .rem-dates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
