:root {
    --bg: #10131C;
    --bg-elev: #171B27;
    --card: #1C2130;
    --card-hi: #232939;
    --border: #2A3145;
    --text: #ECEDF3;
    --text-dim: #9AA2B8;
    --text-faint: #626B84;

    --debt: #EF5A63;
    --debt-dim: #3A2229;
    --credit: #34C77B;
    --credit-dim: #1D3328;
    --gold: #D4AC5C;

    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;

    --shadow-card: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px -12px rgba(0,0,0,0.5);
    --font: 'Vazirmatn', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
}

input, button {
    font-family: var(--font);
}

button {
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

::selection { background: rgba(212,172,92,0.3); }

/* ===================== لاگین ===================== */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 30% 20%, rgba(212,172,92,0.08), transparent 45%),
        var(--bg);
}

.login-card {
    width: 100%;
    max-width: 340px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    box-shadow: var(--shadow-card);
    text-align: center;
}

.login-mark {
    display: inline-block;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.5px;
    color: var(--gold);
    background: rgba(212,172,92,0.1);
    border: 1px solid rgba(212,172,92,0.25);
    border-radius: 999px;
    padding: 4px 16px;
    margin-bottom: 18px;
}

.login-card h1 {
    font-size: 21px;
    font-weight: 700;
    margin: 0 0 6px;
}

.login-sub {
    color: var(--text-dim);
    font-size: 13.5px;
    margin: 0 0 22px;
}

.login-card input {
    width: 100%;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    color: var(--text);
    font-size: 15px;
    text-align: center;
    margin-bottom: 14px;
    outline: none;
    transition: border-color 0.15s;
}
.login-card input:focus { border-color: var(--gold); }

.login-error {
    color: var(--debt);
    font-size: 13px;
    margin-bottom: 12px;
}

.login-card button {
    width: 100%;
    background: var(--gold);
    color: #16130A;
    font-weight: 700;
    font-size: 15px;
    padding: 14px;
    border-radius: var(--radius-sm);
}

/* ===================== صفحه نصب ===================== */

.install-card {
    max-width: 380px;
    text-align: right;
}
.install-card h1 { text-align: center; }
.install-card .login-mark { display: block; width: fit-content; margin: 0 auto 18px; }

.install-status {
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}
.install-status--ok {
    background: var(--credit-dim);
    border-color: rgba(52,199,123,0.3);
}
.install-status--error {
    background: var(--debt-dim);
    border-color: rgba(239,90,99,0.3);
}

.install-status-title {
    font-weight: 700;
    font-size: 14.5px;
    margin-bottom: 6px;
}

.install-status-desc {
    font-size: 12.5px;
    color: var(--text-dim);
    margin: 0;
    line-height: 1.9;
}
.install-status-desc code {
    background: var(--bg-elev);
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 11.5px;
    direction: ltr;
    display: inline-block;
}

.install-error-box {
    margin-top: 10px;
    background: var(--bg-elev);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 11px;
    color: var(--text-faint);
    direction: ltr;
    text-align: left;
    word-break: break-word;
    font-family: monospace;
}

.install-retry {
    display: block;
    text-decoration: none;
    text-align: center;
}

.install-footnote {
    text-align: center;
    font-size: 11px;
    color: var(--text-faint);
    margin: 18px 0 0;
}

/* ===================== لایوت اصلی ===================== */

.app {
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: 100px;
    min-height: 100vh;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 8px;
}

.topbar-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
}
.topbar-mark {
    font-weight: 800;
    font-size: 20px;
    color: var(--gold);
}
.topbar-sub {
    font-size: 13px;
    color: var(--text-faint);
}

/* تب‌بار */
.tabbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    gap: 6px;
    padding: 12px 16px 14px;
    margin: 0 4px;
    background: linear-gradient(180deg, var(--bg) 65%, transparent);
    backdrop-filter: blur(6px);
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 8px;
    border-radius: var(--radius-md);
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 13.5px;
    font-weight: 600;
    transition: all 0.18s;
}
.tab-btn svg { width: 17px; height: 17px; opacity: 0.8; }

.tab-btn.active {
    background: var(--card-hi);
    color: var(--text);
    border-color: rgba(212,172,92,0.4);
    box-shadow: 0 0 0 1px rgba(212,172,92,0.15) inset;
}

.content {
    padding: 4px 16px 24px;
}

.tab-panel { display: none; animation: fadeUp 0.25s ease; }
.tab-panel.active { display: block; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 18px 2px 12px;
}
.section-head--tight { margin-top: 26px; }

.section-head h2 {
    font-size: 15.5px;
    font-weight: 700;
    margin: 0;
    color: var(--text);
}

.count-pill {
    font-size: 12px;
    color: var(--text-faint);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 11px;
}

.empty-state {
    text-align: center;
    color: var(--text-faint);
    font-size: 13.5px;
    padding: 40px 12px;
}

/* ===================== لیست مشتری‌ها ===================== */

.customer-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.customer-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 14px;
    box-shadow: var(--shadow-card);
}

