/* ==========================================================================
   Tooba complex — financial portal design system
   Persian-first, RTL, mobile-first. No external UI framework.
   ========================================================================== */

:root {
    --navy-900: #0b1e3a;
    --navy-800: #0f2748;
    --navy-700: #163460;
    --primary: #1d4f9c;
    --primary-600: #1a4587;
    --primary-050: #eaf1fb;
    --gold: #e0a12a;
    --gold-050: #fdf5e4;
    --teal: #0f8f80;
    --teal-050: #e6f5f2;
    --danger: #c2453d;
    --danger-050: #fceceb;

    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #142033;
    --text-muted: #64748b;
    --text-soft: #94a3b8;

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(15, 39, 72, .06), 0 1px 3px rgba(15, 39, 72, .04);
    --shadow: 0 4px 16px rgba(15, 39, 72, .07);
    --shadow-lg: 0 18px 48px rgba(11, 30, 58, .18);

    --sidebar-width: 268px;
    --topbar-height: 66px;

    --font: "Vazirmatn", "Vazirmatn FD", "Segoe UI", Tahoma, "Iranian Sans", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.5; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.05rem; }
p { margin: 0; }
ul, ol, dl, dd { margin: 0; padding: 0; }
li { list-style: none; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.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;
}

/* ------------------------------- App shell ------------------------------- */

.app-shell { min-height: 100dvh; display: flex; }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

.app-sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px 18px;
    background: linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 100%);
    color: #e8eef7;
    z-index: 40;
    transform: translateX(100%);
    transition: transform .25s ease;
}

.nav-toggle:checked ~ .app-sidebar { transform: translateX(0); }

.nav-scrim {
    position: fixed;
    inset: 0;
    background: rgba(9, 20, 38, .5);
    opacity: 0;
    visibility: hidden;
    transition: opacity .25s ease;
    z-index: 30;
}

.nav-toggle:checked ~ .nav-scrim { opacity: 1; visibility: visible; }

.app-brand { display: flex; align-items: center; gap: 12px; padding-block-end: 6px; }

.app-brand__mark {
    display: grid; place-items: center;
    width: 42px; height: 42px;
    border-radius: 12px;
    background: rgba(224, 161, 42, .16);
    color: var(--gold);
}

.app-brand__text { display: flex; flex-direction: column; line-height: 1.4; }
.app-brand__text strong { font-size: 1.02rem; }
.app-brand__text small { color: #9db2ce; font-size: .76rem; }

.app-nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.app-nav__link {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    color: #c9d7e9;
    font-size: .93rem;
    transition: background .18s ease, color .18s ease;
}

.app-nav__link:hover { background: rgba(255, 255, 255, .07); color: #fff; }

.app-nav__link.active {
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--gold);
}

.app-sidebar__foot { display: flex; flex-direction: column; gap: 10px; }

.user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, .06);
}

.user-card__avatar {
    display: grid; place-items: center;
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(224, 161, 42, .18); color: var(--gold);
}

