@import url('../vendor/fonts/fonts.css');

:root {
    /* Dark Theme (Default) */
    --background: #0a0a0c;
    --surface-low: #111114;
    --surface-high: #1c1c21;
    --text-main: #ffffff;
    --text-dim: #a1a1aa;
    --text-muted: #71717a;
    --accent-primary: #3b82f6;
    --accent-primary-rgb: 59, 130, 246;
    --accent-secondary: #9333ea;
    --status-success: #10b981;
    --status-warning: #f59e0b;
    --status-critical: #ef4444;
    /* Aliases kept for legacy module styles */
    --status-healthy: #10b981;
    --health-healthy: #10b981;
    --border-color: rgba(255, 255, 255, 0.08);
    --bg-secondary: #1c1c21;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow: 0 10px 30px -10px rgba(0,0,0,0.5);

    /* Typography Defaults */
    --font-display: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    /* Light Theme (White) */
    --background: #f8fafc;
    --surface-low: #ffffff;
    --surface-high: #f1f5f9;
    --text-main: #0f172a;
    --text-dim: #475569;
    --text-muted: #94a3b8;
    --accent-primary: #2563eb;
    --accent-primary-rgb: 37, 99, 235;
    --accent-secondary: #7c3aed;
    --status-success: #059669;
    --status-warning: #d97706;
    --status-critical: #dc2626;
    --status-healthy: #059669;
    --health-healthy: #059669;
    --border-color: rgba(0, 0, 0, 0.05);
    --bg-secondary: #f1f5f9;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--background);
    color: var(--text-main);
    font-family: var(--font-display);
    line-height: 1.5;
    transition: background 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styling */
aside {
    width: 280px;
    background: var(--surface-low);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: var(--transition-smooth);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.logo span { color: var(--accent-primary); }

nav.nav-scroll { 
    flex: 1; 
    overflow-y: auto; 
    margin: 0 -0.5rem; 
    padding: 0 0.5rem;
}

/* Custom Lean Scrollbar for Nav-Scroll */
nav.nav-scroll::-webkit-scrollbar { width: 4px; }
nav.nav-scroll::-webkit-scrollbar-track { background: transparent; }
nav.nav-scroll::-webkit-scrollbar-thumb { 
    background: rgba(255, 255, 255, 0.05); 
    border-radius: 10px; 
}
nav.nav-scroll:hover::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); }

nav ul { list-style: none; }
nav li { margin-bottom: 0.25rem; }
.nav-category {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-dim);
    margin: 1.5rem 1rem 0.75rem;
    opacity: 0.7;
    font-family: var(--font-mono);
}
nav a {
    text-decoration: none;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition-smooth);
}

nav a ion-icon { font-size: 1.25rem; }
nav li.active a { 
    background: var(--surface-high); 
    color: var(--text-main); 
    box-shadow: inset 4px 0 0 var(--accent-primary);
}
nav a:hover:not(.active) { color: var(--text-main); background: rgba(255,255,255,0.06); }

.sidebar-search {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 0.6rem 1rem;
    color: var(--text-main);
    font-size: 0.8rem;
    outline: none;
    margin-bottom: 1rem;
    transition: var(--transition-smooth);
}
.sidebar-search::placeholder { color: var(--text-muted); opacity: 0.5; }
.sidebar-search:focus { border-color: var(--accent-primary); background: rgba(255, 255, 255, 0.05); }

/* Main Content Area */
main {
    flex: 1;
    padding: 2rem 3rem;
    background: var(--background);
    overflow-y: auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Vertical alignment fixed */
    margin-bottom: 2rem;
    position: sticky; /* Keep top bar at the top */
    top: -2rem; /* Adjusted for main padding */
    padding: 2rem 0 1rem;
    background: var(--background);
    background: linear-gradient(to bottom, var(--background) 85%, transparent);
    z-index: 50;
    transition: var(--transition-smooth);
}

.header.scrolled {
    backdrop-filter: blur(15px);
    background: rgba(10, 10, 12, 0.82);
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem 1.5rem;
    margin: 0 -1.5rem 2rem;
    border-radius: 0 0 20px 20px;
}

.breadcrumb {
    color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.08);
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 100px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 0.5rem;
    border: 1px solid rgba(59, 130, 246, 0.15);
}

h1 { font-size: 2.25rem; font-weight: 700; color: var(--text-main); line-height: 1.2; }

.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Components */
.card {
    background: var(--surface-low);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: var(--shadow);
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.card:hover {
    border-color: rgba(59, 130, 246, 0.2);
}

.card::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.03),
        transparent
    );
    transition: 0.5s;
}

.card.glass-interactive:hover::after {
    left: 100%;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
}

.glass-interactive:hover {
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.1);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card { padding: 1.75rem; border-radius: 20px; }
.stat-label { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.5rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; font-family: var(--font-mono); }
.stat-value span { font-size: 0.9rem; color: var(--text-muted); }
.stat-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 1rem; font-size: 1.25rem;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}
.empty-state ion-icon {
    font-size: 3rem;
    opacity: 0.3;
    margin-bottom: 1rem;
    display: block;
}
.empty-state p {
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Button Styles */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn:active {
    transform: translateY(0);
    filter: brightness(0.85);
}

.btn-primary { background: var(--accent-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.2); box-shadow: 0 0 20px rgba(59, 130, 246, 0.3); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-main);
}
.btn-outline:hover { background: var(--surface-high); }

