/* ==========================================================================
   سامانه بات‌ساز و سایت‌ساز بله - استایل جامع پنل مدیریت (v2.0 Pro)
   طراحی فوق‌حرفه‌ای، زیبا و ۱۰۰٪ سازگار با موبایل (Responsive & Mobile-First)
   بدون وابستگی به سرویس‌های خارجی (اجرای لوکال هاست و آفلاین)
   ========================================================================== */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-main: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-focus: #3b82f6;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --sidebar-bg: #0f172a;
    --sidebar-text: #f8fafc;
    --sidebar-hover: #1e293b;
    --sidebar-active: #2563eb;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 10px 25px -5px rgba(15,23,42,0.08);
    --shadow-lg: 0 20px 40px -10px rgba(15,23,42,0.14);
    --font-stack: Tahoma, "Vazirmatn", "Shabnam", Arial, "Segoe UI", sans-serif;
}

body.admin-body, body.install {
    font-family: var(--font-stack);
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.65;
    direction: rtl;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
    transition: all 0.2s ease;
}

/* ==========================================================================
   Topbar (نوار ناوبری بالای صفحه)
   ========================================================================== */
.admin-topbar {
    background: #0f172a;
    color: #fff;
    min-height: 66px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 28px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 18px rgba(0,0,0,0.22);
    width: 100%;
    flex-wrap: wrap;
    gap: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.mobile-menu-toggle {
    display: none;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    font-size: 22px;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.mobile-menu-toggle:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.05);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.brand-icon {
    font-size: 26px;
    filter: drop-shadow(0 0 8px rgba(59,130,246,0.6));
}

.brand-version {
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    padding: 3px 12px;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(37,99,235,0.4);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.topbar-link {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.14);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.topbar-link:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-1px);
}

.logout-link {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.logout-link:hover {
    background: #ef4444;
    color: #fff;
}

/* ==========================================================================
   RTL Flexbox Layout & Sidebar (سایدبار و کانتینر اصلی)
   ========================================================================== */
.admin-wrap {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    width: 100%;
    min-height: calc(100vh - 66px);
    position: relative;
}

.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    height: calc(100vh - 66px);
    position: sticky;
    top: 66px;
    overflow-y: auto;
    padding: 24px 16px;
    border-left: 1px solid rgba(255,255,255,0.07);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 90;
}

/* Custom Scrollbar for Sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 999px;
}

.sidebar-header {
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header h3 {
    font-size: 12.5px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.sidebar-category {
    margin-bottom: 22px;
}

.sidebar-cat-title {
    font-size: 13px;
    color: #cbd5e1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-weight: 800;
}

.sidebar-cat-items {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-right: 8px;
}

.sidebar-item {
    padding: 11px 15px;
    border-radius: var(--radius-sm);
    color: #a6b8d4;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 12px;
    line-height: 1.5;
    text-decoration: none;
    word-break: break-word;
    transition: all 0.2s ease;
    font-weight: 500;
}

.sidebar-item:hover {
    background: var(--sidebar-hover);
    color: #ffffff;
    transform: translateX(-3px);
}

.sidebar-item.active {
    background: var(--sidebar-active);
    color: #ffffff;
    font-weight: 700;
    box-shadow: 0 6px 16px rgba(37,99,235,0.45);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 66px;
    right: 0;
    left: 0;
    bottom: 0;
    background: rgba(15,23,42,0.7);
    z-index: 85;
    backdrop-filter: blur(3px);
}

/* ==========================================================================
   Main Content Area (بخش محتوای اصلی)
   ========================================================================== */
.content {
    flex: 1;
    min-width: 0;
    padding: 30px 36px;
    overflow-x: hidden;
    max-width: calc(100% - 300px);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 26px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
}

.page-title {
    font-size: 26px;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

/* --- Panels --- */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 26px;
    margin: 22px 0;
    box-shadow: var(--shadow-md);
    transition: box-shadow 0.2s ease;
}

.panel:hover {
    box-shadow: var(--shadow-lg);
}

.panel h2 {
    font-size: 20px;
    margin-bottom: 18px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
}

.panel h3 {
    font-size: 17px;
    margin-bottom: 14px;
    color: var(--text-primary);
    font-weight: 700;
}

/* ==========================================================================
   Buttons (دکمه‌های حرفه‌ای)
   ========================================================================== */
.button {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: #f8fafc;
    color: var(--text-primary);
    padding: 11px 20px;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.button:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.button.primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: 0 6px 18px rgba(37,99,235,0.35);
}

.button.danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #ffffff;
}

.button.danger:hover {
    background: #dc2626;
    border-color: #dc2626;
    box-shadow: 0 6px 18px rgba(239,68,68,0.35);
}

.button.success {
    background: var(--success);
    border-color: var(--success);
    color: #ffffff;
}

.button.success:hover {
    background: #059669;
    border-color: #059669;
    box-shadow: 0 6px 18px rgba(16,185,129,0.35);
}

.button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

/* ==========================================================================
   Forms (فرم‌ها و ورودی‌های اطلاعات)
   ========================================================================== */
.grid-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.grid-form label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-weight: 700;
    font-size: 13.5px;
    color: var(--text-secondary);
}

.grid-form .wide {
    grid-column: 1 / -1;
}

