/*
 * Hoshmand Finance design system.
 * - Logical properties (inline/block) everywhere so RTL works without overrides.
 * - Tokens on :root; dark theme selected via data-theme or the OS preference.
 * - No inline styles are needed (strict CSP: style-src 'self').
 */

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

:root {
    color-scheme: light;
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f0f3f9;
    --surface-3: #e6ebf4;
    --border: #e2e7f0;
    --border-strong: #c7cfdc;
    --text: #0f172a;
    --text-2: #3b4559;
    --muted: #5b6478;
    --primary: #1450c8;
    --primary-hover: #0f41a6;
    --primary-soft: #e8effd;
    --on-primary: #ffffff;
    --good: #0b7a3b;
    --good-soft: #e3f5e9;
    --bad: #b42318;
    --bad-soft: #fbeae8;
    --warn: #8a5a00;
    --warn-soft: #fbf1dc;
    --info: #1450c8;
    --info-soft: #e8effd;
    --focus: #2f6fe4;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --viz-grid: #e6e9ee;
    --viz-axis: #5b6478;
    --viz-track: #edf0f6;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px -6px rgba(15, 23, 42, .08);
    --shadow-lg: 0 24px 48px -20px rgba(15, 23, 42, .35);
    /* Brand palette, taken from the Hoshmand logo artwork. */
    --brand-navy: #031a40;
    --brand-deep: #062a6e;
    --brand-royal: #0b45b8;
    --brand-blue: #1f6fe0;
    --brand-mint: #40f8bb;
    --brand-gold: #f8b820;
    /* Module colour families (icons and tiles; never the only status cue). */
    --t-blue: #1f6feb;
    --t-green: #12863f;
    --t-rose: #d6335f;
    --t-indigo: #4f46e5;
    --t-violet: #8b3fd9;
    --t-amber: #b86e00;
    --t-teal: #0f8b8d;
    --t-pink: #c92a80;
    --t-orange: #d9580d;
    --t-slate: #475569;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 22px;
    --sidebar-w: 264px;
    --sidebar-w-collapsed: 72px;
    --tabbar-h: 68px;
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Vazirmatn", sans-serif;
    --font-fa: "Vazirmatn", ui-sans-serif, system-ui, "Segoe UI", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0a0f1c;
        --surface: #111a2c;
        --surface-2: #16213a;
        --surface-3: #1d2a47;
        --border: #22304d;
        --border-strong: #33446a;
        --text: #e9eef8;
        --text-2: #c0cadb;
        --muted: #93a0b8;
        --primary: #7aa7ff;
        --primary-hover: #9bbcff;
        --primary-soft: #17284a;
        --on-primary: #06102a;
        --good: #5fd38d;
        --good-soft: #12291d;
        --bad: #ff8a8a;
        --bad-soft: #3a1619;
        --warn: #ffc35c;
        --warn-soft: #33270f;
        --info: #9bbcff;
        --info-soft: #17284a;
        --focus: #7aa7ff;
        --series-1: #3f8cff;
        --series-2: #ef6a35;
        --viz-grid: #1f2a42;
        --viz-axis: #93a0b8;
        --viz-track: #1b2640;
        --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 18px -8px rgba(0, 0, 0, .5);
        --shadow-lg: 0 24px 48px -20px rgba(0, 0, 0, .7);
        --t-blue: #7aa7ff;
        --t-green: #5fd38d;
        --t-rose: #ff7d9b;
        --t-indigo: #a7a3ff;
        --t-violet: #c99bff;
        --t-amber: #ffc35c;
        --t-teal: #4fd6cf;
        --t-pink: #ff8cc8;
        --t-orange: #ffa064;
        --t-slate: #a9b6cb;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a0f1c;
    --surface: #111a2c;
    --surface-2: #16213a;
    --surface-3: #1d2a47;
    --border: #22304d;
    --border-strong: #33446a;
    --text: #e9eef8;
    --text-2: #c0cadb;
    --muted: #93a0b8;
    --primary: #7aa7ff;
    --primary-hover: #9bbcff;
    --primary-soft: #17284a;
    --on-primary: #06102a;
    --good: #5fd38d;
    --good-soft: #12291d;
    --bad: #ff8a8a;
    --bad-soft: #3a1619;
    --warn: #ffc35c;
    --warn-soft: #33270f;
    --info: #9bbcff;
    --info-soft: #17284a;
    --focus: #7aa7ff;
    --series-1: #3f8cff;
    --series-2: #ef6a35;
    --viz-grid: #1f2a42;
    --viz-axis: #93a0b8;
    --viz-track: #1b2640;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 18px -8px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 48px -20px rgba(0, 0, 0, .7);
    --t-blue: #7aa7ff;
    --t-green: #5fd38d;
    --t-rose: #ff7d9b;
    --t-indigo: #a7a3ff;
    --t-violet: #c99bff;
    --t-amber: #ffc35c;
    --t-teal: #4fd6cf;
    --t-pink: #ff8cc8;
    --t-orange: #ffa064;
    --t-slate: #a9b6cb;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
html[lang="fa"] body { font-family: var(--font-fa); font-size: 15.5px; line-height: 1.75; }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -.01em; }
html[lang="fa"] h1, html[lang="fa"] h2, html[lang="fa"] h3 { letter-spacing: 0; line-height: 1.5; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; inset-inline-start: 1rem; inset-block-start: -3rem; z-index: 100; background: var(--primary); color: var(--on-primary); padding: .5rem 1rem; border-radius: var(--radius-sm); }
.skip-link:focus { inset-block-start: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.prewrap { white-space: pre-wrap; }
.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -.2em; }
[dir="rtl"] .icon.dir { transform: scaleX(-1); }
[hidden] { display: none !important; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.sidebar {
    position: sticky; inset-block-start: 0; block-size: 100vh; overflow-y: auto;
    background: var(--surface); border-inline-end: 1px solid var(--border);
    padding: 1rem .75rem; display: flex; flex-direction: column; gap: .5rem;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: .25rem .5rem .75rem; }
.brand { display: flex; align-items: center; gap: .65rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { inline-size: 36px; block-size: 36px; border-radius: 9px; flex: none; box-shadow: 0 6px 14px -6px rgba(3, 26, 64, .55); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 650; }
.brand-sub { font-size: .75rem; color: var(--muted); }
.nav-section { margin-block-end: .5rem; }
.nav-section-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .5rem .75rem .25rem; font-weight: 600; }
html[lang="fa"] .nav-section-title { text-transform: none; letter-spacing: 0; font-size: .8rem; }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav-link {
    display: flex; align-items: center; gap: .7rem; padding: .5rem .75rem; border-radius: var(--radius-sm);
    color: var(--text-2); font-size: .93rem; position: relative;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link.is-planned { color: var(--muted); }
.nav-icon { display: inline-grid; place-items: center; flex: none; }
.nav-label { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-status { font-size: .68rem; padding: .05rem .4rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.nav-status-partial { border-color: var(--warn); color: var(--warn); }
.app.is-collapsed .brand-text, .app.is-collapsed .nav-label, .app.is-collapsed .nav-status, .app.is-collapsed .nav-section-title { display: none; }
.app.is-collapsed .nav-link { justify-content: center; padding: .6rem; }
.app.is-collapsed .sidebar-head { justify-content: center; }
.sidebar .sidebar-close { display: none; }
.backdrop { display: none; }

.main-col { display: flex; flex-direction: column; min-inline-size: 0; }
.topbar {
    position: sticky; inset-block-start: 0; z-index: 20; display: flex; align-items: center; gap: .75rem;
    padding: .65rem 1.5rem; background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(8px); border-block-end: 1px solid var(--border);
}
.nav-toggle { display: none; }
.search { position: relative; flex: 1; max-inline-size: 420px; }
.search-icon { position: absolute; inset-inline-start: .7rem; inset-block-start: 50%; transform: translateY(-50%); color: var(--muted); }
.search input[type="search"] { inline-size: 100%; padding-inline-start: 2.3rem; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; margin-inline-start: auto; }
.content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; max-inline-size: 1280px; inline-size: 100%; }
.content:focus { outline: none; }
.footer { margin-block-start: auto; padding: 1rem 1.5rem 1.5rem; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; justify-content: space-between; font-size: .8rem; color: var(--text-2); }

/* ---------- Menu (details) ---------- */
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
    position: absolute; inset-inline-end: 0; inset-block-start: calc(100% + .4rem); min-inline-size: 220px; z-index: 30;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
    padding: .4rem;
}
.menu-meta { padding: .5rem .6rem; font-size: .8rem; color: var(--muted); border-block-end: 1px solid var(--border); margin-block-end: .3rem; overflow-wrap: anywhere; }
.menu-item {
    display: flex; align-items: center; gap: .6rem; inline-size: 100%; padding: .5rem .6rem; border-radius: var(--radius-sm);
    background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; text-align: start;
}
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.avatar { display: inline-grid; place-items: center; inline-size: 26px; block-size: 26px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .8rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .55rem 1rem;
    border-radius: var(--radius-sm); border: 1px solid transparent; font: inherit; font-weight: 600; font-size: .9rem;
    cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s, border-color .15s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { padding: .38rem .7rem; font-size: .84rem; }
.btn-block { inline-size: 100%; }
.icon-btn { display: inline-grid; place-items: center; inline-size: 36px; block-size: 36px; border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.inline-form { display: inline-flex; margin: 0; }
.link-sm { font-size: .85rem; font-weight: 600; }

/* ---------- Page structure ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.page-head h1 { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; }
.page-head p { margin-block-start: .25rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.back-link { display: inline-flex; align-items: center; gap: .25rem; font-size: .85rem; margin-block-end: .4rem; }
.section { display: flex; flex-direction: column; gap: .75rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.section-title { font-size: 1rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; }
.section-note { font-size: .8rem; font-weight: 400; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.stack { display: flex; flex-direction: column; gap: .75rem; align-items: stretch; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); min-inline-size: 0; }
.card-muted { background: var(--surface-2); box-shadow: none; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-block-end: 1rem; }
.card-title { margin-block-end: .9rem; }
.card-subtitle { font-size: .92rem; margin-block: 1rem .5rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .3rem; min-inline-size: 0; }
.stat-label { display: flex; align-items: center; gap: .35rem; color: var(--text-2); font-size: .85rem; font-weight: 500; }
.stat-value { font-size: 1.45rem; font-weight: 650; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; }
.stat-sm .stat-value { font-size: 1.25rem; }
.stat-help { font-size: .78rem; color: var(--muted); line-height: 1.45; }
.note { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; font-size: .85rem; color: var(--text-2); }

/* ---------- Badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .74rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface-2); vertical-align: middle; white-space: nowrap; }
.badge .icon { width: .95em; height: .95em; }
.badge-pending, .badge-partial { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.badge-posted, .badge-active { color: var(--good); background: var(--good-soft); border-color: transparent; }
.badge-void, .badge-closed { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.badge-planned, .badge-archived { color: var(--muted); }
.pill-list { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.pill-list li { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .75rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .85rem; }

/* ---------- Alerts ---------- */
.alert { display: flex; align-items: flex-start; gap: .65rem; padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid transparent; }
.alert .icon { margin-block-start: .15em; }
.alert-success { background: var(--good-soft); color: var(--good); }
.alert-error { background: var(--bad-soft); color: var(--bad); }
.alert-warning { background: var(--warn-soft); color: var(--text); }
.alert-warning .icon { color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--text-2); }
.alert-info .icon { color: var(--info); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
.form-narrow { max-inline-size: 760px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.form-row-between { display: flex; justify-content: flex-end; font-size: .88rem; }
.field { display: flex; flex-direction: column; gap: .35rem; min-inline-size: 0; }
.field > label, .field .label, fieldset legend { font-weight: 600; font-size: .88rem; color: var(--text); }
.req { color: var(--bad); }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
    inline-size: 100%; padding: .55rem .75rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit; font-size: .93rem; min-block-size: 40px;
}
textarea { resize: vertical; min-block-size: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--focus) 40%, transparent); outline-offset: 0; border-color: var(--focus); }
input[type="date"] { text-align: start; }
[dir="rtl"] input[dir="ltr"] { text-align: right; }
.input-affix { display: flex; align-items: stretch; direction: ltr; }
.input-affix .affix { display: grid; place-items: center; padding: 0 .7rem; border: 1px solid var(--border-strong); border-inline-end: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); background: var(--surface-2); color: var(--muted); }
.input-affix input { border-start-start-radius: 0; border-end-start-radius: 0; }
.help { font-size: .8rem; color: var(--muted); line-height: 1.45; }
.error { display: flex; align-items: center; gap: .3rem; font-size: .82rem; color: var(--bad); font-weight: 500; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }
.field-check { flex-direction: row; align-items: flex-start; gap: .55rem; flex-wrap: wrap; }
.field-check input { inline-size: 18px; block-size: 18px; margin-block-start: .2rem; accent-color: var(--primary); flex: none; }
.field-check label { font-weight: 500; flex: 1; min-inline-size: 0; }
.field-check .error, .field-check .help { flex-basis: 100%; }
.readonly { padding: .55rem .75rem; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); }
fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem; margin-block-end: .9rem; }
.filters .field label { font-size: .8rem; }
.sort-links { display: inline-flex; flex-wrap: wrap; gap: .6rem; font-size: .84rem; margin-inline-start: auto; }
.sort-links a[aria-current] { font-weight: 700; }

