/* ============================================================
   AccountingSystem — modern Persian (RTL) theme
   Shared by the Blazor web app and the MAUI desktop app.
   ============================================================ */

@font-face {
    font-family: 'Vazirmatn';
    src: local('Vazirmatn'), local('Vazir');
    font-display: swap;
}

:root {
    --bg: #0f172a;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #f1f5f9;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --warning: #d97706;
    --warning-soft: #fef3c7;
    --info: #0891b2;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .1);
    --shadow: 0 4px 6px -1px rgba(15, 23, 42, .07), 0 2px 4px -2px rgba(15, 23, 42, .07);
    --shadow-lg: 0 20px 25px -5px rgba(15, 23, 42, .1), 0 8px 10px -6px rgba(15, 23, 42, .08);
    --sidebar-w: 264px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Vazirmatn', 'Segoe UI', Tahoma, system-ui, sans-serif;
    background: var(--surface-3);
    color: var(--text);
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
    color: #e0e7ff;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 40;
}

.sidebar-brand {
    display: flex; align-items: center; gap: .7rem;
    padding: 1.4rem 1.5rem;
    font-size: 1.15rem; font-weight: 800;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-brand .logo {
    width: 38px; height: 38px; border-radius: 11px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    display: grid; place-items: center; font-size: 1.2rem;
    box-shadow: 0 6px 16px rgba(99, 102, 241, .5);
}

.nav-section { padding: 1rem .75rem; flex: 1; overflow-y: auto; }
.nav-label { font-size: .72rem; color: #a5b4fc; padding: .5rem .8rem; letter-spacing: .04em; }

.nav-item {
    display: flex; align-items: center; gap: .8rem;
    padding: .72rem .85rem; margin-bottom: .25rem;
    border-radius: var(--radius-sm);
    color: #c7d2fe; font-weight: 500;
    cursor: pointer; transition: all .16s ease;
}
.nav-item:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-item.active { background: rgba(255, 255, 255, .16); color: #fff; box-shadow: var(--shadow-sm); }
.nav-item .ico { font-size: 1.15rem; width: 1.4rem; text-align: center; }

.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid rgba(255, 255, 255, .08); }
.user-chip { display: flex; align-items: center; gap: .7rem; }
.user-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, #818cf8, #c084fc);
    display: grid; place-items: center; font-weight: 700; color: #fff;
}
.user-chip .name { font-weight: 600; color: #fff; font-size: .9rem; }
.user-chip .role { font-size: .75rem; color: #a5b4fc; }

/* ---------- Main area ---------- */
.main {
    flex: 1;
    margin-inline-start: var(--sidebar-w);
    display: flex; flex-direction: column;
    min-width: 0;
}
.topbar {
    height: 66px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.75rem;
    position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 1.15rem; font-weight: 700; }
.content { padding: 1.75rem; flex: 1; }

/* ---------- Cards & grids ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.4rem; }
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }

.grid { display: grid; gap: 1.1rem; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr; } .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Stat tiles ---------- */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.3rem;
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: .5rem;
    position: relative; overflow: hidden;
}
.stat .stat-ico {
    position: absolute; inset-block-start: 1rem; inset-inline-end: 1rem;
    width: 42px; height: 42px; border-radius: 11px;
    display: grid; place-items: center; font-size: 1.25rem;
}
.stat .stat-label { color: var(--text-muted); font-size: .85rem; }
.stat .stat-value { font-size: 1.65rem; font-weight: 800; letter-spacing: -.01em; }
.stat.i-primary .stat-ico { background: var(--primary-soft); color: var(--primary); }
.stat.i-success .stat-ico { background: var(--success-soft); color: var(--success); }
.stat.i-danger .stat-ico { background: var(--danger-soft); color: var(--danger); }
.stat.i-warning .stat-ico { background: var(--warning-soft); color: var(--warning); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    font-family: inherit; font-size: .9rem; font-weight: 600;
    padding: .62rem 1.15rem; border-radius: var(--radius-sm);
    border: 1px solid transparent; cursor: pointer;
    transition: all .15s ease; white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: .4rem .75rem; font-size: .82rem; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1.05rem; }
.field label { display: block; font-size: .86rem; font-weight: 600; margin-bottom: .4rem; color: #334155; }
.input, .select, textarea.input {
    width: 100%; font-family: inherit; font-size: .92rem;
    padding: .68rem .85rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, textarea.input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.field-error { color: var(--danger); font-size: .8rem; margin-top: .35rem; }
.input-error, .input-error:focus { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.jalali-date-wrap { width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.data { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .9rem; }
table.data thead th {
    background: var(--surface-2); text-align: right;
    padding: .85rem 1rem; font-weight: 700; color: #475569;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data tbody td { padding: .8rem 1rem; border-bottom: 1px solid var(--surface-3); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .25rem .65rem; border-radius: 999px;
    font-size: .78rem; font-weight: 700;
}
.badge-draft { background: var(--surface-3); color: #475569; }
.badge-inworkflow { background: var(--warning-soft); color: var(--warning); }
.badge-approved { background: var(--success-soft); color: var(--success); }
.badge-rejected { background: var(--danger-soft); color: var(--danger); }

/* ---------- Toasts ---------- */
.toast-host {
    position: fixed; inset-block-start: 1.2rem; inset-inline-start: 1.2rem;
    z-index: 100; display: flex; flex-direction: column; gap: .6rem;
}
.toast {
    min-width: 280px; padding: .85rem 1.1rem; border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); color: #fff; font-weight: 600;
    display: flex; align-items: center; gap: .6rem;
    animation: toast-in .2s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Auth screen ---------- */
.auth-wrap {
    min-height: 100vh; display: grid; place-items: center;
    background: radial-gradient(1200px 600px at 100% 0%, #312e81 0%, #0f172a 55%);
    padding: 1.5rem;
}
.auth-card {
    width: 100%; max-width: 410px;
    background: var(--surface); border-radius: 20px;
    box-shadow: var(--shadow-lg); padding: 2.2rem;
}
.auth-brand { text-align: center; margin-bottom: 1.6rem; }
.auth-brand .logo {
    width: 56px; height: 56px; border-radius: 16px; margin: 0 auto .8rem;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    display: grid; place-items: center; font-size: 1.7rem;
    box-shadow: 0 10px 24px rgba(99, 102, 241, .45);
}
.auth-brand h1 { font-size: 1.3rem; }
.auth-brand p { color: var(--text-muted); font-size: .88rem; margin: .35rem 0 0; }

/* ---------- Misc ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.4rem; gap: 1rem; flex-wrap: wrap; }
.page-head h2 { font-size: 1.35rem; }
.muted { color: var(--text-muted); }
.spinner {
    width: 20px; height: 20px; border: 2.5px solid rgba(255,255,255,.35);
    border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner.dark { border-color: var(--surface-3); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.center-state { display: grid; place-items: center; padding: 3rem; gap: 1rem; color: var(--text-muted); }
.toolbar { display: flex; gap: .7rem; align-items: end; flex-wrap: wrap; }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .88rem; font-weight: 600; margin-bottom: 1rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--primary-soft); color: var(--primary); }

/* ---------- Notification bell ---------- */
.bell { position: relative; font-size: 1.35rem; text-decoration: none; line-height: 1; }
.bell-badge {
    position: absolute; inset-block-start: -8px; inset-inline-end: -10px;
    background: var(--danger); color: #fff; font-size: .68rem; font-weight: 800;
    min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px;
    display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.msg-item {
    display: flex; gap: .9rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--surface-3);
    cursor: pointer; transition: background .15s;
}
.msg-item:hover { background: var(--surface-2); }
.msg-item.unread { background: var(--primary-soft); }
.msg-item.unread:hover { background: #e4e9ff; }
.msg-ico {
    width: 40px; height: 40px; flex: 0 0 auto; border-radius: 11px;
    display: grid; place-items: center; font-size: 1.2rem;
}
.msg-ico.t-submitted { background: var(--warning-soft); }
.msg-ico.t-rejected { background: var(--danger-soft); }
.msg-ico.t-approved { background: var(--success-soft); }
.msg-ico.t-returned { background: var(--primary-soft); }
.msg-body { flex: 1; min-width: 0; }
.msg-title { font-weight: 700; margin-bottom: .2rem; }
.msg-text { color: var(--text-muted); font-size: .88rem; }
.msg-time { color: var(--text-muted); font-size: .76rem; white-space: nowrap; }
.msg-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); flex: 0 0 auto; align-self: center; }

/* ---------- Account tree ---------- */
.tree-node {
    display: flex; align-items: center; gap: .75rem;
    padding: .55rem .4rem; border-bottom: 1px solid var(--surface-3);
}
.tree-node:hover { background: var(--surface-2); }
.tree-code {
    font-weight: 700; color: var(--primary);
    background: var(--primary-soft); padding: .15rem .55rem;
    border-radius: 6px; font-size: .82rem; min-width: 70px; text-align: center;
}
.tree-name { flex: 1; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
    display: grid; place-items: center; z-index: 200; padding: 1.5rem;
    animation: modal-fade .15s ease;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
    width: 100%; max-width: 560px; max-height: 85vh;
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
    overflow: hidden;
}
.modal-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
    padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1.05rem; }
.modal-body { padding: 1.3rem; overflow-y: auto; }

/* ---------- History timeline ---------- */
.timeline-item {
    display: flex; gap: .9rem; padding-bottom: 1.3rem; position: relative;
}
.timeline-item:not(:last-child)::before {
    content: ""; position: absolute; inset-inline-start: 5px; top: 16px; bottom: 0;
    width: 2px; background: var(--border);
}
.timeline-dot {
    width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex: 0 0 auto;
    background: var(--text-muted); z-index: 1;
}
.timeline-dot.start { background: var(--info); }
.timeline-dot.primary { background: var(--primary); }
.timeline-dot.success { background: var(--success); }
.timeline-dot.danger { background: var(--danger); }
.timeline-dot.warning { background: var(--warning); }
.timeline-content { flex: 1; min-width: 0; }
.timeline-title { font-weight: 700; font-size: .92rem; }
.timeline-meta { color: var(--text); font-size: .85rem; margin-top: .15rem; }
.timeline-comment {
    background: var(--surface-2); border-radius: var(--radius-sm);
    padding: .5rem .7rem; margin-top: .4rem; font-size: .85rem; color: var(--text);
}
.timeline-time { color: var(--text-muted); font-size: .76rem; margin-top: .35rem; }

/* ---------- Voucher line editor ---------- */
.line-row { display: grid; grid-template-columns: 2.2fr 1.3fr 1.3fr 1.8fr auto; gap: .6rem; margin-bottom: .6rem; align-items: center; }
.line-head { font-size: .8rem; color: var(--text-muted); font-weight: 600; }
.balance-bar {
    display: flex; justify-content: space-between; align-items: center;
    padding: .9rem 1.1rem; border-radius: var(--radius-sm);
    background: var(--surface-2); margin-top: .8rem; font-weight: 700;
}
.balance-bar.ok { background: var(--success-soft); color: var(--success); }
.balance-bar.bad { background: var(--danger-soft); color: var(--danger); }
@media (max-width: 800px) { .line-row { grid-template-columns: 1fr 1fr; } }

/* ---------- Data-table reports: print only the table ---------- */
@page {
    size: A4;
    margin: 14mm 10mm 18mm;
    @bottom-center {
        content: "صفحه " counter(page) " از " counter(pages);
        font-size: 9px;
        color: #555;
    }
}

@media print {
    .sidebar, .topbar, .no-print, .toast-stack { display: none !important; }
    .app-shell { display: block !important; padding: 0 !important; }
    .main { margin: 0 !important; }
    .content { padding: 0 !important; }
    html, body { width: 100% !important; margin: 0 !important; padding: 0 !important; background: #fff !important; }

    .card { border: none !important; box-shadow: none !important; background: #fff !important; }
    .card-body { padding: 0 !important; }
    .table-wrap { border: none !important; overflow: visible !important; }

    table.data { background: #fff !important; color: #111 !important; font-size: .8rem; width: 100%; }
    table.data th, table.data td { border: 1px solid #444 !important; color: #111 !important; }
    table.data thead th { background: #eee !important; }
    table.data thead { display: table-header-group; }
    table.data tfoot { display: table-footer-group; }
    table.data tr { page-break-inside: avoid; }
}

/* ---------- Tenant switcher (topbar) ---------- */
.tenant-switch { position: relative; }
.tenant-switch-menu {
    position: absolute; top: calc(100% + .4rem); inset-inline-start: 0;
    min-width: 220px; z-index: 40;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    padding: .35rem; display: flex; flex-direction: column; gap: .2rem;
}
.tenant-switch-item {
    text-align: right; padding: .55rem .7rem; border: none; border-radius: 8px;
    background: transparent; color: var(--text); cursor: pointer;
    display: flex; justify-content: space-between; align-items: center; gap: .5rem;
}
.tenant-switch-item:hover:not(:disabled) { background: var(--surface-2); }
.tenant-switch-item.active { background: var(--primary-soft); color: var(--primary); cursor: default; }
.tenant-switch-item:disabled { opacity: .7; }

/* ---------- Tenant-conflict blocking overlay ---------- */
.tenant-conflict-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.tenant-conflict-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    padding: 2rem; max-width: 420px; text-align: center;
}
.tenant-conflict-card .logo { font-size: 2.4rem; margin-bottom: .6rem; }
.tenant-conflict-card h2 { margin: 0 0 .6rem; font-size: 1.2rem; }
.tenant-conflict-card p { color: var(--muted, #64748b); margin: 0 0 1.2rem; line-height: 1.7; }

/* ---------- Tenant list (login selection) ---------- */
.tenant-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .8rem; }
