/* --- 0. فونت وزیرمتن --- */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700;900&display=swap');

:root {
    --font-family: 'Vazirmatn', sans-serif;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --danger: #ef4444;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --border: #e5e7eb;
    --link-color: #2563eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius: 12px;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --success: #34d399;
    --danger: #f87171;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --bg-body: #111827;
    --bg-card: #1f2937;
    --border: #374151;
    --link-color: #60a5fa;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    min-height: 100vh;
    display: flex;
    direction: rtl;
    text-align: right;
    overflow-y: auto;
    line-height: 1.6;
    font-size: 14px; /* سایز پیش‌فرض دسکتاپ */
}

a { color: var(--link-color); text-decoration: none; transition: 0.2s; }
a:hover { opacity: 0.8; }

/* --- سایدبار --- */
.sidebar {
    width: 240px;
    background-color: var(--bg-card);
    border-left: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: transform 0.3s ease;
}
.logo {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--primary);
    text-align: center;
    margin-bottom: 30px;
    display: flex; justify-content: space-between; align-items: center;
}
.nav-links { display: flex; flex-direction: column; gap: 8px; flex-grow: 1; overflow-y: auto; }
.nav-item {
    padding: 10px 12px; border-radius: 8px;
    color: var(--text-muted); font-weight: 500;
    display: flex; align-items: center; gap: 10px; font-size: 0.95rem;
}
.nav-item:hover { background-color: rgba(59, 130, 246, 0.1); color: var(--primary); }
.nav-item.active { background-color: var(--primary); color: #fff; }

/* --- دکمه‌ها --- */
.btn-cta {
    background-color: var(--success); color: #fff !important;
    text-align: center; padding: 12px; border-radius: 8px;
    font-weight: 700; margin-top: 15px; border: none; cursor: pointer; width: 100%;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.2);
    font-size: 0.95rem;
}
.toggle-sidebar-btn, .close-sidebar-btn {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px 12px; cursor: pointer; display: none; color: var(--text-main);
}
.toggle-sidebar-btn { position: fixed; top: 15px; right: 15px; z-index: 1001; }

/* --- محتوا --- */
.main-content {
    flex-grow: 1; padding: 20px 30px;
    display: flex; flex-direction: column;
    height: auto; overflow: visible;
}
.header-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; flex-shrink: 0;
}
.page-title { font-size: 1.4rem; font-weight: 800; margin: 0; }
.date-badge {
    background: var(--bg-card); border: 1px solid var(--border);
    padding: 6px 15px; border-radius: 20px; font-size: 0.85rem;
    color: var(--text-main); font-weight: 500; white-space: nowrap;
}

/* --- کارت‌ها --- */
.card, .flex-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px; overflow: hidden;
}
.card { padding: 20px; }
.card-header { padding: 15px 20px; border-bottom: 1px solid var(--border); background-color: rgba(0,0,0,0.02); }
.card-title-small { margin: 0; font-size: 1rem; font-weight: 700; }
.card-footer { padding: 15px 20px; border-top: 1px solid var(--border); background-color: var(--bg-card); }

/* --- گرید آمار --- */
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 20px; }
.summary-card {
    background: var(--bg-card); padding: 15px; border-radius: var(--radius);
    border: 1px solid var(--border); text-align: center; box-shadow: var(--shadow);
}
.summary-card .value { font-size: 1.2rem; font-weight: 800; margin: 5px 0 0 0; }
.summary-card h3 { font-size: 0.85rem; color: var(--text-muted); margin: 0; }

/* --- استایل جدول دسکتاپ --- */
.desktop-table-view { display: block; width: 100%; }
.table-scroll-area { overflow-x: auto; width: 100%; } /* اسکرول افقی برای جدول */
.custom-table {
    width: 100%; border-collapse: collapse; min-width: 800px; /* حداقل عرض برای جلوگیری از له شدن */
}
.custom-table th {
    position: sticky; top: 0; background-color: var(--bg-card);
    padding: 12px 10px; font-weight: 700; font-size: 0.85rem; color: var(--text-muted);
    border-bottom: 2px solid var(--border); text-align: center; white-space: nowrap; z-index: 2;
}
.custom-table td {
    padding: 10px; border-bottom: 1px solid var(--border);
    vertical-align: middle; font-size: 0.9rem; text-align: center; white-space: nowrap;
}
.custom-table tr:hover td { background-color: rgba(0,0,0,0.02); }
.table-input {
    width: 80px; padding: 6px; text-align: center;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg-body); color: var(--text-main); font-family: var(--font-family);
}