.user-card__body { display: flex; flex-direction: column; line-height: 1.4; min-width: 0; }
.user-card__body strong { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card__body small { color: #9db2ce; font-size: .74rem; }

.app-sidebar .btn-ghost {
    background: rgba(255, 255, 255, .06);
    border-color: rgba(255, 255, 255, .16);
    color: #e8eef7;
}
.app-sidebar .btn-ghost:hover { background: rgba(255, 255, 255, .13); color: #fff; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    min-height: var(--topbar-height);
    padding: 10px 16px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.app-topbar__title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.app-topbar__complex { font-weight: 700; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-topbar__meta { color: var(--text-muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-topbar__user { display: none; }

.chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 13px;
    border-radius: 999px;
    font-size: .84rem; font-weight: 600;
    background: var(--primary-050); color: var(--primary-600);
}
.chip--admin { background: var(--gold-050); color: #96650d; }
.chip--owner { background: var(--teal-050); color: #0b6b60; }

.app-content {
    flex: 1;
    width: 100%;
    max-width: 1320px;
    margin-inline: auto;
    padding: 18px 16px 32px;
    display: flex; flex-direction: column; gap: 18px;
}

.app-footer {
    padding: 14px 16px 22px;
    text-align: center;
    color: var(--text-soft);
    font-size: .78rem;
}

.nav-open { display: inline-grid; }

/* ------------------------------- Page header ----------------------------- */

.page-header {
    display: flex; flex-wrap: wrap; gap: 12px;
    align-items: flex-end; justify-content: space-between;
}
.page-header__subtitle { color: var(--text-muted); font-size: .87rem; }
.page-header__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------- Buttons ------------------------------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit; font-size: .9rem; font-weight: 600;
    cursor: pointer;
    transition: background .18s ease, box-shadow .18s ease, color .18s ease, border-color .18s ease;
}
.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-600); color: #fff; }

.btn-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-link { background: none; border: none; color: var(--primary); padding: 6px 4px; font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

.btn-block { width: 100%; }
.btn-lg { padding: 13px 20px; font-size: .98rem; }
.btn-sm { padding: 6px 12px; font-size: .82rem; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: transparent; color: var(--text-muted);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--primary); }

.chip-btn {
    padding: 6px 13px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-muted);
    font-family: inherit; font-size: .81rem; font-weight: 600;
    cursor: pointer;
}
.chip-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.chip-btn:disabled { opacity: .55; cursor: not-allowed; }

/* --------------------------------- Fields -------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label { font-size: .84rem; font-weight: 600; color: var(--text-muted); }

.field-input {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-family: inherit; font-size: .95rem; color: var(--text);
    transition: border-color .18s ease, box-shadow .18s ease;
}
.field-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-050); }
.field-input::placeholder { color: var(--text-soft); }
.field-input.is-invalid, .field-input.invalid { border-color: var(--danger); }
.field-input:disabled { background: var(--surface-2); cursor: not-allowed; }

.field-input--code { letter-spacing: .55em; text-align: center; font-size: 1.25rem; font-weight: 700; }

/* The affixed field wraps an LTR input (phone number), so the icon uses physical
   left/right to stay on the same side as the typed value. */
.field-affix { position: relative; }
.field-affix__icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text-soft); pointer-events: none; display: flex;
}
.field-affix .field-input { padding-left: 40px; }

.field-hint { font-size: .78rem; color: var(--text-soft); }
.field-error, .validation-message { font-size: .8rem; color: var(--danger); }
.valid.modified:not([type=checkbox]) { outline: none; }
.invalid { outline: none; }

/* Switch */
.switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
    position: relative; flex: none;
    width: 44px; height: 25px; margin-top: 3px;
    border-radius: 999px; background: var(--border-strong);
    transition: background .18s ease;
}
.switch__thumb {
    position: absolute; top: 3px; inset-inline-start: 3px;
    width: 19px; height: 19px; border-radius: 50%;
    background: #fff; box-shadow: var(--shadow-sm);
    transition: transform .18s ease;
}
.switch input:checked + .switch__track { background: var(--primary); }
.switch input:checked + .switch__track .switch__thumb { transform: translateX(-19px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--primary-050); }
.switch__text { font-size: .87rem; font-weight: 600; display: flex; flex-direction: column; }
.switch__text small { font-weight: 400; font-size: .76rem; color: var(--text-soft); line-height: 1.6; }

/* --------------------------------- Cards --------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card__head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
}
.card__hint, .card__link { font-size: .8rem; color: var(--text-muted); }
.card__link { color: var(--primary); font-weight: 600; }
.card__body { padding: 18px; }
.card__body--flush { padding: 0; }
.card__padded { padding: 18px; }

.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: 1fr; }
.grid--split { grid-template-columns: 1fr; }

/* ------------------------------- Stat cards ------------------------------ */

.stat-card {
    position: relative;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: 6px;
    overflow: hidden;
}
.stat-card::before {
    content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px;
    background: var(--border-strong);
}
.stat-card__head { display: flex; align-items: center; gap: 9px; color: var(--text-muted); }
.stat-card__icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--surface-2); }
.stat-card__title { font-size: .84rem; font-weight: 600; }
.stat-card__value { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; word-break: break-word; }
.stat-card__unit { font-size: .78rem; font-weight: 600; color: var(--text-soft); margin-inline-start: 5px; }
.stat-card__caption { font-size: .78rem; color: var(--text-soft); }

