/* =========================================
   1. CORE VARIABLES (THEME ENGINE)
   ========================================= */
:root {
    /* --- BRAND COLORS (Red Theme) --- */
    /* Defined as RGB numbers so Tailwind can apply opacity (e.g. bg-primary/50) */
    --color-primary: 220 38 38;       /* #dc2626 */
    --color-primary-hover: 185 28 28; /* #b91c1c */

    /* --- SIDEBAR (The "Black" Theme) --- */
    --color-sidebar: 17 24 39;        /* #111827 */
    --color-sidebar-hover: 31 41 55;  /* #1f2937 */
    --sidebar-text: #9ca3af;          /* Gray 400 */
    --sidebar-text-hover: #ffffff;
    --sidebar-width: 16rem;

    /* --- LAYOUT COLORS (Light Mode Default) --- */
    --background-color: #f3f4f6;      /* Gray 100 */
    --card-background-color: #ffffff;
    --text-color: #111827;            /* Gray 900 */
    --text-muted-color: #6b7280;      /* Gray 500 */
    --border-color: #e5e7eb;          /* Gray 200 */
    --input-bg: #ffffff;
    
    /* Legacy Hex Variables (for compatibility) */
    --primary-color: #dc2626;
    --button-text-color: #ffffff;
}

/* =========================================
   2. DARK MODE OVERRIDES
   ========================================= */
[data-theme="dark"] {
    --background-color: #111827;      /* Gray 900 */
    --card-background-color: #1f2937; /* Gray 800 */
    --text-color: #f9fafb;            /* Gray 50 */
    --text-muted-color: #9ca3af;      /* Gray 400 */
    --border-color: #374151;          /* Gray 700 */
    --input-bg: #1f2937;
}

/* Ensure table headers stay readable in dark mode */
[data-theme="dark"] thead {
    background-color: rgba(255, 255, 255, 0.05) !important;
}

/* Solid primary-colour banner (e.g. Access Level header strip) */
.primary-banner {
    background-color: var(--primary-color);
}

/* Card with primary-colour border accent */
.primary-accent-card {
    border-color: var(--primary-color);
    background-color: var(--card-background-color);
}
[data-theme="dark"] .primary-accent-card {
    border-color: rgb(var(--color-primary) / 0.4);
}

/* Decorative icon box — inherits brand colour, softened in dark mode */
.primary-icon-wrapper {
    background: rgb(var(--color-primary) / 0.10);
}

/* Soften primary-color decorative icon boxes in dark mode */
[data-theme="dark"] .primary-icon-wrapper {
    background: rgb(var(--color-primary) / 0.07) !important;
}
[data-theme="dark"] .primary-icon-wrapper i {
    opacity: 0.65;
}

/* =========================================
   3. GLOBAL DEFAULTS
   ========================================= */
body {
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Component Mapping */
.header, .card {
    background-color: var(--card-background-color);
    border-color: var(--border-color);
}

/* Sidebar always uses its own dark background, independent of light/dark theme */
.sidebar {
    background-color: #111827;
    border-color: rgba(255, 255, 255, 0.06);
}

/* Input Styles */
input, select, textarea {
    background-color: var(--input-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-color) !important;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid rgb(var(--color-primary));
    border-color: transparent;
}

/* =========================================
   4. SIDEBAR & NAVIGATION
   ========================================= */
.sidebar-transition {
    transition: transform 0.3s ease-in-out;
}

/* Shared Nav Link Styles */
.nav-link, .sub-nav-link, .sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    color: #9ca3af;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
    border-radius: 0 0.375rem 0.375rem 0;
    width: 100%;
    text-decoration: none;
    font-size: 0.875rem;
}

/* Hover Effects */
.nav-link:hover, .sub-nav-link:hover, .sidebar-link:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #f9fafb;
}

/* Active State */
.nav-link.active, .sub-nav-link.active, .sidebar-link.active {
    background-color: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border-left-color: var(--primary-color);
}

/* Submenu Specifics */
.submenu-container {
    background-color: rgba(0, 0, 0, 0.15);
    padding-bottom: 0.25rem;
}

/* Sidebar section label */
.sidebar-section-label {
    padding: 0.75rem 1.25rem 0.25rem;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(156, 163, 175, 0.5);
    user-select: none;
}

/* Sidebar tooltip for mini mode */
.sidebar-tooltip {
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background-color: #1f2937;
    color: #f9fafb;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.sidebar-tooltip::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: #1f2937;
}
.sidebar-item:hover .sidebar-tooltip {
    opacity: 1;
}

/* =========================================
   5. UTILITY COMPONENTS (Chips, Buttons)
   ========================================= */

/* Primary Button */
.button-primary {
    background-color: rgb(var(--color-primary));
    color: var(--button-text-color);
    transition: filter 0.2s;
}
.button-primary:hover {
    filter: brightness(0.9);
}

/* Filter Buttons (Message Center) */
.filter-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
    background: var(--card-background-color);
    color: var(--text-muted-color);
}
.filter-btn.active {
    background: rgb(var(--color-primary));
    color: white;
    border-color: rgb(var(--color-primary));
    box-shadow: 0 2px 8px rgb(var(--color-primary) / 0.2);
}

/* Role Chips */
.role-chip {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 800;
    background: rgba(255,255,255,0.05);
    color: var(--text-muted-color);
    border: 1px solid var(--border-color);
}
.role-chip.active {
    border-color: rgb(var(--color-primary));
    color: rgb(var(--color-primary));
    background: rgb(var(--color-primary) / 0.05);
}

/* =========================================
   6. INTERACTION & HOVER EFFECTS
   ========================================= */

/* Row Hover Intensity (Table Rows) */
.row-hover-intensity:hover {
    background-color: var(--card-background-color) !important;
    filter: brightness(96%);
    transition: filter 0.2s ease;
}
[data-theme='dark'] .row-hover-intensity:hover {
    filter: brightness(115%);
}

/* Standard List Row — use this on every <tr> in data tables */
.list-row {
    color: var(--text-color);
    transition: background-color 0.15s ease;
}
.list-row:hover {
    background-color: var(--background-color);
}
[data-theme='dark'] .list-row:hover {
    background-color: rgba(255, 255, 255, 0.04);
}

/* Chat Link Hover */
.chat-link-hover {
    transition: background-color 0.2s ease;
}
.chat-link-hover:hover {
    background-color: rgba(0, 0, 0, 0.03);
}
[data-theme="dark"] .chat-link-hover:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* =========================================
   7. CUSTOM SCROLLBARS
   ========================================= */
.custom-scrollbar::-webkit-scrollbar, 
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track, 
::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb, 
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Sidebar specific scrollbar adjustments */
.sidebar .custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }