/* ═══════════════════════════════════════════════════════════
   ZeroTrace Dashboard v4.3 (Aggregated Alerts + Scroll Support)
   محدث: تصميم محسّن للتنبيهات المجمعة وقابلية التمرير
   ═══════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════
   Main Layout Structure
   ═══════════════════════════════════════════════════════════ */

   body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background-color: var(--bg-body);
}

/* ═══════════════════════════════════════════════════════════
   Top Dashboard Header
   ═══════════════════════════════════════════════════════════ */

.dashboard-header {
    height: 72px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 2rem;
    z-index: 100;
    flex-shrink: 0;
    position: relative !important; 
    top: auto;
    width: 100%;
}

[data-theme="dark"] .dashboard-header {
    background-color: #0f172a;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.header-container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Right Side: Brand & Nav */
.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.brand {
    display: flex;
    align-items: center;
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--text-main);
    text-decoration: none;
}

.brand i {
    color: var(--primary);
    margin-left: 0.5rem;
    font-size: 1.4rem;
}

.divider-vertical {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
}

.nav-menu-horizontal {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-item a {
    color: inherit;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    text-decoration: none;
}

.nav-item:hover {
    background-color: rgba(0,0,0,0.03);
    color: var(--text-main);
}

[data-theme="dark"] .nav-item:hover {
    background-color: rgba(255,255,255,0.05);
    color: var(--text-main);
}

.nav-item.active {
    background-color: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

[data-theme="dark"] .nav-item.active {
    background-color: rgba(56, 189, 248, 0.1);
    color: var(--primary);
}

.nav-item.action-reset {
    color: var(--danger);
}
.nav-item.action-reset:hover {
    background-color: rgba(239, 68, 68, 0.05);
}

/* Left Side: SOC Badge & Actions */
.header-left {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.soc-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    background-color: var(--bg-body);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .soc-badge {
    background-color: rgba(255,255,255,0.03);
    border-color: rgba(255,255,255,0.05);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 4px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px; height: 36px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background-color: var(--bg-body);
    color: var(--primary);
    border-color: var(--primary);
}

.export-group {
    display: flex;
    gap: 0.5rem;
}

/* ═══════════════════════════════════════════════════════════
   Main Content Area (Scrollable)
   ═══════════════════════════════════════════════════════════ */

.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    position: relative;
    padding-bottom: 2rem; 
}

.view-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

/* ═══════════════════════════════════════════════════════════
   Upload Zone (Centered)
   ═══════════════════════════════════════════════════════════ */

.upload-card {
    max-width: 800px;
    margin: 3rem auto;
    text-align: center;
}

.drop-zone {
    background-color: var(--bg-surface);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 4rem 2rem;
    transition: all 0.3s;
    cursor: pointer;
}

[data-theme="dark"] .drop-zone {
    background-color: transparent;
    border: 1px dashed rgba(255,255,255,0.1);
}

.drop-zone:hover {
    border-color: var(--primary);
}

.icon-wrapper {
    width: 64px;
    height: 64px;
    background-color: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin: 0 auto 1.5rem;
}

.drop-zone h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.drop-zone p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.parsing-status {
    margin-top: 2rem;
    padding: 2rem;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .parsing-status {
    background-color: transparent;
    border: 1px solid rgba(255,255,255,0.05);
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--bg-surface);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════
   Security Alerts Section (Fixed & Scrollable 🔥)
   ═══════════════════════════════════════════════════════════ */

.alerts-container {
    margin-bottom: 2rem;
    animation: fadeIn 0.5s ease-out;
}

.alerts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.alerts-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* 🔥 تنسيق حاوية التنبيهات القابلة للتمرير */
.alerts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1rem;
    
    /* تحديد أقصى ارتفاع وتفعيل التمرير */
    max-height: 500px;
    overflow-y: auto;
    overflow-x: hidden;
    
    /* مساحة إضافية للظل وتفادي القص */
    padding: 0.5rem;
    border-radius: 8px;
    align-content: start; /* يمنع تمدد البطاقات إذا كانت قليلة */
}

/* تخصيص شريط التمرير (Webkit) */
.alerts-grid::-webkit-scrollbar {
    width: 6px;
}
.alerts-grid::-webkit-scrollbar-track {
    background: transparent;
}
.alerts-grid::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}
[data-theme="dark"] .alerts-grid::-webkit-scrollbar-thumb {
    background-color: rgba(255,255,255,0.1);
}

.alert-card {
    display: flex;
    gap: 1rem;
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-surface); /* أساس */
}

