@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap');

* {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =============================================================================
   THEME TEXT COLOR CSS VARIABLES
   Activated by data-bs-theme attribute toggled by color mode callback.
   ============================================================================= */

[data-bs-theme="dark"] {
    --text-primary: #c1c2c5;
    --text-secondary: #909296;
}

[data-bs-theme="light"] {
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
}

/* =============================================================================
   BRAND THEME CSS VARIABLES
   Activated by data-brand-theme attribute on root container.
   ============================================================================= */

:root, [data-brand-theme="purple"] {
    --brand-primary: #9C00BF;
    --brand-primary-hover: #8400a2;
    --brand-primary-active: #75008f;
    --brand-primary-rgb: 156, 0, 191;
    --brand-text-on-primary: #ffffff;
}

[data-brand-theme="archblue"] {
    --brand-primary: #244BD8;
    --brand-primary-hover: #1E3EB8;
    --brand-primary-active: #1b36a2;
    --brand-primary-rgb: 36, 75, 216;
    --brand-text-on-primary: #ffffff;
}

/* =============================================================================
   BRAND UTILITY CLASSES
   ============================================================================= */

.brand-color { color: var(--brand-primary) !important; }
.brand-bg { background-color: var(--brand-primary) !important; }
.brand-border { border-color: var(--brand-primary) !important; }
.brand-underline {
    width: 100px; margin: 1rem auto 1.5rem auto;
    border: none; border-top: 3px solid var(--brand-primary); border-radius: 2px;
}
.brand-icon svg { color: var(--brand-primary) !important; }

/* =============================================================================
   BRAND BUTTONS
   ============================================================================= */

.brand-btn {
    background-color: var(--brand-primary) !important;
    border-color: var(--brand-primary) !important;
    color: var(--brand-text-on-primary, #ffffff) !important;
    font-weight: 500;
    transition: all 0.15s ease-in-out;
}

.brand-btn:hover {
    background-color: var(--brand-primary-hover) !important;
    border-color: var(--brand-primary-hover) !important;
    filter: brightness(0.9);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(var(--brand-primary-rgb), 0.3);
}

.brand-btn:active {
    background-color: var(--brand-primary-active) !important;
    border-color: var(--brand-primary-active) !important;
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(var(--brand-primary-rgb), 0.2);
}

.brand-btn-outline {
    background-color: transparent !important;
    border-color: var(--brand-primary) !important;
    color: var(--brand-primary) !important;
    font-weight: 500;
    transition: all 0.15s ease-in-out;
}

.brand-btn-outline:hover {
    background-color: var(--brand-primary) !important;
    border-color: var(--brand-primary) !important;
    color: #ffffff !important;
    filter: brightness(0.9);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(var(--brand-primary-rgb), 0.3);
}

.brand-btn-outline:active {
    background-color: var(--brand-primary-active) !important;
    border-color: var(--brand-primary-active) !important;
    color: #ffffff !important;
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(var(--brand-primary-rgb), 0.2);
}

/* Danger outline button (destructive actions) */
.brand-btn-danger-outline {
    background-color: transparent !important;
    border: 1px solid #c92a2a !important;  /* Deep red — text/border clears 4.5:1 on white (was #fa5252 at 3.28:1) */
    color: #c92a2a !important;  /* Deep red */
    font-weight: 500;
    transition: all 0.15s ease-in-out;
}
/* The outline button is transparent, so on the dark card the deep red (#c92a2a)
   drops to 2.76:1. Use a lighter red in dark mode (>=5:1 on the dark surface). */
[data-bs-theme="dark"] .brand-btn-danger-outline,
[data-mantine-color-scheme="dark"] .brand-btn-danger-outline {
    border-color: #ff8787 !important;  /* Light red — clears 4.5:1 on the dark card */
    color: #ff8787 !important;  /* Light red */
}

.brand-btn-danger-outline:hover {
    background-color: #fa5252 !important;
    border-color: #fa5252 !important;
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(250, 82, 82, 0.3);
}

.brand-btn-danger-outline:active {
    background-color: #e03131 !important;
    border-color: #e03131 !important;
    color: #ffffff !important;
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(250, 82, 82, 0.2);
}

/* =============================================================================
   BRAND LINKS
   ============================================================================= */

.brand-link {
    color: var(--brand-primary) !important;
    text-decoration: none;
}

.brand-link:hover {
    color: var(--brand-primary-hover) !important;
    text-decoration: underline;
}

/* Brand-colored border top (for footer hr dividers) */
.brand-border-top {
    border: none !important;
    border-top: 2px solid var(--brand-primary) !important;
}

/* =============================================================================
   MODERN TABLE SYSTEM
   ============================================================================= */

.table-modern-container {
    border-radius: 12px;
    overflow: auto;
}

.table-modern {
    margin-bottom: 0;
    font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.875rem;
}

/* Brand-colored sticky header */
.table-modern thead th {
    background-color: var(--brand-primary) !important;
    color: var(--brand-text-on-primary, #ffffff) !important;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.875rem 1rem;
    border: none !important;
    white-space: nowrap;
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
}

.table-modern thead th:first-child {
    border-top-left-radius: 12px;
}

.table-modern thead th:last-child {
    border-top-right-radius: 12px;
}

/* Body cells */
.table-modern tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-color: rgba(0, 0, 0, 0.05);
    transition: background-color 0.15s ease;
}

.table-modern.table-dark tbody td {
    border-color: rgba(255, 255, 255, 0.05);
}

/* Brand-tinted hover */
.table-modern tbody tr:hover td {
    background-color: rgba(var(--brand-primary-rgb), 0.08) !important;
}

/* Striped rows: Light mode */
.table-modern.table-striped tbody tr:nth-of-type(odd) td {
    background-color: rgba(0, 0, 0, 0.04);
}

.table-modern.table-striped tbody tr:nth-of-type(even) td {
    background-color: #ffffff;
}

.table-modern.table-striped tbody tr:nth-of-type(odd):hover td {
    background-color: rgba(var(--brand-primary-rgb), 0.12) !important;
}

.table-modern.table-striped tbody tr:nth-of-type(even):hover td {
    background-color: rgba(var(--brand-primary-rgb), 0.08) !important;
}

/* Striped rows: Dark mode */
.table-modern.table-dark.table-striped tbody tr:nth-of-type(odd),
.table-modern.table-dark.table-striped tbody tr:nth-of-type(odd) td,
.table-dark.table-striped tbody tr:nth-of-type(odd),
.table-dark.table-striped tbody tr:nth-of-type(odd) td {
    background-color: #2e2e2e !important;
    --bs-table-striped-bg: #2e2e2e !important;
}

.table-modern.table-dark.table-striped tbody tr:nth-of-type(even),
.table-modern.table-dark.table-striped tbody tr:nth-of-type(even) td,
.table-dark.table-striped tbody tr:nth-of-type(even),
.table-dark.table-striped tbody tr:nth-of-type(even) td {
    background-color: #252525 !important;
    --bs-table-bg: #252525 !important;
}

.table-modern.table-dark.table-striped tbody tr:nth-of-type(odd):hover td {
    background-color: rgba(var(--brand-primary-rgb), 0.15) !important;
}

.table-modern.table-dark.table-striped tbody tr:nth-of-type(even):hover td {
    background-color: rgba(var(--brand-primary-rgb), 0.12) !important;
}

/* Last row bottom rounding */
.table-modern tbody tr:last-child td:first-child {
    border-bottom-left-radius: 8px;
}

.table-modern tbody tr:last-child td:last-child {
    border-bottom-right-radius: 8px;
}

/* --- Brand Theme Table Headers (standalone, not inside .table-modern) --- */
thead.table-brand,
thead.table-brand tr {
    background-color: var(--brand-primary) !important;
}

thead.table-brand th {
    background-color: var(--brand-primary) !important;
    color: var(--brand-text-on-primary, #ffffff) !important;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.875rem 1rem;
    border: none !important;
    white-space: nowrap;
    /* Sticky header support */
    position: sticky;
    top: 0;
    z-index: 1;
}

/* =============================================================================
   TABLE SCROLLBAR STYLING
   ============================================================================= */

/* Light mode scrollbar */
.table-scroll-container {
    scrollbar-width: thin;
    scrollbar-color: var(--brand-primary) #e9ecef;
}

.table-scroll-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.table-scroll-container::-webkit-scrollbar-track {
    background: #e9ecef;
}

.table-scroll-container::-webkit-scrollbar-thumb {
    background: var(--brand-primary);
    border-radius: 5px;
    border: 2px solid #e9ecef;
}

.table-scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--brand-primary-hover);
}

.table-scroll-container::-webkit-scrollbar-corner {
    background: #e9ecef;
}

/* Dark mode scrollbar */
[data-bs-theme="dark"] .table-scroll-container,
.table-scroll-container.dark-mode {
    scrollbar-color: var(--brand-primary) #252525;
}

[data-bs-theme="dark"] .table-scroll-container::-webkit-scrollbar-track,
.table-scroll-container.dark-mode::-webkit-scrollbar-track {
    background: #252525;
}

[data-bs-theme="dark"] .table-scroll-container::-webkit-scrollbar-thumb,
.table-scroll-container.dark-mode::-webkit-scrollbar-thumb {
    background: var(--brand-primary);
    border: 2px solid #252525;
}

[data-bs-theme="dark"] .table-scroll-container::-webkit-scrollbar-corner,
.table-scroll-container.dark-mode::-webkit-scrollbar-corner {
    background: #252525;
}

/* =============================================================================
   GLOBAL DEFAULTS
   ============================================================================= */

.mantine-Switch-root {
    cursor: pointer !important;
}

.table-purple th,
.table-purple thead th,
.table.table-purple thead th {
    background-color: var(--brand-primary, rgba(156, 0, 191, 1)) !important;
    color: var(--brand-text-on-primary, white) !important;
}

/* =============================================================================
   NAVIGATION - Theme-Responsive Text Colors
   Nav links and dropdowns respond to data-bs-theme toggle.
   ============================================================================= */

[data-bs-theme="dark"] .navbar-nav .nav-link {
    color: rgba(255, 255, 255, 0.85) !important;
}
[data-bs-theme="dark"] .navbar-nav .nav-link:hover {
    color: #ffffff !important;
}
[data-bs-theme="light"] .navbar-nav .nav-link {
    color: rgba(0, 0, 0, 0.7) !important;
}
[data-bs-theme="light"] .navbar-nav .nav-link:hover {
    color: #000000 !important;
}
[data-bs-theme="dark"] .dropdown-menu {
    background-color: #2b2b2b;
    border-color: rgba(255, 255, 255, 0.1);
}
[data-bs-theme="dark"] .dropdown-item {
    color: rgba(255, 255, 255, 0.85);
}
[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
}
[data-bs-theme="light"] .dropdown-menu {
    background-color: #ffffff;
    border-color: rgba(0, 0, 0, 0.1);
}
[data-bs-theme="light"] .dropdown-item {
    color: rgba(0, 0, 0, 0.7);
}
[data-bs-theme="light"] .dropdown-item:hover,
[data-bs-theme="light"] .dropdown-item:focus {
    color: #000000;
    background-color: rgba(0, 0, 0, 0.05);
}

/* =============================================================================
   NAVIGATION - Active State & Hover Effects
   ============================================================================= */

/* Active nav link - prominent brand highlight */
.nav-link.active {
    background-color: rgba(var(--brand-primary-rgb, 156, 0, 191), 0.25) !important;
    color: #ffffff !important;
    border-radius: 6px;
    font-weight: 600 !important;
    position: relative;
}

/* Underline effect for active nav link - only on xl screens (matches navbar expand="xl" breakpoint) */
@media (min-width: 1200px) {
    .nav-link.active::after {
        content: '';
        position: absolute;
        bottom: 2px;
        left: 50%;
        transform: translateX(-50%);
        width: 60%;
        height: 2px;
        background-color: var(--brand-primary, #9C00BF);
        border-radius: 1px;
    }
}

/* Hover effect for nav links */
.nav-link:hover:not(.active) {
    background-color: rgba(var(--brand-primary-rgb, 156, 0, 191), 0.1) !important;
    border-radius: 6px;
}

/* Logout button styling — base state responds to theme via data-bs-theme */
#signout-button {
    transition: all 0.2s ease;
}

#signout-button:hover {
    cursor: pointer;
    opacity: 0.85;
}

