/*
 * Meta Ads Dashboard — "Midnight Command" Design
 * ================================================
 * Dark professional dashboard with teal/cyan accents.
 * Font: Tajawal (Arabic), system-ui fallback.
 * RTL-first layout.
 */

/* ── Reset & Base ──────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0B0F1A;
    --bg-secondary: #111827;
    --bg-card: #1A2035;
    --bg-card-hover: #1F2847;
    --bg-input: #0F172A;
    --border: #1E293B;
    --border-light: #334155;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --accent: #06B6D4;
    --accent-light: #22D3EE;
    --accent-dark: #0891B2;
    --accent-bg: rgba(6, 182, 212, 0.08);
    --accent-border: rgba(6, 182, 212, 0.2);
    --success: #10B981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #F59E0B;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --danger: #EF4444;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --info: #3B82F6;
    --info-bg: rgba(59, 130, 246, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
    --font: 'Tajawal', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --transition: 200ms ease;
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-light); }

/* ── Layout ────────────────────────────────────── */
.dashboard-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-logo svg { width: 20px; height: 20px; fill: white; }

.sidebar-brand {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

.sidebar-brand small {
    display: block;
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.nav-link:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-link.active { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent-border); }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

.sync-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sync-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Main Content ──────────────────────────────── */
.main-content {
    flex: 1;
    margin-right: 260px;
    min-height: 100vh;
}

.top-bar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.breadcrumb {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.breadcrumb span { color: var(--text-primary); font-weight: 600; }

.btn-sync {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 1rem;
    background: var(--accent-bg);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.btn-sync:hover { background: rgba(6, 182, 212, 0.15); }
.btn-sync.loading svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-content {
    padding: 2rem;
    max-width: 1400px;
}

/* ── KPI Cards ─────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    opacity: 0;
    transition: opacity var(--transition);
}

.kpi-card:hover { border-color: var(--border-light); transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-card:hover::before { opacity: 1; }

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.kpi-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-bg);
}

.kpi-icon svg { width: 16px; height: 16px; color: var(--accent); }

.kpi-value {
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.kpi-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ── Section Headers ───────────────────────────── */
.section-header {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.section-number {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-bg);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--accent-border);
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.section-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-right: auto;
}

/* ── Charts ────────────────────────────────────── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.chart-card-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.chart-card-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.chart-container {
    position: relative;
    height: 280px;
}

/* ── Data Table ────────────────────────────────── */
.table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 2rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table thead {
    background: rgba(6, 182, 212, 0.04);
}

.data-table th {
    padding: 0.75rem 1rem;
    text-align: right;
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-card-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

.campaign-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.82rem;
}

.campaign-name small {
    display: block;
    font-weight: 400;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.mono { font-family: var(--font-mono); font-size: 0.8rem; letter-spacing: -0.01em; }

/* ── Campaign Cards ────────────────────────────── */
.campaigns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.campaign-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all var(--transition);
}

.campaign-card:hover { border-color: var(--border-light); box-shadow: var(--shadow); }

.campaign-card-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.campaign-card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.15rem;
}

.campaign-card-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.campaign-card-result {
    background: var(--bg-input);
    margin: 0 1.25rem;
    margin-top: -0.5rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    margin-top: 0.75rem;
}

.result-label { font-size: 0.72rem; color: var(--text-muted); }
.result-value { font-family: var(--font-mono); font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.result-cost { font-size: 0.7rem; color: var(--text-muted); font-family: var(--font-mono); }

.campaign-card-metrics {
    padding: 1rem 1.25rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.metric-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 0;
}

.metric-label { font-size: 0.7rem; color: var(--text-muted); }
.metric-value { font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600; color: var(--text-primary); }

/* ── Badges ────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-secondary { background: rgba(100,116,139,0.1); color: var(--text-muted); }

.objective-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius);
    font-size: 0.7rem;
    font-weight: 600;
    border: 1px solid;
}

/* ── Recommendations ───────────────────────────── */
.recs-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.rec-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    gap: 1rem;
    transition: all var(--transition);
    border-right: 4px solid var(--border);
}

.rec-card:hover { border-color: var(--border-light); }
.rec-card.rec-success { border-right-color: var(--success); }
.rec-card.rec-warning { border-right-color: var(--warning); }
.rec-card.rec-danger { border-right-color: var(--danger); }
.rec-card.rec-info { border-right-color: var(--info); }

.rec-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.rec-success .rec-icon { background: var(--success-bg); color: var(--success); }
.rec-warning .rec-icon { background: var(--warning-bg); color: var(--warning); }
.rec-danger .rec-icon { background: var(--danger-bg); color: var(--danger); }
.rec-info .rec-icon { background: var(--info-bg); color: var(--info); }

.rec-content { flex: 1; min-width: 0; }
.rec-title { font-size: 0.85rem; font-weight: 700; color: var(--text-primary); margin-bottom: 0.25rem; }
.rec-desc { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.7; }

/* ── Buttons ───────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-block { width: 100%; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* ── Forms ─────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 0.4rem; }

.form-input {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font);
    transition: border-color var(--transition);
}

.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

/* ── Alerts ────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.82rem;
    margin-bottom: 1rem;
}

.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(16,185,129,0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(59,130,246,0.2); }

/* ── Login Page ────────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
    background-image: radial-gradient(ellipse at top, rgba(6,182,212,0.05) 0%, transparent 60%);
}

.login-container { width: 100%; max-width: 400px; padding: 1.5rem; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    text-align: center;
}

.login-logo { margin-bottom: 1.5rem; }
.login-title { font-size: 1.3rem; font-weight: 800; color: var(--text-primary); margin-bottom: 0.3rem; }
.login-subtitle { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 1.5rem; }
.login-form { text-align: right; }

/* ── Mobile Sidebar Toggle ─────────────────────── */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    z-index: 200;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    align-items: center;
    justify-content: center;
}

.sidebar-toggle svg { width: 22px; height: 22px; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 1024px) {
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: flex; }
    .sidebar-overlay.open { display: block; }
    .main-content { margin-right: 0; }
    .top-bar { padding: 0.75rem 1rem; }
    .page-content { padding: 1rem; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .campaigns-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
}

/* ── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Animations ────────────────────────────────── */
.fade-in {
    opacity: 0;
    transform: translateY(12px);
    animation: fadeIn 0.5s ease forwards;
}

@keyframes fadeIn {
    to { opacity: 1; transform: translateY(0); }
}

.fade-in:nth-child(1) { animation-delay: 0.05s; }
.fade-in:nth-child(2) { animation-delay: 0.1s; }
.fade-in:nth-child(3) { animation-delay: 0.15s; }
.fade-in:nth-child(4) { animation-delay: 0.2s; }
.fade-in:nth-child(5) { animation-delay: 0.25s; }
.fade-in:nth-child(6) { animation-delay: 0.3s; }
.fade-in:nth-child(7) { animation-delay: 0.35s; }
.fade-in:nth-child(8) { animation-delay: 0.4s; }
