:root {
    /* Layer 2: Asymmetrical, Sparse Non-Repeating Contextual Pattern */
    --accounting-pattern: url("data:image/svg+xml,%3Csvg viewBox='0 0 1440 900' preserveAspectRatio='xMidYMid slice' xmlns='http://www.w3.org/2000/svg'%3E%3C!-- Floating Ledger Table Segment (Top Left, fading out) --%3E%3Cg transform='translate(100, 150)' stroke='%2364748b' fill='none'%3E%3Crect width='300' height='150' stroke-width='0.5' opacity='0.3'/%3E%3Cpath d='M0 40h300 M0 80h300 M0 120h300 M60 0v150 M140 0v150' stroke-width='0.5' opacity='0.25'/%3E%3Crect x='150' y='50' width='120' height='6' fill='%2364748b' stroke='none' opacity='0.2'/%3E%3Crect x='150' y='90' width='80' height='6' fill='%2364748b' stroke='none' opacity='0.2'/%3E%3C/g%3E%3C!-- Flowing Diagonal Chart Line (Center to Bottom Right) --%3E%3Cpath d='M-100 850 C 400 800 600 400 900 500 C 1200 600 1300 200 1600 100' fill='none' stroke='%233b82f6' stroke-width='1.5' opacity='0.4'/%3E%3C!-- Faint secondary predictive chart line --%3E%3Cpath d='M300 900 C 700 700 800 600 1100 700 C 1300 800 1400 400 1600 300' fill='none' stroke='%2364748b' stroke-width='1' stroke-dasharray='5 8' opacity='0.25'/%3E%3C!-- Scattered Data Nodes / Intersections --%3E%3Ccircle cx='900' cy='500' r='5' fill='%233b82f6' opacity='0.5'/%3E%3Ccircle cx='1100' cy='700' r='3' fill='%2364748b' opacity='0.4'/%3E%3Ccircle cx='600' cy='400' r='4' fill='none' stroke='%233b82f6' stroke-width='1.5' opacity='0.4'/%3E%3C!-- Floating Financial Bar Chart Segment (Right Side) --%3E%3Cg transform='translate(1150, 400)'%3E%3Cline x1='0' y1='100' x2='200' y2='100' stroke='%2364748b' stroke-width='0.5' opacity='0.3'/%3E%3Crect x='20' y='60' width='12' height='40' fill='%233b82f6' opacity='0.4'/%3E%3Crect x='50' y='30' width='12' height='70' fill='%2364748b' opacity='0.3'/%3E%3Crect x='80' y='50' width='12' height='50' fill='%233b82f6' opacity='0.5'/%3E%3Crect x='110' y='10' width='12' height='90' fill='%2364748b' opacity='0.4'/%3E%3Crect x='140' y='40' width='12' height='60' fill='%233b82f6' opacity='0.3'/%3E%3C/g%3E%3C!-- Subtle invoice block floating bottom left --%3E%3Cg transform='translate(150, 600)' stroke='%2364748b' fill='none' opacity='0.2'%3E%3Crect width='180' height='220' stroke-width='0.5'/%3E%3Cline x1='0' y1='50' x2='180' y2='50' stroke-width='0.5'/%3E%3Crect x='20' y='70' width='100' height='4' fill='%2364748b' stroke='none'/%3E%3Crect x='20' y='90' width='140' height='4' fill='%2364748b' stroke='none'/%3E%3Crect x='20' y='110' width='80' height='4' fill='%2364748b' stroke='none'/%3E%3C!-- Total line --%3E%3Cline x1='20' y1='180' x2='160' y2='180' stroke-width='0.5'/%3E%3Crect x='100' y='195' width='60' height='6' fill='%233b82f6' stroke='none' opacity='0.4'/%3E%3C/g%3E%3C!-- Faint structural grid lines filling large negative space (Top Right) --%3E%3Cg stroke='%2364748b' stroke-width='0.3' stroke-dasharray='10 10' opacity='0.15'%3E%3Cline x1='700' y1='100' x2='1440' y2='100'/%3E%3Cline x1='700' y1='200' x2='1440' y2='200'/%3E%3Cline x1='900' y1='0' x2='900' y2='300'/%3E%3Cline x1='1200' y1='0' x2='1200' y2='300'/%3E%3C/g%3E%3C/svg%3E");
}

