/* ===== CSS Variables ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #ea580c;
    --warning-light: #fff7ed;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --purple: #7c3aed;
    --purple-light: #ede9fe;
    --whatsapp: #25d366;
    --sms: #f59e0b;
    --email: #6366f1;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #2563eb;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.1);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    direction: rtl;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 100;
    transition: transform .3s ease;
}
.sidebar-header { padding: 24px 20px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
    width: 42px; height: 42px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 18px;
}
.logo-text { font-size: 28px; font-weight: 800; color: #fff; letter-spacing: -1px; }
.logo-sub { font-size: 12px; color: var(--sidebar-text); margin-top: 4px; opacity: .7; }
.sidebar-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-radius: 10px;
    color: var(--sidebar-text); text-decoration: none;
    font-size: 14px; font-weight: 500;
    transition: all .2s ease;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item i { width: 20px; text-align: center; font-size: 16px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.08); }
.user-info { display: flex; align-items: center; gap: 12px; }
.user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(255,255,255,.12);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
}
.user-name { font-size: 13px; font-weight: 600; color: #fff; }
.user-role { font-size: 11px; color: var(--sidebar-text); }

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-right: 260px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.top-bar {
    background: var(--surface);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }
.page-title { font-size: 22px; font-weight: 700; flex: 1; }
.demo-badge {
    background: var(--warning-light);
    color: var(--warning);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.content-area { padding: 28px 32px; flex: 1; }

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 { font-size: 16px; font-weight: 700; }
.card-body { padding: 24px; }

/* ===== KPI Cards ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 28px; }
.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 22px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    cursor: pointer;
    transition: all .2s ease;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.kpi-icon.blue { background: var(--primary-light); color: var(--primary); }
.kpi-icon.green { background: var(--success-light); color: var(--success); }
.kpi-icon.orange { background: var(--warning-light); color: var(--warning); }
.kpi-icon.purple { background: var(--purple-light); color: var(--purple); }
.kpi-content { flex: 1; }
.kpi-value { font-size: 28px; font-weight: 800; line-height: 1.1; }
.kpi-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.kpi-trend { font-size: 12px; margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.kpi-trend.up { color: var(--success); }
.kpi-trend.down { color: var(--danger); }

/* ===== Grid Layouts ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 28px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; margin-bottom: 28px; }

/* ===== Tables ===== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
    background: var(--bg);
    padding: 12px 16px;
    text-align: right;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: .5px;
}
tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all .2s ease;
    font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-icon {
    width: 36px; height: 36px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px; background: var(--bg); border: 1px solid var(--border);
    cursor: pointer; color: var(--text-secondary);
    transition: all .2s;
}
.btn-icon:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* ===== Badges ===== */
.badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-purple { background: var(--purple-light); color: var(--purple); }

/* ===== Channel Icons ===== */
.channel-icon {
    width: 28px; height: 28px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 14px; color: #fff;
}
.channel-whatsapp { background: var(--whatsapp); }
.channel-sms { background: var(--sms); }
.channel-email { background: var(--email); }

/* ===== Forms ===== */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color .2s;
    background: var(--surface);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { resize: vertical; min-height: 80px; }

/* ===== Import Source Buttons ===== */
.source-cards { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.source-card {
    flex: 1; min-width: 140px;
    padding: 20px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    text-align: center;
    cursor: pointer;
    transition: all .2s ease;
    background: var(--surface);
}
.source-card:hover { border-color: var(--primary); background: var(--primary-light); }
.source-card.active { border-color: var(--primary); background: var(--primary-light); }
.source-card i { font-size: 32px; color: var(--primary); margin-bottom: 8px; display: block; }
.source-card span { font-size: 14px; font-weight: 600; }

/* ===== Toggle Switch ===== */
.toggle-switch {
    position: relative; display: inline-block;
    width: 44px; height: 24px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #cbd5e1; border-radius: 24px;
    transition: .3s;
}
.toggle-slider:before {
    content: '';
    position: absolute; height: 18px; width: 18px;
    right: 3px; bottom: 3px;
    background: #fff; border-radius: 50%;
    transition: .3s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--success); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(-20px); }

