/* ==========================================================================
   Kawa UI — سیستم طراحی (راست‌به‌چپ، روشن/تیره، شیشه‌ای فقط روی منو و کارت‌های خلاصه)
   ترتیب فایل: ۱) فونت ۲) توکن‌ها ۳) پایه ۴) چیدمان ۵) کامپوننت‌ها ۶) ریسپانسیو ۷) چاپ
   رنگ اصلی از «تنظیمات برند» می‌آید (--primary در base.html)؛ بقیه‌ی رنگ‌ها از همین توکن‌ها.
   ========================================================================== */

/* ---------- ۱) فونت (محلی؛ فایل را در core/static/core/fonts/ بگذار) ---------- */
@font-face {
    font-family: 'Vazirmatn';
    src: url('../fonts/Vazirmatn-Variable.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

/* ---------- ۲) توکن‌ها ---------- */
:root {
    color-scheme: light;
    --danger: #b42318;
    --danger-fg: #ffffff;
    /* نام‌های قدیمی که هنوز در بعضی قالب‌ها استفاده می‌شوند */
    --card-bg: var(--surface);
    --primary-dark: var(--primary-hover);
    --accent-light: #e4f0cc;
    --primary: #022f12;
    --primary-hover: #021408;
    --primary-hover: color-mix(in srgb, var(--primary) 80%, #000);
    --accent: #8bc53d;
    --primary-ui: var(--primary);          /* رنگ تأکید روی سطح‌های روشن */
    --btn-bg: var(--primary);
    --btn-fg: #ffffff;
    --btn-hover: var(--primary-hover);

    --bg: #f3f7ef;
    --surface: #ffffff;
    --surface-2: #eff4ea;
    --hover: rgba(2, 47, 18, .05);
    --text: #14231a;
    --text-light: #52655a;
    --border: #dbe4d6;
    --link: #0b5d2e;

    --debit: #b42318;
    --credit: #217a3c;
    --ok-bg: #dff3e5;   --ok-fg: #14562b;
    --warn-bg: #fdf0cf; --warn-fg: #7a4b00;
    --bad-bg: #fde3e0;  --bad-fg: #9b1c14;

    --glass-bg: rgba(255, 255, 255, .66);
    --glass-strong: rgba(255, 255, 255, .9);
    --glass-border: rgba(255, 255, 255, .9);
    --glass-filter: blur(14px) saturate(150%);

    --shadow: 0 1px 3px rgba(16, 40, 26, .08);
    --shadow-lg: 0 10px 32px rgba(16, 40, 26, .12);
    --bg-art:
        radial-gradient(640px 460px at 92% -4%, rgba(139, 197, 61, .28), transparent 70%),
        radial-gradient(560px 460px at 2% 100%, rgba(120, 170, 230, .22), transparent 70%);

    --radius: 16px;
    --radius-sm: 12px;
    --sidebar-w: 248px;
    --gap: 14px;
    --logo-h: 42px;
    --logo-h-m: 32px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --danger: #ff8f84;
    --danger-fg: #3a0a05;
    --accent-light: rgba(139, 197, 61, .16);
    --primary-ui: var(--accent);
    --btn-bg: var(--accent);
    --btn-fg: #062010;
    --btn-hover: #a3d65e;

    --bg: #07140d;
    --surface: #0f2318;
    --surface-2: #143024;
    --hover: rgba(255, 255, 255, .06);
    --text: #e7f2ea;
    --text-light: #aac5b6;
    --border: rgba(255, 255, 255, .13);
    --link: #8bc53d;

    --debit: #ff9a8f;
    --credit: #7fdc9b;
    --ok-bg: #12432a;   --ok-fg: #9ff0c0;
    --warn-bg: #4a3710; --warn-fg: #ffd98a;
    --bad-bg: #4d1d19;  --bad-fg: #ffb4ac;

    --glass-bg: rgba(255, 255, 255, .07);
    --glass-strong: rgba(15, 35, 24, .92);
    --glass-border: rgba(255, 255, 255, .15);

    --shadow: 0 1px 3px rgba(0, 0, 0, .45);
    --shadow-lg: 0 10px 32px rgba(0, 0, 0, .5);
    --bg-art:
        radial-gradient(640px 460px at 92% -4%, rgba(20, 120, 70, .45), transparent 70%),
        radial-gradient(560px 460px at 2% 100%, rgba(30, 70, 130, .35), transparent 70%);
}

/* شیشه فقط وقتی مرورگر پشتیبانی می‌کند و کاربر «کاهش شفافیت/کنتراست بالا» نخواسته؛ وگرنه سطح مات */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    :root, [data-theme="dark"] { --glass-bg: var(--surface); --glass-strong: var(--surface); --glass-filter: none; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
    :root, [data-theme="dark"] { --glass-bg: var(--surface); --glass-strong: var(--surface); --glass-filter: none; --glass-border: var(--border); }
}

/* ---------- ۳) پایه ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 90px; }
body {
    font-family: 'Vazirmatn', Tahoma, system-ui, sans-serif;
    font-size: 14.5px; line-height: 1.65;
    background: var(--bg); color: var(--text);
    min-height: 100vh; min-height: 100dvh;
    font-variant-numeric: tabular-nums;
}
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: var(--bg-art); pointer-events: none; }
body.no-scroll { overflow: hidden; }
a { color: var(--link); }
a:focus-visible, button:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px;
}
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--text-light); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    -webkit-backdrop-filter: var(--glass-filter);
    backdrop-filter: var(--glass-filter);
    box-shadow: var(--shadow-lg);
}

/* ---------- ۴) چیدمان ---------- */
.sidebar {
    position: fixed; top: var(--gap); bottom: var(--gap); right: var(--gap);
    width: var(--sidebar-w); z-index: 100;
    display: flex; flex-direction: column; border-radius: 22px; overflow: hidden;
}
.sidebar-head { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 18px 16px 10px; }
.sidebar-head .drawer-close { position: absolute; inset-inline-end: 12px; top: 14px; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 4px 10px 10px; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); display: grid; gap: 6px; }

.nav-link {
    display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 9px 12px;
    border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 500; font-size: 14px;
    background: none; border: 0; font-family: inherit; cursor: pointer; width: 100%; text-align: right;
}
.nav-link:hover { background: var(--hover); }
.nav-link[aria-current="page"] { background: var(--btn-bg); color: var(--btn-fg); }
.nav-group > summary {
    list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; font-size: 12px; font-weight: 700; color: var(--text-light); border-radius: 10px;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after {
    content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: rotate(45deg); transition: transform .2s; margin-top: -3px;
}
.nav-group[open] > summary::after { transform: rotate(-135deg); margin-top: 3px; }
.nav-group > summary:hover { background: var(--hover); }
.nav-links { display: grid; gap: 2px; padding-bottom: 6px; }

.brand-logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--text); text-decoration: none; min-width: 0; }
.brand-logo img { height: var(--logo-h); width: auto; max-width: 150px; object-fit: contain; border-radius: 8px; }
.brand-svg { width: 48px; height: 48px; flex: none; display: block; filter: drop-shadow(0 4px 10px rgba(2, 38, 16, .25)); }
.appbar-brand .brand-svg { width: 38px; height: 38px; }
.auth-brand .brand-svg { width: 76px; height: 76px; }
.brand-name { font-weight: 800; font-size: 17px; line-height: 1.2; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--btn-bg); color: var(--btn-fg); display: grid; place-items: center; font-weight: 800; flex: none; }