[data-bs-theme="dark"] #signout-button {
    border: 1px solid white !important;
    color: white !important;
}

[data-bs-theme="dark"] #signout-button:hover {
    background-color: rgba(255, 255, 255, 0.15) !important;
    border-color: white !important;
    color: white !important;
}

[data-bs-theme="light"] #signout-button {
    border: 1px solid #333 !important;
    color: #333 !important;
}

[data-bs-theme="light"] #signout-button:hover {
    background-color: rgba(0, 0, 0, 0.08) !important;
    border-color: #333 !important;
    color: #333 !important;
}

/* =============================================================================
   SIDEBAR NAVIGATION
   ============================================================================= */

/* Base Sidebar Container */
.sidebar-container {
    position: fixed;
    top: 0;
    height: 100vh;
    background-color: #25262b; /* DARK_BG_CARD */
    display: flex;
    flex-direction: column;
    z-index: 1050;
    transition: width 0.3s ease;
    overflow: hidden;
}

/* Hidden sidebar for top/bottom navbar compatibility */
.sidebar-hidden {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    height: 0 !important;
    position: absolute !important;
    pointer-events: none !important;
}

/* Position-specific styles */
.sidebar-container.left {
    left: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-container.right {
    right: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

/* Expanded/Collapsed states */
.sidebar-container.expanded {
    width: 220px;
}

.sidebar-container.collapsed {
    width: 60px;
    overflow: visible;
}

.sidebar-container.collapsed .sidebar-nav {
    overflow: visible;
}

/* --- Sidebar Brand --- */
.sidebar-brand {
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    min-height: 60px;
}

.sidebar-brand-img {
    transition: opacity 0.2s ease, width 0.2s ease;
}

.sidebar-container.collapsed .sidebar-brand-img {
    opacity: 0;
    width: 0;
    display: none;
}

/* Logo/icon shown when sidebar is collapsed */
.sidebar-brand-collapsed-img {
    display: none;
    transition: opacity 0.2s ease;
}

.sidebar-container.collapsed .sidebar-brand-collapsed-img {
    display: block;
}

/* --- Sidebar User Info --- */
.sidebar-user-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-container.collapsed .sidebar-user-info {
    padding: 12px 8px;
    align-items: center;
}

.sidebar-container.collapsed .sidebar-user-info .mantine-Badge-root {
    padding: 4px;
    min-width: auto;
}

.sidebar-container.collapsed .sidebar-user-info .mantine-Badge-label {
    display: none;
}

/* --- Sidebar Toggle Button --- */
.sidebar-toggle-btn {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    transition: background-color 0.2s ease;
}

.sidebar-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.06);
}

