/* v5 — mobile overflow fix (اگر این خط را در style.css?v=5 می‌بینی، نسخهٔ تازه بارگذاری شده) */
/* ============================================================
   Daric · دَریک
   طراحی: دفترچه‌ی آرام مالی + فین‌تک مدرن
   ============================================================ */

@font-face {
  font-family: "Vazirmatn";
  src: url("vendor/vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg:        #eef1f6;
  --surface:   #ffffff;
  --surface-2: #f6f8fc;
  --ink:       #0f172a;
  --ink-2:     #4a586b;
  --ink-3:     #5f6b7a;            /* AA-safe secondary text (>=4.5:1 on white) */
  --line:      #e4e9f1;
  --line-2:    #eef2f7;
  --brand:     #0d9488;
  --brand-ink: #0f766e;
  --brand-wash:#e0f2f0;
  --income:    #16a34a;            /* نشانه‌ی نمودار/سواچ */
  --income-ink:#15803d;            /* متن سبز، AA-safe روی سفید */
  --income-wash:#e6f6ec;
  --expense:   #e11d48;
  --expense-ink:#be123c;           /* متن قرمز، AA-safe روی سفید */
  --expense-wash:#fdeaef;
  --shadow:    0 1px 2px rgba(15,23,42,.04), 0 8px 24px -12px rgba(15,23,42,.14);
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --radius:    18px;
  --radius-sm: 12px;
  --radius-xs: 9px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg:        #0a1120;
  --surface:   #111a2c;
  --surface-2: #0d1524;
  --ink:       #e8eef8;
  --ink-2:     #a3b2c8;
  --ink-3:     #8b98ac;            /* AA-safe secondary text on dark surface */
  --line:      #1f2c42;
  --line-2:    #18233a;
  --brand:     #2dd4bf;
  --brand-ink: #5eead4;
  --brand-wash:#0c2b2a;
  --income:    #34d399;
  --income-ink:#34d399;            /* روی سطح تیره روشن است و AA پاس می‌شود */
  --income-wash:#0c2b20;
  --expense:   #fb7185;
  --expense-ink:#fb7185;
  --expense-wash:#2c1620;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 12px 30px -14px rgba(0,0,0,.6);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
/* هیچ‌وقت کلِ صفحه افقی اسکرول/سرریز نشود؛ clip (برخلافِ hidden) چسبندگیِ هدر را خراب نمی‌کند */
html, body { overflow-x: clip; max-width: 100%; }

body {
  font-family: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background .3s ease, color .3s ease;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; }
p { margin: 0; }
.muted { color: var(--ink-3); }
.small { font-size: .84rem; }
.ta-end { text-align: left; }

/* ----------------------------- Topbar ----------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 20px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  font-size: 26px; line-height: 1;
  filter: drop-shadow(0 3px 6px rgba(13,148,136,.3));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 1.05rem; }
.brand-sub { font-size: .72rem; color: var(--ink-3); }

.tabs { display: flex; gap: 4px; margin-inline: auto; }
.tab {
  border: none; background: transparent; cursor: pointer;
  font-family: inherit; font-size: .92rem; font-weight: 600;
  color: var(--ink-2); padding: 8px 16px; border-radius: 999px;
  transition: background .18s, color .18s;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.is-active { background: var(--brand-wash); color: var(--brand-ink); }

.topbar-tools { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  width: 38px; height: 38px; border-radius: 11px; font-size: 17px;
  display: grid; place-items: center; transition: border-color .18s, transform .1s;
}
.icon-btn:hover { border-color: var(--brand); }
.icon-btn:active { transform: scale(.94); }

/* segmented control */
.seg {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px;
}
.seg.wide { width: 100%; }
.seg.wide button { flex: 1; }
.seg button {
  border: none; background: transparent; cursor: pointer; font-family: inherit;
  font-size: .84rem; font-weight: 600; color: var(--ink-2);
  padding: 6px 13px; border-radius: 8px; transition: all .16s;
}
.seg button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ----------------------------- Layout ----------------------------- */
.wrap { max-width: 1160px; margin: 0 auto; padding: clamp(18px, 3vw, 30px) clamp(16px, 4vw, 40px) 64px; }
.view { display: none; animation: rise .35s cubic-bezier(.2,.7,.3,1); }
.view.is-active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2.top { align-items: start; }
.grid-2 > .card { margin-bottom: 0; }

/* ------------------------------ KPIs ------------------------------ */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 4px; background: var(--kpi-accent, var(--brand));
}
.kpi-label { display: flex; align-items: center; gap: 7px; font-size: .78rem; font-weight: 600; color: var(--ink-3); letter-spacing: .01em; }
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kpi-accent); }
.kpi-value { font-size: 1.72rem; font-weight: 800; margin-top: 8px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-value .unit { font-size: .82rem; font-weight: 600; color: var(--ink-3); margin-inline-start: 5px; }
.kpi-sub { font-size: .78rem; color: var(--ink-3); margin-top: 3px; }
.kpi.income  { --kpi-accent: var(--income); }
.kpi.expense { --kpi-accent: var(--expense); }
.kpi.net     { --kpi-accent: var(--brand); }
.kpi.balance { --kpi-accent: var(--brand); }
.kpi.income .kpi-value  { color: var(--income-ink); }
.kpi.expense .kpi-value { color: var(--expense-ink); }
.kpi.balance .kpi-value { color: var(--brand); }

/* -------------------- Signature: flow spine ----------------------- */
.flow-card .card-head { margin-bottom: 14px; }
.flow {
  display: flex; height: 46px; border-radius: 13px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line); gap: 3px; padding: 3px;
}
.flow-seg {
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; color: #fff; font-weight: 700; font-size: .82rem;
  min-width: 3px; transition: flex-basis .6s cubic-bezier(.3,.8,.3,1);
  white-space: nowrap; overflow: hidden;
}
/* پس‌زمینه‌ی ثابت و به‌قدر کافی تیره تا متن سفید در هر دو پوسته AA پاس کند */
.flow-seg.income  { background: linear-gradient(120deg, #188a45, #12703a); }
.flow-seg.expense { background: linear-gradient(120deg, #c81e4a, #a5153c); }
.flow-legend { display: flex; gap: 22px; margin-top: 14px; flex-wrap: wrap; }
.flow-legend .fl { display: flex; align-items: center; gap: 8px; font-size: .86rem; }
.flow-legend .fl b { font-variant-numeric: tabular-nums; }
.flow-legend .sw { width: 11px; height: 11px; border-radius: 4px; }
.fl.income .sw { background: var(--income); } .fl.income b { color: var(--income-ink); }
.fl.expense .sw { background: var(--expense); } .fl.expense b { color: var(--expense-ink); }
.fl.net .sw { background: var(--brand); }

/* ------------------------- Donut + legend ------------------------- */
.donut-wrap { display: grid; grid-template-columns: 190px 1fr; gap: 20px; align-items: center; }
.donut-canvas { position: relative; width: 190px; height: 190px; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none; text-align: center;
}
.donut-center .dc-val { font-size: 1.12rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.donut-center .dc-lbl { font-size: .72rem; color: var(--ink-3); }
.cat-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; max-height: 210px; overflow-y: auto; }
.cat-legend li { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 9px; align-items: center; padding: 6px 8px; border-radius: 9px; font-size: .87rem; }
.cat-legend li:hover { background: var(--surface-2); }
.cat-legend .sw { width: 11px; height: 11px; border-radius: 4px; }
.cat-legend .nm { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-legend .amt { font-variant-numeric: tabular-nums; font-weight: 700; }
.cat-legend .pct { color: var(--ink-3); font-size: .78rem; min-width: 40px; text-align: left; }

.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 280px; }

/* ------------------------------ Empty ----------------------------- */
.empty { text-align: center; padding: 40px 20px; }
.empty-emoji { font-size: 44px; margin-bottom: 8px; }
.empty h3 { margin-bottom: 6px; }
.empty p { color: var(--ink-3); margin-bottom: 18px; }

/* ------------------------------ Toolbar --------------------------- */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar .input[type="search"] { flex: 1; min-width: 180px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--brand); }

/* ------------------------------ Inputs ---------------------------- */
.input {
  font-family: inherit; font-size: .92rem; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-xs); padding: 9px 12px; width: 100%; outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.input::placeholder { color: var(--ink-3); }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-wash); }
.textarea { resize: vertical; line-height: 1.9; min-height: 150px; direction: rtl; }
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235f6b7a' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center; padding-left: 30px; }
.color-in { padding: 4px; height: 40px; cursor: pointer; }
.emoji-in { text-align: center; font-size: 1.2rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--ink-2); }
.row-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ------------------------------ Buttons --------------------------- */
.btn {
  font-family: inherit; font-size: .9rem; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 18px; border-radius: var(--radius-xs); transition: all .16s;
}
.btn:hover { border-color: var(--brand); color: var(--brand-ink); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; box-shadow: 0 6px 16px -6px var(--brand); }
.link-btn { background: none; border: none; color: var(--brand-ink); font-family: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.notice { margin-top: 14px; padding: 11px 14px; border-radius: var(--radius-xs); font-size: .88rem; font-weight: 600; }
.notice.ok { background: var(--income-wash); color: var(--income-ink); }
.notice.info { background: var(--brand-wash); color: var(--brand-ink); }

/* ------------------------------ Tables ---------------------------- */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
.tx-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tx-table th {
  text-align: right; font-size: .74rem; font-weight: 700; color: var(--ink-3);
  letter-spacing: .02em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tx-table td { padding: 11px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tx-table tbody tr { transition: background .12s; }
.tx-table tbody tr:hover { background: var(--surface-2); }
.tx-table.compact td, .tx-table.compact th { padding: 8px 10px; }

.tx-date { color: var(--ink-2); font-size: .82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-date b { display: block; color: var(--ink); font-size: .88rem; }
.tx-desc { display: flex; align-items: center; gap: 8px; }
.tx-desc .q { color: #d97706; font-weight: 800; cursor: help; }
.tx-type { display: inline-block; font-size: .72rem; font-weight: 700; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 7px; padding: 1px 7px; margin-top: 2px; }
.tx-amount { font-variant-numeric: tabular-nums; font-weight: 800; text-align: left; white-space: nowrap; }
.tx-amount.income { color: var(--income-ink); }
.tx-amount.expense { color: var(--expense-ink); }

.cat-pill {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-family: inherit; line-height: 1.5;
  font-size: .82rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--pc, var(--line)); color: var(--pc, var(--ink-3));
  background: color-mix(in srgb, var(--pc, var(--ink-3)) 10%, transparent);
  transition: filter .15s; white-space: nowrap;
}
.cat-pill:hover { filter: brightness(.96); }
.cat-pill.none { color: var(--ink-3); background: var(--surface-2); border-style: dashed; }
.cat-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); }

.rowbtn { border: none; background: none; cursor: pointer; color: var(--ink-3); font-size: 15px; padding: 5px; border-radius: 7px; }
.rowbtn:hover { background: var(--surface-2); color: var(--ink); }
.rowbtn.del:hover { color: var(--expense); }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 14px; color: var(--ink-3); font-size: .84rem; flex-wrap: wrap; }
.table-foot b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ------------------------- Categories view ------------------------ */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.cat-chip {
  display: flex; align-items: center; gap: 11px; padding: 12px 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2);
  position: relative;
}
.cat-chip .ci { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 19px; }
.cat-chip .cx { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.cat-chip .cx b { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-chip .cx span { font-size: .72rem; color: var(--ink-3); }
.cat-chip .cedit { position: absolute; inset-inline-start: 10px; top: 10px; opacity: 0;
  color: var(--ink-3); font-size: 13px; transition: opacity .15s; }
.cat-chip:hover .cedit, .cat-chip:focus-visible .cedit { opacity: 1; }

.sep { border: none; border-top: 1px solid var(--line); margin: 22px 0; }
.rule-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-bottom: 12px; }
.rule-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rule-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-xs); font-size: .86rem; }
.rule-list .rp { font-weight: 700; }
.rule-list .arr { color: var(--ink-3); }
.rule-list .rc { display: inline-flex; align-items: center; gap: 5px; }
.rule-list .rc .dot { width: 8px; height: 8px; border-radius: 50%; }
.rule-list .rdel { margin-inline-start: auto; }