/* --- استایل کارت موبایل --- */
.mobile-card-view { display: none; }
.data-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; padding: 12px; margin-bottom: 10px;
    box-shadow: var(--shadow); position: relative;
}
.data-card-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed var(--border); font-size: 0.85rem;
}
.data-card-row:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.dc-label { color: var(--text-muted); }
.dc-value { font-weight: 600; color: var(--text-main); }
.dc-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dc-title { font-size: 1rem; font-weight: 800; color: var(--primary); }

/* --- فرم‌ها --- */
.form-group { margin-bottom: 15px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 0.85rem; }
.form-control, .form-select {
    width: 100%; padding: 10px; border-radius: 8px;
    border: 1px solid var(--border); background-color: var(--bg-body);
    color: var(--text-main); font-family: var(--font-family); font-size: 0.95rem;
}
/* گرید دسکتاپ برای فرم‌های کنار هم */
.form-row-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

/* --- اتوکامپلیت --- */
.ac-results {
    position: absolute; top: 100%; left: 0; right: 0;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 0 0 8px 8px; z-index: 50; max-height: 150px; overflow-y: auto; box-shadow: var(--shadow);
}
.ac-item { padding: 10px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.ac-item:hover { background-color: rgba(37, 99, 235, 0.1); }
.position-relative { position: relative; }
.pwt-datepicker-container { font-family: var(--font-family) !important; z-index: 9999 !important; }

/* رنگ‌ها */
.text-success { color: var(--success) !important; font-weight: 700; }
.text-danger { color: var(--danger) !important; font-weight: 700; }
.text-neutral { color: var(--text-muted) !important; }
.text-warning { color: #ffc107 !important; font-weight: 700; }
.text-orange { color: #fd7e14 !important; font-weight: 700; }

/* --- ریسپانسیو (موبایل) --- */
@media (max-width: 768px) {
    /* تنظیمات کلی موبایل */
    body {
        flex-direction: column;
        font-size: 12.5px; /* فونت کلی کوچک‌تر */
    }

    /* سایدبار موبایل */
    .sidebar {
        position: fixed; right: 0; top: 0; bottom: 0;
        width: 240px; padding: 15px;
        transform: translateX(100%);
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    }
    .sidebar.open { transform: translateX(0); }
    .toggle-sidebar-btn, .close-sidebar-btn { display: block; }
    .nav-links, .sidebar-footer { display: flex; }

    /* محتوای اصلی موبایل */
    .main-content {
        padding: 15px; padding-top: 55px; padding-bottom: 70px; /* فضای بالا و پایین */
    }
    .header-row { margin-bottom: 15px; }
    .page-title { font-size: 1.1rem; }

    /* کارت‌های خلاصه */
    .summary-grid { grid-template-columns: 1fr; gap: 10px; }
    .summary-card { padding: 10px; display: flex; flex-direction: row; justify-content: space-between; align-items: center; text-align: right; }
    .summary-card h3 { margin: 0; font-size: 0.85rem; }
    .summary-card .value { margin: 0; font-size: 1rem; }

    /* تبدیل ستون‌بندی‌ها به تک‌ستونه */
    .form-row-2, .stats-grid {
        grid-template-columns: 1fr !important; /* همه چیز زیر هم */
        gap: 15px;
    }

    /* گرید نتایج جستجو در موبایل */
    .grid-results { grid-template-columns: 1fr !important; }

    /* جدول‌ها و کارت‌ها */
    .desktop-table-view { display: none; } /* جدول مخفی */
    .mobile-card-view { display: block; } /* کارت نمایان */

    /* اسکرول جدول در جایی که مجبوریم جدول داشته باشیم */
    .table-scroll-area { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* کوچک کردن فرم‌ها */
    .form-control, .form-select {
        padding: 8px; font-size: 0.9rem;
    }
    .btn-cta { padding: 10px; font-size: 0.9rem; margin-top: 10px; }

    /* فاصله و پدینگ کارت‌های موبایل */
    .card, .flex-card { padding: 15px; margin-bottom: 15px; }
    .card-header { padding: 10px 15px; }
}

/* منوی پایین موبایل */
.mobile-nav {
    display: none; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg-card); border-top: 1px solid var(--border);
    padding: 6px; justify-content: space-around; z-index: 999;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}
.mobile-item {
    text-align: center; color: var(--text-muted); font-size: 0.7rem;
    display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1;
}
.mobile-search-btn {
    width: 36px; height: 36px; background: var(--bg-body);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); font-size: 1rem; margin-bottom: 4px;
}
.mobile-item svg { width: 20px; height: 20px; }

@media (max-width: 768px) { .mobile-nav { display: flex; } }