.btn-danger {
    background: transparent;
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--status-critical);
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--status-critical);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.15);
}

/* Table Styling */
.it-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.it-table th {
    text-align: left;
    padding: 1rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    font-family: var(--font-mono);
    border-bottom: 1px solid var(--glass-border);
}

.it-table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--glass-border);
    transition: var(--transition-smooth);
}

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

.it-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.015);
}

.it-table tbody tr:hover {
    background: rgba(var(--accent-primary-rgb), 0.08);
}

.it-table tbody tr:hover td {
    color: var(--text-main);
}

.account-cell { display: flex; align-items: center; gap: 1rem; }
.account-avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    background: var(--surface-high);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--accent-primary);
}

/* Health Badges */
.health-badge {
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.health-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
}

.health-healthy { background: rgba(16, 185, 129, 0.1); color: var(--status-success); border: 1px solid rgba(16, 185, 129, 0.2); }
.health-risk { background: rgba(245, 158, 11, 0.1); color: var(--status-warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.health-critical { background: rgba(239, 68, 68, 0.1); color: var(--status-critical); border: 1px solid rgba(239, 68, 68, 0.2); }

/* Animation Spells */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.5s ease forwards; }

@keyframes ping {
    0% { transform: scale(1); opacity: 0.8; }
    70%, 100% { transform: scale(2.5); opacity: 0; }
}
.ping {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--status-critical);
    animation: ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
    pointer-events: none;
    z-index: -1;
}

/* Form System - Enterprise Glass Design */
.form-group {
    margin-bottom: 1.5rem;
    position: relative;
    transition: var(--transition-smooth);
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-dim);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-family: var(--font-mono);
    transition: var(--transition-smooth);
}

.form-group:focus-within label {
    color: var(--accent-primary);
    transform: translateX(4px);
}

.form-control {
    width: 100%;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.1rem 1.4rem;
    color: var(--text-main);
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    outline: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(0,0,0,0.1);
    backdrop-filter: blur(5px);
}

/* Date and Number Specific Refinements */
input[type="date"].form-control,
input[type="datetime-local"].form-control,
input[type="number"].form-control {
    font-family: var(--font-mono);
    font-weight: 500;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.4;
    cursor: pointer;
    transition: var(--transition-smooth);
}

input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
    transition: var(--transition-smooth);
}

[data-theme="light"] .form-control {

.form-control:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

.form-control:focus {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15), 
                0 20px 25px -5px rgba(0, 0, 0, 0.2),
                inset 0 0 10px rgba(59, 130, 246, 0.05);
    transform: translateY(-2px);
}

.form-control:focus::placeholder {
    opacity: 0.2;
    transform: translateX(10px);
}

/* Premium Select/Dropdown Implementation */
select.form-control,
select.premium-input,
select.target-select {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='rgba(255, 255, 255, 0.4)' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 1rem center !important;
    background-size: 1rem !important;
    cursor: pointer;
    padding-right: 3rem !important;
}

select.form-control:focus,
select.premium-input:focus,
select.target-select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%233b82f6' stroke-width='3'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E") !important;
}

/* Fallback background for select options on some browsers */
select.form-control option,
select.premium-input option,
select.target-select option {
    background-color: #0f172a; /* Deep charcoal for options */
    color: #fff;
    padding: 10px;
}

/* Input with Icon Wrapper */
.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon ion-icon {
    position: absolute;
    left: 1.25rem;
    font-size: 1.25rem;
    color: var(--text-muted);
    transition: var(--transition-smooth);
    pointer-events: none;
}

.input-with-icon .form-control {
    padding-left: 3.25rem;
}

.input-with-icon:focus-within ion-icon {
    color: var(--accent-primary);
    transform: scale(1.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 120px;
    line-height: 1.7;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1.25rem center;
    background-size: 1.1rem;
    padding-right: 3.25rem;
    cursor: pointer;
}

[data-theme="light"] .form-control {
    background: rgba(0, 0, 0, 0.015);
    border-color: rgba(0, 0, 0, 0.08);
    color: var(--text-main);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02), inset 0 1px 2px rgba(0,0,0,0.03);
}

[data-theme="light"] .form-control:focus {
    background: #ffffff;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08), 
                0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}

/* Success/Error States */
.form-control.success { border-color: var(--status-success); }
.form-control.error { border-color: var(--status-critical); }
.form-control.error:focus { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15); }

/* Theme Toggle Button Styling */
.theme-toggle-container { margin-top: auto; padding: 1rem 0; display: flex; align-items: center; width: 100%; }
.theme-btn {
    background: var(--surface-high);
    border: 1px solid var(--glass-border);
    border-radius: 100px;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text-main);
    font-size: 0.8rem;
    font-weight: 600;
}

/* --- RESPONSIVE ADAPTATIONS --- */

@media (max-width: 1200px) {
    .kanban-board { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) !important; }
    .chart-grid { grid-template-columns: 1fr; }
}