/* ---------- Tables ---------- */
.table-wrap { position: relative; overflow-x: auto; margin-inline: -.25rem; min-inline-size: 0; max-inline-size: calc(100% + .5rem); }
.table { inline-size: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: .65rem .6rem; text-align: start; border-block-end: 1px solid var(--border); vertical-align: top; }
.table thead th { font-size: .78rem; font-weight: 600; color: var(--muted); background: var(--surface); }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: end; }
.table tr.is-void td { color: var(--muted); text-decoration: line-through; }
.tx-desc { font-weight: 600; color: var(--text); }
.sub { display: block; font-size: .8rem; }
.type-label { display: inline-flex; align-items: center; gap: .3rem; white-space: nowrap; }
.type-in .icon, .amount-in { color: var(--good); }
.type-out .icon { color: var(--bad); }
.type-move .icon { color: var(--info); }
.amount-in { font-weight: 600; }
.amount-out { color: var(--text); }
.amount-move { color: var(--text-2); }
.ua { font-size: .82rem; overflow-wrap: anywhere; }

/* ---------- Accounts ---------- */
.account-list { list-style: none; margin: 0; padding: 0; }
.account-row + .account-row { border-block-start: 1px solid var(--border); }
.account-link { display: flex; align-items: center; gap: .9rem; padding: .8rem .25rem; color: var(--text); }
.account-link:hover { text-decoration: none; background: var(--surface-2); border-radius: var(--radius-sm); }
.account-icon { display: grid; place-items: center; inline-size: 38px; block-size: 38px; border-radius: 10px; background: var(--surface-2); color: var(--primary); flex: none; }
.account-main { flex: 1; min-inline-size: 0; }
.account-name { font-weight: 600; display: block; }
.account-balance { text-align: end; font-weight: 650; }

