/* ========================================================
   MetaAutoNews Platform - Ultra-Premium Design System & Pro UI
   Bootstrap 5 Enhanced | Dark / Light Mode | Glassmorphism
   Enterprise Responsive & High-Resolution Precision
   ======================================================== */

:root {
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    /* Light Theme Palette */
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-glass: rgba(255, 255, 255, 0.85);
    --bg-sidebar: #0f172a;
    --text-sidebar: #94a3b8;
    --text-sidebar-hover: #ffffff;
    --text-sidebar-active: #38bdf8;
    --border-color: #e2e8f0;
    --border-card: rgba(226, 232, 240, 0.8);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    /* Brand Accent Colors */
    --primary: #2563eb;
    --primary-gradient: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --primary-light: #eff6ff;
    --accent: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    --success: #10b981;
    --success-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --warning: #f59e0b;
    --warning-gradient: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --danger: #ef4444;
    --danger-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --info: #06b6d4;
    --info-gradient: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);

    /* Depth Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.08), 0 4px 10px rgba(15, 23, 42, 0.03);
    --shadow-xl: 0 20px 35px rgba(15, 23, 42, 0.12), 0 8px 16px rgba(15, 23, 42, 0.05);
}

[data-bs-theme="dark"] {
    --bg-body: #080c14;
    --bg-card: #0f172a;
    --bg-card-glass: rgba(15, 23, 42, 0.82);
    --bg-sidebar: #070b12;
    --text-sidebar: #94a3b8;
    --text-sidebar-hover: #ffffff;
    --text-sidebar-active: #38bdf8;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-card: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #3b82f6;
    --primary-light: rgba(59, 130, 246, 0.14);
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.65);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.8);
}

/* ========================================================
   Global Core Styling
   ======================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.25s ease, color 0.25s ease;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.6);
}

/* ========================================================
   Sidebar Navigation
   ======================================================== */
.app-sidebar {
    width: 270px;
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.07);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

.sidebar-header {
    height: 72px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar-brand {
    font-size: 1.18rem;
    font-weight: 800;
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    letter-spacing: -0.025em;
}

.sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: linear-gradient(135deg, #1877f2 0%, #7c3aed 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.3rem;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
    transition: transform 0.2s ease;
}

.sidebar-brand:hover .brand-icon {
    transform: scale(1.05);
}

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

.nav-section-title {
    font-size: 0.70rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #475569;
    padding: 0.85rem 0.75rem 0.35rem;
    margin-top: 0.4rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.62rem 0.85rem;
    border-radius: 0.65rem;
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.16s ease-in-out;
    margin-bottom: 3px;
    position: relative;
}

.sidebar-link i {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    opacity: 0.85;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.sidebar-link:hover {
    color: var(--text-sidebar-hover);
    background-color: rgba(255, 255, 255, 0.08);
}

.sidebar-link:hover i {
    opacity: 1;
    transform: scale(1.08);
}

.sidebar-link.active {
    color: #ffffff;
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.95), rgba(37, 99, 235, 0.75));
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
    font-weight: 600;
}

.sidebar-link.active i {
    opacity: 1;
}

/* Sidebar backdrop for mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    z-index: 1030;
    opacity: 0;
    transition: opacity 0.28s ease;
}

.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}

/* ========================================================
   Main Layout & Sticky Navbar
   ======================================================== */
.app-main {
    margin-left: 270px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.28s ease;
}

.app-navbar {
    height: 72px;
    background-color: var(--bg-card-glass);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1020;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}

@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.show {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0 !important;
    }
    .app-navbar {
        padding: 0 1rem;
    }
}

/* ========================================================
   Emergency Stop Button & Active Banner
   ======================================================== */
.emergency-btn {
    background: var(--danger-gradient);
    color: #fff;
    border: none;
    font-weight: 700;
    font-size: 0.84rem;
    padding: 0.5rem 1rem;
    border-radius: 0.65rem;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.38);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.emergency-btn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.5);
}

.emergency-btn.active-emergency {
    background: var(--success-gradient);
    box-shadow: 0 0 18px rgba(16, 185, 129, 0.55);
    animation: resumePulse 2s infinite ease-in-out;
}

.emergency-btn.active-emergency:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    box-shadow: 0 0 24px rgba(16, 185, 129, 0.7);
}

@keyframes resumePulse {
    0%, 100% {
        box-shadow: 0 0 15px rgba(16, 185, 129, 0.45);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 26px rgba(16, 185, 129, 0.85);
        transform: scale(1.02);
    }
}

.emergency-banner {
    background: linear-gradient(90deg, #991b1b, #ef4444);
    color: #fff;
    padding: 0.75rem 1.5rem;
    font-weight: 700;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: pulseAlert 2.8s infinite;
    box-shadow: 0 4px 16px rgba(185, 28, 28, 0.35);
}

@keyframes pulseAlert {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.88; }
}