/* ================= HAMBURGER & BACKDROP ================= */
.sidebar-toggle {
    display: none; /* hidden on desktop */
    background: var(--surface-low);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 48px; height: 48px;
    border-radius: 12px;
    font-size: 1.6rem;
    align-items: center; justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
    box-shadow: 0 6px 20px -6px rgba(0,0,0,0.35);
}
.sidebar-toggle ion-icon { pointer-events: none; }
.sidebar-toggle:hover { background: rgba(var(--accent-primary-rgb),0.12); border-color: rgba(var(--accent-primary-rgb),0.45); }
.sidebar-toggle:active { transform: scale(0.94); }

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 1024px) {
    /* Hamburger is a FIXED floating button (always visible, always clickable) */
    .sidebar-toggle {
        display: inline-flex;
        position: fixed;
        top: 0.85rem;
        left: 0.85rem;
        z-index: 2001; /* above drawer so you can close it too if desired */
    }
    /* Give page content breathing room so FAB doesn't cover the title on narrow screens */
    .header { padding-left: 60px !important; }

    /* Sidebar becomes a fixed off-screen drawer */
    aside {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 280px;
        max-width: 82vw;
        transform: translateX(-102%);
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
        z-index: 1999;
        background: var(--surface-low);
        border-right: 1px solid var(--glass-border);
        box-shadow: 12px 0 40px -10px rgba(0,0,0,0.5);
        padding: 1.5rem 1rem;
        overflow-y: auto;
        align-items: stretch;
        flex-direction: column;
    }
    aside nav.nav-scroll, aside nav { flex-direction: column; }
    aside .logo span, aside nav a span { display: inline !important; }
    aside nav a { justify-content: flex-start !important; padding: 0.7rem 0.9rem !important; flex-direction: row !important; gap: 0.8rem !important; }

    /* Drawer OPEN */
    body.sidebar-open aside { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { display: block; opacity: 1; }
    body.sidebar-open { overflow: hidden; }

    /* Main content takes full width */
    .app-container { flex-direction: column; }
    main { padding: 2rem; margin-left: 0 !important; width: 100%; }
    .header h1 { font-size: 1.6rem; }
    .header { gap: 0.75rem; align-items: flex-start; }
}

@media (max-width: 768px) {
    main { padding: 1.25rem; padding-bottom: 2.5rem; }
    
    .header { flex-direction: column; gap: 1rem; margin-bottom: 2rem; }
    .header .actions { width: 100%; display: flex; flex-wrap: wrap; gap: 0.5rem; }
    .header .actions .btn { flex: 1; justify-content: center; min-width: 140px; }

    .stats-grid { grid-template-columns: 1fr; }
    .kanban-board { grid-template-columns: 1fr !important; }
    .chart-grid { grid-template-columns: 1fr; }
    .content-section { grid-template-columns: 1fr !important; }
    
    .it-table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; border: 1px solid var(--glass-border); }
    .it-table { min-width: 600px; }
    
    .card { padding: 1.5rem; border-radius: 16px; }
}

@media (max-width: 480px) {
    h1 { font-size: 1.5rem; }
    .stat-value { font-size: 1.5rem; }
    .btn { width: 100%; padding: 0.85rem; font-size: 0.8rem; }
    .header .actions { flex-direction: column; }
}
/* --- PREMIUM NOTIFICATION & ALERT SYSTEM --- */

.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 10005; /* High-priority layer */
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 320px;
    padding: 1.25rem 1.75rem;
    background: var(--surface-low);
    backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    animation: toastIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    transition: all 0.3s ease;
    border-left: 5px solid var(--accent-primary);
}

.toast.success { border-left-color: var(--status-success); }
.toast.warning { border-left-color: var(--status-warning); }
.toast.critical { border-left-color: var(--status-critical); }

.toast-icon {
    font-size: 1.75rem;
    display: flex;
    align-items: center;
}

.toast-content { flex: 1; }
.toast-title { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.25rem; color: var(--text-main); }
.toast-msg { font-size: 0.8rem; color: var(--text-dim); line-height: 1.4; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0) scale(1); }
    to { opacity: 0; transform: translateX(50px) scale(0.9); }
}

/* Custom Confirmation Dialog - Theme Adaptive */
.custom-confirm-dialog {
    background: var(--surface-low);
    backdrop-filter: blur(40px);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    padding: 3rem;
    width: 480px;
    color: var(--text-main);
    box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.6);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
}

/* --- UNIVERSAL MODAL & DIALOG ARCHITECTURE --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(12px) saturate(180%);
    z-index: 9000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
    overflow-y: auto;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--surface-low);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.6);
    position: relative;
    max-height: calc(100vh - 5rem);
    padding: 3rem;
    overflow-y: auto;
}

.modal-overlay.active .modal-content {
    animation: modalSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(30px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Standardized Modal Sizes */
.modal-sm { width: 440px; }
.modal-md { width: 640px; }
.modal-lg { width: 940px; }
.modal-xl { width: 1140px; }

@media (max-width: 1200px) {
    .modal-xl { width: 90vw; }
    .modal-lg { width: 85vw; }
}

@media (max-width: 768px) {
    .modal-md, .modal-sm { width: 95vw; }
    .modal-content { padding: 1.5rem !important; border-radius: 20px; }
}

/* <dialog> Tag Modernization */
dialog[open] {
    margin: auto;
}