/* --- Sidebar Navigation --- */
.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

/* Sidebar links (dark sidebar default) */
.sidebar-link {
    display: flex !important;
    align-items: center;
    gap: 9px;
    padding: 6px 14px !important;
    color: rgba(255, 255, 255, 0.85) !important;
    text-decoration: none !important;
    transition: all 0.2s ease;
    white-space: nowrap;
    border-radius: 0 !important;
}

.sidebar-link:hover {
    background-color: rgba(var(--brand-primary-rgb, 156, 0, 191), 0.2) !important;
    color: #ffffff !important;
    text-decoration: none !important;
}

.sidebar-link.active {
    background-color: rgba(var(--brand-primary-rgb, 156, 0, 191), 0.4) !important;
    color: #ffffff !important;
    font-weight: 600;
}

/* Remove underline from sidebar link container */
.sidebar-link.active::after {
    display: none !important;
}

/* Add underline to sidebar label text only */
.sidebar-link.active .sidebar-label {
    position: relative;
}

.sidebar-link.active .sidebar-label::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--brand-primary, #9C00BF);
    border-radius: 1px;
}

/* Hide label underline in collapsed mode (label becomes tooltip) */
.sidebar-container.collapsed .sidebar-link.active .sidebar-label::after {
    display: none;
}

