/* بيت أم حسوني — واجهة الموبايل أولاً، RTL، وضع داكن تلقائي */

:root {
  --brand: #0E7C7B;
  --brand-ink: #0A5F5E;
  --brand-soft: #E1F0EF;
  --accent: #F2A541;
  --bg: #F6F1E9;
  --card: #FFFFFF;
  --ink: #1F2933;
  --muted: #6B7280;
  --line: #E7E0D4;
  --in: #1E9E5A;
  --out: #D9534F;
  --warn: #B45309;
  --warn-bg: #FFF4E5;
  --good-bg: #E8F7EE;
  --bad-bg: #FDECEC;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 41, 51, .06), 0 4px 14px rgba(31, 41, 51, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417; --card: #1C2026; --ink: #ECEFF3; --muted: #9AA3AE; --line: #2A3038;
    --brand-soft: #16302F; --warn-bg: #3A2A12; --good-bg: #12301F; --bad-bg: #3A1B1B;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
h1, h2, h3 { margin: 0; font-weight: 800; line-height: 1.3; }
p { margin: 0; }
code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; background: var(--brand-soft); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.neg { color: var(--out); }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 10px; }
.h1 { font-size: 1.4rem; margin: 6px 0 12px; }
.h2 { font-size: 1.05rem; margin: 18px 0 8px; display: flex; align-items: center; justify-content: space-between; }
.h2 .more { color: var(--brand); font-weight: 600; font-size: .85rem; }
.big-emoji { font-size: 3rem; }
.grow { flex: 1; min-width: 0; }

/* ------------------------------------------------------------ الإطار */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.05rem; }
.brand img { border-radius: 9px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-soft); display: grid; place-items: center; font-size: 1.2rem; }
.net-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--in); }
.net-dot.off { background: var(--out); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.page { max-width: 640px; margin: 0 auto; padding: 12px 14px calc(96px + var(--safe-b)); }
.page.narrow { max-width: 420px; padding-top: 32px; }
body.bare .page { padding-bottom: 32px; }

.bottom {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
}
.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: .68rem; color: var(--muted); padding: 4px 0; font-weight: 600; }
.bottom a.on { color: var(--brand); }
.bottom .ni { font-size: 1.35rem; line-height: 1; }
.bottom .fab { flex: 0 0 auto; width: 58px; height: 58px; margin-top: -26px; border-radius: 50%; background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(14,124,123,.4); display: grid; place-items: center; }
.bottom .fab span { font-size: 2rem; line-height: 1; font-weight: 400; }

/* ------------------------------------------------------------ عناصر */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card.center { text-align: center; padding: 32px 16px; }
.card h2 { font-size: 1rem; margin-bottom: 8px; }
.flash { padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; font-weight: 600; font-size: .92rem; background: var(--brand-soft); border-inline-start: 4px solid var(--brand); }
.flash.ok { background: var(--good-bg); border-color: var(--in); }
.flash.error { background: var(--bad-bg); border-color: var(--out); }
.flash.warn { background: var(--warn-bg); border-color: var(--warn); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; min-height: 44px;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--out); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .88rem; }
.btn.big { width: 100%; font-size: 1.1rem; min-height: 52px; }
.btn.block { display: flex; width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .6; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.actions form { display: inline; }
.sticky-actions { position: sticky; bottom: calc(76px + var(--safe-b)); padding: 8px 0; background: linear-gradient(transparent, var(--bg) 40%); }

.badge { font-size: .7rem; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); font-style: normal; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

/* ------------------------------------------------------------ الشرائح */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.chips.wrap { flex-wrap: wrap; }
.scroll-x { display: flex; gap: 8px; overflow-x: auto; flex-wrap: nowrap; margin: 8px -14px; padding: 2px 14px 6px; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); font-size: .85rem; font-weight: 600; white-space: nowrap; font-family: inherit; color: var(--ink); cursor: pointer;
}
.chip.good { background: var(--good-bg); color: var(--in); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--out); border-color: transparent; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip.ghost { background: transparent; color: var(--muted); }
.chip.acc b { font-weight: 800; }
.chip.tpl { background: var(--brand-soft); border-color: transparent; }
.chip.sel { padding: 0; }
.chip.sel input { position: absolute; opacity: 0; pointer-events: none; }
.chip.sel span { padding: 8px 14px; border-radius: 999px; display: block; }
.chip.sel:has(input:checked) { background: var(--brand); border-color: var(--brand); }
.chip.sel:has(input:checked) span { color: #fff; }

/* ------------------------------------------------------------ اللوحة */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 12px; }
.mn-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-size: 1.4rem; }
.mn-title { text-align: center; font-size: 1.15rem; }
.mn-today { display: inline-block; margin-inline-start: 8px; font-size: .75rem; color: var(--brand); background: var(--brand-soft); padding: 1px 10px; border-radius: 999px; }