dialog.glass {
    background: var(--surface-low);
    backdrop-filter: blur(40px);
    border: none;
    border-radius: 32px;
    padding: 3rem;
    color: var(--text-main);
    box-shadow: 0 40px 80px -20px rgba(0, 0, 0, 0.6);
    outline: none;
    margin: auto;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

dialog.glass[open] {
    animation: dialogFadeIn 0.3s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

dialog.glass::backdrop {
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(12px);
}

@keyframes dialogFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Modal Headers */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 1.25rem;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
}

.modal-header .close-btn {
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition-smooth);
    padding: 0.5rem;
    margin: -0.5rem -0.5rem -0.5rem 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.modal-header .close-btn:hover {
    color: var(--accent-primary);
    transform: rotate(90deg);
}

.confirm-header { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 2rem; }
.confirm-icon {
    width: 56px; height: 56px; border-radius: 16px;
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
}

.confirm-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.custom-confirm-dialog {
    opacity: 0;
    transform: translate(-50%, -45%) scale(0.95);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.confirm-title { font-size: 1.5rem; font-weight: 700; color: var(--text-main); letter-spacing: -0.5px; }
.confirm-msg { color: var(--text-dim); font-size: 1.05rem; line-height: 1.6; margin-bottom: 2.5rem; }
.confirm-actions { display: flex; gap: 1.25rem; justify-content: flex-end; }

/* --- MODAL REINFORCEMENT & UTILITIES --- */
.modal-description { font-size: 0.9rem; color: var(--text-dim); margin-bottom: 2.5rem; line-height: 1.6; opacity: 0.8; }
.modal-icon { width: 64px; height: 64px; border-radius: 16px; background: rgba(59, 130, 246, 0.1); color: var(--accent-primary); display: flex; align-items: center; justify-content: center; font-size: 2.5rem; margin-bottom: 1.5rem; box-shadow: 0 10px 20px rgba(0,0,0,0.2); border: 1px solid rgba(59, 130, 246, 0.15); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.form-actions { display: flex; gap: 1rem; justify-content: flex-end; margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--glass-border); }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* =========================================================
   QARC NEXUS — RESPONSIVE PATCH
   Covers: inline grid collapse, sidebar-to-bottom-nav fixes,
   header/modal/table polish, overflow guards.
   ========================================================= */

/* Prevent any horizontal scroll caused by sticky/scrolled headers */
html, body { overflow-x: hidden; max-width: 100%; }

/* Attribute-selector overrides: collapse inline grids used across modules
   (campaigns, reports, email-studio, suppressions). Inline styles normally
   win, but media-scoped !important overrides them.                        */
/* Attribute selectors match both spaced "repeat(4, 1fr)" and un-spaced
   "repeat(4,1fr)" forms used inline across module files. We intentionally
   do NOT match repeat(auto-fit / auto-fill since those already self-adapt. */
@media (max-width: 1100px) {
    [style*="repeat(6,"] { grid-template-columns: repeat(3, 1fr) !important; }
    [style*="repeat(5,"] { grid-template-columns: repeat(3, 1fr) !important; }
    [style*="repeat(4,"] { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 768px) {
    [style*="repeat(6,"],
    [style*="repeat(5,"],
    [style*="repeat(4,"],
    [style*="repeat(3,"] { grid-template-columns: repeat(2, 1fr) !important; }

    [style*="2fr 1fr"],
    [style*="1.3fr 1fr"],
    [style*="1fr 1fr"]   { grid-template-columns: 1fr !important; }

    /* Sticky header horizontal bleed fix (.header.scrolled uses -1.5rem margin) */
    .header.scrolled { margin: 0 !important; border-radius: 0 !important; padding: 1rem !important; }
    .header { top: 0 !important; padding: 1rem 0 !important; }

    /* Drawer mode overrides old bottom-nav layout — keep categories vertical */
    aside nav.nav-scroll { display: flex; flex-direction: column; overflow-y: auto; width: 100%; padding: 0; }
    aside nav ul { flex-direction: column; gap: 0.2rem; }
    aside nav li { flex: initial; }
    .nav-category { display: block !important; font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 1rem 0.5rem 0.4rem; }
}

@media (max-width: 600px) {
    [style*="repeat(6,"],
    [style*="repeat(5,"],
    [style*="repeat(4,"],
    [style*="repeat(3,"],
    [style*="repeat(2,"] { grid-template-columns: 1fr 1fr !important; gap: 0.75rem !important; }
}

@media (max-width: 480px) {
    /* Single-column at phone widths */
    [style*="repeat(6,"],
    [style*="repeat(5,"],
    [style*="repeat(4,"],
    [style*="repeat(3,"],
    [style*="repeat(2,"] { grid-template-columns: 1fr !important; }

    main { padding: 1rem !important; padding-bottom: 90px !important; }
    .card { padding: 1rem !important; border-radius: 12px !important; }

    h1 { font-size: 1.35rem !important; }
    h3 { font-size: 1rem !important; }
    .breadcrumb { font-size: 0.6rem; }

    /* Stat values shrink so 1.5rem-2rem numbers don't overflow narrow cards */
    .card [style*="font-size: 1.5rem"],
    .card [style*="font-size: 2rem"] { font-size: 1.15rem !important; }

    /* Header action buttons already stack; shrink text */
    .header .actions .btn { font-size: 0.7rem; padding: 0.65rem 0.75rem; min-width: 0; }

    /* Modals: edge-to-edge on phones */
    .modal-overlay { padding: 0.5rem !important; }
    .modal-content { padding: 1.25rem !important; max-height: 95vh; width: 100% !important; }
    .modal-md, .modal-sm, .modal-lg, .modal-xl { width: 100% !important; }

    /* Tables: wrap inside a horizontal-scroll shell automatically */
    .card .it-table { display: block; overflow-x: auto; white-space: nowrap; min-width: 0; }

    /* Forms: inputs full-width, smaller labels */
    .form-control { font-size: 0.9rem; padding: 0.75rem 0.9rem; }
    label { font-size: 0.75rem; }

    /* Flash / alerts */
    .flash { font-size: 0.8rem; padding: 0.6rem 0.8rem; }
}

/* Touch-target minimum for interactive elements on coarse pointers */
@media (hover: none) and (pointer: coarse) {
    .btn, button, a.btn, nav a { min-height: 44px; }
}

/* =========================================================
   GLOBAL MOBILE SAFETY NET — covers every module
   ========================================================= */
@media (max-width: 900px) {
    /* Any element using inline width: 200px..800px should cap at 100% */
    [style*="width: 200px"],
    [style*="width: 220px"],
    [style*="width: 240px"],
    [style*="width: 250px"],
    [style*="width: 280px"],
    [style*="width: 300px"],
    [style*="width: 320px"],
    [style*="width: 360px"],
    [style*="width: 400px"],
    [style*="width: 420px"],
    [style*="width: 480px"],
    [style*="width: 500px"],
    [style*="width: 520px"],
    [style*="width: 600px"],
    [style*="width: 640px"],
    [style*="width: 720px"],
    [style*="width: 800px"] {
        width: 100% !important;
        max-width: 100% !important;
    }
    /* Inline min-width: overwrite so they don't burst narrow screens */
    [style*="min-width: 400px"],
    [style*="min-width: 480px"],
    [style*="min-width: 500px"],
    [style*="min-width: 600px"],
    [style*="min-width: 720px"],
    [style*="min-width: 800px"] {
        min-width: 0 !important;
    }

    /* Flex/grid rows that used inline flex-direction: row forced to wrap */
    [style*="display: flex"][style*="justify-content: space-between"] { flex-wrap: wrap; gap: 0.75rem; }

    /* All media stays within its parent */
    img, video, iframe, canvas, svg { max-width: 100%; height: auto; }

    /* Pre/code blocks scroll instead of overflowing */
    pre, code { max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }

    /* Tables without wrapper still scroll */
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

    /* Common "hero stat" grids */
    .stats-grid, .kpi-grid, .metric-grid { grid-template-columns: repeat(2, 1fr) !important; }

    /* Modal max width */
    .modal-content { max-width: 95vw !important; }

    /* Buttons with fixed height don't crop icons */
    .btn { white-space: normal; line-height: 1.15; }
}

@media (max-width: 560px) {
    .stats-grid, .kpi-grid, .metric-grid { grid-template-columns: 1fr !important; }

    /* Forms stack */
    .form-grid, [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }

    /* Headers with inline flex row collapse */
    [style*="display: flex"] { flex-wrap: wrap !important; }

    /* Filter bars / action rows */
    .filters, .filter-bar, .toolbar { flex-direction: column !important; align-items: stretch !important; }
    .filters > *, .filter-bar > *, .toolbar > * { width: 100% !important; }
}

/* Prevent horizontal page overflow regardless of module-specific CSS */
.app-container, main, .card, .modal-content { max-width: 100%; }

/* =========================================================
   QARC NEXUS — PREMIUM GLOBAL POLISH
   Typography, focus, scrollbars, selection, skeletons.
   ========================================================= */

html { scroll-behavior: smooth; }

body {
    text-rendering: optimizeLegibility;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01", "kern";
}

/* Refined heading rhythm */
h1, h2, h3, h4 { letter-spacing: -0.02em; }
h1 { font-weight: 700; }
h2 { font-weight: 700; font-size: 1.75rem; line-height: 1.25; }
h3 { font-weight: 600; font-size: 1.25rem; line-height: 1.35; }

p { line-height: 1.65; }

a { color: var(--accent-primary); text-decoration: none; transition: var(--transition-smooth); }
a:hover { filter: brightness(1.15); }

/* Premium selection */
::selection { background: rgba(59, 130, 246, 0.3); color: var(--text-main); }

/* Global keyboard-focus ring (hide for mouse) */
*:focus { outline: none; }
*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 3px;
    border-radius: 6px;
}
.btn:focus-visible,
.form-control:focus-visible { outline-offset: 4px; }

/* Slim custom scrollbar across the app */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.12) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); background-clip: content-box; }
[data-theme="light"] * { scrollbar-color: rgba(0,0,0,0.18) transparent; }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); background-clip: content-box; }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.3); background-clip: content-box; }