:root,
[data-theme="dark"] {
    --bg-base: #0b0f19;
    --bg-surface: rgba(17, 24, 39, 0.4);
    --bg-surface-elevated: #1f2937;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --border-subtle: #1e293b;
    --id-highlight: #ffffff;

    /* Layering Colors: Deep Dark Theme */
    --theme-base-bg: linear-gradient(#0b0f19, #0b0f19);
    --theme-overlay: linear-gradient(rgba(11, 15, 25, 0.85), rgba(11, 15, 25, 0.85));
}

[data-theme="light"] {
    --bg-base: #eff6ff;
    --bg-surface: rgba(255, 255, 255, 0.45);
    --bg-surface-elevated: #f1f5f9;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-subtle: #e2e8f0;
    --id-highlight: #000000;

    /* Layering Colors: Clean Light Theme */
    --theme-base-bg: linear-gradient(#eff6ff, #eff6ff);
    --theme-overlay: linear-gradient(rgba(239, 246, 255, 0.65), rgba(239, 246, 255, 0.65));
}

/* Global Transition for Theme Switching */
body,
.main-container,
section,
.card,
.navbar-glass,
footer,
.feature-icon-box {
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
span,
i,
a,
.text-dark,
.text-white,
.text-secondary {
    transition: color 0.3s ease;
}

/* General Layout */
body {
    background-color: var(--bg-base) !important;
    color: var(--text-secondary) !important;
    position: relative;
}

/* Global Contextual Background Overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
    /* 3-Layer System */
    background-image:
        var(--theme-overlay),
        /* Layer 3: Theme Overlay */
        var(--accounting-pattern),
        /* Layer 2: Neutral Contextual Visual */
        var(--theme-base-bg);
    /* Layer 1: Base Background */

    background-size: 100% 100%, cover, 100% 100%;
    background-position: center, center top, center;
    background-repeat: no-repeat, no-repeat, no-repeat;
    transition: background-image 0.4s ease;
}

.main-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: unset !important;
    background-color: transparent !important;
    box-shadow: none !important;
    position: relative;
    z-index: 1;
    /* Sits naturally over the body background grid */
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary) !important;
}

/* Dynamic Texts */
.text-main {
    color: var(--text-primary) !important;
}

.text-dark,
.text-white {
    color: var(--text-primary) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

.text-primary {
    color: var(--accent-blue) !important;
}

.bg-light,
.bg-white {
    background-color: transparent !important;
}

/* Typography Tokens */
.typo-h1 {
    font-size: clamp(36px, 4vw, 48px) !important;
    font-weight: 700 !important;
    line-height: 1.25 !important;
    letter-spacing: 0.5px !important;
}

.typo-h2 {
    font-size: clamp(24px, 3vw, 32px) !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
}

.typo-h3 {
    font-size: 20px !important;
    font-weight: 600 !important;
    line-height: 1.3 !important;
}

.typo-body-lead {
    font-size: 18px !important;
    font-weight: 400 !important;
    line-height: 1.6 !important;
}

.typo-body {
    font-size: 16px !important;
    font-weight: 400 !important;
    line-height: 1.6 !important;
}

.typo-caption {
    font-size: 14px !important;
    font-weight: 400 !important;
    line-height: 1.5 !important;
}

/* Navbar */
.navbar-glass {
    background-color: var(--bg-surface) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
    border-bottom: 1px solid var(--border-subtle) !important;
}

[data-theme="dark"] .navbar-glass {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2) !important;
}

.navbar-brand span {
    color: var(--text-primary) !important;
}

/* Original Logo - Height and Aspect Ratio */
.logo {
    height: 40px;
    width: auto;
    transition: filter 0.3s ease;
}

/* Dark theme → convert logo to white using CSS filter */
[data-theme="dark"] .logo {
    filter: brightness(0) invert(1);
}