.overlay { display: none; position: fixed; inset: 0; z-index: 90; background: rgba(4, 14, 9, .5); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.overlay.open { display: block; }

.main { margin-right: calc(var(--sidebar-w) + var(--gap) * 2); padding: var(--gap) 24px 48px var(--gap); min-width: 0; }
.page { max-width: 1280px; margin-inline: auto; }
.appbar {
    position: sticky; top: var(--gap); z-index: 60; display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; min-height: 56px; border-radius: 18px; margin-bottom: 20px;
}
.appbar .spacer { flex: 1; }
.menu-toggle, .drawer-close, .appbar-brand { display: none; }
.icon-btn {
    width: 42px; height: 42px; display: grid; place-items: center; flex: none; cursor: pointer;
    border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

.bottom-nav {
    display: none; position: fixed; z-index: 80; right: 10px; left: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
    padding: 6px; border-radius: 22px; align-items: center; justify-content: space-around;
}
.tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px;
    color: var(--text-light); text-decoration: none; font-size: 10.5px; font-weight: 600; white-space: nowrap;
    background: none; border: 0; font-family: inherit; cursor: pointer; border-radius: 14px;
}
.tab[aria-current="page"] { color: var(--primary-ui); }
.tab-fab {
    flex: none; width: 54px; height: 54px; margin: -26px 6px 0; border-radius: 18px; display: grid; place-items: center;
    background: var(--btn-bg); color: var(--btn-fg); box-shadow: var(--shadow-lg);
}

/* ---------- ۵) کامپوننت‌ها ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.topbar h1 { font-size: 21px; font-weight: 700; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 9px 18px;
    background: var(--btn-bg); color: var(--btn-fg); border: 0; border-radius: var(--radius-sm);
    text-decoration: none; font-size: 14px; font-weight: 600; font-family: inherit; cursor: pointer;
    transition: background .15s, transform .05s;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 13px; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--hover); }
.btn-danger { background: var(--danger); color: var(--danger-fg); }
.btn-danger:hover { background: var(--danger); filter: brightness(.93); }
.btn-block { width: 100%; }

.chip, .chip-warn, .chip-bad, .chip-danger { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip { background: var(--ok-bg); color: var(--ok-fg); }
.chip-warn { background: var(--warn-bg); color: var(--warn-fg); }
.chip-bad, .chip-danger { background: var(--bad-bg); color: var(--bad-fg); }
.badge-debit { color: var(--debit); font-weight: 600; }
.badge-credit { color: var(--credit); font-weight: 600; }

table {
    width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
th, td { padding: 11px 14px; text-align: right; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { background: var(--surface-2); font-weight: 600; color: var(--text-light); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--hover); }
th.num, td.num { text-align: left; }
.table-scroll { overflow-x: auto; border-radius: 14px; -webkit-overflow-scrolling: touch; }
.table-scroll table { box-shadow: none; }

input, select, textarea {
    width: 100%; min-height: 42px; padding: 9px 12px; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: inherit; font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; line-height: 1.7; }
input::placeholder, textarea::placeholder { color: var(--text-light); opacity: .8; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 197, 61, .38);
}
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; padding: 0; margin: 0; accent-color: var(--primary-ui); cursor: pointer; }
label { display: block; margin: 10px 0 5px; font-size: 13px; color: var(--text-light); }
.search-box { max-width: 340px; margin-bottom: 16px; }
.jalali-date-group, .jalali-datetime-group { display: flex; gap: 6px; flex-wrap: wrap; }
.jalali-part { width: auto; min-width: 84px; flex: 1; }
.jalali-time { min-width: 68px; }

.messages { list-style: none; margin-bottom: 16px; display: grid; gap: 6px; }
.messages li { background: var(--ok-bg); color: var(--ok-fg); padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; }
.messages li.msg-warning { background: var(--warn-bg); color: var(--warn-fg); }
.messages li.msg-error { background: var(--bad-bg); color: var(--bad-fg); }

.stats-row { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-box {
    flex: 1; min-width: 150px; padding: 16px 18px; border-radius: var(--radius);
    background: var(--glass-bg); border: 1px solid var(--glass-border); box-shadow: var(--shadow);
    -webkit-backdrop-filter: var(--glass-filter); backdrop-filter: var(--glass-filter);
}
.stat-box .label { font-size: 12.5px; color: var(--text-light); margin-bottom: 6px; }
.stat-box .value { font-size: 18px; font-weight: 800; }

.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 200; align-items: flex-start; justify-content: center;
    padding: 30px 16px; overflow-y: auto; background: rgba(4, 14, 9, .55);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal-box {
    width: 100%; max-width: 480px; padding: 24px; border-radius: 20px;
    background: var(--glass-strong); border: 1px solid var(--glass-border); box-shadow: var(--shadow-lg);
    -webkit-backdrop-filter: var(--glass-filter); backdrop-filter: var(--glass-filter);
}
.modal-box h3 { margin-bottom: 16px; font-size: 16px; }
.modal-close { float: left; background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--text-light); }

.task-list { list-style: none; padding: 0; margin: 10px 0 0; counter-reset: task; }
.task-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); counter-increment: task; }
.task-item:last-child { border-bottom: 0; }
.task-item::before { content: counter(task) "."; color: var(--text-light); font-size: 13px; min-width: 22px; }
.task-toggle { display: flex; align-items: center; gap: 10px; flex: 1; margin: 0; }
.task-text { flex: 1; line-height: 1.8; }
.task-author { color: var(--text-light); font-size: 12.5px; }
.task-item.done .task-text { text-decoration: line-through; color: var(--text-light); }
.task-actions { display: flex; align-items: center; gap: 12px; font-size: 12.5px; }
.task-actions form { margin: 0; }
.task-delete { background: none; border: 0; color: var(--debit); cursor: pointer; font-family: inherit; font-size: 12.5px; padding: 0; }

.reminder-toasts { position: fixed; bottom: 20px; left: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; max-width: 340px; }
.reminder-toast {
    background: var(--glass-strong); border: 1px solid var(--glass-border); border-right: 5px solid var(--accent);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 14px 16px;
    -webkit-backdrop-filter: var(--glass-filter); backdrop-filter: var(--glass-filter);
}
.reminder-toast h4 { margin-bottom: 4px; font-size: 14px; }
.reminder-toast p { font-size: 12.5px; color: var(--text-light); margin-bottom: 10px; }
.reminder-toast .toast-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- ۶) ریسپانسیو ---------- */
@media (max-width: 900px) { .report-grid { grid-template-columns: 1fr; } }
@media (max-width: 1023px) {
    .sidebar {
        top: 0; bottom: 0; right: 0; width: min(86vw, 310px); border-radius: 22px 0 0 22px;
        transform: translateX(110%); visibility: hidden; transition: transform .25s ease, visibility .25s;
    }
    .sidebar.open { transform: none; visibility: visible; }
    .main { margin-right: 0; padding: 10px 14px 40px; }
    .menu-toggle, .drawer-close, .appbar-brand { display: grid; }
    .appbar-brand { display: inline-flex; }
    .appbar { top: 10px; }
}
@media (max-width: 700px) {
    body { font-size: 14px; }
    .bottom-nav { display: flex; }
    .main { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
    .appbar-cta { display: none; }
    .topbar h1 { font-size: 18px; }
    .card { padding: 16px; border-radius: 14px; }
    th, td { padding: 9px 10px; font-size: 12.5px; }
    input, select, textarea { font-size: 16px; }       /* جلوگیری از زوم خودکار iPhone */
    .stat-box { min-width: 140px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .kpi-card { padding: 12px 14px; }
    .kpi-value { font-size: 16.5px; }
    .auth-card { padding: 26px 20px; }
    .hero { padding: 16px; }
    .reminder-toasts { left: 10px; right: 10px; max-width: none; bottom: calc(92px + env(safe-area-inset-bottom)); }
}
@media (pointer: coarse) {
    .btn, .nav-link, .icon-btn { min-height: 44px; }
    .btn-sm { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- ۵ب) ورود، داشبورد، صفحه‌ی خانه ---------- */
.auth-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-theme { position: fixed; top: 14px; left: 14px; }
.auth-card {
    width: 100%; max-width: 400px; padding: 32px 28px; border-radius: 24px;
    background: var(--glass-strong); border: 1px solid var(--glass-border); box-shadow: var(--shadow-lg);
    -webkit-backdrop-filter: var(--glass-filter); backdrop-filter: var(--glass-filter);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; text-align: center; }
.auth-brand img { height: calc(var(--logo-h) * 1.4); width: auto; max-width: 200px; object-fit: contain; }
.auth-brand .brand-mark { width: 56px; height: 56px; border-radius: 18px; font-size: 24px; }
.auth-brand h1 { font-size: 19px; font-weight: 800; }
.auth-brand p { font-size: 13px; color: var(--text-light); }
.auth-card .btn { width: 100%; min-height: 46px; margin-top: 14px; font-size: 15px; }
.auth-error { background: var(--bad-bg); color: var(--bad-fg); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 12px; }
.field-error { color: var(--bad-fg); font-size: 12.5px; margin-top: 4px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-left: 46px; }
.pw-toggle {
    position: absolute; top: 50%; left: 6px; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center;
    border: 0; background: none; color: var(--text-light); cursor: pointer; border-radius: 10px;
}
.pw-toggle:hover { background: var(--hover); }

.kpi-section-title { font-size: 13px; font-weight: 700; color: var(--text-light); margin: 4px 2px 10px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-card {
    padding: 16px 18px; border-radius: var(--radius); background: var(--glass-bg); border: 1px solid var(--glass-border);
    border-right: 4px solid var(--border); box-shadow: var(--shadow);
    -webkit-backdrop-filter: var(--glass-filter); backdrop-filter: var(--glass-filter);
}
.kpi-label { font-size: 12.5px; color: var(--text-light); margin-bottom: 6px; }
.kpi-value { font-size: 20px; font-weight: 800; line-height: 1.35; }
.kpi-sub { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.kpi-card.sale, .kpi-card.cash-in { border-right-color: var(--credit); }
.kpi-card.buy, .kpi-card.cash-out { border-right-color: var(--debit); }
.kpi-card.profit { border-right-color: var(--accent); }
.kpi-card.warn { border-right-color: #e0a02b; }

.report-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; align-items: start; }
.rank-list { list-style: none; }
.rank-list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.rank-list li:last-child { border-bottom: 0; }
.rank-name { display: flex; gap: 8px; min-width: 0; }
.rank-num { color: var(--text-light); min-width: 18px; }
.card h3 { font-size: 15px; margin-bottom: 10px; }

.disclosure { padding: 0; }
.disclosure > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; font-weight: 700; font-size: 14px; }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--text-light); border-bottom: 2px solid var(--text-light); transform: rotate(45deg); transition: transform .2s; }
.disclosure[open] > summary::after { transform: rotate(-135deg); }
.disclosure[open] > summary { border-bottom: 1px solid var(--border); }
.disclosure-body { padding: 14px 18px; }
.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.link-grid a { display: block; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); text-decoration: none; font-size: 13.5px; }
.link-grid a:hover { background: var(--hover); }
.filter-form { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.filter-form > div { min-width: 0; }

.trend { position: relative; }
.trend svg { display: block; width: 100%; height: auto; overflow: visible; }
.trend .grid-line { stroke: var(--border); stroke-width: 1; }
.trend .axis-label { fill: var(--text-light); font-size: 11px; }
.trend .line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.trend .line-sale { stroke: var(--credit); }
.trend .line-buy { stroke: var(--debit); }
.trend .area-sale { fill: var(--credit); opacity: .12; }
.trend .area-buy { fill: var(--debit); opacity: .1; }
.trend .dot-sale { fill: var(--credit); }
.trend .dot-buy { fill: var(--debit); }
.trend .hover-line { stroke: var(--text-light); stroke-dasharray: 3 3; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-light); margin-bottom: 8px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; }
.chart-legend .lg-sale { background: var(--credit); }
.chart-legend .lg-buy { background: var(--debit); }
.card-alert { border-right: 4px solid var(--debit); }
.chart-tip {
    position: absolute; z-index: 5; pointer-events: none; min-width: 150px; padding: 8px 10px; border-radius: 10px; font-size: 12.5px;
    background: var(--glass-strong); border: 1px solid var(--glass-border); box-shadow: var(--shadow-lg);
}

.hero { padding: 20px 22px; margin-bottom: 18px; border-radius: 20px; display: flex; gap: 18px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.hero h2 { font-size: 20px; }
.hero p { color: var(--text-light); font-size: 13px; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; }
.inline-form > div { flex: 1; min-width: 0; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.quick-tile {
    display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: var(--radius); color: var(--text); text-decoration: none; font-weight: 600;
    background: var(--glass-bg); border: 1px solid var(--glass-border); box-shadow: var(--shadow);
    -webkit-backdrop-filter: var(--glass-filter); backdrop-filter: var(--glass-filter);
}
.quick-tile:hover { border-color: var(--accent); }
.quick-tile .i { width: 22px; height: 22px; color: var(--primary-ui); }
.task-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.task-boxes .card { margin-bottom: 0; }
.card-accent { border-right: 4px solid var(--accent); }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--text); }

/* ---------- ۵ج) فاکتور، فرم‌ها، لیست‌ها ---------- */
.text-bad { color: var(--debit); }
.panel { padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.totals-bar { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 14px; display: flex; gap: 8px 24px; flex-wrap: wrap; }
.picker-scroll { max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.row-total td { background: var(--surface-2); font-weight: 700; }
.product-pick { flex: 1; cursor: pointer; min-width: 0; }
.cell-product { display: flex; gap: 6px; min-width: 240px; }
.cell-muted { color: var(--text-light); }
.items-table .line-total { white-space: nowrap; }
.items-table input, .items-table select { min-width: 84px; }
.items-table .cell-product input[type="hidden"] { display: none; }

/* ردیف‌های فاکتور روی موبایل: هر ردیف یک کارت (برچسب‌ها از data-label) */
@media (max-width: 700px) {
    .table-scroll:has(.items-table) { overflow: visible; box-shadow: none; }
    .items-table { display: block; border: 0; background: none; box-shadow: none; border-radius: 0; }
    .items-table thead { display: none; }
    .items-table tbody { display: block; }
    .items-table tr.item-row {
        display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; margin-bottom: 12px;
        background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
    }
    .items-table td { display: block; padding: 0; border: 0; min-width: 0; background: none; }
    .items-table td::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--text-light); margin-bottom: 3px; }
    .items-table td.cell-product { grid-column: 1 / -1; display: flex; min-width: 0; flex-wrap: wrap; }
    .items-table td.cell-product::before { display: none; }
    .items-table td.cell-delete { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
    .items-table td.cell-delete::before { margin: 0; }
    .items-table input, .items-table select { min-width: 0; }
}

/* ---------- ایمنی چیدمان (جلوگیری از اسکرول افقی و بیرون‌زدن محتوا) ---------- */
.main { overflow-x: clip; }
.page, .page > *, .topbar > * { min-width: 0; }
.topbar h1 { overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.actions .btn { max-width: 100%; text-align: center; }
.card, .panel, .stat-box, .kpi-card { overflow-wrap: anywhere; }
@media (max-width: 700px) {
    .topbar { align-items: stretch; }
    .topbar > .actions, .topbar > div:not(:first-child) { width: 100%; }
    .actions .btn { flex: 1 1 calc(50% - 8px); }
    .btn-sm { white-space: normal; line-height: 1.4; }
}

/* ---------- سازگاری موقت: صفحه‌ی گفتگو تمام‌قد است؛ تا بازطراحی خودِ چت (مرحله‌ی د) ---------- */
.main:has(.chat-app) .page { max-width: none; }
.main:has(.chat-app) .appbar { margin: 10px; }
.main .chat-app { height: calc(100vh - 76px); height: calc(100dvh - 76px); }
body:has(.chat-app) .bottom-nav { display: none; }

/* ---------- ۷) چاپ ---------- */
@media print {
    :root, [data-theme="dark"] {
        color-scheme: light;
        --bg: #fff; --surface: #fff; --surface-2: #f3f4f6; --hover: #f3f4f6; --text: #111; --text-light: #444; --border: #cfd6cc;
        --link: #0b5d2e; --debit: #b42318; --credit: #217a3c;
        --ok-bg: #dff3e5; --ok-fg: #14562b; --warn-bg: #fdf0cf; --warn-fg: #7a4b00; --bad-bg: #fde3e0; --bad-fg: #9b1c14;
        --glass-bg: #fff; --glass-strong: #fff; --glass-border: #cfd6cc; --glass-filter: none;
        --btn-bg: #022f12; --btn-fg: #fff; --primary-ui: #022f12; --accent-light: #e4f0cc;
    }
    .sidebar, .appbar, .bottom-nav, .overlay, .reminder-toasts, .no-print { display: none !important; }
    body::before { display: none; }
    body { background: #fff; color: #000; }
    .main { margin: 0 !important; padding: 0 !important; }
}