/* ---------------------------- Date filter ------------------------- */
.toolbar-dates { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.date-in { max-width: 165px; font-variant-numeric: tabular-nums; }

/* ------------------------------- Modal ---------------------------- */
.modal { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }   /* باید [hidden] را بازنویسی کند وگرنه مودال همیشه باز می‌ماند */
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(3px); }
.modal-card {
  position: relative; width: min(560px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 24px 60px -12px rgba(0,0,0,.4); padding: 22px;
  animation: pop .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-body .form-grid { margin: 0; }
.form-grid label.full { grid-column: 1 / -1; }
.modal-foot { display: flex; align-items: center; gap: 10px; margin-top: 22px; }
.btn.del-ghost { color: var(--expense); border-color: transparent; background: transparent; padding-inline: 8px; }
.btn.del-ghost:hover { background: var(--expense-wash); color: var(--expense); border-color: transparent; }

.cat-chip { cursor: pointer; transition: border-color .15s, transform .1s; }
.cat-chip:hover { border-color: var(--brand); }
.cat-chip:active { transform: scale(.99); }

/* --------------------------- Popover menu ------------------------- */
.cat-menu {
  position: absolute; z-index: 100; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 6px; min-width: 210px; max-height: 320px; overflow-y: auto;
}
.cat-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: right;
  border: none; background: none; cursor: pointer; font-family: inherit; font-size: .87rem;
  color: var(--ink); padding: 8px 10px; border-radius: 8px;
}
.cat-menu button:hover { background: var(--surface-2); }
.cat-menu .dot { width: 10px; height: 10px; border-radius: 50%; }
.cat-menu .mi { font-size: 15px; }

/* ------------------------------ Toast ----------------------------- */
.toast {
  position: fixed; bottom: 24px; inset-inline-start: 50%; transform: translateX(50%) translateY(10px);
  background: var(--ink); color: var(--surface); padding: 11px 20px; border-radius: 12px;
  font-size: .88rem; font-weight: 600; box-shadow: var(--shadow); opacity: 0; z-index: 200;
  transition: opacity .25s, transform .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }

/* ------------------------------- BI ------------------------------- */
.period-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.period-bar-2 { margin-top: -8px; }
.period-bar-2 select { max-width: 155px; }
.period-label { margin-inline-start: auto; font-variant-numeric: tabular-nums; }

.kpi-delta { display: inline-flex; align-items: center; gap: 2px; font-size: .7rem; font-weight: 700;
  padding: 1px 7px; border-radius: 999px; margin-inline-start: 7px; vertical-align: middle; }
.kpi-delta.up { color: var(--income-ink); background: var(--income-wash); }
.kpi-delta.down { color: var(--expense-ink); background: var(--expense-wash); }
.kpi-delta.flat { color: var(--ink-3); background: var(--surface-2); }

.insights-head { margin: 28px 4px 14px; }
.insights-head h2 { font-size: 1.12rem; }
.kpis.mini { grid-template-columns: repeat(2, 1fr); }
.kpi.mini-stat .kpi-value { font-size: 1.42rem; }

.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.mini-list li { display: flex; gap: 11px; align-items: center; padding: 9px 6px; font-size: .88rem; }
.mini-list li + li { border-top: 1px solid var(--line-2); }
.mini-list .mi-ic { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 14px; background: var(--surface-2); }
.mini-list .mi-name { flex: 1; min-width: 0; }
.mini-list .mi-name b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.mini-list .mi-name span { font-size: .74rem; color: var(--ink-3); }
.mini-list .mi-amt { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; text-align: left; }
.mini-list .mi-amt.income { color: var(--income-ink); }
.mini-list .mi-amt.expense { color: var(--expense-ink); }
.mini-list .empty-line { color: var(--ink-3); padding: 16px 8px; text-align: center; justify-content: center; }
.btn.tiny { flex: none; padding: 3px 11px; font-size: .72rem; }

.burn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.burn-item { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; }
.burn-item .bl { display: block; font-size: .76rem; color: var(--ink-3); margin-bottom: 4px; }
.burn-item b { font-size: 1rem; font-variant-numeric: tabular-nums; }
.expense-c { color: var(--expense-ink); }
.income-c { color: var(--income-ink); }
.recon-op { display: inline-block; min-width: 1em; color: var(--ink-3); font-weight: 700; }
.recon-total { color: var(--brand); font-size: 1.08rem !important; }
#balanceReconCard .burn-item:last-child { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, var(--surface-2)); }
.chips-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.fq-chip { font-size: .76rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.fq-chip.warn { background: #fef3c7; color: #b45309; }
:root[data-theme="dark"] .fq-chip.warn { background: #3a2f16; color: #fbbf24; }
.fq-chip.ok { background: var(--income-wash); color: var(--income-ink); }
.badge-warn { color: #b45309; background: #fef3c7; font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
:root[data-theme="dark"] .badge-warn { background: #3a2f16; color: #fbbf24; }

.budget-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 8px 0 20px; }
.budget-summary .bs { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.budget-summary .bs .lbl { font-size: .74rem; color: var(--ink-3); }
.budget-summary .bs .val { font-size: 1.14rem; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 3px; }
.budget-list { display: flex; flex-direction: column; gap: 10px; }
.budget-row { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center;
  padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.budget-row .b-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; }
.budget-main { min-width: 0; }
.budget-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 9px; flex-wrap: wrap; }
.budget-top b { font-size: .92rem; }
.budget-in { display: flex; align-items: center; gap: 6px; }
.budget-in input { width: 140px; text-align: left; font-variant-numeric: tabular-nums; }
.budget-in .u { font-size: .74rem; color: var(--ink-3); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .5s cubic-bezier(.3,.8,.3,1); }
.budget-meta { display: flex; justify-content: space-between; margin-top: 7px; font-size: .76rem; color: var(--ink-3); }
.budget-meta .over { color: var(--expense-ink); font-weight: 700; }

.tx-note { display: block; margin-top: 3px; font-size: .74rem; color: var(--ink-3);
  background: var(--surface-2); border-radius: 6px; padding: 2px 7px; width: fit-content; max-width: 100%; }

/* ------------------------------ People ---------------------------- */
.tags-cell { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.person-chip {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  font-family: inherit; line-height: 1.4;
  font-size: .74rem; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent; color: var(--pc, var(--ink-3));
  background: color-mix(in srgb, var(--pc, var(--ink-3)) 13%, transparent);
  transition: filter .15s; white-space: nowrap;
}
.person-chip:hover { filter: brightness(.96); }
.person-chip.none { color: var(--ink-3); background: transparent; border: 1px dashed var(--line-2); font-weight: 500; }
.person-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pc); }

.people-list { display: flex; flex-direction: column; gap: 10px; }
.person-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); position: relative;
}
.person-row[data-id] { cursor: pointer; transition: border-color .15s; }
.person-row[data-id]:hover { border-color: var(--brand); }
.person-row .p-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; }
.person-row .p-main { min-width: 0; }
.person-row .p-main b { font-size: .95rem; }
.person-row .p-stats { display: flex; flex-wrap: wrap; gap: 3px 14px; margin-top: 5px;
  font-size: .78rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.person-row .p-stats .inc { color: var(--income-ink); }
.person-row .p-stats .exp { color: var(--expense-ink); }
.person-row .p-stats .net { font-weight: 700; color: var(--ink-2); }
.person-row .p-stats .net.neg { color: var(--expense-ink); }
.person-row .cedit { position: absolute; inset-inline-start: 12px; top: 12px; opacity: 0;
  color: var(--ink-3); font-size: 13px; transition: opacity .15s; }
.person-row:hover .cedit, .person-row:focus-visible .cedit { opacity: 1; }

/* ----------------------- BI extra components ---------------------- */
.gauge-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.gauge { width: 130px; height: 130px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.gauge-hole { width: 96px; height: 96px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; text-align: center; line-height: 1.1; }
.gauge-hole b { font-size: 2rem; font-weight: 800; }
.gauge-hole span { font-size: .7rem; color: var(--ink-3); }
.gauge-parts { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 210px; display: flex; flex-direction: column; gap: 9px; }
.gauge-parts li { display: grid; grid-template-columns: 1fr 90px auto; gap: 9px; align-items: center; font-size: .82rem; }
.gauge-parts .pn { color: var(--ink-2); }
.gauge-parts .pbar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.gauge-parts .pbar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.gauge-parts .pv { font-variant-numeric: tabular-nums; font-weight: 700; }

.split-bar { display: flex; height: 16px; border-radius: 999px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.split-bar > i { height: 100%; }
.split-bar .ess { background: var(--income); }
.split-bar .disc { background: var(--expense); }
.split-bar .unk { background: var(--line-2); }
.split-legend { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.split-legend li { display: flex; align-items: center; gap: 8px; font-size: .84rem; }
.split-legend .sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.split-legend .sw.ess { background: var(--income); }
.split-legend .sw.disc { background: var(--expense); }
.split-legend .sw.unk { background: var(--line-2); }
.split-legend b { font-variant-numeric: tabular-nums; margin-inline-start: auto; }

.filter-chip { display: inline-flex; align-items: center; gap: 6px; font-size: .76rem; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--brand); margin-inline-start: 8px; }
.filter-chip button { background: none; border: none; cursor: pointer; color: inherit; font-size: .9rem; padding: 0; line-height: 1; }

.goals-list { display: flex; flex-direction: column; gap: 12px; }
.goal-row { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 13px 14px; }
.goal-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.goal-top b { font-size: .95rem; }
.goal-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: .77rem; color: var(--ink-3); flex-wrap: wrap; }
.goal-actions { display: flex; gap: 8px; margin-top: 10px; }

.bar { position: relative; }
.bar > i.ghost { position: absolute; inset-block: 0; inset-inline-start: 0; height: 100%;
  background: repeating-linear-gradient(45deg, var(--ink-3) 0 3px, transparent 3px 7px); opacity: .45; border-radius: 999px; }
.budget-meta .warn-t { color: #b45309; font-weight: 700; }
:root[data-theme="dark"] .budget-meta .warn-t { color: #fbbf24; }

.person-row .owe { display: block; margin-top: 6px; font-size: .8rem; font-weight: 600; }
.person-row .owe.pos { color: var(--income-ink); }
.person-row .owe.neg { color: var(--expense-ink); }
.person-row .p-main[data-edit] { cursor: pointer; }
.person-row .psettle { align-self: flex-start; }

.hm-toolbar { margin-bottom: 12px; }
.hm-select { width: auto; min-width: 200px; max-width: 100%; }
.hm-month { margin-bottom: 18px; }
.hm-title { font-size: .85rem; font-weight: 700; margin-bottom: 8px; }
.hm-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; direction: rtl; max-width: 360px; }
.hm-wd { text-align: center; font-size: .68rem; color: var(--ink-3); padding-bottom: 2px; }
.hm-cell { aspect-ratio: 1; border-radius: 5px; display: grid; place-items: center; font-size: .64rem; color: var(--ink-3); background: var(--surface-2); }
.hm-cell.empty { background: transparent; }
.hm-cell.lvl1 { background: color-mix(in srgb, var(--brand) 22%, var(--surface-2)); }
.hm-cell.lvl2 { background: color-mix(in srgb, var(--brand) 45%, var(--surface-2)); }
.hm-cell.lvl3 { background: color-mix(in srgb, var(--brand) 68%, var(--surface-2)); color: #fff; }
.hm-cell.lvl4 { background: var(--brand); color: #fff; }

.subs-list { display: flex; flex-direction: column; gap: 10px; }
.sub-row { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.sub-row.off { opacity: .55; }
.sub-row .b-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; }
.sub-main { min-width: 0; }
.sub-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.sub-top b { font-size: .95rem; }
.sub-amt { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.sub-amt.expense { color: var(--expense-ink); }
.sub-amt.income { color: var(--income-ink); }
.sub-meta { font-size: .77rem; color: var(--ink-3); margin-top: 4px; }
.adjust-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.adjust-row .input { max-width: 220px; }
.check-lbl { flex-direction: row !important; align-items: center; gap: 8px; font-weight: 500; }
.check-lbl input { width: auto; }
.notice.warn { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
:root[data-theme="dark"] .notice.warn { background: #3a2f16; color: #fbbf24; border-color: #4a3d1e; }

@media print {
  .topbar, #tabs, .period-bar, .btn, .rowbtn, .link-btn, .icon-btn, #toast, #catMenu, #personMenu, #modal { display: none !important; }
  .view:not(.is-active) { display: none !important; }
  body { background: #fff !important; }
  main { max-width: 100% !important; padding: 0 !important; }
  .card { break-inside: avoid; box-shadow: none !important; border: 1px solid #ddd; }
  .chart-box, .grid-2, .kpi, .burn-item, .goal-row, .budget-row { break-inside: avoid; }
}

/* --------------------------- Responsive --------------------------- */
@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .cat-legend { width: 100%; }
  .tabs { order: 3; width: 100%; margin: 6px 0 0; overflow-x: auto; justify-content: flex-start; }
  .topbar { flex-wrap: wrap; gap: 12px; }
  /* کنترل‌های سگمنتی (به‌ویژه نوارِ «دوره» با ۵ دکمه) به‌جای سرریزِ افقی، می‌شکنند */
  .seg { flex-wrap: wrap; }
  .period-bar { gap: 8px 10px; }
  .period-label { margin-inline-start: 0; }
  .form-grid, .rule-add { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* focus visibility */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* --------------------- login + account (multi-user) --------------------- */
/* بدونِ این، خاصیتِ hidden روی عناصری که display دارند بی‌اثر می‌شود
   (مثلِ صفحه‌ی ورود که display:grid دارد) و هیچ‌وقت مخفی نمی‌شوند. */
[hidden] { display: none !important; }
.login-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center;
  background: var(--bg); padding: 20px; }
.login-card { width: min(370px, 92vw); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 24px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.15rem; color: var(--ink); }
.login-brand .brand-mark { font-size: 1.5rem; }
.login-card label { display: grid; gap: 6px; font-size: .82rem; color: var(--ink-2); }
.login-err { color: var(--expense-ink); background: var(--expense-wash); font-size: .84rem;
  padding: 9px 11px; border-radius: var(--radius-sm); text-align: center; }
.btn.danger { color: var(--expense-ink); border-color: var(--expense-wash); }
.btn.danger:hover { background: var(--expense-wash); }
.users-table { width: 100%; border-collapse: collapse; margin: 6px 0 2px; }
.users-table th, .users-table td { text-align: right; padding: 7px 6px; border-bottom: 1px solid var(--line); font-size: .86rem; }
.acct-sec { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 12px; }
.acct-sec h3 { margin: 0 0 8px; font-size: .95rem; }
.token-box { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.token-box input { flex: 1; font-family: ui-monospace, monospace; font-size: .8rem; }
.invite-result { background: var(--brand-wash); border: 1px solid var(--brand); border-radius: var(--radius-sm);
  padding: 11px 13px; margin-top: 10px; font-size: .85rem; line-height: 1.9; }
.invite-result code { background: var(--surface); padding: 2px 6px; border-radius: 6px; user-select: all;
  font-family: ui-monospace, monospace; }