/* 🔥 شارة عداد التكرار */
.alert-count-badge {
    background-color: var(--text-main);
    color: var(--bg-body);
    font-size: 0.75rem;
    font-weight: 800;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    margin-right: auto; /* دفع الشارة لليسار في RTL */
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Critical Alert */
.alert-critical {
    background-color: #fef2f2;
    border-color: #fee2e2;
}

.alert-critical .alert-icon-wrapper {
    background-color: #fee2e2;
    color: #ef4444;
}

.alert-critical .alert-title {
    color: #b91c1c;
}

[data-theme="dark"] .alert-critical {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .alert-critical .alert-icon-wrapper {
    background-color: rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .alert-critical .alert-title {
    color: #fca5a5;
}

/* High Alert */
.alert-high {
    background-color: #fffbeb;
    border-color: #fef3c7;
}

.alert-high .alert-icon-wrapper {
    background-color: #fef3c7;
    color: #f59e0b;
}

.alert-high .alert-title {
    color: #b45309;
}

[data-theme="dark"] .alert-high {
    background-color: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .alert-high .alert-icon-wrapper {
    background-color: rgba(245, 158, 11, 0.2);
}

[data-theme="dark"] .alert-high .alert-title {
    color: #fcd34d;
}

.alert-icon-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.alert-content-wrapper {
    flex: 1;
}

.alert-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.alert-desc {
    font-size: 0.95rem;
    color: var(--text-main);
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

.alert-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
}

.alert-meta span {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════
   Stats Cards (KPIs)
   ═══════════════════════════════════════════════════════════ */

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

[data-theme="dark"] .stat-card {
    background-color: transparent;
    border: 1px solid rgba(255,255,255,0.05);
}

.stat-content { display: flex; flex-direction: column; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text-main); line-height: 1.2; margin-bottom: 0.25rem; }
.stat-label { font-size: 0.85rem; color: var(--text-secondary); font-weight: 500; }
.stat-icon { width: 42px; height: 42px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }

.icon-primary { background: var(--info-bg); color: var(--info); }
.icon-danger { background: var(--danger-bg); color: var(--danger); }
.icon-warning { background: var(--warning-bg); color: var(--warning); }

/* ═══════════════════════════════════════════════════════════
   Charts & Tables
   ═══════════════════════════════════════════════════════════ */

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.data-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

[data-theme="dark"] .card {
    background-color: transparent;
    border: 1px solid rgba(255,255,255,0.05);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h3 { font-size: 1rem; font-weight: 600; color: var(--text-main); margin: 0; }
.chart-container { position: relative; height: 300px; width: 100%; }

.table-responsive { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th { text-align: right; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-color); color: var(--text-secondary); font-weight: 600; font-size: 0.8rem; }
.data-table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border-color); color: var(--text-main); }
.data-table tr:last-child td { border-bottom: none; }

.flag-img {
    width: 24px;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.terminal-card { height: 100%; }

.terminal-window {
    background-color: #1e293b;
    border-radius: var(--radius-md);
    padding: 1rem;
    height: 400px;
    overflow-y: auto;
    color: #e2e8f0;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
}

[data-theme="dark"] .terminal-window {
    background-color: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.08);
}

.terminal-line { padding: 0.25rem 0; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; gap: 0.5rem; flex-wrap: wrap; }
.terminal-line:last-child { border-bottom: none; }

/* ═══════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════ */

.hide-mobile { display: inline; }

@media (max-width: 1024px) {
    .data-grid { grid-template-columns: 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .dashboard-header { height: auto; padding: 1rem; flex-direction: column; gap: 1rem; }
    .header-container { flex-direction: column; gap: 1rem; }
    .header-right, .header-left { width: 100%; justify-content: space-between; }
    .nav-menu-horizontal { overflow-x: auto; padding-bottom: 0.5rem; width: 100%; }
    .hide-mobile { display: none; }
    .view-container { padding: 1rem; }
    .upload-card { margin: 1rem auto; }
    .drop-zone { padding: 2rem 1rem; }
    
    .alerts-grid { grid-template-columns: 1fr; max-height: 600px; }
    .alert-card { flex-direction: column; }
    .alert-icon-wrapper { width: 40px; height: 40px; font-size: 1.2rem; }
}