/* ========================================================
   Cards & Elevated Surfaces
   ======================================================== */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1.15rem 1.45rem;
    font-weight: 700;
}

.card-body {
    padding: 1.45rem;
}

/* ========================================================
   Ultra-Pro KPI / Metric Stat Cards
   ======================================================== */
.stat-card {
    padding: 1.4rem 1.5rem;
    border-radius: 1rem;
    position: relative;
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(37, 99, 235, 0.6), transparent);
    opacity: 0;
    transition: opacity 0.22s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.2s ease;
}

.stat-card:hover .stat-icon {
    transform: scale(1.08);
}

/* Distinct high-contrast stat icon color themes */
.stat-icon.icon-primary {
    background: rgba(37, 99, 235, 0.12);
    color: #2563eb;
    border: 1px solid rgba(37, 99, 235, 0.22);
}
[data-bs-theme="dark"] .stat-icon.icon-primary {
    background: rgba(59, 130, 246, 0.18);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.3);
}

.stat-icon.icon-info {
    background: rgba(6, 182, 212, 0.12);
    color: #0891b2;
    border: 1px solid rgba(6, 182, 212, 0.22);
}
[data-bs-theme="dark"] .stat-icon.icon-info {
    background: rgba(6, 182, 212, 0.18);
    color: #38bdf8;
    border-color: rgba(6, 182, 212, 0.3);
}

.stat-icon.icon-success {
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
    border: 1px solid rgba(16, 185, 129, 0.22);
}
[data-bs-theme="dark"] .stat-icon.icon-success {
    background: rgba(16, 185, 129, 0.20);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.35);
}

.stat-icon.icon-warning {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
    border: 1px solid rgba(245, 158, 11, 0.22);
}
[data-bs-theme="dark"] .stat-icon.icon-warning {
    background: rgba(245, 158, 11, 0.20);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.35);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.80rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ========================================================
   Tables, Overflow & Cell Layouts
   ======================================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    color: var(--text-primary);
    width: 100%;
    margin-bottom: 0;
    vertical-align: middle;
}

.table th {
    font-size: 0.76rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    background-color: transparent;
    padding: 0.9rem 1.1rem;
    white-space: nowrap;
}

.table td {
    border-bottom: 1px solid var(--border-color);
    padding: 0.95rem 1.1rem;
    vertical-align: middle;
    font-size: 0.88rem;
}

.table tbody tr {
    transition: background-color 0.15s ease;
}

.table tbody tr:hover {
    background-color: rgba(37, 99, 235, 0.03);
}
[data-bs-theme="dark"] .table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Table Utilities */
.table-nowrap th, .table-nowrap td {
    white-space: nowrap;
}

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.35;
}

/* ========================================================
   Badges & Pills
   ======================================================== */
.badge {
    padding: 0.4em 0.72em;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge-mode {
    font-size: 0.75rem;
    padding: 0.35rem 0.75rem;
    border-radius: 2rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

.badge-mode-3 {
    background: rgba(16, 185, 129, 0.16);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.badge-mode-2 {
    background: rgba(245, 158, 11, 0.16);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-mode-1 {
    background: rgba(59, 130, 246, 0.16);
    color: #3b82f6;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* ========================================================
   Form Controls & Inputs
   ======================================================== */
.form-control, .form-select {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 0.65rem;
    padding: 0.62rem 0.95rem;
    font-size: 0.90rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-card);
    border-color: var(--primary);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.25rem rgba(37, 99, 235, 0.18);
}

.form-check-input {
    cursor: pointer;
    width: 2.4em;
    height: 1.25em;
}
.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* Buttons */
.btn {
    border-radius: 0.65rem;
    font-weight: 600;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background: var(--primary-gradient);
    border: none;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
    box-shadow: 0 5px 14px rgba(37, 99, 235, 0.45);
    transform: translateY(-1px);
}

.btn-outline-primary {
    border-color: rgba(37, 99, 235, 0.4);
}
.btn-outline-primary:hover {
    background: var(--primary-gradient);
    border-color: transparent;
    transform: translateY(-1px);
}

/* ========================================================
   Toasts & Modals
   ======================================================== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1100;
}

.toast {
    border-radius: 0.85rem;
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-xl);
}

.modal-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 1.2rem;
    box-shadow: var(--shadow-xl);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 1.35rem 1.5rem;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 1.15rem 1.5rem;
}

/* Pulse animation utility */
.pulse-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulseDot 2s infinite;
}

@keyframes pulseDot {
    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 6px rgba(16, 185, 129, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Mobile fine-tuning */
@media (max-width: 575.98px) {
    .stat-value {
        font-size: 1.55rem;
    }
    .stat-card {
        padding: 1.15rem 1.15rem;
    }
    .card-header {
        padding: 1rem 1.15rem;
    }
    .table td, .table th {
        padding: 0.75rem 0.85rem;
    }
    .emergency-btn {
        padding: 0.45rem 0.75rem;
        font-size: 0.78rem;
    }
}