/* ---------- Details, timeline, lists ---------- */
.details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.25rem; margin: 0 0 1rem; }
.details div { min-inline-size: 0; }
.details .full { grid-column: 1 / -1; }
.details dt { font-size: .78rem; color: var(--muted); font-weight: 600; }
.details dd { margin: .15rem 0 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .75rem; }
.timeline li { padding-inline-start: 1rem; border-inline-start: 2px solid var(--border); }
.changes { margin: .3rem 0 0; padding-inline-start: 1rem; font-size: .85rem; }
.budget-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1.1rem; }
.budget-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; margin-block-end: .4rem; }
.progress { block-size: .55rem; background: var(--surface-2, var(--border)); border-radius: 999px; overflow: hidden; }
.progress-svg { display: block; inline-size: 100%; block-size: 100%; }
[dir="rtl"] .progress-svg { transform: scaleX(-1); }
.progress-bar { fill: var(--good); }
.budget-warning .progress-bar, .budget-critical .progress-bar { fill: var(--warn); }
.budget-exceeded .progress-bar { fill: var(--bad); }
.budget-progress .sub { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: .4rem 0 0; font-size: .85rem; }
.bell { position: relative; }
.bell-count { position: absolute; inset-block-start: 2px; inset-inline-end: 2px; min-inline-size: 1.1rem; padding: 0 .25rem; border-radius: 999px; background: var(--bad); color: #fff; font-size: .68rem; line-height: 1.1rem; text-align: center; font-weight: 700; }
.notification-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.notification { display: flex; gap: .75rem; align-items: flex-start; padding: .7rem .8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.notification.is-unread { border-inline-start: 3px solid var(--primary); }
.notification-body { flex: 1; min-inline-size: 0; }
.notification-body p { margin: 0; }
.notification-actions { display: flex; gap: .25rem; }
.sev-critical .notification-icon { color: var(--bad); }
.sev-warning .notification-icon { color: var(--warn); }
.cal-toolbar { display: flex; flex-direction: column; gap: .75rem; }
.cal-nav { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.cal-title { margin: 0 .5rem; font-size: 1.1rem; }
.cal-grid { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-row + .cal-row { border-block-start: 1px solid var(--border); }
.cal-dow { padding: .4rem; font-size: .78rem; font-weight: 600; color: var(--muted); text-align: center; }
.cal-dow abbr { text-decoration: none; }
.cal-cell { min-block-size: 6.2rem; padding: .3rem; display: flex; flex-direction: column; gap: .2rem; min-inline-size: 0; }
.cal-cell + .cal-cell { border-inline-start: 1px solid var(--border); }
.cal-cell.is-outside { background: var(--surface-2); color: var(--muted); }
.cal-cell.is-today .cal-daynum { background: var(--primary); color: var(--on-primary); }
.cal-daynum { align-self: flex-start; min-inline-size: 1.6rem; padding: 0 .3rem; border-radius: 999px; text-align: center; font-size: .82rem; font-weight: 600; color: inherit; text-decoration: none; }
.cal-item { display: flex; align-items: center; gap: .25rem; font-size: .76rem; padding: .1rem .3rem; border-radius: 4px; background: var(--primary-soft); color: var(--text); text-decoration: none; overflow: hidden; }
.cal-item .cal-item-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agenda .cal-item .cal-item-text { white-space: normal; }
.cal-bill { background: var(--warn-soft); }
.cal-payday { background: var(--good-soft); }
.cal-more { font-size: .74rem; }
.agenda { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.agenda-date { font-size: .92rem; margin: 0 0 .4rem; }
.agenda .cal-item { font-size: .9rem; padding: .35rem .5rem; }
@media (max-width: 640px) {
    .cal-cell { min-block-size: 3.6rem; }
    .cal-cell .cal-item .cal-item-text { display: none; }
}
.form-inline, .form.form-inline { display: flex; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem; margin-block-end: 1rem; }
.form-inline input { max-inline-size: 10rem; }
.doc-preview { display: block; max-inline-size: 100%; max-block-size: 28rem; margin: 0 auto 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.task-row { display: flex; align-items: center; gap: .6rem; padding: .6rem 0; border-block-end: 1px solid var(--border); }
.task-main { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; }
.chat { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .6rem; max-block-size: 34rem; overflow-y: auto; }
.chat-q { align-self: flex-end; max-inline-size: 85%; background: var(--primary-soft); padding: .5rem .8rem; border-radius: var(--radius-sm); }
.chat-q p { margin: 0; }
.chat-a { border: 1px solid var(--border); padding: .7rem .9rem; border-radius: var(--radius-sm); }
.assistant-answer p { margin: 0 0 .5rem; }
.assumptions { list-style: none; padding: 0; margin: .4rem 0; font-size: .82rem; color: var(--muted); display: flex; flex-direction: column; gap: .2rem; }
.recovery-codes { columns: 2; font-size: .95rem; margin: .5rem 0 1rem; }
.secret { display: inline-block; overflow-wrap: anywhere; padding: .1rem .35rem; background: var(--surface-2); border-radius: 4px; user-select: all; }
.steps { padding-inline-start: 1.2rem; display: flex; flex-direction: column; gap: .5rem; }
.simple-list .btn { white-space: normal; text-align: start; block-size: auto; }
.grid-2 > *, .stack > *, .content > * { min-inline-size: 0; }
.disclosure { border: 1px solid var(--border); border-radius: var(--radius-sm, 8px); padding: .6rem .8rem; margin-block-start: .6rem; }
.disclosure > summary { cursor: pointer; font-weight: 600; }
.disclosure[open] > summary { margin-block-end: .6rem; }
.simple-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 30%, var(--border)); display: flex; flex-direction: column; gap: .75rem; }
.category-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.5rem; }
.category-tree { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 1.5rem; font-size: .9rem; }
.category-tree li { break-inside: avoid; padding: .15rem 0; }
.category-tree .depth-0 { font-weight: 650; margin-block-start: .5rem; }
.category-tree .depth-1 { padding-inline-start: 1rem; color: var(--text-2); }

/* ---------- Empty states ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .75rem; padding: 2.5rem 1.5rem; }
.empty-state p { max-inline-size: 560px; }
.empty-state-sm { padding: 1.5rem; }
.empty-icon { inline-size: 44px; block-size: 44px; color: var(--primary); padding: .55rem; background: var(--primary-soft); border-radius: 12px; }
.empty-inline { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; padding: .5rem 0; }

/* ---------- Pagination ---------- */
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-block-start: 1rem; font-size: .85rem; }
.pagination-links { display: flex; align-items: center; gap: .5rem; }

/* ---------- Charts ---------- */
.chart { inline-size: 100%; block-size: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--viz-grid); stroke-width: 1; }
.chart-baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart-axis { fill: var(--viz-axis); font-size: 11px; font-family: inherit; }
.chart-hit { fill: transparent; }
.chart-mark:hover .chart-hit { fill: var(--surface-2); }
.bar-1 { fill: var(--series-1); }
.bar-2 { fill: var(--series-2); }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: .9rem; margin: 0; padding: 0; font-size: .82rem; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: .4rem; }
.swatch { inline-size: 10px; block-size: 10px; border-radius: 3px; display: inline-block; }
.swatch-1 { background: var(--series-1); }
.swatch-2 { background: var(--series-2); }
.data-table { margin-block-start: .75rem; font-size: .88rem; }
.data-table summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: .84rem; }
.chart-note { font-size: .78rem; margin-block-start: .5rem; }
.hbar-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .8rem; }
.hbar-head { display: flex; justify-content: space-between; gap: .75rem; font-size: .88rem; margin-block-end: .3rem; }
.hbar-label { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.hbar-value { color: var(--text-2); font-weight: 600; }
.hbar-track { display: block; inline-size: 100%; block-size: 8px; }
[dir="rtl"] .hbar-track { transform: scaleX(-1); }
.hbar-bg { fill: var(--viz-track); }
.hbar-fill { fill: var(--series-1); }

/* ---------- Guest (auth) layout ---------- */
.guest-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); min-height: 100vh; }
.guest-aside {
    position: relative; overflow: hidden; isolation: isolate; color: #e9eef6; display: flex; align-items: center; padding: 3rem;
    background: radial-gradient(90% 70% at 85% 10%, rgba(64, 248, 187, .16), transparent 60%), linear-gradient(160deg, var(--brand-navy) 0%, var(--brand-deep) 45%, var(--brand-royal) 100%);
}
.guest-aside::before {
    content: ""; position: absolute; z-index: -1; inline-size: 520px; aspect-ratio: 1; inset-block-end: -260px; inset-inline-end: -200px;
    border-radius: 50%; border: 2px solid rgba(64, 248, 187, .35); box-shadow: 0 0 60px rgba(64, 248, 187, .18);
}
.guest-logo { inline-size: 88px; block-size: 88px; border-radius: 22px; box-shadow: 0 22px 44px -16px rgba(0, 0, 0, .6); }
.guest-aside-inner { max-inline-size: 440px; display: flex; flex-direction: column; gap: 1.25rem; }
.guest-brand { font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
html[lang="fa"] .guest-brand { text-transform: none; letter-spacing: 0; }
.guest-headline { font-size: 2rem; font-weight: 650; line-height: 1.25; color: #fff; }
.guest-points { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .8rem; font-size: .95rem; }
.guest-points li { display: flex; gap: .6rem; align-items: flex-start; }
.guest-points .icon { margin-block-start: .2em; color: #9cc2f2; }
.guest-main { display: flex; flex-direction: column; align-items: center; padding: 1.5rem; gap: 1.25rem; }
.guest-main:focus { outline: none; }
.guest-top { inline-size: 100%; max-inline-size: 440px; display: flex; justify-content: space-between; align-items: center; }
.guest-card { inline-size: 100%; max-inline-size: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 2rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1rem; margin-block: auto; }
.guest-title { font-size: 1.45rem; }
.guest-switch { text-align: center; font-size: .9rem; color: var(--text-2); }
.guest-foot { max-inline-size: 440px; text-align: center; font-size: .75rem; }
.error-page h1 { font-size: 1.4rem; }

/* ---------- Module colour families ---------- */
.tone-blue { --tone: var(--t-blue); }
.tone-green { --tone: var(--t-green); }
.tone-rose { --tone: var(--t-rose); }
.tone-indigo { --tone: var(--t-indigo); }
.tone-violet { --tone: var(--t-violet); }
.tone-amber { --tone: var(--t-amber); }
.tone-teal { --tone: var(--t-teal); }
.tone-pink { --tone: var(--t-pink); }
.tone-orange { --tone: var(--t-orange); }
.tone-slate { --tone: var(--t-slate); }

/* ---------- Dashboard hero (net worth) ---------- */
.position-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; align-items: stretch; }
.stat-grid-side { grid-template-columns: minmax(0, 1fr); }
.hero-card {
    position: relative; overflow: hidden; isolation: isolate; display: flex; flex-direction: column; gap: .35rem;
    padding: 1.5rem 1.6rem 1.3rem; border-radius: var(--radius-lg); color: #fff;
    background:
        radial-gradient(70% 90% at 0% 100%, rgba(248, 184, 32, .16), transparent 60%),
        linear-gradient(135deg, var(--brand-deep) 0%, var(--brand-royal) 55%, var(--brand-blue) 100%);
    box-shadow: 0 22px 44px -22px rgba(11, 69, 184, .75);
}
.hero-card::before {
    content: ""; position: absolute; z-index: -1; inline-size: 78%; aspect-ratio: 1; inset-block-start: -48%; inset-inline-end: -22%;
    border-radius: 50%; border: 2px solid rgba(64, 248, 187, .55);
    box-shadow: 0 0 46px rgba(64, 248, 187, .28), inset 0 0 36px rgba(64, 248, 187, .16);
}
.hero-card::after {
    content: ""; position: absolute; z-index: -1; inline-size: 55%; aspect-ratio: 1; inset-block-end: -38%; inset-inline-start: -12%;
    border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 255, 255, .13), transparent);
}
:root[data-theme="dark"] .hero-card { background: radial-gradient(70% 90% at 0% 100%, rgba(248, 184, 32, .12), transparent 60%), linear-gradient(135deg, #041a45 0%, #08389a 60%, #1150c8 100%); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .hero-card { background: radial-gradient(70% 90% at 0% 100%, rgba(248, 184, 32, .12), transparent 60%), linear-gradient(135deg, #041a45 0%, #08389a 60%, #1150c8 100%); }
}
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.hero-label { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; font-weight: 600; color: rgba(255, 255, 255, .86); }
.hero-label .icon { color: var(--brand-mint); }
.hero-logo { inline-size: 34px; block-size: 34px; border-radius: 9px; box-shadow: 0 8px 18px -8px rgba(0, 0, 0, .6); }
.hero-value { font-size: clamp(2rem, 7.4vw, 2.65rem); font-weight: 750; letter-spacing: -.02em; line-height: 1.15; margin-block: .1rem .8rem; }
html[lang="fa"] .hero-value { letter-spacing: 0; }
.hero-split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin: 0; }
.hero-split > div {
    min-inline-size: 0; padding: .65rem .8rem; border-radius: 15px;
    background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .16);
    backdrop-filter: blur(6px);
}
.hero-split dt { display: flex; align-items: center; gap: .35rem; font-size: .76rem; font-weight: 600; color: rgba(255, 255, 255, .78); }
.hero-split dd { margin: .15rem 0 0; font-size: 1.08rem; font-weight: 700; }
.hero-help { margin-block-start: auto; padding-block-start: .75rem; font-size: .76rem; line-height: 1.5; color: rgba(255, 255, 255, .74); }
.stat-tone .stat-label { gap: .5rem; }
.stat-icon {
    display: inline-grid; place-items: center; inline-size: 30px; block-size: 30px; border-radius: 10px; flex: none;
    background: color-mix(in srgb, var(--tone) 13%, transparent); color: var(--tone);
}
.stat-icon .icon { inline-size: 17px; block-size: 17px; vertical-align: 0; }

