/* ===== متغیرها ===== */
:root {
    --primary: #0057b7;
    --primary-dark: #004494;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --text: #1a1a2e;
    --muted: #6b7280;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.1);
    --radius: 14px;
    --radius-sm: 10px;
}

* {
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Vazirmatn', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ===== Layout اصلی ===== */
.app-body {
    padding-top: 64px; /* header */
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)); /* بود: 70px → حالا: 90px */
}

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
}

.btn-icon {
    background: transparent;
    border: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    cursor: pointer;
    transition: background .15s;
}

    .btn-icon:active {
        background: rgba(0,0,0,.05);
    }

.app-brand .brand-mark {
    font-weight: 800;
    font-size: 1.15rem;
    color: var(--primary);
    letter-spacing: -.5px;
}

.avatar-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-md {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
}

.app-content {
    /* min-height حالا با padding جدید هماهنگ است */
    min-height: calc(100vh - 64px - 90px - env(safe-area-inset-bottom, 0px));
    /* بود: calc(100vh - 64px - 70px) */
}

.page-container {
    padding: 16px;
    /* فالبک: اگر صفحه‌ای padding اختصاصی نداشت، حداقل این فاصله حفظ شود */
    padding-bottom: max(16px, calc(24px + env(safe-area-inset-bottom, 0px)));
    max-width: 720px;
    margin: 0 auto;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    /* height شامل safe-area نمی‌شود — safe-area جداگانه اضافه می‌شود */
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-start; /* محتوا بالای نوار — بالای safe-area */
    z-index: 1000;
    box-shadow: 0 -2px 8px rgba(0,0,0,.04);
}

.bottom-nav-item {
    flex: 1;
    height: 64px; /* ارتفاع محتوا = 64px بدون safe-area */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--muted);
    font-size: .7rem;
    gap: 2px;
}

    .bottom-nav-item i {
        font-size: 1.4rem;
    }

    .bottom-nav-item.active {
        color: var(--primary);
        font-weight: 600;
    }

        .bottom-nav-item.active i {
            transform: scale(1.1);
        }

/* ===== Cards ===== */
.card {
    border: 0;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-body {
    padding: 16px;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
}

/* ===== Hero Card (Dashboard) ===== */
.hero-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    padding: 24px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.hero-label {
    font-size: .85rem;
    opacity: .9;
}

.hero-amount {
    font-size: 2rem;
    font-weight: 800;
    margin: 6px 0;
    letter-spacing: -1px;
}

.hero-sub {
    font-size: .85rem;
}

.info-banner {
    background: #fff8e6;
    border: 1px solid #ffe4a0;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: #7a5b00;
}

/* ===== Stat rows ===== */
.stat-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

    .stat-row:last-child {
        border-bottom: 0;
    }

.stat-label {
    font-size: .8rem;
    color: var(--muted);
    margin-bottom: 2px;
}

.stat-value {
    font-weight: 700;
    font-size: 1.05rem;
}

.stats-mini {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

    .stats-mini > div {
        background: var(--surface);
        border-radius: var(--radius-sm);
        padding: 12px 8px;
        text-align: center;
        box-shadow: var(--shadow-sm);
    }

    .stats-mini strong {
        display: block;
        font-size: 1.05rem;
    }

    .stats-mini small {
        color: var(--muted);
        font-size: .72rem;
    }

.section-heading {
    margin: 16px 4px 12px;
    font-weight: 700;
}

/* ===== City rows ===== */
.city-row {
    display: flex;
    gap: 12px;
    align-items: center;
    border: 0 !important;
    padding: 12px 16px;
}

.city-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.city-main {
    flex: 1;
    min-width: 0;
}

.city-name {
    font-weight: 600;
    font-size: .95rem;
}

.city-meta {
    font-size: .75rem;
}

.city-stats {
    flex-shrink: 0;
}

/* ===== Debtor rows ===== */
.debtor-row {
    display: flex;
    gap: 12px;
    align-items: center;
    border: 0 !important;
    padding: 14px 16px;
    text-decoration: none;
    color: inherit;
}

.debtor-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.debtor-main {
    flex: 1;
    min-width: 0;
}

.debtor-amount {
    flex-shrink: 0;
    text-align: left;
}

/* ===== Balance card ===== */
.balance-card {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 18px 20px;
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
}

/* ===== Sidebar ===== */
.offcanvas-header {
    border-bottom: 1px solid var(--border);
}

.sidebar-balance {
    background: linear-gradient(135deg, #e0f2fe, #bae6fd);
    padding: 16px;
    margin: 12px;
    border-radius: var(--radius-sm);
    text-align: center;
}

.sidebar-nav {
    padding: 0 8px 20px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: .95rem;
    transition: background .15s;
}

    .sidebar-item:active {
        background: var(--bg);
    }

    .sidebar-item i {
        font-size: 1.15rem;
        color: var(--primary);
    }

.sidebar-divider {
    padding: 12px 16px 6px;
    font-size: .72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
}

/* ===== Auth ===== */
.auth-body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.auth-wrapper {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: var(--surface);
    border-radius: 24px;
    padding: 32px 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.auth-logo {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 8px 24px rgba(0,87,183,.35);
}

/* ===== Form controls ===== */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    padding: 10px 14px;
    transition: border-color .15s, box-shadow .15s;
}

    .form-control:focus, .form-select:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 .15rem rgba(0,87,183,.15);
    }

.form-floating > .form-control,
.form-floating > .form-select {
    padding: 1rem .75rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

    .btn-primary:hover {
        background: var(--primary-dark);
        border-color: var(--primary-dark);
    }

.rounded-pill {
    border-radius: 999px !important;
}

/* ===== Badges ===== */
.badge {
    font-weight: 500;
    padding: .35em .65em;
}

.bg-success-subtle {
    background: #d1fae5 !important;
}

.bg-danger-subtle {
    background: #fee2e2 !important;
}

.bg-warning-subtle {
    background: #fef3c7 !important;
}

.bg-info-subtle {
    background: #dbeafe !important;
}

.bg-primary-subtle {
    background: #dbeafe !important;
}

/* ===== Profile header ===== */
.profile-header {
    text-align: center;
    padding: 24px 0;
}

.profile-avatar {
    width: 96px;
    height: 96px;
    margin: 0 auto;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,87,183,.25);
}

    .profile-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

/* ===== List group ===== */
.list-group-item {
    border-color: var(--border);
    padding: 14px 16px;
}

.list-group-item-action:active {
    background: var(--bg);
}

/* ===== Progress ===== */
.progress {
    border-radius: 999px;
    background: #e5e7eb;
}

.progress-bar {
    border-radius: 999px;
    transition: width .4s ease;
}

/* ===== Alerts ===== */
.alert {
    border-radius: var(--radius-sm);
    border: 0;
}

/* ===== Responsive tweaks ===== */
@media (max-width: 380px) {
    .hero-amount {
        font-size: 1.6rem;
    }

    .page-container {
        padding: 12px;
    }
}