/* Active state border */
.sidebar-container.left .sidebar-link.active {
    border-left: 3px solid var(--brand-primary, #9C00BF);
}

.sidebar-container.right .sidebar-link.active {
    border-right: 3px solid var(--brand-primary, #9C00BF);
}

.sidebar-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 22px;
    text-align: center;
}

.sidebar-label {
    font-size: 0.9rem;
    transition: opacity 0.3s ease, width 0.3s ease;
}

.sidebar-container.collapsed .sidebar-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Tooltip: reuse .sidebar-label as a floating tooltip when collapsed */
.sidebar-container.collapsed .sidebar-link {
    padding: 8px;
    justify-content: center;
    position: relative;
    overflow: visible;
}

.sidebar-container.collapsed .sidebar-link:hover .sidebar-label {
    opacity: 1;
    width: auto;
    overflow: visible;
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: #1a1b1e;
    color: #fff;
    padding: 4px 12px;
    border-radius: 6px;
    white-space: nowrap;
    font-size: 0.85rem;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: opacity 0.15s ease;
}

/* Light mode tooltip */
.sidebar-container.sidebar-light.collapsed .sidebar-link:hover .sidebar-label {
    background: #212529;
    color: #fff;
}

/* Right sidebar: tooltip appears on the left */
.sidebar-container.collapsed.right .sidebar-link:hover .sidebar-label {
    left: auto;
    right: calc(100% + 8px);
}

/* --- Sidebar Logout --- */
.sidebar-logout {
    margin-top: auto;
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 15px;
    padding-bottom: 25px;
}

.sidebar-logout-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    cursor: pointer;
}

.sidebar-logout-link:hover {
    background-color: rgba(255, 100, 100, 0.2) !important;
}

/* --- Content Wrapper for Sidebar Layouts --- */
.content-with-sidebar-left {
    margin-left: 220px;
    width: calc(100vw - 220px);
    max-width: calc(100vw - 220px);
    transition: margin-left 0.3s ease, width 0.3s ease;
    overflow-x: hidden;
}

.content-with-sidebar-left.sidebar-collapsed {
    margin-left: 60px;
    width: calc(100vw - 60px);
    max-width: calc(100vw - 60px);
}

.content-with-sidebar-right {
    margin-right: 220px;
    width: calc(100vw - 220px);
    max-width: calc(100vw - 220px);
    transition: margin-right 0.3s ease, width 0.3s ease;
    overflow-x: hidden;
}

.content-with-sidebar-right.sidebar-collapsed {
    margin-right: 60px;
    width: calc(100vw - 60px);
    max-width: calc(100vw - 60px);
}

/* --- Layout Flexbox for Sidebar --- */
.layout-left,
.layout-right {
    display: flex;
    flex-direction: row;
}

.layout-right {
    flex-direction: row-reverse;
}