/* Premium card gradient border (opt-in) */
.card-glow {
    position: relative;
    isolation: isolate;
}
.card-glow::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    padding: 1px;
    background: linear-gradient(135deg, rgba(59,130,246,0.4), rgba(147,51,234,0.2), transparent 60%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.4s ease;
}
.card-glow:hover::before { opacity: 1; }

/* Loading skeleton utility */
.skeleton {
    background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.09) 50%, rgba(255,255,255,0.04) 100%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.4s ease-in-out infinite;
    border-radius: 8px;
}
@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Smoother button press + ripple-esque */
.btn { position: relative; overflow: hidden; }
.btn::after {
    content: '';
    position: absolute; inset: 0;
    background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), rgba(255,255,255,0.15), transparent 40%);
    opacity: 0; transition: opacity 0.4s ease;
    pointer-events: none;
}
.btn:hover::after { opacity: 1; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Print-friendly output */
@media print {
    aside, .header .actions, .theme-toggle-container { display: none !important; }
    main { padding: 0 !important; }
    .card { break-inside: avoid; box-shadow: none; border-color: #ddd; }
}

/* Tablet landing polish (syncs with bottom-nav breakpoint) */
@media (max-width: 768px) {
    .modal-header h2 { font-size: 1.15rem; }
    .form-grid { grid-template-columns: 1fr; }
}

/* ==============================================================
   GLOBAL MOBILE SAFETY-NET for inline-styled grids
   Many module pages inline `grid-template-columns: repeat(N, 1fr)`
   which overflows on narrow screens. We attack the inline `style`
   attribute directly and collapse to 2 columns on tablet, 1 on phone.
   ============================================================== */
@media (max-width: 1100px) {
    [style*="repeat(5, 1fr)"],
    [style*="repeat(5,1fr)"],
    [style*="repeat(4, 1fr)"],
    [style*="repeat(4,1fr)"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
@media (max-width: 640px) {
    [style*="repeat(5, 1fr)"],
    [style*="repeat(5,1fr)"],
    [style*="repeat(4, 1fr)"],
    [style*="repeat(4,1fr)"],
    [style*="repeat(3, 1fr)"],
    [style*="repeat(3,1fr)"],
    [style*="repeat(2, 1fr)"],
    [style*="repeat(2,1fr)"] {
        grid-template-columns: 1fr !important;
    }
    .stats-grid { grid-template-columns: 1fr 1fr !important; }
    .it-table { font-size: 0.75rem; }
    .card { padding: 1rem; }
    .modal-content { width: 95vw !important; max-width: 95vw !important; }
}

/* Tables — horizontal scroll on mobile to prevent layout break */
@media (max-width: 900px) {
    .table-wrapper, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .it-table { min-width: 720px; }
}

/* ==============================================================
   GLOBAL UI POLISH (applies to every module)
   ============================================================== */

/* Card hover lift for all glass cards */
.card.glass {
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1),
                box-shadow 0.25s cubic-bezier(0.4,0,0.2,1),
                border-color 0.25s ease;
}
.card.glass:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 36px -12px rgba(0,0,0,0.55),
                0 0 0 1px rgba(var(--accent-primary-rgb), 0.15);
    border-color: rgba(var(--accent-primary-rgb), 0.25);
}

/* Consistent card internal spacing where inline padding wasn't set */
.card { padding: 1.5rem; }

/* Buttons — unified focus-visible ring */
.btn:focus-visible, button:focus-visible, a.btn:focus-visible {
    outline: 2px solid rgba(var(--accent-primary-rgb), 0.55);
    outline-offset: 2px;
}
.btn { transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

/* Table row hover — subtle highlight */
.it-table tbody tr { transition: background 0.15s ease; }
.it-table tbody tr:hover { background: rgba(var(--accent-primary-rgb), 0.05); }

/* Status badges — unified pill style */
.status-badge, .badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid transparent;
}

/* Form inputs — consistent focus */
.form-control:focus, input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: rgba(var(--accent-primary-rgb), 0.55);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.15);
}