/* ---------- Mobile app bar, tab bar and sheets (hidden on desktop) ---------- */
.topbar-brand { display: none; align-items: center; gap: .55rem; font-weight: 750; font-size: 1.05rem; color: var(--text); margin-inline-end: auto; }
.topbar-brand:hover { text-decoration: none; }
.topbar-brand img { inline-size: 34px; block-size: 34px; border-radius: 9px; box-shadow: 0 6px 14px -6px rgba(3, 26, 64, .55); }
.search-toggle { display: none; }
.sheet-handle { display: none; inline-size: 40px; block-size: 5px; border-radius: 999px; background: var(--border-strong); margin: .3rem auto .6rem; }
.tabbar {
    display: none; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: end;
    position: fixed; z-index: 35; inset-inline: 0; inset-block-end: 0;
    padding: .3rem .4rem calc(.3rem + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
    border-block-start: 1px solid var(--border);
    box-shadow: 0 -10px 30px -18px rgba(15, 23, 42, .3);
}
.tab-item {
    display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: .12rem;
    min-block-size: 54px; padding: .25rem 0 .1rem; border: 0; background: none; cursor: pointer;
    font: inherit; font-size: .69rem; font-weight: 600; color: var(--muted); text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.tab-item:hover { text-decoration: none; color: var(--text); }
.tab-icon { display: grid; place-items: center; inline-size: 58px; block-size: 30px; border-radius: 999px; transition: background-color .2s, transform .15s; }
.tab-icon .icon { inline-size: 22px; block-size: 22px; }
.tab-item.is-active { color: var(--primary); }
.tab-item.is-active .tab-icon { background: var(--primary-soft); }
.tab-item:active .tab-icon, .tab-item:active .tab-add-btn { transform: scale(.9); }
.tab-label { max-inline-size: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-add-btn {
    display: grid; place-items: center; inline-size: 54px; block-size: 54px; margin-block: -24px .1rem; border-radius: 19px; color: #fff;
    background: linear-gradient(135deg, var(--brand-royal) 0%, var(--brand-blue) 55%, #1fc79a 120%);
    box-shadow: 0 0 0 4px var(--bg), 0 12px 22px -8px rgba(11, 69, 184, .75); transition: transform .15s;
}
.tab-add-btn .icon { inline-size: 26px; block-size: 26px; stroke-width: 2.25; }
.tab-add { color: var(--text-2); }

.sheet {
    inline-size: 100%; max-inline-size: 560px; max-block-size: 88vh; margin: auto auto 0; padding: .4rem 1.1rem calc(1.25rem + env(safe-area-inset-bottom));
    border: 0; border-radius: 26px 26px 0 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.sheet .sheet-handle { display: block; }
.sheet::backdrop { background: rgba(6, 12, 28, .5); backdrop-filter: blur(2px); }
.sheet[open] { animation: sheet-up .3s cubic-bezier(.2, .9, .3, 1.05); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-block-end: .9rem; }
.sheet-head h2 { font-size: 1.05rem; }
.sheet-head form { margin: 0; }
.quick-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
.quick-item {
    display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: .9rem .35rem .8rem;
    border-radius: 18px; background: var(--surface-2); color: var(--text); font-size: .8rem; font-weight: 600; text-align: center;
    line-height: 1.3; transition: transform .15s, background-color .15s; -webkit-tap-highlight-color: transparent;
}
.quick-item:hover { text-decoration: none; background: var(--surface-3); }
.quick-item:active { transform: scale(.95); }
.quick-icon {
    display: grid; place-items: center; inline-size: 48px; block-size: 48px; border-radius: 16px;
    background: color-mix(in srgb, var(--tone) 14%, var(--surface)); color: var(--tone);
}
.quick-icon .icon { inline-size: 23px; block-size: 23px; }
@media (min-width: 961px) {
    .sheet { margin: auto; border-radius: var(--radius-lg); }
}
@keyframes sheet-up { from { transform: translateY(40%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Transaction cards (phones) ---------- */
.tx-list { display: none; flex-direction: column; list-style: none; margin: 0 -.4rem; padding: 0; }
.tx-list li + li { border-block-start: 1px solid var(--border); }
.tx-item { display: flex; align-items: center; gap: .75rem; padding: .7rem .4rem; border-radius: 14px; color: var(--text); -webkit-tap-highlight-color: transparent; }
.tx-item:hover { text-decoration: none; background: var(--surface-2); }
.tx-item:active { background: var(--surface-3); }
.tx-ava { display: grid; place-items: center; flex: none; inline-size: 42px; block-size: 42px; border-radius: 14px; }
.tx-ava .icon { inline-size: 20px; block-size: 20px; }
.tx-ava-in { background: var(--good-soft); color: var(--good); }
.tx-ava-out { background: color-mix(in srgb, var(--t-rose) 13%, transparent); color: var(--t-rose); }
.tx-ava-move { background: var(--primary-soft); color: var(--primary); }
.tx-main { flex: 1; min-inline-size: 0; display: flex; flex-direction: column; gap: .1rem; }
.tx-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: .77rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta .icon { inline-size: .9em; block-size: .9em; }
.tx-side { display: flex; flex-direction: column; align-items: flex-end; gap: .15rem; flex: none; }
.tx-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.amount-out { color: var(--text); }
.tx-date { font-size: .74rem; color: var(--muted); white-space: nowrap; }
.tx-item.is-void .tx-title, .tx-item.is-void .tx-amt { color: var(--muted); text-decoration: line-through; }

/* ---------- Reporting-period picker ---------- */
.period-picker { display: flex; flex-direction: column; gap: .75rem; }
.period-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem .75rem; }
.period-title { font-size: 1.05rem; }
.period-range {
    display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .75rem; border-radius: 999px;
    background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 650; font-variant-numeric: tabular-nums;
}
.segmented {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; padding: 4px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 15px;
}
.seg {
    display: flex; align-items: center; justify-content: center; min-block-size: 42px; padding: .35rem .5rem;
    border-radius: 11px; color: var(--text-2); font-size: .86rem; font-weight: 600; text-align: center; line-height: 1.25;
    transition: background-color .15s, color .15s, transform .15s; -webkit-tap-highlight-color: transparent;
}
.seg:hover { text-decoration: none; background: var(--surface); color: var(--text); }
.seg:active { transform: scale(.97); }
.seg.is-active {
    background: var(--primary); color: var(--on-primary);
    box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--primary) 70%, transparent);
}
.period-custom { border: 1px dashed var(--border-strong); border-radius: 15px; }
.period-custom.is-active, .period-custom[open] { border-style: solid; border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.period-custom > summary {
    display: flex; align-items: center; gap: .5rem; min-block-size: 44px; padding: .5rem .9rem; cursor: pointer; list-style: none;
    font-size: .88rem; font-weight: 600; color: var(--text-2); border-radius: 15px; -webkit-tap-highlight-color: transparent;
}
.period-custom > summary::-webkit-details-marker { display: none; }
.period-custom > summary .icon { color: var(--primary); }
.period-custom > summary::after {
    content: ""; margin-inline-start: auto; inline-size: .5rem; block-size: .5rem; border: solid var(--muted);
    border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .2s;
}
.period-custom[open] > summary::after { transform: rotate(-135deg); }
.period-custom.is-active > summary { color: var(--primary); }
.period-custom-form {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: .65rem;
    padding: .1rem .9rem .9rem;
}
.period-custom-form .field label { font-size: .8rem; color: var(--muted); }
.cashflow-card { display: flex; flex-direction: column; gap: 1rem; }
.report-nav { display: flex; align-items: center; justify-content: center; gap: .4rem; }
.report-nav .period-range { min-inline-size: 0; white-space: nowrap; }
.cashflow-card .stat-grid-flow { gap: .75rem; }
.cashflow-card .stat-grid-flow > .stat { background: var(--surface-2); border-color: transparent; box-shadow: none; }
.cashflow-card .note { margin: 0; }

/* ---------- Choice controls: one structure everywhere ----------
 * "Pick one of a few" = segmented control (.tabs, .segmented).
 * "Pick one of many"  = grid of icon tiles (.type-grid).
 * "Pick several"      = grid of check tiles inside a disclosure (.check-grid).
 */
.tabs {
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 15px;
}
.tab {
    display: flex; align-items: center; justify-content: center; gap: .4rem; min-block-size: 42px; padding: .35rem .6rem;
    border-radius: 11px; color: var(--text-2); font-size: .88rem; font-weight: 600; text-align: center; line-height: 1.25;
    transition: background-color .15s, color .15s; -webkit-tap-highlight-color: transparent;
}
.tab:hover { text-decoration: none; background: var(--surface); color: var(--text); }
.tab.is-active { background: var(--primary); color: var(--on-primary); box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--primary) 70%, transparent); }
.tab .icon { flex: none; }

.type-picker > legend { margin-block-end: .5rem; }
.type-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
.type-tile { position: relative; display: block; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.type-tile input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.type-tile-body {
    display: flex; align-items: center; gap: .65rem; block-size: 100%; min-block-size: 58px; padding: .6rem .75rem;
    border: 1.5px solid var(--border); border-radius: 16px; background: var(--surface);
    transition: border-color .15s, background-color .15s, transform .15s, box-shadow .15s;
}
.type-tile:hover .type-tile-body { border-color: var(--border-strong); }
.type-tile:active .type-tile-body { transform: scale(.97); }
.type-tile-icon {
    display: grid; place-items: center; flex: none; inline-size: 36px; block-size: 36px; border-radius: 12px;
    background: color-mix(in srgb, var(--tone) 13%, transparent); color: var(--tone);
}
.type-tile-icon .icon { inline-size: 19px; block-size: 19px; }
.type-tile-label { min-inline-size: 0; font-size: .86rem; font-weight: 600; line-height: 1.3; color: var(--text); }
.type-tile input:checked + .type-tile-body {
    border-color: var(--tone); background: color-mix(in srgb, var(--tone) 9%, var(--surface));
    box-shadow: 0 0 0 1px var(--tone), 0 8px 18px -10px color-mix(in srgb, var(--tone) 70%, transparent);
}
.type-tile input:checked + .type-tile-body .type-tile-icon { background: var(--tone); color: #fff; }
.type-tile input:focus-visible + .type-tile-body { outline: 2px solid var(--focus); outline-offset: 2px; }
.has-error .type-tile-body { border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }

.disclosure-panel { border: 1px solid var(--border); border-radius: 15px; background: var(--surface); }
.disclosure-panel > summary {
    display: flex; align-items: center; gap: .5rem; min-block-size: 46px; padding: .55rem .9rem; cursor: pointer; list-style: none;
    font-size: .9rem; font-weight: 600; color: var(--text); border-radius: 15px; -webkit-tap-highlight-color: transparent;
}
.disclosure-panel > summary::-webkit-details-marker { display: none; }
.disclosure-panel > summary > .icon { color: var(--primary); }
.disclosure-panel > summary::after {
    content: ""; margin-inline-start: auto; inline-size: .5rem; block-size: .5rem; border: solid var(--muted);
    border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .2s;
}
.disclosure-panel[open] > summary::after { transform: rotate(-135deg); }
.disclosure-panel[open] > summary { border-block-end: 1px solid var(--border); border-end-start-radius: 0; border-end-end-radius: 0; }
.disclosure-body { padding: .85rem .9rem .9rem; gap: .85rem; }
.disclosure-body > .btn { align-self: flex-start; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .5rem; }
.check-tile {
    position: relative; display: flex; align-items: center; gap: .6rem; min-block-size: 46px; padding: .5rem .75rem;
    border: 1.5px solid var(--border); border-radius: 13px; background: var(--surface); cursor: pointer;
    font-size: .86rem; font-weight: 550; line-height: 1.3; -webkit-tap-highlight-color: transparent;
}
.check-tile input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.check-mark {
    display: grid; place-items: center; flex: none; inline-size: 22px; block-size: 22px; border-radius: 7px;
    border: 1.5px solid var(--border-strong); color: transparent; background: var(--surface);
}
.check-mark .icon { inline-size: 15px; block-size: 15px; stroke-width: 2.5; }
.check-tile:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.check-tile input:checked + .check-mark { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.check-tile input:focus-visible + .check-mark { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Light / dark toggle ---------- */
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-toggle .i-sun { display: inline; }
    :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}
.theme-toggle .icon { transition: transform .35s ease; }
.theme-toggle:active .icon { transform: rotate(-30deg) scale(.9); }
.guest-actions { display: flex; align-items: center; gap: .25rem; }
@media (prefers-reduced-motion: no-preference) {
    html.theme-anim, html.theme-anim *, html.theme-anim *::before, html.theme-anim *::after {
        transition: background-color .3s ease, border-color .3s ease, color .3s ease, fill .3s ease !important;
    }
}

/* ---------- Collapsible filter panel ---------- */
.filters-panel, .filters-panel.card { padding: 0; }
.filters-summary {
    display: flex; align-items: center; gap: .6rem; padding: .85rem 1.25rem; cursor: pointer; list-style: none;
    font-weight: 650; border-radius: var(--radius); -webkit-tap-highlight-color: transparent;
}
.filters-summary::-webkit-details-marker { display: none; }
.filters-summary::after {
    content: ""; margin-inline-start: auto; inline-size: .55rem; block-size: .55rem; border: solid var(--muted);
    border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .2s;
}
.filters-panel[open] > .filters-summary::after { transform: rotate(-135deg); }
.filters-panel[open] > .filters-summary { border-block-end: 1px solid var(--border); border-end-start-radius: 0; border-end-end-radius: 0; }
.filters-summary-label { display: inline-flex; align-items: center; gap: .5rem; }
.filters-summary-label .icon { color: var(--primary); }
.filters-panel .filters { padding: 1rem 1.25rem 1.25rem; }

/* ---------- Gentle entrance (disabled for reduced motion) ---------- */
.content > * { animation: rise .32s ease-out both; }
.content > :nth-child(2) { animation-delay: .03s; }
.content > :nth-child(3) { animation-delay: .06s; }
.content > :nth-child(4) { animation-delay: .09s; }
.content > :nth-child(n+5) { animation-delay: .12s; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .position-grid { grid-template-columns: minmax(0, 1fr); }
    .stat-grid-side { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
    .app, .app.is-collapsed { grid-template-columns: minmax(0, 1fr); }
    .main-col { padding-block-end: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
    html.nav-locked { overflow: hidden; }

    /* "More" sheet: the sidebar becomes a bottom sheet with a grid of module tiles. */
    .sidebar, [dir="rtl"] .sidebar {
        position: fixed; z-index: 50; inset-inline: 0; inset-block: auto 0; inline-size: 100%; block-size: auto;
        max-block-size: 86vh; max-block-size: 86dvh; border: 0; border-radius: 26px 26px 0 0;
        padding: .4rem 1rem calc(1rem + env(safe-area-inset-bottom));
        box-shadow: var(--shadow-lg); visibility: hidden; transform: translateY(105%);
        transition: transform .32s cubic-bezier(.2, .9, .3, 1), visibility 0s linear .32s;
    }
    .app.nav-open .sidebar { transform: none; visibility: visible; transition: transform .32s cubic-bezier(.2, .9, .3, 1), visibility 0s; }
    .sidebar .sheet-handle { display: block; }
    .sidebar-head { padding: 0 .25rem .25rem; }
    .sidebar .sidebar-close { display: inline-grid; }
    .app.is-collapsed .brand-text, .app.is-collapsed .nav-label, .app.is-collapsed .nav-status, .app.is-collapsed .nav-section-title { display: revert; }
    .app.is-collapsed .sidebar-head { justify-content: space-between; }
    .nav-section { margin-block-end: .25rem; }
    .nav-section-title { padding: .7rem .35rem .35rem; }
    .nav-section ul { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .25rem; }
    .nav-link, .app.is-collapsed .nav-link {
        flex-direction: column; justify-content: flex-start; gap: .4rem; padding: .55rem .15rem .5rem;
        border-radius: 16px; color: var(--text); font-size: .72rem; line-height: 1.3; text-align: center;
        -webkit-tap-highlight-color: transparent; transition: transform .15s;
    }
    .nav-link:hover { background: var(--surface-2); }
    .nav-link:active { transform: scale(.95); }
    .nav-icon {
        inline-size: 50px; block-size: 50px; border-radius: 17px;
        background: color-mix(in srgb, var(--tone) 13%, transparent); color: var(--tone);
    }
    .nav-icon .icon { inline-size: 23px; block-size: 23px; }
    .nav-label { flex: none; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .nav-link.is-active { background: transparent; color: var(--primary); }
    .nav-link.is-active .nav-icon { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--tone); }
    .backdrop { display: block; position: fixed; inset: 0; background: rgba(6, 12, 28, .5); z-index: 40; backdrop-filter: blur(2px); }

    /* Compact app bar */
    .topbar { flex-wrap: wrap; column-gap: .25rem; row-gap: 0; padding: .5rem .75rem; padding-block-start: calc(.5rem + env(safe-area-inset-top)); }
    .topbar-brand { flex: 1 1 0; min-inline-size: 0; }
    .topbar-brand span { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar .icon-btn { inline-size: 38px; }
    .topbar-actions { flex: none; gap: 0; }
    .topbar-actions .inline-form .btn, .topbar-actions .menu > summary { padding-inline: .45rem; }
    .nav-toggle, .collapse-toggle, .topbar-add { display: none; }
    .topbar-brand { display: inline-flex; }
    .search-toggle { display: inline-grid; }
    .search { display: none; order: 10; flex-basis: 100%; max-inline-size: none; margin-block: .35rem .15rem; }
    .topbar.search-open .search { display: block; }
    .topbar .icon-btn { inline-size: 40px; block-size: 40px; border-radius: 12px; }
    .tabbar { display: grid; }
    .hero-logo { display: none; }

    .grid-2, .category-columns { grid-template-columns: minmax(0, 1fr); }
    .guest-shell { grid-template-columns: minmax(0, 1fr); }
    .guest-aside { display: none; }
    /* Guest pages on phones: brand band behind the card. */
    .guest-main { background: linear-gradient(180deg, var(--brand-navy) 0, var(--brand-royal) 220px, var(--bg) 220px); padding-block-start: calc(1.25rem + env(safe-area-inset-top)); }
    .guest-top .brand, .guest-top .btn-ghost, .guest-top .icon-btn { color: #fff; }
    .guest-top .icon-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
    .guest-top .btn-ghost:hover { background: rgba(255, 255, 255, .12); color: #fff; }
    .guest-card { box-shadow: var(--shadow-lg); margin-block: .5rem auto; }
}
@media (max-width: 640px) {
    body { font-size: 15px; }
    .content { padding: 1rem 1rem 1.5rem; gap: 1.1rem; }
    .hide-sm { display: none; }
    .page-head { align-items: flex-start; gap: .75rem; }
    .page-actions { inline-size: 100%; }
    .page-actions > .btn { flex: 1 1 auto; }
    .form-grid, .details { grid-template-columns: minmax(0, 1fr); }
    .card { padding: 1.05rem; border-radius: 18px; }
    .stat { border-radius: 16px; padding: .85rem .95rem; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
    .stat-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }
    /* Dashboard figures on phones: one grouped list card, label and amount on one row. */
    .stat-grid-side, .stat-grid-flow {
        display: flex; flex-direction: column; gap: 0; padding: .2rem 0; background: var(--surface);
        border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
    }
    .stat-grid-side > .stat, .stat-grid-flow > .stat {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: .75rem; row-gap: .1rem;
        padding: .75rem .95rem; border: 0; border-radius: 0; box-shadow: none; background: none;
    }
    .stat-grid-side > .stat + .stat, .stat-grid-flow > .stat + .stat { border-block-start: 1px solid var(--border); }
    .stat-grid-side .stat-label, .stat-grid-flow .stat-label { font-size: .88rem; color: var(--text); }
    .stat-grid-side .stat-value, .stat-grid-flow .stat-value { font-size: 1.02rem; text-align: end; }
    .stat-grid-side .stat-help, .stat-grid-flow .stat-help { grid-column: 1 / -1; padding-inline-start: calc(30px + .5rem); }
    .filters-summary { padding: .8rem 1rem; }
    .type-grid { gap: .5rem; }
    .type-tile-body { flex-direction: column; justify-content: center; gap: .4rem; min-block-size: 86px; padding: .65rem .35rem; text-align: center; }
    .type-tile-icon { inline-size: 40px; block-size: 40px; border-radius: 13px; }
    .type-tile-label { font-size: .8rem; }
    .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .check-tile { font-size: .82rem; padding-inline: .6rem; }
    .disclosure-body > .btn { align-self: stretch; }
    .tab { padding-inline: .3rem; font-size: .84rem; }
    .tab .icon { display: none; }
    /* Period picker on phones: presets as a 3 + 2 segmented grid, dates in two columns. */
    .segmented { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .seg { grid-column: span 2; min-block-size: 44px; font-size: .84rem; }
    .seg:nth-child(n+4) { grid-column: span 3; }
    .period-custom-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .form-inline, .form.form-inline { display: grid; grid-template-columns: minmax(0, 1fr); align-items: stretch; }
    .form-inline input { max-inline-size: none; }
    .period-custom-form .btn { grid-column: 1 / -1; }
    .period-custom-form input[type="date"] { min-inline-size: 0; padding-inline: .6rem; }
    .cashflow-card { gap: .9rem; }
    .cashflow-card .stat-grid-flow { padding: 0; background: none; border: 0; box-shadow: none; border-radius: 0; }
    .cashflow-card .stat-grid-flow > .stat { background: none; padding-inline: 0; }
    .filters-panel .filters { padding: .9rem 1rem 1rem; }
    .stat-sm .stat-value, .stat-value { font-size: clamp(1.02rem, 4.6vw, 1.2rem); }
    .stat-help { font-size: .72rem; }
    .guest-card { padding: 1.35rem; }
    .category-tree { columns: 1; }
    h1 { font-size: 1.4rem; }
    input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
        font-size: 16px; min-block-size: 46px; border-radius: 12px;
    }
    .btn { min-block-size: 44px; border-radius: 12px; }
    .btn-sm { min-block-size: 38px; }
    .form-actions .btn { flex: 1 1 auto; }
    .tx-table-wrap { display: none; }
    .tx-list { display: flex; }
    .footer { font-size: .72rem; padding: .5rem 1rem 1.25rem; }
    .hero-card { padding: 1.2rem 1.15rem 1.1rem; border-radius: 24px; }
    .hero-split { gap: .5rem; }
    .hero-split dd { font-size: .98rem; }
}
@media (max-width: 380px) {
    .topbar-brand span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (forced-colors: active) {
    .bar-1, .bar-2, .hbar-fill { fill: CanvasText; }
    .swatch { forced-color-adjust: none; }
}

/* Sub-form groups (e.g. payroll breakdown) */
.subform { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 1rem; gap: .75rem; }
.subform legend { padding-inline: .35rem; }

/* ---------- Print (reports print view, browser "Save as PDF") ---------- */
@media print {
    .sidebar, .topbar, .backdrop, .no-print, .skip-link, .footer, .flash { display: none !important; }
    .app, .main-col, .content { display: block; margin: 0; padding: 0; }
    body { background: #fff; color: #000; }
    .card, .stat { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
    a { color: inherit; text-decoration: none; }
}