.nav-link {
    color: var(--text-secondary) !important;
}

.nav-link:hover {
    color: var(--text-primary) !important;
}

/* Theme Toggle Button */
.theme-toggle-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 18px;
}

.mobile-menu-toggle:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}

/* Mobile Menu Toggle - Default Hidden */
.mobile-menu-toggle {
    display: none;
}

/* Show mobile menu toggle on mobile devices */
@media (max-width: 991px) {
    .mobile-menu-toggle {
        display: flex !important;
    }
}

/* Hero Section */
.theme-toggle-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.hero-gradient {
    /* Transparent back so global grid shows through, relying on body's base color */
    background-color: transparent !important;
    background-image: radial-gradient(ellipse at top, var(--bg-surface-elevated) 0%, transparent 80%) !important;
    position: relative;
    border-bottom: 1px solid var(--border-subtle) !important;
    overflow: hidden;
}

.hero-gradient>.row {
    position: relative;
    z-index: 1;
}

.hero-glass-panel {
    background-color: var(--bg-surface) !important;
    padding: 3.5rem;
    border-radius: 16px;
    border: 1px solid var(--border-subtle) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

[data-theme="dark"] .hero-glass-panel {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.text-gradient {
    color: var(--accent-blue) !important;
}

/* Hero Contextual Visuals */
.hero-icon-visual {
    position: absolute;
    color: var(--text-secondary);
    opacity: 0.04;
    z-index: 0;
    pointer-events: none;
    transition: color 0.3s ease, opacity 0.3s ease;
}

[data-theme="light"] .hero-icon-visual {
    opacity: 0.02;
    /* Lower opacity for light mode to maintain contrast */
}

.hero-visual-1 {
    top: -20px;
    left: 2%;
    font-size: 20rem;
    transform: rotate(-15deg);
}

.hero-visual-2 {
    bottom: -40px;
    right: 2%;
    font-size: 24rem;
    transform: rotate(10deg);
}

.hero-visual-3 {
    top: 30%;
    right: 75%;
    font-size: 12rem;
    transform: rotate(-5deg);
    opacity: 0.02;
}

/* Buttons */
.btn-premium,
.btn-primary {
    background: var(--accent-blue) !important;
    border: 1px solid var(--accent-blue) !important;
    color: #ffffff !important;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

.btn-premium:hover,
.btn-primary:hover {
    background: var(--accent-blue-hover) !important;
    border-color: var(--accent-blue-hover) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2) !important;
}

/* Logout Button - Red variant for visual distinction */
.btn-logout {
    background: transparent !important;
    border: 1.5px solid #ef4444 !important;
    /* Tailwind-ish red */
    color: #ef4444 !important;
    transition: all 0.2s ease;
}

.btn-logout:hover {
    background: #ef4444 !important;
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.2) !important;
}

/* Header Placeholder to minimize CLS */
#navbar-placeholder {
    min-height: 57px;
    /* Matches the navbar height */
    display: block;
}

/* Feature Cards Layout */
#features {
    background: linear-gradient(to bottom, transparent 0%, var(--bg-surface) 10%, var(--bg-surface) 90%, transparent 100%) !important;
}

/* Global Theme-Aware Cards */
.card {
    border-radius: 12px !important;
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-subtle) !important;
    padding: 1.15rem !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03) !important;
    backdrop-filter: blur(8px);
}

[data-theme="dark"] .card {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.06) !important;
    border-color: var(--accent-blue) !important;
}

[data-theme="dark"] .card:hover {
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25) !important;
}

.card .card-title {
    color: var(--text-primary) !important;
    font-weight: 600 !important;
}

.card .feature-icon-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background-color: var(--bg-surface-elevated) !important;
    color: var(--accent-blue) !important;
    border-radius: 12px;
    border: 1px solid var(--border-subtle) !important;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

[data-theme="dark"] .card .feature-icon-box {
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.card:hover .feature-icon-box {
    background-color: var(--accent-blue) !important;
    color: #ffffff !important;
    border-color: transparent !important;
}

.card:hover .feature-icon-box i {
    color: #ffffff !important;
}

/* About Section */
#about {
    background-color: var(--bg-surface) !important;
}