/* ===== Bot Flow Items ===== */
.flow-item {
    display: flex; align-items: center; gap: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    transition: all .2s;
}
.flow-item:hover { border-color: var(--primary); background: #fafbff; }
.flow-number {
    width: 32px; height: 32px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px;
    flex-shrink: 0;
}
.flow-info { flex: 1; }
.flow-name { font-weight: 600; font-size: 14px; }
.flow-trigger { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ===== Progress Bar ===== */
.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width .6s ease;
}
.progress-fill.blue { background: var(--primary); }
.progress-fill.green { background: var(--success); }
.progress-fill.orange { background: var(--warning); }

/* ===== Campaign Status ===== */
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 6px;
}
.status-dot.active { background: var(--success); }
.status-dot.draft { background: var(--sms); }
.status-dot.completed { background: var(--text-secondary); }

/* ===== Channel Select (Campaigns) ===== */
.channel-options { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.channel-option {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 20px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all .2s;
    user-select: none;
}
.channel-option:hover { border-color: var(--primary); }
.channel-option.selected { border-color: var(--primary); background: var(--primary-light); }
.channel-option i { font-size: 22px; }
.channel-option.whatsapp i { color: var(--whatsapp); }
.channel-option.sms i { color: var(--sms); }
.channel-option.email i { color: var(--email); }
.channel-option span { font-weight: 600; font-size: 14px; }

/* ===== Section Titles ===== */
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.section-title i { color: var(--primary); }

/* ===== Action bar ===== */
.action-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.search-box {
    position: relative; flex: 1; max-width: 320px;
}
.search-box input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}
.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ===== Chart Container ===== */
.chart-container { position: relative; width: 100%; height: 280px; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--surface);
    border-radius: 16px;
    width: 90%;
    max-width: 520px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    animation: modalIn .3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-secondary); }
.modal-body { padding: 24px; font-size: 14px; line-height: 1.8; color: var(--text); }
.modal-body ul { padding-right: 20px; margin: 12px 0; }
.modal-body li { margin-bottom: 6px; }
.modal-body .feature-highlight {
    background: var(--primary-light);
    padding: 14px 18px;
    border-radius: 10px;
    border-right: 4px solid var(--primary);
    margin: 14px 0;
    font-size: 13px;
}
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 24px;
    left: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--surface);
    border-radius: 10px;
    padding: 14px 20px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    min-width: 280px;
    animation: toastIn .3s ease, toastOut .3s ease 3s forwards;
    border-right: 4px solid var(--success);
}
.toast.info { border-right-color: var(--primary); }
.toast i { font-size: 18px; color: var(--success); }
.toast.info i { color: var(--primary); }
@keyframes toastIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-right: 0; }
    .menu-toggle { display: block; }
    .kpi-grid { grid-template-columns: 1fr; }
    .content-area { padding: 20px 16px; }
    .top-bar { padding: 12px 16px; }
    .source-cards { flex-direction: column; }
    .channel-options { flex-direction: column; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===== Animations ===== */
.fade-in { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Ranking list ===== */
.rank-list { list-style: none; }
.rank-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.rank-item:last-child { border-bottom: none; }
.rank-num {
    width: 28px; height: 28px;
    background: var(--bg);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: var(--text-secondary);
    flex-shrink: 0;
}
.rank-item:nth-child(1) .rank-num { background: #fef3c7; color: #d97706; }
.rank-item:nth-child(2) .rank-num { background: #e2e8f0; color: #475569; }
.rank-item:nth-child(3) .rank-num { background: #fed7aa; color: #c2410c; }
.rank-name { flex: 1; font-size: 14px; font-weight: 500; }
.rank-value { font-size: 14px; font-weight: 700; color: var(--primary); }
