/* =============================================================
   BigData News Dashboard — Design System v2
   ============================================================= */

:root {
    /* === Color Palette === */
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #dbeafe;
    --color-primary-soft: #eff6ff;

    --color-success: #10b981;
    --color-success-light: #d1fae5;
    --color-warning: #f59e0b;
    --color-warning-light: #fef3c7;
    --color-danger: #ef4444;
    --color-danger-light: #fee2e2;
    --color-info: #06b6d4;
    --color-info-light: #cffafe;

    /* === Surfaces === */
    --bg-app: #f8fafc;
    --bg-card: #ffffff;
    --bg-soft: #f1f5f9;
    --bg-hover: #f8fafc;

    /* === Text === */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --text-on-dark: #ffffff;

    /* === Borders === */
    --border-color: #e2e8f0;
    --border-soft: #f1f5f9;

    /* === Shadows === */
    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, .04);
    --shadow-md: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .03);
    --shadow-lg: 0 4px 6px -1px rgba(15, 23, 42, .07), 0 2px 4px -1px rgba(15, 23, 42, .04);
    --shadow-xl: 0 10px 15px -3px rgba(15, 23, 42, .08), 0 4px 6px -2px rgba(15, 23, 42, .04);

    /* === Spacing === */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* === Radius === */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* === Layout === */
    --sidebar-width: 250px;
    --sidebar-collapsed: 70px;
    --topbar-height: 60px;

    /* === Transitions === */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* === Base === */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: 'Tajawal', 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    margin: 0;
    overflow-x: hidden;
}

/* منع overflow على المحتوى الرئيسي - يبقى الـ scroll محصور داخل العناصر */
.main-content { max-width: 100%; overflow-x: hidden; }
.page-content { max-width: 100%; }
.card { max-width: 100%; }
.table-responsive {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

a { color: var(--color-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-primary-dark); }

/* === Sidebar Layout === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: #0f172a;
    color: #cbd5e1;
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.sidebar-brand-text {
    color: white;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
    font-family: 'Cairo', sans-serif;
}
.sidebar-brand-sub {
    color: #64748b;
    font-size: .7rem;
    margin-top: 2px;
}

.sidebar-section {
    padding: 12px 0;
}
.sidebar-section-title {
    color: #475569;
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 8px 18px 4px;
    margin: 0;
}

.sidebar-nav { list-style: none; padding: 0; margin: 0; }
.sidebar-nav-item { margin: 0; }
.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    color: #cbd5e1;
    font-weight: 500;
    transition: all var(--transition-fast);
    border-inline-start: 3px solid transparent;
    position: relative;
}
.sidebar-nav-link:hover {
    background: rgba(255, 255, 255, .04);
    color: white;
}
.sidebar-nav-link.active {
    background: rgba(37, 99, 235, .15);
    color: #60a5fa;
    border-inline-start-color: #2563eb;
}
.sidebar-nav-link i {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-nav-badge {
    margin-inline-start: auto;
    background: rgba(255, 255, 255, .1);
    color: #cbd5e1;
    padding: 1px 7px;
    border-radius: 10px;
    font-size: .68rem;
    font-weight: 600;
}
.sidebar-nav-link.active .sidebar-nav-badge {
    background: #2563eb;
    color: white;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 18px;
    border-top: 1px solid rgba(255, 255, 255, .08);
    color: #64748b;
    font-size: .75rem;
    text-align: center;
}

/* === Main Layout === */
.main-content {
    flex: 1;
    margin-inline-start: var(--sidebar-width);
    min-height: 100vh;
}

.topbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    height: var(--topbar-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.topbar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'Cairo', sans-serif;
    margin: 0;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
    cursor: pointer;
}
.topbar-user:hover { background: var(--bg-soft); }
.topbar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.page-content {
    padding: 24px;
    width: 100%;
    box-sizing: border-box;
}

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: 0;
    color: var(--text-primary);
    font-size: 1.4rem;
    padding: 6px;
    cursor: pointer;
}

/* === Cards === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-fast);
}
.card:hover {
    box-shadow: var(--shadow-md);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-soft);
    padding: 16px 20px;
    font-weight: 600;
    color: var(--text-primary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card-body { padding: 20px; }
.card.shadow-sm { box-shadow: var(--shadow-sm) !important; }

/* === KPI Cards === */
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.kpi-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    border-color: var(--color-primary-light);
}
.kpi-card .kpi-label {
    font-size: .78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}