.cc-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    background: linear-gradient(155deg, #2B3350, #1E2436);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.cc-body {
    flex: 1;
    min-width: 0;
}

.cc-name {
    font-size: 14.5px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cc-phone {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 2px;
    direction: ltr;
    text-align: right;
}

.cc-balance {
    font-weight: 800;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    direction: ltr;
}
.cc-balance.negative { color: var(--debt); }
.cc-balance.positive { color: var(--credit); }
.cc-balance.zero { color: var(--text-faint); }

.cc-edit {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-faint);
    flex-shrink: 0;
}
.cc-edit svg { width: 16px; height: 16px; }

/* ===================== فرم تراکنش ===================== */

.txn-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-card);
}

.field-label {
    display: block;
    font-size: 12.5px;
    color: var(--text-faint);
    margin-bottom: 7px;
    font-weight: 600;
}

.txn-search, .amount-input, .sheet-input {
    width: 100%;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 14px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.15s;
}
.txn-search:focus, .amount-input:focus, .sheet-input:focus { border-color: var(--gold); }

.amount-input {
    font-weight: 800;
    font-size: 20px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    margin-bottom: 16px;
}

.suggestions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.suggestions:empty { margin-top: 0; }

.suggestion-chip {
    flex: 1;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 8px;
    text-align: center;
    min-width: 0;
}
.suggestion-chip .sg-name {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.suggestion-chip .sg-balance {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 3px;
    font-variant-numeric: tabular-nums;
    direction: ltr;
}
.suggestion-chip:active { background: var(--card-hi); }

.selected-customer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-elev);
    border: 1px solid rgba(212,172,92,0.3);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-top: 12px;
}
.selected-customer.hidden { display: none; }

.sc-info { display: flex; flex-direction: column; gap: 2px; }
.sc-name { font-weight: 700; font-size: 14.5px; }
.sc-balance { font-size: 12.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }

.sc-clear {
    font-size: 12px;
    color: var(--gold);
    border: 1px solid rgba(212,172,92,0.3);
    border-radius: 999px;
    padding: 5px 13px;
}

.amount-area { margin-top: 16px; }
.amount-area.hidden { display: none; }

.quick-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}
.quick-row {
    display: flex;
    gap: 8px;
}
.quick-btn {
    flex: 1;
    padding: 11px 4px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
    border: 1px solid transparent;
    transition: transform 0.1s;
}
.quick-btn:active { transform: scale(0.94); }

@keyframes quickBtnFlash {
    0% { box-shadow: 0 0 0 0 rgba(212,172,92,0.55); }
    100% { box-shadow: 0 0 0 10px rgba(212,172,92,0); }
}
.quick-btn--flash {
    animation: quickBtnFlash 0.45s ease-out;
}

.quick-row--add .quick-btn {
    background: var(--credit-dim);
    color: var(--credit);
    border-color: rgba(52,199,123,0.25);
}
.quick-row--sub .quick-btn {
    background: var(--debt-dim);
    color: var(--debt);
    border-color: rgba(239,90,99,0.25);
}

.sign-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.sign-btn {
    flex: 1;
    padding: 12px 8px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 13.5px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text-faint);
}
.sign-btn--plus.active {
    background: var(--credit-dim);
    color: var(--credit);
    border-color: rgba(52,199,123,0.4);
}
.sign-btn--minus.active {
    background: var(--debt-dim);
    color: var(--debt);
    border-color: rgba(239,90,99,0.4);
}

.confirm-btn {
    width: 100%;
    background: var(--gold);
    color: #16130A;
    font-weight: 800;
    font-size: 15px;
    padding: 15px;
    border-radius: var(--radius-sm);
    transition: opacity 0.15s;
}
.confirm-btn:disabled {
    opacity: 0.4;
    pointer-events: none;
}
.confirm-btn.is-loading {
    opacity: 0.75;
    pointer-events: none;
}

/* ===================== لیست‌های کوچک (بدهکارترین/آخرین تغییرات) ===================== */

.mini-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mini-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 14px;
}

.mini-row .mr-name {
    font-size: 13.5px;
    font-weight: 700;
}
.mini-row .mr-sub {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 2px;
}
.mini-row .mr-val {
    font-weight: 800;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    direction: ltr;
}
.mr-val.negative { color: var(--debt); }
.mr-val.positive { color: var(--credit); }

.mr-rank {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-faint);
    flex-shrink: 0;
    margin-left: 10px;
}

.mini-row-left { display: flex; align-items: center; min-width: 0; }
.mini-row-text { min-width: 0; }
.mini-row-text .mr-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===================== تاریخچه ===================== */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.hist-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.hist-badge {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
    margin-left: 12px;
}
.hist-badge.add { background: var(--debt-dim); color: var(--debt); }
.hist-badge.sub { background: var(--credit-dim); color: var(--credit); }