/* Footer */
footer.bg-dark {
    background-color: var(--bg-base) !important;
    border-top: 1px solid var(--border-subtle) !important;
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .hero-section {
        padding: 2rem 1rem !important;
    }

    .hero-glass-panel {
        padding: 1.5rem !important;
    }

    .typo-h1 {
        font-size: clamp(28px, 8vw, 36px) !important;
    }

    .typo-body-lead {
        font-size: 16px !important;
    }

    .feature-icon-box {
        width: 48px !important;
        height: 48px !important;
    }
}

@media (max-width: 576px) {
    .hero-section .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .hero-section {
        padding: 1.5rem 1rem !important;
    }

    .hero-glass-panel {
        padding: 1rem !important;
    }

    .typo-h1 {
        font-size: clamp(20px, 6vw, 28px) !important;
    }

    .typo-body-lead {
        font-size: 14px !important;
    }

    .feature-icon-box {
        width: 40px !important;
        height: 40px !important;
    }

    .px-4 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }

    .py-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .mb-4 {
        margin-bottom: 1rem !important;
    }

    .gap-3 {
        gap: 0.75rem !important;
    }

    #features .row {
        gap: 1rem !important;
    }
}

/* Large Tablets / Small Laptops (992px - 1199px) */
@media (min-width: 992px) and (max-width: 1199px) {
    .typo-h1 {
        font-size: clamp(36px, 3.5vw, 44px) !important;
    }

    .hero-section {
        padding: 4rem 2rem !important;
    }

    .hero-glass-panel {
        padding: 2.5rem !important;
    }
}

/* Extra Large Devices (1200px - 1399px) */
@media (min-width: 1200px) and (max-width: 1399px) {
    .hero-section {
        padding: 5rem 3rem !important;
    }

    .hero-glass-panel {
        padding: 3rem !important;
    }
}

/* Extra Small Devices (320px - 375px) */
@media (max-width: 375px) {
    .hero-section {
        padding: 1rem 0.75rem !important;
    }

    .hero-glass-panel {
        padding: 0.75rem !important;
    }

    .typo-h1 {
        font-size: clamp(18px, 5vw, 24px) !important;
        line-height: 1.2 !important;
    }

    .typo-body-lead {
        font-size: 12px !important;
        line-height: 1.4 !important;
    }

    .feature-icon-box {
        width: 36px !important;
        height: 36px !important;
    }

    .btn {
        padding: 0.5rem 1rem !important;
        font-size: 13px !important;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        word-break: break-word;
    }

    .container,
    .container-fluid {
        padding: 0 0.5rem !important;
    }

    .row {
        margin-left: -0.375rem !important;
        margin-right: -0.375rem !important;
    }

    [class*="col"] {
        padding-left: 0.375rem !important;
        padding-right: 0.375rem !important;
    }
}

/* Ultra Wide Screens (2000px+) */
@media (min-width: 2000px) {
    .hero-section {
        padding: 6rem 4rem !important;
    }

    .hero-glass-panel {
        padding: 5rem !important;
    }

    .typo-h1 {
        font-size: 64px !important;
    }

    .typo-h2 {
        font-size: 40px !important;
    }

    .typo-body-lead {
        font-size: 22px !important;
    }

    .container {
        max-width: 1800px !important;
    }
}

/* Landscape Mobile Fix */
@media (max-height: 500px) and (orientation: landscape) {
    .hero-section {
        padding: 1rem !important;
    }

    .hero-glass-panel {
        padding: 1rem !important;
    }

    .typo-h1 {
        font-size: clamp(20px, 4vw, 28px) !important;
    }

    .feature-icon-box {
        width: 32px !important;
        height: 32px !important;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
    }

    .nav-link {
        padding: 0.75rem 1rem !important;
    }

    .card:hover {
        transform: none;
    }
}

/* Reduced Motion for Accessibility */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High DPI / Retina Displays */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .logo {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}