/* Page flash messages — shared style for .flash.ok / .flash.err */
.flash {
    padding: 0.8rem 1.1rem;
    border-radius: 10px;
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
    line-height: 1.4;
    border: 1px solid transparent;
    animation: flashIn 0.3s ease;
}
.flash.ok, .flash-success { background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.28); color: var(--status-success); }
.flash.err, .flash-error { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.28); color: var(--status-critical); }
.flash.warn, .flash-warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.28); color: var(--status-warning); }
@keyframes flashIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Modal backdrop blur (matches glass aesthetic) */
.modal-overlay { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }

/* Empty state */
.empty-state, td.empty-row {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* Scrollbar polish */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(var(--accent-primary-rgb), 0.25); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(var(--accent-primary-rgb), 0.45); }

/* Print/reduced-motion safety */
@media (prefers-reduced-motion: reduce) {
    .card.glass, .btn, .it-table tbody tr { transition: none !important; }
    .card.glass:hover, .btn:hover { transform: none !important; }
}

/* =========================================================
   QARC NEXUS — COMPREHENSIVE RESPONSIVE OVERHAUL
   Covers: All modules, inline grids, fixed widths, tables,
   modals, dialogs, filter bars, profile grids, workforce,
   geo-intel, developer-analytics, and more.
   ========================================================= */

/* --- UNIVERSAL TABLE SCROLL WRAPPER --- */
.card > .it-table,
.card > table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