.hist-info { flex: 1; min-width: 0; }
.hist-name { font-size: 13.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-time { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.hist-amounts { text-align: left; flex-shrink: 0; }
.hist-amount { font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; direction: ltr; }
.hist-amount.negative { color: var(--debt); }
.hist-amount.positive { color: var(--credit); }
.hist-after { font-size: 10.5px; color: var(--text-faint); margin-top: 2px; direction: ltr; }

/* ===================== دکمه شناور ===================== */

.fab {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--gold);
    color: #16130A;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px -6px rgba(212,172,92,0.5);
    z-index: 30;
}
.fab.visible { display: flex; }
.fab svg { width: 24px; height: 24px; }
.fab:active { transform: translateX(-50%) scale(0.92); }

/* ===================== شیت‌ها (پاپ‌آپ داخلی) ===================== */

.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6,8,14,0.6);
    backdrop-filter: blur(3px);
    z-index: 50;
    display: flex;
    align-items: flex-end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
}
.sheet-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.sheet {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    background: var(--card-hi);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 26px 26px 0 0;
    padding: 10px 20px calc(24px + env(safe-area-inset-bottom, 0));
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}
.sheet-overlay.open .sheet {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: 6px auto 16px;
}

.sheet h3 {
    font-size: 17px;
    font-weight: 700;
    margin: 0 0 18px;
    text-align: center;
}

.sheet-input { margin-bottom: 14px; }

.sheet-actions {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

.sheet-cancel, .sheet-confirm, .sheet-delete {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 14px;
}

.sheet-cancel {
    background: var(--bg-elev);
    color: var(--text-dim);
    border: 1px solid var(--border);
}
.sheet-cancel--full { width: 100%; margin-top: 10px; }

.sheet-confirm {
    background: var(--gold);
    color: #16130A;
}

.sheet-delete {
    background: var(--debt-dim);
    color: var(--debt);
    border: 1px solid rgba(239,90,99,0.3);
}

/* ===================== توست ===================== */

.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--card-hi);
    border: 1px solid rgba(52,199,123,0.35);
    color: var(--credit);
    padding: 12px 22px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 700;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    box-shadow: 0 10px 30px -8px rgba(0,0,0,0.5);
    white-space: nowrap;
}
.toast.error {
    border-color: rgba(239,90,99,0.35);
    color: var(--debt);
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===================== ردیف پرتراکنش‌ترین‌ها ===================== */

.most-active-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.most-active-row:empty { margin-bottom: 0; }

.active-chip {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 8px;
    text-align: center;
    min-width: 0;
}
.active-chip:active { background: var(--card-hi); }

.active-chip .ac-name {
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.active-chip .ac-count {
    font-size: 10.5px;
    color: var(--gold);
    margin-top: 3px;
}

/* ===================== یادداشت تاریخچه ===================== */

.hist-note {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===================== قابل کلیک بودن ردیف‌ها ===================== */

.cc-clickable, .mini-row-clickable {
    cursor: pointer;
    transition: background 0.12s;
}
.cc-clickable:active, .mini-row-clickable:active {
    background: var(--card-hi);
}

/* ===================== صفحه تمام‌صفحه‌ی وارد کردن مبلغ ===================== */

.amount-screen {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: var(--bg);
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 0.22s ease, transform 0.22s ease;
    overflow-y: auto;
}
.amount-screen.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

body.no-scroll { overflow: hidden; }

.amount-screen-inner {
    max-width: 480px;
    margin: 0 auto;
    padding: 28px 20px calc(28px + env(safe-area-inset-bottom, 0));
}

.as-customer {
    text-align: center;
    margin-bottom: 22px;
}

.as-avatar {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    margin: 0 auto 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 20px;
    background: linear-gradient(155deg, #2B3350, #1E2436);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.as-name {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 4px;
}

.as-balance {
    font-size: 13px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    direction: ltr;
    text-align: center;
}

.as-running {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
}

.as-running-label {
    font-size: 12px;
    color: var(--text-faint);
    font-weight: 600;
    display: block;
    margin-bottom: 8px;
}

.as-running-value {
    font-size: 34px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    direction: ltr;
    color: var(--text-dim);
}
.as-running-value.negative-run { color: var(--debt); }

@keyframes runningValueBump {
    0% { transform: scale(1.14); }
    100% { transform: scale(1); }
}
.as-running-value--bump {
    animation: runningValueBump 0.22s ease-out;
}
.as-running-value.positive-run { color: var(--credit); }

.manual-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}
.manual-row .amount-input { margin-bottom: 0; }

.note-input {
    width: 100%;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    resize: none;
    margin-bottom: 18px;
    transition: border-color 0.15s;
    font-family: var(--font);
}
.note-input:focus { border-color: var(--gold); }

.reset-btn {
    width: 100%;
    background: transparent;
    color: var(--text-faint);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
}
.reset-btn:active { background: var(--bg-elev); }

.confirm-btn--sticky {
    position: sticky;
    bottom: 12px;
}

/* ===================== ریسپانسیو ===================== */

@media (max-width: 360px) {
    .content { padding: 4px 12px 24px; }
    .quick-btn { font-size: 12px; padding: 10px 2px; }
}

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