/* ======================================== */
/* ============== CSS STYLES ============== */
/* ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;700&display=swap');

/* حفظ پالت رنگی اولیه شما */
:root {
    --sidebar-bg: #2c3e50;
    --sidebar-bg-hover: #34495e;
    --sidebar-bg-active: #1abc9c;
    --sidebar-text: #ecf0f1;
    --sidebar-text-muted: #95a5a6;
    --main-bg: #f8f9fa;
    --sidebar-width: 270px;
    --sidebar-width-collapsed: 80px;
}

body {
    font-family: 'Vazirmatn', sans-serif;
    margin: 0;
    background-color: var(--main-bg);
    transition: margin-right 0.3s ease;
}

/* --- 1. ساختار سه‌بخشی جدید --- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    right: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 1000;
}

/* --- 2. هدر ثابت و هوشمند شده --- */
.sidebar-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0; /* جلوگیری از کوچک شدن */
    background-color: rgba(0,0,0,0.1);
}
.sidebar-logo { font-size: 1.4em; font-weight: 700; white-space: nowrap; }
.quick-actions { display: flex; align-items: center; }
.quick-actions button {
    background: none; border: none; color: var(--sidebar-text); font-size: 1.2em;
    cursor: pointer; margin: 0 5px; padding: 5px; border-radius: 5px;
}
.quick-actions button:hover { background-color: var(--sidebar-bg-hover); }

/* --- 3. بخش میانی اسکرول‌شونده --- */
.sidebar-nav {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px 0;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background-color: #4b5563; border-radius: 3px; }

.nav-item a {
    display: flex; align-items: center; padding: 12px 25px;
    color: var(--sidebar-text); text-decoration: none;
    transition: background-color 0.2s; white-space: nowrap;
}
.nav-item a:hover { background-color: var(--sidebar-bg-hover); }
.nav-item.active > a { background-color: var(--sidebar-bg-active); font-weight: 500; }
.nav-item a i.fa-fw { width: 1.5em; margin-left: 15px; font-size: 1.1em; }
.nav-item .nav-text { opacity: 1; transition: opacity 0.2s ease; }

/* زیرمنو ها (بدون تغییر) */
.submenu { background-color: rgba(0,0,0,0.15); max-height: 0; overflow: hidden; transition: max-height 0.3s ease-out; }
.nav-item.open > .submenu { max-height: 500px; }
.submenu .nav-item a { padding-right: 50px; }
.nav-item.has-submenu > a { position: relative; }
.nav-item.has-submenu > a::after {
    content: '\f078'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
    position: absolute; left: 20px; transition: transform 0.3s ease;
}
.nav-item.has-submenu.open > a::after { transform: rotate(180deg); }
.divider { height: 1px; margin: 15px 25px; background-color: rgba(255,255,255,0.1); }

/* --- 4. فوتر ثابت و مدرن --- */
.sidebar-footer {
    position: relative; /* <<<< این خط برای جای‌گیری منوی پاپ‌آپ ضروری است */
    height: 65px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px 0 20px;
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.user-profile { display: flex; align-items: center; cursor: pointer; flex-grow: 1; overflow: hidden; padding: 10px 0; }
.user-profile .avatar { font-size: 2.2em; margin-left: 10px; }
.user-details { display: flex; flex-direction: column; white-space: nowrap; }
.user-name { font-weight: 500; }
.user-role { font-size: 0.8em; color: var(--sidebar-text-muted); }
#sidebar-toggle {
    background: none; border: none; color: var(--sidebar-text);
    font-size: 1.2em; cursor: pointer; padding: 5px;
}

/* ======================================================= */
/* ===== کدهای جدید برای استایل‌دهی منوی پاپ‌آپ تنظیمات ===== */
/* ======================================================= */
.profile-menu {
    position: absolute;
    bottom: 70px; /* بالای فوتر قرار می‌گیرد */
    right: 15px;
    width: 240px;
    background-color: #3e5165; /* کمی روشن‌تر از پس‌زمینه اصلی */
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    padding: 8px;
    z-index: 1010;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.profile-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.profile-menu a {
    display: flex; align-items: center; padding: 10px;
    color: var(--sidebar-text); text-decoration: none; border-radius: 5px;
}

.profile-menu a:hover {
    background-color: var(--sidebar-bg-hover);
}

.profile-menu a i {
    margin-left: 10px;
    width: 20px; /* برای هم‌ترازی آیکون‌ها */
}

/* --- حالت کوچک شده (Collapsed) --- */
.sidebar.collapsed { width: var(--sidebar-width-collapsed); }
.sidebar.collapsed .sidebar-logo, .sidebar.collapsed .nav-text,
.sidebar.collapsed .user-details,
.sidebar.collapsed .nav-item.has-submenu > a::after {
    opacity: 0; width: 0; visibility: hidden;
}
.sidebar.collapsed .nav-item a, .sidebar.collapsed .quick-actions,
.sidebar.collapsed .user-profile { justify-content: center; }
.sidebar.collapsed .nav-item a i.fa-fw { margin-left: 0; }
.sidebar.collapsed .submenu { display: none; }

/* مهم: مخفی کردن منوی پاپ‌آپ در حالت کوچک شده */
.sidebar.collapsed .profile-menu {
    display: none !important;
}

main.main-content { margin-right: var(--sidebar-width); padding: 30px; transition: margin-right 0.3s ease; }
main.main-content.full-width { margin-right: var(--sidebar-width-collapsed); }

/* ======================================== */
/* === استایل‌های داشبورد (نسخه حرفه‌ای) === */
/* ======================================== */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.dashboard-widget {
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    display: flex;
    flex-direction: column;
}

.widget-header {
    padding: 15px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.widget-header h3 {
    margin: 0;
    font-size: 1.1em;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 10px;
}

.widget-content {
    padding: 20px;
    flex-grow: 1;
}

/* --- ویجت عملکرد فصلی --- */
.performance-chart {
    /* ... استایل برای نمودار ... */
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px dashed #e2e8f0;
    margin-bottom: 20px;
}
.performance-summary .summary-value { font-size: 2em; font-weight: 700; color: #1e293b; }
.performance-summary .summary-label { font-size: 0.9em; color: #64748b; }

.performance-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.detail-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.95em;
}
.detail-item.gap { font-weight: 700; color: #ef4444; }

/* --- ویجت‌های جدولی --- */
.table-widget table {
    width: 100%;
    border-collapse: collapse;
}
.table-widget th, .table-widget td {
    padding: 10px 5px;
    text-align: right;
    border-bottom: 1px solid #f1f5f9;
}
.table-widget thead { font-size: 0.85em; color: #64748b; }

/* امتیاز هوش مصنوعی */
.ai-score {
    padding: 3px 8px;
    border-radius: 20px;
    font-weight: 700;
}
.ai-score.high { background-color: #dcfce7; color: #16a34a; }
.ai-score.medium { background-color: #fef9c3; color: #ca8a04; }

/* وضعیت پوسیدگی */
.status-pill {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 500;
}
.status-pill.red { background-color: #fee2e2; color: #dc2626; }
.status-pill.orange { background-color: #ffedd5; color: #f97316; }

/* --- ویجت قیف فروش --- */
.funnel-stages {
    display: flex;
    justify-content: space-around;
    gap: 10px;
}
.funnel-stage {
    text-align: center;
}
.stage-name { font-size: 0.9em; font-weight: 500; color: #475569; }
.stage-value { display: block; font-size: 1.4em; font-weight: 700; color: #1e293b; margin-top: 5px; }
.stage-weighted-value { font-size: 0.8em; color: #64748b; }