.kpi-card .kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
    font-family: 'Cairo', sans-serif;
    font-variant-numeric: tabular-nums;
}
.kpi-card .kpi-icon {
    font-size: 1.5rem;
    opacity: .35;
    position: absolute;
    inset-inline-end: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-primary);
}
.kpi-card .kpi-trend {
    font-size: .8rem;
    margin-top: 6px;
    font-weight: 500;
}
.kpi-card .kpi-trend.up { color: var(--color-success); }
.kpi-card .kpi-trend.down { color: var(--color-danger); }

/* === Buttons === */
.btn {
    border-radius: var(--radius-md);
    font-weight: 500;
    padding: 8px 16px;
    transition: all var(--transition-fast);
    border-width: 1px;
    font-size: .875rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
}
.btn-sm { padding: 5px 10px; font-size: .8rem; gap: 4px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }

.btn-outline-primary { border-color: var(--color-primary); color: var(--color-primary); background: transparent; }
.btn-outline-primary:hover { background: var(--color-primary); color: white; }

.btn-outline-secondary {
    border-color: var(--border-color);
    color: var(--text-secondary);
    background: var(--bg-card);
}
.btn-outline-secondary:hover {
    background: var(--bg-soft);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-success { background: var(--color-success); border-color: var(--color-success); color: white; }
.btn-success:hover { background: #059669; border-color: #059669; }

.btn-danger { background: var(--color-danger); border-color: var(--color-danger); color: white; }
.btn-warning { background: var(--color-warning); border-color: var(--color-warning); color: white; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--text-primary); }

/* === Segmented Control (نمط حديث للـ period switcher) === */
.segmented {
    display: inline-flex;
    background: var(--bg-soft);
    border-radius: 999px;
    padding: 4px;
    gap: 2px;
    flex-wrap: nowrap;
    border: 1px solid var(--border-color);
}
.segmented .btn-check {
    position: absolute;
    clip: rect(0, 0, 0, 0);
    pointer-events: none;
}
.segmented label {
    padding: 6px 16px;
    border: 0 !important;
    background: transparent !important;
    border-radius: 999px !important;
    color: var(--text-secondary) !important;
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    margin: 0 !important;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.segmented label:hover {
    color: var(--text-primary) !important;
    background: rgba(255, 255, 255, .5) !important;
}
.segmented .btn-check:checked + label {
    background: white !important;
    color: var(--color-primary) !important;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .1);
    font-weight: 600;
}

/* === Forms === */
.form-control, .form-select {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    font-size: .875rem;
    transition: all var(--transition-fast);
    background: var(--bg-card);
}
.form-control:focus, .form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.form-control-sm, .form-select-sm { padding: 6px 10px; font-size: .8rem; }
.form-label {
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.form-text { font-size: .75rem; color: var(--text-tertiary); margin-top: 4px; }

.input-group-text {
    background: var(--bg-soft);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

/* === Tables === */
.table {
    --bs-table-bg: transparent;
    margin: 0;
    color: var(--text-primary);
}
.table thead {
    background: var(--bg-soft);
}
.table thead th {
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .3px;
    padding: 12px 16px;
    background: var(--bg-soft);
}
.table tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
.table tbody tr:hover {
    background: var(--bg-hover);
}
.table tbody tr:last-child td { border-bottom: 0; }

/* الجدول الداكن (للتحليل) */
.table-dark thead th, .table-dark th {
    background: var(--text-primary) !important;
    color: white !important;
}

/* === جدول الأخبار === */
.news-table {
    table-layout: fixed;
    width: 100%;
}
.news-table thead th {
    background: var(--bg-soft) !important;
    color: var(--text-secondary) !important;
    text-transform: none;
    letter-spacing: 0;
    font-size: .76rem;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 14px;
}
.news-table th, .news-table td {
    padding: 14px 14px;
}
.news-table td {
    vertical-align: top;
    font-size: .88rem;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.55;
}
.news-table tbody tr {
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-soft);
}
.news-table tbody tr:hover {
    background: var(--color-primary-soft) !important;
}
.news-table tbody tr:last-child { border-bottom: 0; }

.news-table .col-title {
    width: 26%;
    font-size: .92rem;
    color: var(--text-primary);
}
.news-table .col-title .line-clamp-2 {
    font-weight: 600;
    line-height: 1.45;
}
.news-table .col-summary {
    width: 26%;
    color: var(--text-secondary);
    font-size: .82rem;
}
.news-table .col-source {
    width: 13%;
    color: var(--text-secondary);
    font-size: .8rem;
}
.news-table .col-folder { width: 11%; }
.news-table .col-tags { width: 11%; }
.news-table .col-date {
    width: 9%;
    direction: ltr;
    text-align: end;
    color: var(--text-tertiary);
    font-size: .76rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.news-table .col-actions { width: 4%; text-align: center; }

.news-table.compact .col-title  { width: 40%; }
.news-table.compact .col-source { width: 23%; }
.news-table.compact .col-folder { width: 14%; }
.news-table.compact .col-date   { width: 14%; }
.news-table.compact .col-actions{ width: 9%; }

/* أزرار الإجراءات في الجدول */
.news-table .btn-sm {
    padding: 4px 8px;
    font-size: .85rem;
}
.news-table td .btn + .btn { margin-inline-start: 4px; }

/* === Badges === */
.badge {
    font-weight: 500;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: .72rem;
}
.badge-folder {
    background: var(--color-info-light);
    color: #155e75;
    white-space: normal;
    word-break: break-word;
    display: inline-block;
    max-width: 100%;
}
.badge-tag {
    background: var(--color-warning-light);
    color: #92400e;
    margin: 2px;
    white-space: normal;
    word-break: break-word;
    display: inline-block;
    max-width: 100%;
}

.topic-chip {
    display: inline-block;
    font-size: .72rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    margin: 2px;
    line-height: 1.5;
    transition: all var(--transition-fast);
}
.topic-chip:hover { transform: translateY(-1px); }

/* === Empty states === */
.na-empty {
    color: var(--text-tertiary);
    font-style: italic;
    font-size: .82rem;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
}
.empty-state-icon {
    font-size: 4rem;
    color: var(--border-color);
    margin-bottom: 16px;
}
.empty-state-title {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
}
.empty-state-desc {
    font-size: .85rem;
    color: var(--text-tertiary);
    max-width: 400px;
    margin: 0 auto 20px;
}

/* === Login === */
.login-page {
    min-height: 100vh;
    margin: 0;
    background: var(--bg-card);
}
.login-split {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.05fr 1fr;
}

/* --- اللوحة التعريفية (يمين في RTL) --- */
.login-brand {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 56px 64px;
    color: #fff;
    background:
        radial-gradient(ellipse 80% 60% at 85% 10%, rgba(124, 58, 237, .45), transparent 60%),
        radial-gradient(ellipse 70% 60% at 10% 90%, rgba(37, 99, 235, .40), transparent 60%),
        #0b1220;
}
.login-brand::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: radial-gradient(ellipse 70% 70% at 50% 40%, #000, transparent 75%);
    -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 40%, #000, transparent 75%);
    pointer-events: none;
}
.login-brand > * { position: relative; z-index: 1; }

.login-logo {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    box-shadow: 0 12px 28px -6px rgba(37, 99, 235, .6);
    margin-bottom: 28px;
}
.login-brand h2 {
    font-family: 'Cairo', sans-serif;
    font-weight: 800;
    font-size: 2rem;
    line-height: 1.35;
    margin: 0 0 14px;
    letter-spacing: -.5px;
}
.login-brand p {
    color: rgba(226, 232, 240, .72);
    font-size: .95rem;
    max-width: 420px;
    margin: 0 0 36px;
    line-height: 1.8;
}
.login-features {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.login-features li {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: .9rem;
    color: rgba(226, 232, 240, .9);
}
.login-features i {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    color: #bfdbfe;
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .1);
}

/* --- لوحة النموذج (يسار في RTL) --- */
.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    background: var(--bg-card);
}
.login-card {
    width: 100%;
    max-width: 380px;
}
.login-card h1 {
    font-family: 'Cairo', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 6px;
}
.login-card .login-sub {
    color: var(--text-tertiary);
    font-size: .875rem;
    margin-bottom: 28px;
}

/* شعار مصغّر يظهر على الشاشات الصغيرة فقط */
.login-card-logo { display: none; }

.login-field { margin-bottom: 18px; }
.login-field .form-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.login-input {
    position: relative;
    display: flex;
    align-items: center;
}
.login-input > .bi {
    position: absolute;
    inset-inline-start: 14px;
    font-size: .95rem;
    color: var(--text-tertiary);
    pointer-events: none;
    transition: color var(--transition-fast);
}
.login-input .form-control {
    height: 46px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-soft);
    padding-inline-start: 42px;
    padding-inline-end: 14px;
    font-size: .9rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
.login-input .form-control::placeholder { color: var(--text-tertiary); }
.login-input .form-control:focus {
    background: var(--bg-card);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}
.login-input:focus-within > .bi { color: var(--color-primary); }
.login-input.has-toggle .form-control { padding-inline-end: 44px; }

.login-toggle {
    position: absolute;
    inset-inline-end: 6px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-tertiary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color var(--transition-fast), background var(--transition-fast);
}
.login-toggle:hover { color: var(--text-secondary); background: var(--bg-soft); }

.login-submit {
    width: 100%;
    height: 46px;
    border: 0;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: .95rem;
    color: #fff;
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    box-shadow: 0 8px 20px -6px rgba(37, 99, 235, .55);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
}
.login-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 26px -6px rgba(37, 99, 235, .65);
}
.login-submit:active { transform: translateY(0); }
.login-submit:disabled { opacity: .7; cursor: default; transform: none; }

.login-alert {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px;
    margin-bottom: 20px;
    border-radius: var(--radius-md);
    font-size: .85rem;
    font-weight: 500;
    color: #b91c1c;
    background: var(--color-danger-light);
    border: 1px solid rgba(239, 68, 68, .25);
}

.login-foot {
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--border-soft);
    text-align: center;
    font-size: .75rem;
    color: var(--text-tertiary);
}