/* --- Dark Mode Sidebar --- */
.sidebar-container.sidebar-dark {
    background: linear-gradient(180deg,
        #25262b 0%,
        rgba(var(--brand-primary-rgb, 156, 0, 191), 0.04) 50%,
        #25262b 100%),
        #25262b;
    border-color: rgba(255, 255, 255, 0.1);
}

.sidebar-container.sidebar-dark .sidebar-brand,
.sidebar-container.sidebar-dark .sidebar-user-info,
.sidebar-container.sidebar-dark .sidebar-toggle-btn,
.sidebar-container.sidebar-dark .sidebar-logout {
    border-color: rgba(255, 255, 255, 0.08);
}

.sidebar-container.sidebar-dark .sidebar-toggle-btn {
    color: rgba(255, 255, 255, 0.85);
}

.sidebar-container.sidebar-dark .sidebar-link {
    color: rgba(255, 255, 255, 0.85) !important;
}

.sidebar-container.sidebar-dark .sidebar-link:hover {
    background-color: rgba(var(--brand-primary-rgb, 156, 0, 191), 0.2) !important;
    color: #ffffff !important;
}

.sidebar-container.sidebar-dark .sidebar-link.active {
    background-color: rgba(var(--brand-primary-rgb, 156, 0, 191), 0.4) !important;
    color: #ffffff !important;
}

/* --- Light Mode Sidebar --- */
.sidebar-container.sidebar-light {
    background: linear-gradient(180deg,
        #e2e6ea 0%,
        rgba(var(--brand-primary-rgb, 156, 0, 191), 0.04) 50%,
        #e2e6ea 100%),
        #e2e6ea;
    border-color: rgba(0, 0, 0, 0.1);
}

.sidebar-container.sidebar-light .sidebar-brand,
.sidebar-container.sidebar-light .sidebar-user-info,
.sidebar-container.sidebar-light .sidebar-toggle-btn,
.sidebar-container.sidebar-light .sidebar-logout {
    border-color: rgba(0, 0, 0, 0.1);
}

.sidebar-container.sidebar-light.left {
    border-right-color: rgba(0, 0, 0, 0.1);
}

.sidebar-container.sidebar-light.right {
    border-left-color: rgba(0, 0, 0, 0.1);
}

.sidebar-container.sidebar-light .sidebar-toggle-btn {
    color: #212529;
}

.sidebar-container.sidebar-light .sidebar-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.sidebar-container.sidebar-light .sidebar-link {
    color: #212529 !important;
}

.sidebar-container.sidebar-light .sidebar-link:hover {
    background-color: rgba(0, 0, 0, 0.08) !important;
    color: #000 !important;
}

.sidebar-container.sidebar-light .sidebar-link.active {
    background-color: rgba(var(--brand-primary-rgb, 156, 0, 191), 0.15) !important;
    color: #000 !important;
}

/* --- Responsive Sidebar --- */
@media (max-width: 991px) {
    .sidebar-container {
        width: 60px !important;
        overflow: visible;
    }

    .sidebar-container .sidebar-nav {
        overflow: visible;
    }

    .sidebar-container .sidebar-label,
    .sidebar-container .sidebar-brand-img {
        opacity: 0;
        width: 0;
    }

    .sidebar-container .sidebar-link {
        padding: 12px;
        justify-content: center;
        position: relative;
        overflow: visible;
    }

    /* Tooltip on responsive collapse */
    .sidebar-container .sidebar-link:hover .sidebar-label {
        opacity: 1;
        width: auto;
        overflow: visible;
        position: absolute;
        left: calc(100% + 8px);
        top: 50%;
        transform: translateY(-50%);
        background: #1a1b1e;
        color: #fff;
        padding: 4px 12px;
        border-radius: 6px;
        white-space: nowrap;
        font-size: 0.85rem;
        z-index: 10000;
        pointer-events: none;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    }

    .sidebar-container.right .sidebar-link:hover .sidebar-label {
        left: auto;
        right: calc(100% + 8px);
    }

    .content-with-sidebar-left {
        margin-left: 60px !important;
        max-width: calc(100vw - 60px) !important;
    }

    .content-with-sidebar-right {
        margin-right: 60px !important;
        max-width: calc(100vw - 60px) !important;
    }
}

@media (max-width: 576px) {
    .sidebar-container {
        width: 50px !important;
    }

    .content-with-sidebar-left {
        margin-left: 50px !important;
        max-width: calc(100vw - 50px) !important;
    }

    .content-with-sidebar-right {
        margin-right: 50px !important;
        max-width: calc(100vw - 50px) !important;
    }

    .sidebar-icon {
        font-size: 1rem;
    }
}

/* =============================================================================
   DARK MODE — Heading Color Fix
   Bootstrap defaults headings to dark color, overriding Mantine's scheme.
   This ensures headings (skeleton titles, etc.) use light text in dark mode.
   ============================================================================= */

[data-mantine-color-scheme="dark"] h1,
[data-mantine-color-scheme="dark"] h2,
[data-mantine-color-scheme="dark"] h3,
[data-mantine-color-scheme="dark"] h4,
[data-mantine-color-scheme="dark"] h5,
[data-mantine-color-scheme="dark"] h6 {
    color: #c1c2c5;
}

/* =============================================================================
   DARK MODE — Bootstrap Overrides
   Activated when data-bs-theme="dark" is set on an ancestor element.
   ============================================================================= */

[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .form-control {
    background-color: #2c2e33;
    color: #c1c2c5;
    border-color: #373A40;
}

[data-bs-theme="dark"] .table {
    --bs-table-bg: #25262b;
    --bs-table-color: #c1c2c5;
    --bs-table-border-color: #373A40;
}

[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-striped-bg: #2c2e33;
    --bs-table-striped-color: #c1c2c5;
}

[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * {
    --bs-table-hover-bg: #373A40;
    --bs-table-hover-color: #c1c2c5;
}

[data-bs-theme="dark"] .accordion-button {
    background-color: #2c2e33;
    color: #c1c2c5;
}

[data-bs-theme="dark"] .accordion-button:not(.collapsed) {
    background-color: #373A40;
    color: #c1c2c5;
}

[data-bs-theme="dark"] .accordion-body {
    background-color: #25262b;
    color: #c1c2c5;
}

[data-bs-theme="dark"] .card {
    background-color: #25262b;
    border-color: #373A40;
    color: #c1c2c5;
}

/* =============================================================================
   DARK MODE — Mantine Portaled Component Overrides
   Mantine combobox dropdowns, modals, and inputs render inside a portal
   outside the main React tree. These selectors target dark scheme attributes.
   ============================================================================= */

/* Dark mode combobox — dual selectors for both data-mantine-color-scheme AND data-bs-theme
   (portals render outside MantineProvider, so we sync both attributes to html/body) */
[data-mantine-color-scheme="dark"] .mantine-Combobox-dropdown,
[data-bs-theme="dark"] .mantine-Combobox-dropdown {
    background-color: #25262b !important;
    border-color: #373A40;
}

[data-mantine-color-scheme="dark"] .mantine-Combobox-option,
[data-bs-theme="dark"] .mantine-Combobox-option {
    color: #c1c2c5 !important;
    background-color: transparent !important;
}

[data-mantine-color-scheme="dark"] .mantine-Combobox-option:hover,
[data-mantine-color-scheme="dark"] .mantine-Combobox-option[data-combobox-active],
[data-mantine-color-scheme="dark"] .mantine-Combobox-option[data-hovered],
[data-bs-theme="dark"] .mantine-Combobox-option:hover,
[data-bs-theme="dark"] .mantine-Combobox-option[data-combobox-active],
[data-bs-theme="dark"] .mantine-Combobox-option[data-hovered] {
    background-color: #404040 !important;
}

[data-mantine-color-scheme="dark"] .mantine-Combobox-option[data-combobox-selected],
[data-bs-theme="dark"] .mantine-Combobox-option[data-combobox-selected] {
    background-color: var(--brand-primary, #9c00bf) !important;
    color: var(--brand-text-on-primary, #ffffff) !important;
}

/* Light mode combobox */
[data-mantine-color-scheme="light"] .mantine-Combobox-option,
[data-bs-theme="light"] .mantine-Combobox-option {
    color: #1a1a1a !important;
    background-color: transparent !important;
}

[data-mantine-color-scheme="light"] .mantine-Combobox-option:hover,
[data-mantine-color-scheme="light"] .mantine-Combobox-option[data-combobox-active],
[data-mantine-color-scheme="light"] .mantine-Combobox-option[data-hovered],
[data-bs-theme="light"] .mantine-Combobox-option:hover,
[data-bs-theme="light"] .mantine-Combobox-option[data-combobox-active],
[data-bs-theme="light"] .mantine-Combobox-option[data-hovered] {
    background-color: #f0f0f0 !important;
}

[data-mantine-color-scheme="light"] .mantine-Combobox-option[data-combobox-selected],
[data-bs-theme="light"] .mantine-Combobox-option[data-combobox-selected] {
    background-color: var(--brand-primary, #9c00bf) !important;
    color: var(--brand-text-on-primary, #ffffff) !important;
}

[data-mantine-color-scheme="dark"] .mantine-Modal-content {
    background-color: #25262b;
    color: #c1c2c5;
}

[data-mantine-color-scheme="dark"] .mantine-Modal-header {
    background-color: #25262b;
    color: #c1c2c5;
}

[data-mantine-color-scheme="dark"] .mantine-Input-input {
    background-color: #2c2e33;
    color: #c1c2c5 !important;
    border-color: #373A40;
}

[data-mantine-color-scheme="dark"] .mantine-Pill {
    color: #c1c2c5;
}

/* =============================================================================
   CHECKBOX ACCENT — Both Modes
   ============================================================================= */

.mantine-Checkbox-input:checked {
    background-color: var(--brand-primary, #9C00BF);
    border-color: var(--brand-primary, #9C00BF);
}

/* =============================================================================
   DARK MODE — Scrollbar Styling
   ============================================================================= */

[data-bs-theme="dark"] ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

[data-bs-theme="dark"] ::-webkit-scrollbar-track {
    background: #1a1b1e;
}

[data-bs-theme="dark"] ::-webkit-scrollbar-thumb {
    background: #373A40;
    border-radius: 4px;
}

[data-bs-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: #4a4d54;
}

/* =============================================================================
   VERTICAL INDENTATION LINE — subordinate/conditional settings
   ============================================================================= */

.indent-line {
    border-left: 3px solid var(--brand-primary);
    padding-left: 15px;
    margin-left: 5px;
    margin-top: 10px;
}

/* =============================================================================
   UPLOAD DROPZONE HOVER
   ============================================================================= */

.upload-dropzone {
    transition: all 0.15s ease-in-out;
}

.upload-dropzone:hover {
    border-color: var(--brand-primary) !important;
    background-color: rgba(var(--brand-primary-rgb), 0.06) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(var(--brand-primary-rgb), 0.15);
}

/* =============================================================================
   DARK MODE — Dash DataTable Hover/Selection Fix
   DataTable's built-in active/selected cell styles use light backgrounds
   that turn cells pure white in dark mode, making text unreadable.
   ============================================================================= */

[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner td.dash-cell.cell--active,
[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner td.dash-cell.cell--selected {
    background-color: rgba(var(--brand-primary-rgb), 0.2) !important;
    color: #d1d4dc !important;
}

[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner td.dash-cell.focused {
    box-shadow: inset 0 0 0 2px var(--brand-primary) !important;
    background-color: rgba(var(--brand-primary-rgb), 0.15) !important;
    color: #d1d4dc !important;
}

[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner input {
    background-color: #2c2e33 !important;
    color: #d1d4dc !important;
}

/* Dark mode — DataTable filter row (white-on-white fix) */
[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner td.dash-filter {
    background-color: #1e1e1e !important;
    color: #d1d4dc !important;
    border-bottom: 1px solid #3a3a3a !important;
}

[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner td.dash-filter input {
    background-color: #2c2e33 !important;
    color: #d1d4dc !important;
    border: 1px solid #3a3a3a !important;
    border-radius: 3px !important;
}

[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner td.dash-filter input::placeholder {
    color: #6c7086 !important;
}

/* Dark mode — DataTable row hover (too bright fix) */
[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner tr:hover td.dash-cell {
    background-color: #333333 !important;
    color: #d1d4dc !important;
}

/* Preserve alternating row color on hover for odd rows */
[data-mantine-color-scheme="dark"] .dash-spreadsheet-container .dash-spreadsheet-inner tr:nth-child(odd):hover td.dash-cell {
    background-color: #383838 !important;
}

/* Dark mode — Mantine checkbox visibility fix (unchecked border invisible on dark bg) */
[data-mantine-color-scheme="dark"] .mantine-Checkbox-input:not(:checked) {
    border-color: #5c5f66 !important;
}

/* Mantine checkbox — pointer cursor on non-disabled checkboxes */
.mantine-Checkbox-input:not(:disabled) {
    cursor: pointer !important;
}
.mantine-Checkbox-root:has(.mantine-Checkbox-input:not(:disabled)) {
    cursor: pointer !important;
}
.mantine-Checkbox-root:has(.mantine-Checkbox-input:not(:disabled)) .mantine-Checkbox-label {
    cursor: pointer !important;
}

/* =============================================================================
   ACCESSIBILITY (WCAG 2.1 AA)
   ============================================================================= */

/* --- Skip link (2.4.1): first focusable element, hidden until focused --- */
.skip-link {
    position: absolute;
    top: -60px;
    left: 8px;
    z-index: 20000;
    padding: 10px 16px;
    background-color: var(--brand-primary, #9C00BF); /* Brand purple/blue */
    color: #ffffff; /* White */
    border-radius: 0 0 8px 8px;
    text-decoration: none;
    font-weight: 600;
    transition: top 0.15s ease;
}
.skip-link:focus {
    top: 0;
    outline: 3px solid #ffffff; /* White ring on the brand background */
    outline-offset: 2px;
}

/* --- Visible focus indicator (2.4.7 / 1.4.11) ---
   A blue ring that keeps >=3:1 non-text contrast in BOTH themes: a mid blue on
   light surfaces, a lighter blue on dark. The brand purple/blue would fail 3:1
   against the dark card background, so the focus ring is intentionally its own
   token rather than the brand color. */
:root { --focus-ring: #0b5cff; } /* Accessible blue (light mode) */
[data-bs-theme="dark"], [data-mantine-color-scheme="dark"] { --focus-ring: #7db3ff; } /* Lighter blue (dark mode) */

/* --- Status text colors that meet 4.5:1 in each theme (1.4.3) ---
   A single yellow cannot pass on both a white row and a dark row, so the "live"
   status text is a dark amber on light rows and a light amber on dark rows. The
   status WORD is always present, so meaning is never color-only (1.4.1). */
:root { --status-live-text: #8a6d00; } /* Dark amber (light rows) */
[data-bs-theme="dark"], [data-mantine-color-scheme="dark"] { --status-live-text: #ffe066; } /* Light amber (dark rows) */

/* --- Text contrast overrides (1.4.3): Mantine muted/dimmed text and control
   labels that fall below 4.5:1, especially in dark mode. Raise the muted tokens
   and force accordion / segmented-control labels to the primary text color. --- */
[data-mantine-color-scheme="light"] { --mantine-color-dimmed: #595959; } /* >=7:1 on white */
[data-mantine-color-scheme="dark"]  { --mantine-color-dimmed: #a6a7ab; } /* >=5.5:1 on the dark card */
[data-bs-theme="dark"] { --text-secondary: #a6a7ab; } /* was #909296 (borderline); lighter passes on more surfaces */

/* Accordion control titles (filter / info sections) -> primary text for contrast */
.mantine-Accordion-label .mantine-Text-root,
.mantine-Accordion-control .mantine-Text-root {
    color: var(--text-primary) !important; /* Theme primary (near-black / near-white) */
}
/* Segmented-control labels: inactive labels use the primary text color (readable
   on the track), while the ACTIVE label sits on the brand-colored indicator and
   must be white. Target the active state by both data-active and :checked so it
   wins regardless of the Mantine build. */
.mantine-SegmentedControl-innerLabel,
.mantine-SegmentedControl-label {
    color: var(--text-primary) !important; /* Inactive: theme primary text */
}
.mantine-SegmentedControl-label[data-active],
.mantine-SegmentedControl-label[data-active] .mantine-SegmentedControl-innerLabel,
.mantine-SegmentedControl-label:has(input:checked),
.mantine-SegmentedControl-label:has(input:checked) .mantine-SegmentedControl-innerLabel {
    color: var(--brand-text-on-primary, #ffffff) !important; /* Active: white on brand */
}

:focus-visible {
    outline: 3px solid var(--focus-ring, #0b5cff); /* Accessible blue */
    outline-offset: 2px;
    border-radius: 2px;
}
/* Keep the sidebar/nav custom controls' focus visible too (they had none). */
.sidebar-link:focus-visible,
.sidebar-toggle-btn:focus-visible,
.sidebar-logout-link:focus-visible,
.nav-link:focus-visible,
.upload-dropzone:focus-visible {
    outline: 3px solid var(--focus-ring, #0b5cff); /* Accessible blue */
    outline-offset: 2px;
}

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

/* --- Data-table text-color tokens that meet 4.5:1 in each theme (1.4.3) ---
   Data-driven table content (activity log keywords, fills side / slippage
   values, strategy description + code cells) previously hardcoded bright text
   colors that fail against the light table cells the page renders (and some
   fail against the dark card in dark mode). A single value cannot pass on both
   a white/#e6e8eb light cell AND the dark #25262b card, so each color is a
   theme-aware pair: a darkened value for light surfaces and a brightened value
   for dark. Every pair is verified >=4.5:1 (semantic meaning is preserved -
   red stays red-ish, green green-ish, etc.). */
:root {
    --a11y-red:   #a81717; /* Errors / False / sell — deep red; >=4.5:1 on white AND on broker-tinted rows */
    --a11y-green: #13733c; /* Success / True / buy — vivid green; brightened for visibility, still >=4.5:1 on white, striped, row-hover, AND every broker tint (min 4.58:1 on crypto.com) */
    --a11y-teal:  #0b6d80; /* Info — dark teal on light cell */
    --a11y-amber: #92400e; /* Warning — dark amber on light cell */
    --a11y-gray:  #595959; /* Muted description text — >=5.7:1 on light cell */
    --a11y-pink:  #a61e69; /* Inline <code> — dark magenta on light cell */
}
[data-bs-theme="dark"], [data-mantine-color-scheme="dark"] {
    --a11y-red:   #ff8787; /* Light red on the dark card */
    --a11y-green: #51cf66; /* Light green on the dark card */
    --a11y-teal:  #3bc9db; /* Light teal on the dark card */
    --a11y-amber: #ffa94d; /* Light amber on the dark card */
    --a11y-gray:  #a6a7ab; /* Light gray on the dark card */
    --a11y-pink:  #f06595; /* Light magenta on the dark card */
}

/* --- Broker brand-identity text tokens (1.4.3) ---
   The Universe table colors broker rows with each broker's brand color. Those
   brand colors are legible on only one theme (cyan/green are too light for the
   white cell; navy/purple/forest-green/red are too dark for the dark card), so
   each broker gets a theme-aware pair: the readable side keeps the true brand
   hue, the other side is nudged in lightness just enough to clear 4.5:1 while
   staying recognizably the same brand color. */
:root {
    --broker-gemini:     #0a6d82; /* darkened brand cyan  (#00DCFA stays bright in dark) */
    --broker-robinhood:  #15703a; /* darkened brand green (#00C367 stays bright in dark) */
    --broker-coinbase:   #0047e0; /* brand blue (light);   lightened for dark */
    --broker-cryptocom:  #1A3FA3; /* brand navy (light);   lightened for dark */
    --broker-kraken:     #663399; /* brand purple (light); lightened for dark */
    --broker-okx:        #2B6D16; /* brand green (light);  lightened for dark */
    --broker-tastytrade: #c8102e; /* brand red (light);    lightened for dark */
    --broker-fallback:   #1a1a1a; /* unknown broker -> primary text (was invisible white) */
}
[data-bs-theme="dark"], [data-mantine-color-scheme="dark"] {
    --broker-gemini:     #00DCFA; /* true brand cyan  — bright on dark card */
    --broker-robinhood:  #00C367; /* true brand green — bright on dark card */
    --broker-coinbase:   #4dabf7; /* lightened brand blue */
    --broker-cryptocom:  #748ffc; /* lightened brand navy */
    --broker-kraken:     #b197fc; /* lightened brand purple */
    --broker-okx:        #69db7c; /* lightened brand green */
    --broker-tastytrade: #ff8787; /* lightened brand red */
    --broker-fallback:   #c1c2c5; /* unknown broker -> primary text (dark theme) */
}

/* --- dash_table internals axe flags for contrast (1.4.3) ---
   dash renders these sub-controls itself; Python props don't reach them, so
   they're styled here. Each is theme-aware against the filter/pagination row. */
/* The "Aa" case-sensitivity toggle in the native filter row. dash_table fades
   the INACTIVE toggle to ~0.1 opacity (so the dark text renders near-white on
   the white cell); force full opacity + dark text. Cell stays white both themes. */
input.dash-filter--case,
.dash-filter--case {
    color: #343a40 !important;            /* Dark slate text */
    opacity: 1 !important;                /* override dash_table's ~0.1 inactive fade */
    background-color: #e9ecef !important; /* Light-gray chip */
    border-radius: 3px !important;
    padding: 0 3px !important;
}
/* The current-page number input in native pagination (was black on dark in dark mode) */
[data-bs-theme="dark"] .dash-table-container input.current-page,
[data-mantine-color-scheme="dark"] .dash-table-container input.current-page,
[data-bs-theme="dark"] input.current-page,
[data-mantine-color-scheme="dark"] input.current-page {
    color: #d1d4dc !important; /* Light page-number text on dark pagination */
}

/* --- dmc.Switch on/off track labels (1.4.3) ---
   The trackLabel element shows the current state's label ON the track, so each
   state needs a color that clears its own track background. */
.mantine-Switch-trackLabel {
    color: #ffffff !important; /* On-label: light on the colored (checked) track */
}
.mantine-Switch-track:not([data-checked]) .mantine-Switch-trackLabel {
    color: #343a40 !important; /* Off-label: dark slate on the light-gray off-track */
}
[data-bs-theme="dark"] .mantine-Switch-track:not([data-checked]) .mantine-Switch-trackLabel,
[data-mantine-color-scheme="dark"] .mantine-Switch-track:not([data-checked]) .mantine-Switch-trackLabel {
    color: #c1c2c5 !important; /* Off-label: light gray on the dark off-track */
}

/* --- Filled red (danger) buttons/badges: white text contrast (1.4.3) ---
   Mantine's default red-filled is red.6 (#fa5252); white text on it is only 3.28:1.
   Darken the filled-red token so white "X"/delete labels clear 4.5:1 app-wide.
   (The light/outline red variants use different tokens and are unaffected.) */
:root,
[data-mantine-color-scheme="light"],
[data-mantine-color-scheme="dark"] {
    --mantine-color-red-filled: #c92a2a;        /* white text -> ~5.4:1 */
    --mantine-color-red-filled-hover: #b02222;  /* darker on hover */
}

/* --- Card title (create_beautiful_card) sizing ---
   The card title is an <h2> (for heading order) whose size lives here, not only
   inline, so the color-mode callback replacing its `style` with a color-only dict
   can't leave it at the large default h2 size ("Display Settings" growing bug). */
.settings-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

/* --- Visually hidden (screen-reader only) ---
   Removes an element visually while keeping it in the accessibility tree, e.g. a
   page's required <h1> when the visible title lives in deferred/conditional content. */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}