.hero { text-align: center; padding: 18px 14px 14px; }
.hero.small { padding: 12px; }
.hero-net small { color: var(--muted); font-weight: 600; }
.hero-net strong { display: block; font-size: 2rem; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; }
.hero-net.pos strong { color: var(--in); }
.hero-net.neg strong { color: var(--out); }
.hero-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.tile { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.tile small { display: block; color: var(--muted); font-weight: 600; font-size: .78rem; }
.tile b { font-size: 1.15rem; font-weight: 800; }
.tile.in b { color: var(--in); }
.tile.out b { color: var(--out); }
.hero-meta { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.hero-meta .chip { font-size: .78rem; padding: 3px 10px; }

.insight { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; border-inline-start: 4px solid var(--brand); box-shadow: var(--shadow); }
.insight.warn { border-color: var(--warn); }
.insight.good { border-color: var(--in); }
.insight .ii { font-size: 1.5rem; line-height: 1; margin-top: 2px; }
.insight strong { display: block; font-size: .95rem; }
.insight p { color: var(--muted); font-size: .85rem; }

.ai { display: flex; gap: 14px; align-items: center; background: linear-gradient(135deg, var(--brand), var(--brand-ink)); color: #fff; }
.ai .ai-text strong { display: block; }
.ai .ai-text p { font-size: .9rem; opacity: .95; }
.ai .ai-text small { opacity: .8; font-size: .78rem; }
.score { --p: 0; flex: 0 0 auto; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; position: relative;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), rgba(255,255,255,.25) 0); }
.score::before { content: ''; position: absolute; inset: 7px; border-radius: 50%; background: var(--brand-ink); }
.score b, .score small { position: relative; z-index: 1; }
.score b { font-size: 1.25rem; }
.score.big { width: 84px; height: 84px; }
.score.big b { font-size: 1.6rem; line-height: 1; }
.score.big small { font-size: .65rem; opacity: .8; }
.ai-full { background: var(--card); }
.ai-full .ai-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.ai-full .score::before { background: var(--card); }
.ai-full .score { background: conic-gradient(var(--brand) calc(var(--p) * 1%), var(--line) 0); }
.ai-full .score b { color: var(--brand); }
.ai-full .praise { color: var(--in); font-weight: 600; margin-top: 4px; }
.tips { padding-inline-start: 22px; margin: 0; }
.tips li { margin-bottom: 12px; }
.tips li p { color: var(--muted); font-size: .9rem; }
.tips .chip { margin-top: 4px; font-size: .78rem; }
.total-saving { margin-top: 10px; padding: 10px; border-radius: 12px; background: var(--good-bg); text-align: center; }

.brow { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .92rem; margin-top: 8px; }
.brow:first-child { margin-top: 0; }
.brow .bnum { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.prog { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 4px; }
.prog span { display: block; height: 100%; border-radius: 999px; transition: width .4s; }
.prog.over span { background: var(--out) !important; }
.prog.near span { opacity: .85; }

.donut-wrap { display: flex; gap: 14px; align-items: center; }
.donut { flex: 0 0 auto; }
.donut-num { font-size: 15px; font-weight: 800; fill: var(--ink); font-family: inherit; }
.donut-lbl { font-size: 11px; fill: var(--muted); font-family: inherit; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; font-size: .85rem; }
.legend li { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.legend li a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.legend b { font-weight: 800; }
.legend small { color: var(--muted); }
.bars .bar-in { fill: var(--in); }
.bars .bar-out { fill: var(--out); }
.bars .bar-lbl { font-size: 10px; fill: var(--muted); font-family: inherit; }
.legend-inline { display: flex; gap: 14px; justify-content: center; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.lg::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; vertical-align: middle; }
.lg.in::before { background: var(--in); }
.lg.out::before { background: var(--out); }

.list .li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.list .li:first-child { border-top: 0; padding-top: 0; }
.list .li > span:first-child { flex: 1; min-width: 0; }
.list .li small { color: var(--muted); white-space: nowrap; }
.list .li.col { flex-direction: column; align-items: stretch; }

/* ------------------------------------------------------------ العمليات */
.tx-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx-day { padding: 8px 14px 4px; font-size: .78rem; font-weight: 700; color: var(--muted); background: var(--bg); }
.tx-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.tx-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; flex: 0 0 auto; }
.tx-main { flex: 1; min-width: 0; }
.tx-main strong { display: block; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-main small { color: var(--muted); font-size: .78rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-amt.income, b.income { color: var(--in); }
.tx-amt.expense, b.expense { color: var(--out); }
.tx-amt.transfer { color: var(--muted); }
.sums { display: flex; gap: 14px; align-items: center; margin: 6px 4px 8px; font-weight: 700; font-size: .9rem; }
.sums .in { color: var(--in); }
.sums .out { color: var(--out); }
.filters { padding: 10px; }
.filters input[type=search] { width: 100%; margin-bottom: 8px; }
.filters select { flex: 1; min-width: 120px; }

/* ------------------------------------------------------------ النماذج */
.form label, .txform label:not(.chip):not(.cat):not(.check) { display: block; font-size: .85rem; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: inherit; font-size: 1rem; margin-top: 4px; min-height: 44px;
}
input[type=color] { width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); margin-top: 4px; padding: 4px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row > label { margin-bottom: 10px; }
.w-emoji { flex: 0 0 72px; }
.w-color { flex: 0 0 64px; }
.w-sign { flex: 0 0 64px; }
.w-small { flex: 0 0 120px; }
.check { display: flex !important; align-items: center; gap: 8px; color: var(--ink) !important; font-weight: 600 !important; }
.check input { width: 20px; height: 20px; margin: 0; }
textarea { resize: vertical; }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-bottom: 12px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px 4px; border-radius: 11px; font-weight: 700; color: var(--muted); }
.seg label:has(input:checked) span { color: #fff; }
.seg label.expense:has(input:checked) span { background: var(--out); }
.seg label.income:has(input:checked) span { background: var(--in); }
.seg label.transfer:has(input:checked) span { background: var(--muted); }
.seg.small span { padding: 6px 4px; font-size: .9rem; }

.smart { margin-bottom: 12px; }
.smart input { border-style: dashed; border-color: var(--brand); background: var(--brand-soft); }
.smart small { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; min-height: 1.2em; }

.amount-box { position: relative; margin-bottom: 8px; }
.amount-box input { font-size: 2.2rem; font-weight: 800; text-align: center; padding: 8px 60px 8px 14px; min-height: 72px; letter-spacing: .01em; font-variant-numeric: tabular-nums; border-width: 2px; }
.amount-box .unit { position: absolute; top: 50%; right: 16px; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.chips.quick { justify-content: center; }

.sect { margin-top: 14px; }
.sect h3 { font-size: .85rem; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 480px) { .cat-grid { grid-template-columns: repeat(5, 1fr); } }
.cat { position: relative; text-align: center; cursor: pointer; }
.cat input { position: absolute; opacity: 0; pointer-events: none; }
.cat .ci { --c: var(--brand); display: grid; place-items: center; width: 100%; aspect-ratio: 1; max-height: 64px; border-radius: 16px; font-size: 1.6rem; background: color-mix(in srgb, var(--c) 14%, var(--card)); border: 2px solid transparent; transition: transform .1s; }
.cat .cn { display: block; font-size: .72rem; font-weight: 700; margin-top: 3px; line-height: 1.2; color: var(--ink); }
.cat:has(input:checked) .ci { border-color: var(--c); background: var(--c); transform: scale(1.04); box-shadow: 0 4px 12px color-mix(in srgb, var(--c) 40%, transparent); }
.cat:has(input:checked) .cn { color: var(--c); }
.date-quick { display: flex; gap: 6px; margin-bottom: 10px; }
.txform .actions { margin-top: 16px; }

.budgets .bamt { width: 130px; text-align: center; margin: 0; }
.brow-edit { padding: 10px 12px; margin-bottom: 8px; }

/* ------------------------------------------------------------ العناصر القابلة للفتح */
.item summary { list-style: none; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.item summary::-webkit-details-marker { display: none; }
.item summary small, .item .brow small { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; }
.item .ic { --c: var(--brand); width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.3rem; background: color-mix(in srgb, var(--c) 14%, var(--card)); flex: 0 0 auto; }
.item.off { opacity: .55; }
.item.add { border: 1px dashed var(--line); box-shadow: none; background: transparent; }
.item .form, .item .rec-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.item b { white-space: nowrap; }

.menu { padding: 4px 0; }
.menu a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); font-weight: 600; }
.menu a:first-child { border-top: 0; }
.menu a span:first-child { width: 32px; text-align: center; font-size: 1.3rem; }
.menu a.danger { color: var(--out); }

.log-row { display: flex; gap: 8px; flex-wrap: wrap; font-size: .8rem; padding: 4px 0; border-top: 1px solid var(--line); }
.log-row small { color: var(--muted); }
.log-row em { color: var(--muted); font-style: normal; }

.login-hero { text-align: center; margin-bottom: 20px; }
.login-hero img { border-radius: 28px; box-shadow: var(--shadow); }
.login-hero h1 { font-size: 1.6rem; margin-top: 10px; }
.login-hero .tagline { color: var(--muted); font-weight: 600; }

.toast { position: fixed; bottom: calc(84px + var(--safe-b)); inset-inline: 14px; z-index: 40; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-weight: 700; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.error { background: var(--out); color: #fff; }

/* ------------------------------------------------------------ الطباعة */
body.print { background: #fff; color: #111; }
body.print .page { max-width: 900px; padding-bottom: 24px; }
.rep-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.rep-head h1 { font-size: 1.4rem; }
.rep-head p { color: #555; font-size: .85rem; }
.report h2 { font-size: 1.05rem; margin: 18px 0 6px; }
.rep-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.rep-table th, .rep-table td { border: 1px solid #ddd; padding: 6px 8px; text-align: right; }
.rep-table th { background: #f3f3f3; }
.rep-table.small { font-size: .8rem; }
.rep-table .in { color: var(--in); }
.rep-table .out { color: var(--out); }
.rep-table td.income { color: var(--in); }
.rep-table td.expense { color: var(--out); }
.rep-tips { padding-inline-start: 22px; }
@media print {
  .no-print { display: none !important; }
  body.print .page { padding: 0; }
  .rep-table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
}