@media (max-width: 900px) {
    .login-split { grid-template-columns: 1fr; }
    .login-brand { display: none; }
    .login-panel {
        min-height: 100vh;
        padding: 32px 20px;
        background:
            radial-gradient(ellipse 90% 50% at 50% 0%, rgba(124, 58, 237, .12), transparent 60%),
            var(--bg-app);
    }
    .login-card {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-xl);
        padding: 32px 24px;
        box-shadow: var(--shadow-xl);
        text-align: center;
    }
    .login-card-logo {
        display: inline-flex;
        margin: 0 auto 18px;
    }
    .login-card .login-field,
    .login-card .login-alert { text-align: start; }
}

/* === Charts === */
.chart-wrap { position: relative; height: 280px; }
.chart-wrap.tall { height: 360px; }
.chart-wrap.short { height: 200px; }

/* === Filters === */
.filters-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

/* === Pagination === */
.pagination {
    gap: 4px;
}
.page-link {
    border-radius: var(--radius-sm) !important;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    margin: 0;
    padding: 6px 12px;
    font-size: .85rem;
    font-weight: 500;
}
.page-link:hover { background: var(--bg-soft); color: var(--text-primary); border-color: var(--border-color); }
.page-item.active .page-link {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

/* === Status Badges === */
.status-badge {
    font-size: .72rem;
    padding: 3px 8px;
    border-radius: 999px;
    font-weight: 600;
    display: inline-block;
}
.status-success { background: var(--color-success-light); color: #065f46; }
.status-failed  { background: var(--color-danger-light); color: #991b1b; }
.status-partial { background: var(--color-warning-light); color: #92400e; }
.status-running { background: var(--color-primary-light); color: #1e40af; }

/* === Code Box === */
.code-box {
    background: #0f172a;
    color: #38bdf8;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: .82rem;
    direction: ltr;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-all;
    border: 1px solid #1e293b;
}

/* === Alerts === */
.alert {
    border-radius: var(--radius-md);
    border-width: 1px;
    padding: 12px 16px;
    font-size: .88rem;
}
.alert-soft-success { background: var(--color-success-light); color: #065f46; border-color: #a7f3d0; }
.alert-soft-warning { background: var(--color-warning-light); color: #92400e; border-color: #fde68a; }
.alert-soft-danger  { background: var(--color-danger-light); color: #991b1b; border-color: #fecaca; }

/* === Trending Row === */
.trending-row {
    display: grid;
    grid-template-columns: 30px 1fr auto auto;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft);
    transition: background var(--transition-fast);
}
.trending-row:last-child { border-bottom: 0; }
.trending-row.alt { background: var(--bg-soft); }
.trending-row:hover { background: var(--color-primary-soft); }

.trending-rank {
    color: var(--text-tertiary);
    font-weight: 600;
    font-size: .85rem;
    text-align: center;
}
.trending-name {
    font-weight: 700;
    font-size: .92rem;
}
.trending-stats {
    text-align: end;
    direction: ltr;
}
.trending-current {
    font-size: .82rem;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    margin-bottom: 2px;
}
.trending-current .trending-num {
    font-weight: 700;
    font-size: 1.05rem;
}
.trending-current .trending-arrow {
    color: var(--text-tertiary);
    margin: 0 4px;
    font-size: .8rem;
}
.trending-current .trending-prev {
    color: var(--text-tertiary);
    font-size: .85rem;
}
.trending-change {
    font-size: .78rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    display: inline-block;
    font-variant-numeric: tabular-nums;
}
.trending-change.success {
    background: var(--color-success-light);
    color: #065f46;
}
.trending-change.danger {
    background: var(--color-danger-light);
    color: #991b1b;
}
.trending-pct {
    opacity: .7;
    font-weight: 500;
    font-size: .75rem;
}

/* === Topic Toggle (multi-select buttons) === */
.topic-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.topic-toggle {
    --topic-color: #6c757d;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
}
.topic-toggle:hover {
    background: var(--bg-soft);
    border-color: var(--topic-color);
}
.topic-toggle.active {
    background: var(--topic-color);
    border-color: var(--topic-color);
    color: white;
    box-shadow: 0 2px 6px color-mix(in srgb, var(--topic-color) 40%, transparent);
}
.topic-toggle-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--topic-color);
    display: inline-block;
}
.topic-toggle.active .topic-toggle-dot {
    background: rgba(255, 255, 255, .9);
}

/* === Topic stat card (in dashboard) === */
.topic-stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}
.topic-stat-card::before {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-color, var(--color-primary));
}
.topic-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.topic-stat-name {
    font-size: .78rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topic-stat-count {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1;
    font-family: 'Cairo', sans-serif;
}
.topic-stat-label {
    font-size: .68rem;
    color: var(--text-tertiary);
}

/* === Heatmap === */
.heatmap-table-scroll { overflow-x: auto; padding: 8px; }
.heatmap-table { border-collapse: separate; border-spacing: 3px; font-size: .75rem; }
.heatmap-table th { background: transparent; padding: 4px; text-align: center; font-size: .68rem; color: var(--text-tertiary); }
.heatmap-table .hm-day { width: 22px; min-width: 22px; }
.heatmap-table .hm-topic-col {
    text-align: start;
    white-space: nowrap;
    padding: 6px 12px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    min-width: 140px;
    font-weight: 600;
}
.heatmap-table .hm-cell {
    width: 22px; height: 22px;
    text-align: center;
    border-radius: 3px;
    font-size: .65rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: transform var(--transition-fast);
}
.heatmap-table .hm-cell:hover {
    transform: scale(1.4);
    z-index: 1;
    position: relative;
    box-shadow: 0 0 0 2px var(--color-primary);
}

/* === Activity Calendar (GitHub-style) === */
.cal-grid-wrap {
    overflow-x: auto;
    padding: 8px 4px;
}
.cal-months {
    display: grid;
    direction: ltr;
    column-gap: 3px;
    font-size: .68rem;
    color: var(--text-tertiary);
    font-weight: 600;
    margin-bottom: 4px;
    height: 16px;
}
.cal-month-label {
    grid-row: 1;
    white-space: nowrap;
    padding-inline-end: 4px;
}
.cal-cells {
    display: grid;
    grid-template-rows: repeat(7, 12px);
    direction: ltr;
    gap: 3px;
}
.cal-cell {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: #ebedf0;
    cursor: pointer;
    transition: transform var(--transition-fast);
}
.cal-cell:hover {
    transform: scale(1.5);
    box-shadow: 0 0 0 1px var(--color-primary);
    z-index: 2;
    position: relative;
}
.cal-cell.lvl-0 { background: #ebedf0; }
.cal-cell.lvl-1 { background: #c6e48b; }
.cal-cell.lvl-2 { background: #7bc96f; }
.cal-cell.lvl-3 { background: #239a3b; }
.cal-cell.lvl-4 { background: #196127; }
.cal-legend .cal-cell {
    width: 11px;
    height: 11px;
    margin: 0 2px;
    vertical-align: middle;
    display: inline-block;
}

/* === Percentage Bar === */
.pct-bar-wrap {
    position: relative;
    height: 22px;
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    overflow: hidden;
    min-width: 140px;
}
.pct-bar { height: 100%; transition: width var(--transition-normal); }
.pct-bar-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .76rem;
    color: var(--text-primary);
}

/* === Analysis Table === */
.analysis-table thead th {
    background: var(--text-primary);
    color: #cbd5e1 !important;
    text-transform: none;
    letter-spacing: 0;
}

/* === Modal === */
.modal-content {
    border-radius: var(--radius-lg);
    border: 0;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border-soft); gap: 8px; }

/* === Modal الأخبار === */
.news-modal .modal-content {
    border-radius: var(--radius-lg);
}
.news-modal-header {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    color: white;
    padding: 20px 24px;
    border-bottom: 0;
    align-items: flex-start;
}
.news-modal-header-content { flex: 1; min-width: 0; }
.news-modal-eyebrow {
    color: #60a5fa;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .8px;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}
.news-modal-title {
    color: white;
    font-size: 1.15rem;
    line-height: 1.4;
    font-weight: 700;
    margin: 0;
    font-family: 'Cairo', sans-serif;
}
.news-modal-header .btn-close {
    filter: invert(1) brightness(2);
    margin: 0;
    margin-inline-start: 12px;
    flex-shrink: 0;
}

.news-modal-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}
.news-modal-meta-item {
    background: var(--bg-soft);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    border: 1px solid var(--border-soft);
}
.news-modal-meta-label {
    color: var(--text-tertiary);
    font-size: .72rem;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.news-modal-meta-value {
    color: var(--text-primary);
    font-weight: 600;
    font-size: .88rem;
    word-break: break-word;
    line-height: 1.4;
}

.news-modal-section {
    margin-bottom: 16px;
}
.news-modal-section-title {
    color: var(--text-secondary);
    font-size: .76rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.news-modal-summary {
    background: var(--bg-soft);
    border-inline-start: 4px solid var(--color-primary);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    line-height: 1.85;
    font-size: .95rem;
    color: var(--text-primary);
}

.news-modal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.news-modal-link-row {
    background: var(--color-primary-soft);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .82rem;
    direction: ltr;
}
.news-modal-link-row a {
    color: var(--color-primary);
    word-break: break-all;
}

@media (max-width: 576px) {
    .news-modal-meta-grid { grid-template-columns: 1fr; }
}

/* === Line Clamp === */
.line-clamp-1 { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; line-clamp: 1; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-clamp: 2; }
.line-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; line-clamp: 3; }

/* === Page header (h-section) === */
.page-header {
    margin-bottom: 24px;
}
.page-header-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--text-primary);
    font-family: 'Cairo', sans-serif;
}
.page-header-desc {
    color: var(--text-secondary);
    font-size: .88rem;
    margin: 0;
}

/* === Tabs === */
.nav-tabs {
    border-bottom: 1px solid var(--border-color);
    gap: 4px;
}
.nav-tabs .nav-link {
    color: var(--text-secondary);
    border: 0;
    padding: 10px 16px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    transition: all var(--transition-fast);
}
.nav-tabs .nav-link:hover { color: var(--text-primary); }
.nav-tabs .nav-link.active {
    color: var(--color-primary);
    background: transparent;
    border-bottom-color: var(--color-primary);
    border-radius: 0;
}

/* === Mobile responsive === */
@media (max-width: 992px) {
    /* في RTL، الـ sidebar على اليمين، فنخفيه بإزاحته لليمين بمقدار عرضه */
    .sidebar {
        transform: translateX(100%);
        box-shadow: -20px 0 50px rgba(0, 0, 0, .3);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-inline-start: 0;
    }
    .mobile-menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .news-table { table-layout: auto; min-width: 1100px; }
    .page-content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .topbar-title { font-size: 1rem; }
    .kpi-card { padding: 14px; }
    .kpi-card .kpi-value { font-size: 1.4rem; }
}

@media (max-width: 576px) {
    .topbar-user > div.d-none { display: none !important; }
    .page-content { padding: 12px; }
    .card-body { padding: 14px; }
    .kpi-card .kpi-icon { display: none; }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 99;
}
.sidebar.show ~ .sidebar-overlay { display: block; }

/* === Spinner === */
.spinner-border { color: var(--color-primary); }

/* === Utilities === */
.fw-bold { font-weight: 700 !important; }
.text-muted { color: var(--text-tertiary) !important; }
.bg-soft { background: var(--bg-soft); }

/* Ensure dropdown menu styling */
.dropdown-menu {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    padding: 6px;
}
.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: .88rem;
    color: var(--text-primary);
}
.dropdown-item:hover { background: var(--bg-soft); }