.stat-card--primary::before { background: var(--primary); }
.stat-card--primary .stat-card__icon { background: var(--primary-050); color: var(--primary); }
.stat-card--positive::before { background: var(--teal); }
.stat-card--positive .stat-card__icon { background: var(--teal-050); color: var(--teal); }
.stat-card--positive .stat-card__value { color: #0b6b60; }
.stat-card--negative::before { background: var(--danger); }
.stat-card--negative .stat-card__icon { background: var(--danger-050); color: var(--danger); }
.stat-card--negative .stat-card__value { color: #a5322b; }
.stat-card--warning::before { background: var(--gold); }
.stat-card--warning .stat-card__icon { background: var(--gold-050); color: #96650d; }

/* -------------------------------- Filters -------------------------------- */

.filter-bar {
    display: flex; flex-direction: column; gap: 16px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.filter-bar__fields { display: grid; gap: 14px; grid-template-columns: 1fr; align-items: start; }
.filter-bar__actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.quick-range { display: flex; flex-wrap: wrap; gap: 7px; }

/* ------------------------------ Date picker ------------------------------ */

.datefield { position: relative; display: flex; flex-direction: column; gap: 6px; }
.datefield__control { position: relative; display: flex; }
.datefield__control .field-input { padding-inline-end: 42px; }
.datefield__toggle {
    position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px; display: grid; place-items: center;
    border: none; background: transparent; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm);
}
.datefield__toggle:hover { color: var(--primary); background: var(--surface-2); }

.datefield__backdrop { position: fixed; inset: 0; z-index: 50; }

.calendar {
    position: absolute; z-index: 60; top: calc(100% + 8px); inset-inline-start: 0;
    width: 280px; padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.calendar__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.calendar__title { font-weight: 700; font-size: .92rem; display: flex; gap: 6px; }
.calendar__title span { color: var(--text-muted); font-weight: 600; }
.calendar__nav {
    width: 32px; height: 32px; display: grid; place-items: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-muted); cursor: pointer;
}
.calendar__nav:hover { color: var(--primary); border-color: var(--primary); }
.calendar__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.calendar__grid--head { margin-bottom: 4px; }
.calendar__weekday { text-align: center; font-size: .74rem; color: var(--text-soft); font-weight: 600; }
.calendar__cell {
    height: 34px; display: grid; place-items: center;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    background: transparent; color: var(--text);
    font-family: inherit; font-size: .84rem; cursor: pointer;
}
.calendar__cell:hover { background: var(--primary-050); color: var(--primary-600); }
.calendar__cell--blank { cursor: default; }
.calendar__cell--blank:hover { background: transparent; }
.calendar__cell.is-today { border-color: var(--border-strong); font-weight: 700; }
.calendar__cell.is-selected { background: var(--primary); color: #fff; font-weight: 700; }
.calendar__foot { display: flex; justify-content: space-between; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }

/* --------------------------------- Tables -------------------------------- */

.table-wrap { display: none; width: 100%; overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: .89rem; }
.data-table th, .data-table td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table thead th {
    position: sticky; top: 0;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: .8rem; font-weight: 700;
    white-space: nowrap;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tfoot td { background: var(--surface-2); font-weight: 700; border-bottom: none; }
.data-table .col-num { width: 62px; color: var(--text-soft); }
.data-table .col-date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table .col-amount { text-align: left; white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table .col-action { width: 54px; text-align: center; }
.cell-title { display: block; font-weight: 600; }
.cell-sub { display: block; font-size: .78rem; color: var(--text-soft); }

.amount--debit { color: #a5322b; }
.amount--credit { color: #0b6b60; }
.balance { display: inline-flex; align-items: baseline; gap: 5px; font-weight: 700; }
.balance__type { font-size: .72rem; font-weight: 600; color: var(--text-soft); }

.tag {
    display: inline-flex; align-items: center;
    padding: 3px 10px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: .75rem; font-weight: 600; color: var(--text-muted);
    white-space: nowrap;
}
.tag--debit { background: var(--danger-050); border-color: #f2d5d3; color: #a5322b; }
.tag--credit { background: var(--teal-050); border-color: #cbe9e4; color: #0b6b60; }
.tag--unit { background: var(--primary-050); border-color: #cfe0f6; color: var(--primary-600); }

/* Mobile record cards (table replacement) */
.record-list { display: flex; flex-direction: column; }
.record { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 9px; }
.record:last-child { border-bottom: none; }
.record__head { display: flex; align-items: center; gap: 9px; }
.record__index {
    display: grid; place-items: center; flex: none;
    width: 26px; height: 26px; border-radius: 8px;
    background: var(--surface-2); color: var(--text-soft);
    font-size: .76rem; font-weight: 700;
}
.record__title { flex: 1; font-weight: 700; font-size: .92rem; }
.record__meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--text-muted); font-size: .78rem; }
.record__meta span { display: inline-flex; align-items: center; gap: 5px; }
.record__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.record__grid dt { font-size: .74rem; color: var(--text-soft); }
.record__grid dd { margin: 0; font-weight: 700; font-size: .87rem; font-variant-numeric: tabular-nums; }
.record__grid dd small { font-weight: 600; font-size: .7rem; color: var(--text-soft); }

/* ------------------------------- Breakdown ------------------------------- */

.breakdown { display: flex; flex-direction: column; gap: 16px; }
.breakdown__row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.breakdown__name { font-weight: 700; font-size: .9rem; }
.breakdown__value { font-weight: 700; font-variant-numeric: tabular-nums; }
.breakdown__value small { font-size: .72rem; color: var(--text-soft); font-weight: 600; }
.breakdown__meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: .76rem; color: var(--text-soft); }

.bar { height: 9px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar__fill { display: block; height: 100%; border-radius: 999px; transition: width .5s ease; }
.bar__fill--debit { background: linear-gradient(90deg, #d97066, #c2453d); }
.bar__fill--credit { background: linear-gradient(90deg, #35b3a2, #0f8f80); }

/* -------------------------------- Timeline ------------------------------- */

.timeline { display: flex; flex-direction: column; }
.timeline__item { display: flex; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--border); }
.timeline__item:last-child { border-bottom: none; }
.timeline__dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 9px; flex: none; }
.timeline__dot--debit { background: var(--danger); }
.timeline__dot--credit { background: var(--teal); }
.timeline__body { flex: 1; min-width: 0; }
.timeline__top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.timeline__top strong { font-size: .89rem; font-weight: 700; }
.timeline__meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 4px; color: var(--text-soft); font-size: .77rem; }
.timeline__meta span { display: inline-flex; align-items: center; gap: 5px; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --------------------------------- Modal --------------------------------- */

.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: end center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(9, 20, 38, .55); }
.modal__panel {
    position: relative;
    width: 100%; max-width: 520px; max-height: 88dvh;
    display: flex; flex-direction: column;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-lg);
    animation: sheet-in .22s ease;
}
@keyframes sheet-in { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.modal__body { padding: 18px; overflow-y: auto; }
.modal__foot { padding: 13px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-start; }

.detail-list { display: flex; flex-direction: column; gap: 12px; }
.detail-list > div { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; border-bottom: 1px dashed var(--border); padding-bottom: 10px; }
.detail-list > div:last-child { border-bottom: none; padding-bottom: 0; }
.detail-list dt { color: var(--text-muted); font-size: .84rem; flex: none; }
.detail-list dd { margin: 0; font-weight: 700; text-align: left; font-size: .9rem; }

/* --------------------------- States and feedback -------------------------- */

.alert {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 12px 14px; margin-bottom: 16px;
    border-radius: var(--radius-sm);
    font-size: .87rem; font-weight: 600;
}
.alert--error { background: var(--danger-050); color: #93302a; border: 1px solid #f0cdcb; }
.alert--info { background: var(--primary-050); color: var(--primary-600); border: 1px solid #cfe0f6; }

.state-panel {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 46px 22px; text-align: center;
}
.state-panel p { color: var(--text-muted); font-size: .88rem; max-width: 420px; }
.state-panel .btn { margin-top: 8px; }
.state-panel--page { min-height: 60dvh; justify-content: center; }
.state-panel__code { font-size: .78rem; }
.state-icon {
    display: grid; place-items: center;
    width: 62px; height: 62px; border-radius: 50%;
    background: var(--primary-050); color: var(--primary);
}
.state-icon--error { background: var(--danger-050); color: var(--danger); }
.state-icon--warn { background: var(--gold-050); color: #96650d; }

.route-authorizing { padding: 60px 0; }

.spinner-block { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 34px 0; color: var(--text-muted); font-size: .88rem; }
.spinner {
    width: 20px; height: 20px; flex: none;
    border: 2.5px solid currentColor; border-top-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    display: inline-block;
}
.spinner--sm { width: 15px; height: 15px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton-rows { display: flex; flex-direction: column; gap: 10px; }
.skeleton-row, .skeleton-card {
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, #eef1f6 25%, #f7f9fc 37%, #eef1f6 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease infinite;
}
.skeleton-row { height: 42px; }
.skeleton-card { height: 118px; border-radius: var(--radius); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

#blazor-error-ui {
    display: none;
    position: fixed; inset-inline: 0; bottom: 0; z-index: 1000;
    gap: 14px; align-items: center; justify-content: center;
    padding: 12px 16px;
    background: var(--navy-900); color: #fff;
    font-size: .87rem;
}
#blazor-error-ui .reload { color: var(--gold); font-weight: 700; }
#blazor-error-ui .dismiss { cursor: pointer; }

.blazor-error-boundary { background: var(--danger); color: #fff; padding: 14px 18px; border-radius: var(--radius-sm); }
.blazor-error-boundary::after { content: "خطایی رخ داده است."; }

/* --------------------------------- Login --------------------------------- */

.auth-shell { min-height: 100dvh; display: flex; background: var(--bg); }
.login { flex: 1; display: flex; flex-direction: column; }

.login__hero {
    display: none;
    background:
        radial-gradient(1100px 420px at 90% -10%, rgba(224, 161, 42, .22), transparent 60%),
        linear-gradient(160deg, var(--navy-800), var(--navy-900));
    color: #e8eef7;
    padding: 48px;
}
.login__hero-inner { max-width: 420px; margin: auto; display: flex; flex-direction: column; gap: 16px; }
.login__mark {
    display: grid; place-items: center;
    width: 62px; height: 62px; border-radius: 18px;
    background: rgba(224, 161, 42, .16); color: var(--gold);
}
.login__hero h2 { font-size: 1.55rem; }
.login__hero p { color: #b8c8de; }
.login__points { display: flex; flex-direction: column; gap: 11px; margin-top: 10px; }
.login__points li { display: flex; align-items: center; gap: 10px; color: #cfdcec; font-size: .9rem; }
.login__points svg { color: var(--gold); flex: none; }

.login__panel { flex: 1; display: flex; align-items: center; justify-content: center; padding: 26px 18px 40px; }
.login__card { width: 100%; max-width: 400px; }
.login__head { margin-bottom: 20px; display: flex; flex-direction: column; gap: 6px; }
.login__step { font-size: .76rem; font-weight: 700; color: var(--primary); }
.login__head h1 { font-size: 1.5rem; }
.login__head p { color: var(--text-muted); font-size: .87rem; }
.login__secondary { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.login__note { margin-top: 22px; color: var(--text-soft); font-size: .78rem; text-align: center; line-height: 1.8; }

/* --------------------- Role picker (login) & owner portal ------------------ */

.role-picker { border: 0; margin: 0 0 18px; padding: 0; }
.role-picker legend { padding: 0; margin-bottom: 8px; }

.role-picker__options { display: grid; gap: 10px; }

.role-option { display: block; position: relative; cursor: pointer; }

.role-option__input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }

.role-option__body {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.role-option:hover .role-option__body { border-color: var(--border-strong); }

.role-option__icon {
    display: grid; place-items: center;
    width: 38px; height: 38px; flex: 0 0 38px;
    border-radius: 11px;
    background: var(--surface-2); color: var(--text-muted);
}

.role-option__text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.5; }
.role-option__text strong { font-size: .95rem; }
.role-option__text small { color: var(--text-muted); font-size: .76rem; }

.role-option__check {
    display: grid; place-items: center;
    width: 24px; height: 24px; flex: 0 0 24px;
    border-radius: 999px;
    border: 1.5px solid var(--border-strong);
    color: transparent;
    transition: background .18s ease, border-color .18s ease, color .18s ease;
}

.role-option__input:checked ~ .role-option__body {
    border-color: var(--primary);
    background: var(--primary-050);
    box-shadow: 0 0 0 3px rgba(29, 79, 156, .1);
}
.role-option__input:checked ~ .role-option__body .role-option__icon { background: #fff; color: var(--primary); }
.role-option__input:checked ~ .role-option__body .role-option__check {
    background: var(--primary); border-color: var(--primary); color: #fff;
}
.role-option__input:focus-visible ~ .role-option__body { outline: 2px solid var(--primary); outline-offset: 2px; }

.login__mode-badge { display: flex; justify-content: center; margin-bottom: 16px; }

/* Controls card holding the unit picker and the billing type picker. */
.card--controls .card__body { display: grid; gap: 20px; }

.choice-group { display: grid; gap: 10px; }
.choice-group__label { font-size: .82rem; font-weight: 700; color: var(--text-muted); }
.choice-group__options { display: grid; gap: 10px; }

.choice {
    display: flex; align-items: center; gap: 11px;
    padding: 11px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-family: inherit; text-align: start; cursor: pointer;
    transition: border-color .18s ease, background .18s ease;
}
.choice:disabled { opacity: .6; cursor: not-allowed; }
.choice:hover:not(:disabled) { border-color: var(--border-strong); }

.choice__dot {
    width: 18px; height: 18px; flex: 0 0 18px;
    border-radius: 999px;
    border: 2px solid var(--border-strong);
    background: var(--surface);
    transition: border-color .18s ease, box-shadow .18s ease;
}

.choice__text { display: flex; flex-direction: column; line-height: 1.5; min-width: 0; }
.choice__text strong { font-size: .9rem; }
.choice__text small { color: var(--text-muted); font-size: .74rem; }

.choice--active { border-color: var(--primary); background: var(--primary-050); }
.choice--active .choice__dot { border-color: var(--primary); box-shadow: inset 0 0 0 3.5px var(--primary); }

.unit-picker { display: grid; gap: 10px; }
.unit-picker__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.unit-picker__count { font-size: .76rem; color: var(--text-soft); }
.unit-picker__options { display: grid; gap: 10px; }

.unit-chip {
    display: flex; align-items: center; gap: 11px;
    padding: 11px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-family: inherit; text-align: start; cursor: pointer;
    transition: border-color .18s ease, background .18s ease;
}
.unit-chip:disabled { opacity: .6; cursor: not-allowed; }
.unit-chip:hover:not(:disabled) { border-color: var(--border-strong); }

.unit-chip__box {
    display: grid; place-items: center;
    width: 22px; height: 22px; flex: 0 0 22px;
    border-radius: 7px;
    border: 1.5px solid var(--border-strong);
    background: var(--surface);
    color: transparent;
    transition: background .18s ease, border-color .18s ease, color .18s ease;
}

.unit-chip__body { display: flex; flex-direction: column; line-height: 1.5; min-width: 0; }
.unit-chip__body strong { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit-chip__body small { color: var(--text-muted); font-size: .74rem; }

.unit-chip--active { border-color: var(--primary); background: var(--primary-050); }
.unit-chip--active .unit-chip__box { background: var(--primary); border-color: var(--primary); color: #fff; }
.unit-chip--all.unit-chip--active { border-color: var(--teal); background: var(--teal-050); }
.unit-chip--all.unit-chip--active .unit-chip__box { background: var(--teal); border-color: var(--teal); }

.unit-grid { display: grid; gap: 14px; }

.unit-card {
    display: flex; flex-direction: column; gap: 12px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    border-inline-start: 4px solid var(--border-strong);
}
.unit-card--debit { border-inline-start-color: var(--danger); }
.unit-card--credit { border-inline-start-color: var(--teal); }
.unit-card--flat { border-inline-start-color: var(--border-strong); }

.unit-card__head { display: flex; align-items: center; gap: 11px; }
.unit-card__icon {
    display: grid; place-items: center;
    width: 36px; height: 36px; flex: 0 0 36px;
    border-radius: 11px; background: var(--primary-050); color: var(--primary);
}
.unit-card__title { display: flex; flex-direction: column; min-width: 0; line-height: 1.5; }
.unit-card__title strong { font-size: .95rem; }
.unit-card__title small { color: var(--text-muted); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.unit-card__balance { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.unit-card__amount { font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em; }
.unit-card__unit { font-size: .76rem; color: var(--text-soft); }

.unit-card__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.unit-card__grid dt { font-size: .72rem; color: var(--text-soft); }
.unit-card__grid dd { font-size: .84rem; font-weight: 600; }

.unit-card__empty { font-size: .78rem; color: var(--text-soft); }

.unit-card__foot { display: flex; }
.unit-card__foot .btn { width: 100%; justify-content: center; }

/* ------------------------------- Breakpoints ------------------------------ */

@media (min-width: 560px) {
    .grid--stats { grid-template-columns: repeat(2, 1fr); }
    .role-picker__options { grid-template-columns: repeat(3, 1fr); }
    .role-option__body { flex-direction: column; align-items: flex-start; gap: 9px; height: 100%; padding-top: 14px; }
    .role-option__check { position: absolute; inset-block-start: 12px; inset-inline-end: 12px; }
    .choice-group__options { grid-template-columns: repeat(3, 1fr); }
    .unit-picker__options { grid-template-columns: repeat(2, 1fr); }
    .unit-grid { grid-template-columns: repeat(2, 1fr); }
    .filter-bar__fields { grid-template-columns: repeat(2, 1fr); }
    .filter-bar__switch { grid-column: 1 / -1; }
    .modal { place-items: center; }
    .modal__panel { border-radius: var(--radius-lg); max-height: 82dvh; }
}

@media (min-width: 860px) {
    .app-content { padding: 24px 26px 40px; }
    .table-wrap { display: block; max-height: 620px; }
    .record-list { display: none; }
    .filter-bar { flex-direction: row; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
    .filter-bar__fields { grid-template-columns: 190px 190px minmax(220px, 1fr); flex: 1; }
    .filter-bar__switch { grid-column: auto; }
    .filter-bar__actions { justify-content: flex-end; gap: 14px; }
    .login { flex-direction: row; }
    .login__hero { display: flex; flex: 1; }
    .login__panel { flex: 0 0 min(52%, 560px); }
}

@media (min-width: 1080px) {
    .unit-picker__options { grid-template-columns: repeat(3, 1fr); }
    .unit-grid { grid-template-columns: repeat(3, 1fr); }
    .app-sidebar { transform: none; }
    .nav-scrim, .nav-open { display: none; }
    .app-main { margin-inline-start: var(--sidebar-width); }
    .app-topbar { padding-inline: 26px; }
    .app-topbar__user { display: block; }
    .grid--stats { grid-template-columns: repeat(4, 1fr); }
    .grid--split { grid-template-columns: 1fr 1fr; }
    .grid--split-wide { grid-template-columns: minmax(320px, 2fr) 3fr; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