.grid-form input,
.grid-form select,
.grid-form textarea {
    width: 100%;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-family: inherit;
    font-size: 14px;
    background: #f8fafc;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.grid-form input:focus,
.grid-form select:focus,
.grid-form textarea:focus {
    background: #ffffff;
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-light);
}

.grid-form textarea {
    min-height: 130px;
    resize: vertical;
}

/* Inline Form */
.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 4px 0;
}

/* Checkbox & Radio styling */
.checks {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.checks label {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: 999px;
    padding: 8px 16px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.checks label:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* ==========================================================================
   Tables (جداول اطلاعات و گزارش‌ها)
   ========================================================================== */
.table-wrap {
    overflow-x: auto;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-top: 18px;
    box-shadow: var(--shadow-sm);
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
}

th, td {
    padding: 15px 18px;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
    font-size: 13.5px;
}

th {
    background: #f8fafc;
    color: var(--text-secondary);
    font-weight: 800;
    position: sticky;
    top: 0;
}

tr:hover td {
    background: #f8fafc;
}

.actions-cell {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* ==========================================================================
   Cards & Grids (کارت‌های آمار و اطلاعات)
   ========================================================================== */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 20px;
    margin-bottom: 26px;
}

.card {
    background: #ffffff;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 24px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.2s ease;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: #cbd5e1;
}

.card b {
    font-size: 34px;
    color: var(--primary);
    margin-top: 8px;
    font-weight: 900;
}

.card span {
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
}

/* ==========================================================================
   Notices & Flashes (نوتیفیکیشن‌ها و هشدارها)
   ========================================================================== */
.notice {
    border-radius: var(--radius-md);
    padding: 16px 20px;
    margin: 18px 0;
    display: flex;
    align-items: center;
    gap: 14px;
    font-weight: 700;
    font-size: 14px;
}

.notice.success {
    background: var(--success-light);
    color: #065f46;
    border: 1.5px solid #a7f3d0;
}

.notice.error {
    background: var(--danger-light);
    color: #991b1b;
    border: 1.5px solid #fecaca;
}

.notice-icon {
    font-size: 20px;
}

/* ==========================================================================
   Visual Site Builder Styling (.visual-builder-wrap)
   ========================================================================== */
.visual-builder-wrap {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
    align-items: start;
}

.builder-sections-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.builder-section-card {
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: all 0.2s ease;
}

.builder-section-header {
    background: #f8fafc;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: move;
}

.builder-section-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.drag-handle {
    cursor: grab;
    font-size: 20px;
    color: #94a3b8;
}

.preview-box {
    background: #f8fafc;
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius-lg);
    padding: 34px;
    text-align: center;
    min-height: 230px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Module Manager Cards (.module-grid)
   ========================================================================== */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 22px;
}

.module-card {
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    position: relative;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.module-card.is-active {
    border-color: var(--success);
    background: #f0fdf4;
}

.module-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 14px;
}

.module-badge {
    font-size: 11.5px;
    padding: 5px 12px;
    border-radius: 999px;
    font-weight: 800;
}

.module-badge.active {
    background: var(--success);
    color: #ffffff;
}

.module-badge.inactive {
    background: #e2e8f0;
    color: var(--text-secondary);
}

.module-actions {
    display: flex;
    gap: 12px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

/* ==========================================================================
   Login & Install Screens (.install)
   ========================================================================== */
.install {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    padding: 20px;
}

.install-card {
    width: min(520px, 94vw);
    background: #ffffff;
    border-radius: 28px;
    box-shadow: 0 25px 70px rgba(0,0,0,0.35);
    padding: 36px;
}

.install-card h1 {
    font-size: 26px;
    font-weight: 900;
    margin-bottom: 24px;
    color: var(--text-primary);
    text-align: center;
}

/* ==========================================================================
   Footer (فوتر ادمین)
   ========================================================================== */
.admin-footer {
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    padding: 20px 28px;
    margin-top: auto;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    color: var(--text-muted);
    font-size: 13.5px;
}

.footer-credit {
    font-weight: 700;
    color: var(--text-secondary);
}

/* ==========================================================================
   Responsive Media Queries (سازگاری کامل و زیبا با موبایل و تبلت)
   ========================================================================== */
@media (max-width: 1024px) {
    .visual-builder-wrap {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .admin-wrap {
        flex-direction: column;
    }
    .mobile-menu-toggle {
        display: flex;
    }
    .sidebar {
        position: fixed;
        right: 0;
        top: 66px;
        bottom: 0;
        width: 290px;
        height: calc(100vh - 66px);
        z-index: 95;
        transform: translateX(100%);
        box-shadow: -15px 0 40px rgba(0,0,0,0.35);
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .sidebar-overlay.mobile-open {
        display: block;
    }
    .content {
        max-width: 100%;
        width: 100%;
        padding: 20px 16px;
    }
    .grid-form {
        grid-template-columns: 1fr;
    }
    .topbar-brand b {
        font-size: 15px;
    }
    .cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .topbar-left .topbar-link {
        padding: 6px 10px;
        font-size: 12px;
    }
    .page-title {
        font-size: 21px;
    }
    .panel {
        padding: 18px;
    }
    .admin-topbar {
        padding: 10px 16px;
    }
    .cards {
        grid-template-columns: 1fr;
    }
    table {
        min-width: 600px;
    }
}