/* --- RESPONSIVE GRID COLLAPSE (INLINE STYLE OVERRIDES) --- */
@media (max-width: 1200px) {
    [style*="repeat(6,"] { grid-template-columns: repeat(3, 1fr) !important; }
    [style*="repeat(5,"] { grid-template-columns: repeat(3, 1fr) !important; }
    [style*="repeat(4,"] { grid-template-columns: repeat(2, 1fr) !important; }
    [style*="1.5fr 1fr"],
    [style*="1.3fr 1fr"] { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 900px) {
    [style*="repeat(6,"],
    [style*="repeat(5,"],
    [style*="repeat(4,"],
    [style*="repeat(3,"] { grid-template-columns: repeat(2, 1fr) !important; }

    [style*="2fr 1fr"],
    [style*="1fr 2fr"],
    [style*="1.5fr 1fr"],
    [style*="1.3fr 1fr"],
    [style*="1.1fr 1fr"],
    [style*="1fr 1fr"] { grid-template-columns: 1fr !important; }

    [style*="1fr 2fr 1fr 1fr"],
    [style*="1fr 1fr 1fr"] { grid-template-columns: 1fr !important; }

    [style*="1fr 350px"],
    [style*="300px 1fr"],
    [style*="250px 1fr"],
    [style*="280px 1fr"] { grid-template-columns: 1fr !important; }

    .header.scrolled { margin: 0 !important; border-radius: 0 !important; padding: 1rem !important; }
    .header { top: 0 !important; padding: 1rem 0 !important; }

    aside nav.nav-scroll { display: flex; flex-direction: column; overflow-y: auto; width: 100%; padding: 0; }
    aside nav ul { flex-direction: column; gap: 0.2rem; }
    aside nav li { flex: initial; }
    .nav-category { display: block !important; }

    .it-table { min-width: 600px; }
}

@media (max-width: 640px) {
    [style*="repeat(6,"],
    [style*="repeat(5,"],
    [style*="repeat(4,"],
    [style*="repeat(3,"],
    [style*="repeat(2,"] { grid-template-columns: 1fr !important; }

    .stats-grid { grid-template-columns: 1fr 1fr !important; }
    .it-table { font-size: 0.75rem; }
    .card { padding: 1rem; }
    .modal-content { width: 95vw !important; max-width: 95vw !important; }
    .modal-md, .modal-sm, .modal-lg, .modal-xl { width: 95vw !important; }

    h1 { font-size: 1.35rem !important; }
    h2 { font-size: 1.15rem !important; }
    h3 { font-size: 1rem !important; }
}

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

    [style*="repeat(6,"],
    [style*="repeat(5,"],
    [style*="repeat(4,"],
    [style*="repeat(3,"],
    [style*="repeat(2,"] { grid-template-columns: 1fr !important; }

    main { padding: 1rem !important; padding-bottom: 90px !important; }
    .card { padding: 1rem !important; border-radius: 12px !important; }

    h1 { font-size: 1.25rem !important; }

    .header .actions .btn { font-size: 0.7rem; padding: 0.6rem 0.7rem; min-width: 0; }
    .header .actions { flex-wrap: wrap; gap: 0.5rem; }

    .modal-overlay { padding: 0.5rem !important; }
    .modal-content,
    .modal-md,
    .modal-sm,
    .modal-lg,
    .modal-xl { width: 100% !important; max-width: 100vw !important; border-radius: 16px !important; }

    .form-control { font-size: 0.9rem; padding: 0.75rem 0.9rem; }

    .it-table { font-size: 0.7rem; min-width: 500px; }
    .it-table th, .it-table td { padding: 0.75rem 0.5rem; }
}

/* --- FIXED-WIDTH ELEMENT RESETS --- */
@media (max-width: 900px) {
    [style*="width: 320px"]:not(.it-table):not(.modal-content),
    [style*="width: 350px"],
    [style*="width: 400px"],
    [style*="width: 420px"],
    [style*="width: 480px"],
    [style*="width: 500px"],
    [style*="width: 550px"],
    [style*="width: 600px"],
    [style*="width: 640px"] {
        width: 100% !important;
        max-width: 100% !important;
    }

    [style*="min-width: 220px"]:not(.it-table),
    [style*="min-width: 400px"],
    [style*="min-width: 500px"],
    [style*="min-width: 600px"],
    [style*="min-width: 720px"],
    [style*="min-width: 1000px"] {
        min-width: 0 !important;
    }

    [style*="width: 200px"]:not(.it-table):not(.it-table th),
    [style*="width: 180px"]:not(.it-table),
    [style*="width: 150px"]:not(.it-table),
    [style*="width: 120px"]:not(.it-table),
    [style*="width: 100px"]:not(.it-table) {
        width: auto !important;
        min-width: 0 !important;
        flex: 1 1 100% !important;
    }
}

/* --- FLEX WRAP ENFORCEMENT --- */
@media (max-width: 900px) {
    [style*="display: flex"][style*="justify-content: space-between"] {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
    }

    [style*="display: flex"][style*="gap: 2rem"],
    [style*="display: flex"][style*="gap: 1.5rem"] {
        flex-wrap: wrap !important;
    }
}

@media (max-width: 640px) {
    [style*="display: flex"] {
        flex-wrap: wrap !important;
    }

    .filters, .filter-bar, .toolbar,
    [style*="display: flex"][style*="gap: 1rem"][style*="align-items: center"] {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .filters > *, .filter-bar > *, .toolbar > * { width: 100% !important; }
}

/* --- DIALOG & MODAL RESPONSIVE --- */
@media (max-width: 900px) {
    dialog.glass {
        width: 92vw !important;
        max-width: 92vw !important;
        padding: 1.5rem !important;
        margin: auto !important;
    }

    dialog[style*="width: 400px"],
    dialog[style*="width: 500px"],
    dialog[style*="width: 550px"],
    dialog[style*="width: 600px"],
    dialog[style*="width: 640px"],
    dialog[style*="width: 700px"] {
        width: 92vw !important;
        max-width: 92vw !important;
        margin: auto !important;
    }
}

@media (max-width: 480px) {
    dialog.glass {
        width: 98vw !important;
        max-width: 98vw !important;
        padding: 1rem !important;
        border-radius: 16px !important;
    }
}

/* --- NOTIFICATION PANEL & USER DROPDOWN (top-header.php) --- */
@media (max-width: 900px) {
    #notif-panel {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        box-shadow: 0 -10px 40px rgba(0,0,0,0.5) !important;
        z-index: 10002 !important;
    }

    #user-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        min-width: 0 !important;
        width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        box-shadow: 0 -10px 40px rgba(0,0,0,0.5) !important;
        z-index: 10002 !important;
    }
}

/* --- CARD & STAT IMPROVEMENTS --- */
.card {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.card h2 {
    word-break: break-word;
}

.stat-card {
    min-width: 0;
    overflow: hidden;
}

.stat-value {
    word-break: break-all;
    overflow-wrap: break-word;
}

/* --- TAB NAVIGATION RESPONSIVE --- */
@media (max-width: 768px) {
    [style*="display: flex"][style*="gap: 0.5rem"][style*="border-bottom"] {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    [style*="display: flex"][style*="gap: 0.5rem"][style*="border-bottom"]::-webkit-scrollbar {
        display: none;
    }

    [style*="display: flex"][style*="gap: 0.5rem"][style*="border-bottom"] > * {
        flex-shrink: 0;
    }
}

/* --- PAGINATION RESPONSIVE --- */
@media (max-width: 640px) {
    .pagination,
    [style*="display: flex"][style*="gap: 0.25rem"][style*="justify-content: center"] {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
}

/* --- PROFILE GRID RESPONSIVE --- */
@media (max-width: 900px) {
    .profile-grid,
    [style*="grid-template-columns: 300px 1fr"],
    [style*="grid-template-columns: 250px 1fr"],
    [style*="grid-template-columns: 280px 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* --- WORKFORCE GRID RESPONSIVE --- */
@media (max-width: 900px) {
    .workforce-grid,
    [style*="grid-template-columns: 1fr 350px"],
    [style*="grid-template-columns: 350px 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* --- GEO-INTELLIGENCE GRID --- */
@media (max-width: 900px) {
    .geo-grid {
        grid-template-columns: 1fr !important;
    }
}

/* --- IMAGE / MEDIA SAFETY --- */
img, video, iframe, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* --- PRE/CODE SCROLL --- */
pre, code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* --- TOUCH TARGETS --- */
@media (hover: none) and (pointer: coarse) {
    .btn, button, a.btn, nav a { min-height: 44px; }
    .it-table td, .it-table th { padding: 0.85rem 0.75rem; }
}

/* --- PRINT --- */
@media print {
    aside, .header .actions, .theme-toggle-container, .sidebar-toggle, .sidebar-backdrop { display: none !important; }
    main { padding: 0 !important; width: 100% !important; }
    .card { break-inside: avoid; box-shadow: none; border-color: #ddd; }
}

/* --- REDUCED MOTION --- */
@media (prefers-reduced-motion: reduce) {
    .card.glass, .btn, .it-table tbody tr, .stat-card { transition: none !important; }
    .card.glass:hover, .btn:hover, .stat-card:hover { transform: none !important; }
}

/* --- LIGHT THEME ADJUSTMENTS FOR RESPONSIVE --- */
[data-theme="light"] .it-table tbody tr:hover {
    background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .card.glass:hover {
    box-shadow: 0 14px 36px -12px rgba(0,0,0,0.12),
                0 0 0 1px rgba(37, 99, 235, 0.1);
}

/* --- HORIZONTAL SCROLL INDICATOR --- */
.card > .it-table {
    background-image: linear-gradient(to right, var(--surface-low) 30%, transparent),
                      linear-gradient(to left, var(--surface-low) 30%, transparent);
    background-position: left center, right center;
    background-repeat: no-repeat;
    background-size: 20px 100%, 20px 100%;
}

/* --- KANBAN BOARD SAFE --- */
@media (max-width: 768px) {
    .kanban-board { grid-template-columns: 1fr !important; }
}

/* --- CHART GRID --- */
@media (max-width: 900px) {
    .chart-grid,
    [style*="repeat(auto-fit, minmax(400px"] {
        grid-template-columns: 1fr !important;
    }
}

/* --- CONTENT SECTION COLLAPSE --- */
@media (max-width: 768px) {
    .content-section,
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns: 1fr 2fr"],
    [style*="grid-template-columns: 1.5fr 1fr"],
    [style*="grid-template-columns: 1.3fr 1fr"],
    [style*="grid-template-columns: 1.1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

