:root {
            scrollbar-gutter: stable;
            /* Vibrant Modern Palette */
            --accent: #007AFF;
            --accent-glow: color-mix(in srgb, var(--accent), transparent 70%);
            --blue-lt: rgba(229, 241, 255, 0.4);
            
            /* Glassmorphism Tokens */
            --glass-bg: rgba(255, 255, 255, 0.7);
            --glass-border: rgba(255, 255, 255, 0.4);
            --glass-blur: blur(8px);
            --sheet-bg: #f5f7fa;
            
            --surface: var(--glass-bg);
            --surface2: rgba(245, 247, 250, 0.5);
            --surface-hover: rgba(226, 231, 238, 0.6);
            --sep: rgba(0, 0, 0, 0.06);
            
            --label: #1C2B3A;
            --label2: #3A4B5A;
            --label3: #5A6B7A;
            --label4: #8A9BAE;
            
            --green: #34C759;
            --red: #FF3B30;
            --orange: #FF9500;
            
            /* Radius */
            --r-sm: 10px;
            --r-md: 14px;
            --r-lg: 20px;
            --r-xl: 28px;

            /* Spacing */
            --sp-xs: 4px;
            --sp-sm: 8px;
            --sp-md: 16px;
            --sp-lg: 24px;
            --sp-xl: 32px;
            
            /* Shadows - Very Subtle Accent Tint */
            --shadow-sm: 0 4px 12px color-mix(in srgb, var(--accent), transparent 94%);
            --shadow-md: 0 8px 24px color-mix(in srgb, var(--accent), transparent 90%);
            --shadow-lg: 0 16px 48px color-mix(in srgb, var(--accent), transparent 85%);

            /* Dynamic Accents */
            --accent-10: color-mix(in srgb, var(--accent), transparent 90%);
            --accent-20: color-mix(in srgb, var(--accent), transparent 80%);

            /* Premium Mesh Gradient Background (Respecting Accent) */
            --bg-gradient: 
                radial-gradient(at 0% 0%, var(--accent-10) 0px, transparent 50%),
                radial-gradient(at 100% 0%, rgba(52, 199, 89, 0.1) 0px, transparent 50%),
                radial-gradient(at 100% 100%, var(--accent-10) 0px, transparent 50%),
                radial-gradient(at 0% 100%, rgba(52, 199, 89, 0.1) 0px, transparent 50%),
                #f8fafc;
        }

        :root.dark {
            /* Base: Deep near-black tinted with the accent color for coherence */
            --surface:  color-mix(in srgb, var(--accent) 6%, #0a0f1e);
            --surface2: color-mix(in srgb, var(--accent) 10%, #141b2d);
            --surface-hover: color-mix(in srgb, var(--accent) 15%, #1e2a40);

            /* Glass: subtle frosted effect on dark */
            --glass-bg:     color-mix(in srgb, var(--accent) 8%, rgba(10, 15, 30, 0.92));
            --glass-border: color-mix(in srgb, var(--accent) 25%, rgba(255, 255, 255, 0.08));
            --sheet-bg: color-mix(in srgb, var(--accent) 6%, #0e1425);

            /* Text — maximum legibility */
            --label:  #F0F4FF;
            --label2: #C8D3E8;
            --label3: #8A9ABB;
            --label4: color-mix(in srgb, var(--accent) 50%, #8A9ABB);

            /* Accents — keep vivid against dark bg */
            --accent-10: color-mix(in srgb, var(--accent) 18%, transparent);
            --accent-20: color-mix(in srgb, var(--accent) 30%, transparent);
            --accent-glow: color-mix(in srgb, var(--accent) 45%, transparent);

            /* Separators */
            --sep: color-mix(in srgb, var(--accent) 12%, rgba(255,255,255,0.07));

            /* Shadows — deeper, accent-tinted */
            --shadow-sm: 0 4px 16px rgba(0,0,0,0.45);
            --shadow-md: 0 10px 32px rgba(0,0,0,0.55);
            --shadow-lg: 0 20px 56px rgba(0,0,0,0.65), 0 0 0 1px var(--glass-border);

            /* Background: rich mesh with accent influence */
            --accent-15: color-mix(in srgb, var(--accent) 20%, transparent);
            --bg-gradient:
                radial-gradient(at 10% 10%, var(--accent-15) 0px, transparent 55%),
                radial-gradient(at 90% 5%,  color-mix(in srgb, var(--accent) 12%, rgba(52,199,89,0.08)) 0px, transparent 50%),
                radial-gradient(at 85% 90%, var(--accent-15) 0px, transparent 50%),
                radial-gradient(at 5%  90%, color-mix(in srgb, var(--accent) 10%, rgba(52,199,89,0.06)) 0px, transparent 45%),
                color-mix(in srgb, var(--accent) 5%, #080d1a);
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
            -webkit-font-smoothing: antialiased;
        }

        body {
            background: var(--bg-gradient);
            color: var(--label);
            display: flex;
            height: 100vh;
            overflow: hidden;
            align-items: flex-start !important;
            justify-content: flex-start !important;
        }

        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
            opacity: 0.03;
            pointer-events: none;
            z-index: -1;
        }

        /* Typography */
        h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; }
        h1 { font-size: 28px; margin-bottom: var(--sp-lg); }
        h2 { font-size: 22px; margin-bottom: var(--sp-md); }
        p { font-size: 15px; line-height: 1.6; color: var(--label2); }

        /* Layout Overhaul */
        .sidebar {
            width: 280px;
            min-height: 100vh;
            background: var(--glass-bg);
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
            border-right: 1px solid var(--glass-border);
            display: flex;
            flex-direction: column;
            padding: var(--sp-lg);
            position: relative;
            z-index: 100;
        }

        .main-content {
            flex: 1;
            display: flex;
            flex-direction: column;
            height: 100vh;
            overflow-y: auto;
            padding: 40px;
            background: transparent;
            min-height: 0; /* Critical for flex content scrolling in WebKit */
        }

        /* Views */
        .view {
            display: none;
            max-width: 1300px;
            margin: 0 auto;
            width: 100%;
            padding-bottom: 80px;
        }

        .view.active {
            display: block;
            animation: viewEnter 0.5s cubic-bezier(0.23, 1, 0.32, 1);
        }

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

        /* Sidebar Nav */
        .nav-item {
            display: flex;
            align-items: center;
            padding: 10px 12px;
            border-radius: var(--r-md);
            margin-bottom: 4px;
            cursor: pointer;
            color: var(--label);
            font-weight: 500;
            font-size: 15px;
            transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
            text-decoration: none;
        }

        .nav-item:hover {
            background: rgba(255, 255, 255, 0.4);
            color: var(--accent);
            transform: translateX(5px);
        }

        .nav-item.active {
            background: white;
            color: var(--accent);
            box-shadow: var(--shadow-sm);
            transform: translateX(5px);
            border-color: var(--glass-border);
        }

        .brand {
            font-size: 20px;
            font-weight: 800;
            margin-bottom: 40px;
            display: flex;
            align-items: center;
            gap: 12px;
            color: var(--accent);
        }

        /* UI Components */
        /* Buttons - Modern Pill Shapes */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 10px 20px;
            border-radius: 100px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            border: none;
            transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
            gap: 10px;
            font-family: inherit;
        }

        .btn:hover:not(:disabled) {
            transform: translateY(-2px);
            filter: brightness(1.05);
        }

        .btn:active:not(:disabled) {
            transform: translateY(1px);
        }

        .btn-filled {
            background: var(--accent);
            color: white;
            box-shadow: 0 8px 16px var(--accent-glow);
        }

        .btn-plain {
            background: rgba(255, 255, 255, 0.5);
            backdrop-filter: none;
            border: 1px solid var(--glass-border);
            color: var(--label);
        }

        .btn-success { background: var(--green); color: white; box-shadow: 0 8px 16px rgba(52, 199, 89, 0.2); }
        .btn-danger { background: var(--red); color: white; box-shadow: 0 8px 16px rgba(255, 59, 48, 0.2); }
        /* Sheets & Modals - Consolidated & Fixed */
        .sheet-overlay {
            position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); 
            backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
            z-index: 10000; display: none; opacity: 0;
            transition: opacity 0.3s ease;
            align-items: center; justify-content: center;
        }
        .sheet-overlay.active { display: flex !important; opacity: 1; }

        .sheet {
            position: fixed; top: 50%; left: 50%;
            transform: translate(-50%, -45%) scale(0.95);
            background: var(--sheet-bg);
            border: 1px solid var(--glass-border);
            border-top: 5px solid var(--accent);
            border-radius: var(--r-xl);
            padding: var(--sp-xl);
            width: 90%; max-width: 600px;
            max-height: 90vh;
            z-index: 10001; box-shadow: var(--shadow-lg);
            display: none; flex-direction: column;
            transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
            opacity: 0; visibility: hidden;
        }
        .sheet.active { 
            display: flex; 
            transform: translate(-50%, -50%) scale(1); 
            opacity: 1; 
            visibility: visible;
        }

        .sheet-wide {
            width: 95% !important;
            max-width: 1600px !important;
            height: 90vh;
            padding: 0 !important;
            flex-direction: row !important;
            overflow: hidden;
        }
        .sheet-wide.active { display: flex !important; }

        .sheet-column-form {
            flex: 1.2;
            display: flex;
            flex-direction: column;
            overflow-y: auto;
            border-right: 1px solid var(--sep);
            padding: var(--sp-xl);
            background: transparent;
        }
        :root.dark .sheet-column-form {
            background: var(--bg);
        }

        .sheet-column-preview {
            flex: 1;
            display: flex;
            flex-direction: column;
            background: var(--surface-hover);
            padding: var(--sp-xl);
            position: relative;
        }

        :root.dark .sheet-column-preview {
            background: #0f172a; /* Deeper contrast for PDF in dark mode */
        }
        
        .sheet-header {
            display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--sp-lg);
            padding-bottom: var(--sp-md); border-bottom: 1px solid var(--sep);
        }
        .sheet-header h2 { font-size: 20px; font-weight: 800; color: var(--accent); letter-spacing: -0.02em; }
        .close-sheet { font-size: 24px; cursor: pointer; color: var(--label4); transition: color 0.2s; }
        .close-sheet:hover { color: var(--red); }
        
        .btn-sm { padding: 6px 14px; font-size: 12px; }

        /* Cards - Frosted Glass */
        .card {
            background: var(--glass-bg);
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
            border-radius: var(--r-xl);
            border: 1px solid var(--glass-border);
            padding: var(--sp-xl);
            box-shadow: var(--shadow-md);
            margin-bottom: var(--sp-lg);
            transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
        }

        .card:hover {
            box-shadow: var(--shadow-lg);
            transform: translateY(-5px);
            border-color: rgba(255, 255, 255, 0.6);
        }

        /* Tables & Lists */
        .card table { width: 100%; border-collapse: separate; border-spacing: 0; }
        th { padding: 16px; font-weight: 600; color: var(--label2); font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; }
        td { padding: 16px; font-size: 15px; border-top: 1px solid var(--sep); color: var(--label); }
        .form-label { display: block; margin-bottom: 8px; font-weight: 600; color: var(--label2); font-size: 13px; }
        
        tbody tr { transition: all 0.2s ease; }
        tbody tr:hover { background: rgba(255, 255, 255, 0.4); }

        /* Dashboard KPI */
        .kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 40px; }
        
        .kpi-card {
            padding: 24px;
            background: var(--glass-bg);
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
            border-radius: var(--r-lg);
            border: 1px solid var(--glass-border);
            box-shadow: var(--shadow-sm);
            transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
            display: flex;
            flex-direction: column;
            position: relative;
            overflow: hidden;
        }
        .kpi-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 4px;
            height: 100%;
            background: var(--accent);
            opacity: 0.5;
        }
        .kpi-card:hover { 
            transform: translateY(-5px); 
            box-shadow: 0 12px 24px var(--accent-glow);
            border-color: var(--accent);
        }
        .kpi-value { font-size: 32px; font-weight: 800; margin-top: 10px; color: var(--accent); letter-spacing: -0.02em; }
        .kpi-label { font-size: 11px; color: var(--label4); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; opacity: 0.8; }

        /* Form Controls */
        .form-group { margin-bottom: 24px; }
        .form-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; color: var(--label2); }
        
        .form-control {
            width: 100%;
            padding: 12px 16px;
            border-radius: var(--r-md);
            border: 1px solid var(--glass-border);
            font-size: 15px;
            background: var(--accent-10);
            color: var(--label);
            backdrop-filter: blur(2px);
            transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
        }
        
        .form-control:focus {
            outline: none;
            background: var(--glass-bg);
            border-color: var(--accent);
            box-shadow: 0 0 0 4px var(--accent-glow);
            transform: scale(1.01);
        }

        /* Toggles */
        .tp { position: relative; display: inline-block; width: 50px; height: 28px; }
        .tp input { opacity: 0; width: 0; height: 0; }
        .tp-track { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: var(--label4); transition: .4s; border-radius: 34px; opacity: 0.3; }
        .tp input:checked + .tp-track { background: var(--accent); opacity: 1; }
        .tp-track:before { position: absolute; content: ""; height: 22px; width: 22px; left: 3px; bottom: 3px; background: white; transition: .4s; border-radius: 50%; box-shadow: var(--shadow-sm); }
        .tp input:checked + .tp-track:before { transform: translateX(22px); }

        /* Sub-Sheet Stacking (For modals opened from other modals) */
        #product-picker-sheet.active,
        #desc-detail-sheet.active,
        #customer-sheet.active,
        #product-sheet.active {
            z-index: 10002;
        }

        #desc-detail-text:focus {
            background: var(--surface2);
        }

        .sheet-header { padding: 24px 32px; border-bottom: 1px solid var(--sep); display: flex; justify-content: space-between; align-items: center; background: var(--surface2); }
        .sheet-content { padding: 32px; overflow-y: auto; flex: 1; }
        .sheet-footer { padding: 24px 32px; border-top: 1px solid var(--sep); display: flex; justify-content: flex-end; gap: 12px; background: var(--surface2); }

        /* Toast Container */
        #toast-container {
            position: fixed;
            top: 30px;
            right: 30px;
            z-index: 20000;
            display: flex;
            flex-direction: column;
            gap: 12px;
            pointer-events: none;
        }

        /* Toast */
        .toast {
            pointer-events: auto;
            min-width: 300px; padding: 16px 20px; border-radius: var(--r-lg);
            color: #fff; font-weight: 600; box-shadow: var(--shadow-lg);
            background: #1a2035;
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255,255,255,0.12);
            display: flex; align-items: center; gap: 12px;
            animation: toastEnter 0.4s cubic-bezier(0.23, 1, 0.32, 1);
        }
        .toast.success { background: #0d2b1a; border-color: rgba(52,199,89,0.3); }
        .toast.error   { background: #2b0d0d; border-color: rgba(255,59,48,0.3); }
        .toast.warning { background: #2b1f0d; border-color: rgba(255,149,0,0.3); }
        @keyframes toastEnter { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

        /* Login Overlay Styling Refinement */
        #login-overlay {
            position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
            background: radial-gradient(circle at 30% 30%, rgba(0, 122, 255, 0.15), transparent),
                        radial-gradient(circle at 70% 70%, rgba(52, 199, 89, 0.15), transparent),
                        #f8fafc;
            z-index: 5000; display: none; align-items: center; justify-content: center;
        }
        #login-overlay.active { display: flex; animation: fadeIn 0.6s ease; }
        
        .login-card {
            width: 440px; padding: 50px;
            background: rgba(255, 255, 255, 0.7);
            backdrop-filter: none;
            -webkit-backdrop-filter: none;
            border-radius: var(--r-xl);
            border: 1px solid var(--glass-border);
            box-shadow: 0 40px 100px rgba(0, 0, 0, 0.1);
            text-align: center;
            animation: slideUp 0.8s cubic-bezier(0.23, 1, 0.32, 1);
        }
        
        .login-logo { font-size: 56px; margin-bottom: 24px; filter: drop-shadow(0 10px 20px rgba(0,0,0,0.1)); }
        .login-title { font-size: 28px; margin-bottom: 12px; }
        .login-subtitle { font-size: 15px; margin-bottom: 40px; color: var(--label3); }
        .login-btn { padding: 16px; font-size: 17px; margin-top: 20px; }

        /* Utilities */
        .flex-grow { flex: 1; }
        .text-muted { color: var(--label4); }
        .sync-status { border-top: 1px solid var(--sep); padding-top: 20px; margin-top: 20px; font-size: 12px; color: var(--label4); display: flex; align-items: center; gap: 8px; }
        .sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 10px var(--orange); transition: all 0.3s; }
        .sync-dot.active { background: var(--green); box-shadow: 0 0 10px var(--green); }

        /* Mode Toggle UI */
        .mode-toggle-card {
            background: linear-gradient(to right, rgba(0, 122, 255, 0.05), rgba(52, 199, 89, 0.05));
            border: 1px solid var(--blue-lt);
            padding: 16px;
            border-radius: var(--r-lg);
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .mode-info h4 {
            font-size: 15px;
            margin-bottom: 4px;
            color: var(--accent);
        }

        .mode-info p {
            font-size: 12px;
            color: var(--label4);
        }

        /* ─────────────────────────────────────────────────
           Dark Mode Component Overrides
           Accent-adaptive, coherent, maximum legibility
        ───────────────────────────────────────────────── */

        /* Sidebar */
        :root.dark .sidebar {
            background: color-mix(in srgb, var(--accent) 8%, rgba(8, 13, 28, 0.96));
            border-right-color: var(--glass-border);
        }

        /* Active nav item: accent-filled pill */
        :root.dark .nav-item.active {
            background: var(--accent);
            color: #fff;
            box-shadow: 0 4px 16px var(--accent-glow);
        }

        /* Nav hover */
        :root.dark .nav-item:hover {
            background: var(--surface-hover);
            color: var(--accent);
        }

        /* Cards */
        :root.dark .card {
            background: var(--surface2);
            border-color: var(--glass-border);
        }

        /* Table rows */
        :root.dark table tr:hover td {
            background: var(--surface-hover);
        }
        :root.dark thead {
            background: var(--surface2) !important;
        }

        /* Inputs & Selects */
        :root.dark .form-control,
        :root.dark select,
        :root.dark textarea,
        :root.dark input[type="text"],
        :root.dark input[type="email"],
        :root.dark input[type="number"],
        :root.dark input[type="date"] {
            background: color-mix(in srgb, var(--accent) 8%, #0d1526) !important;
            border-color: var(--glass-border) !important;
            color: var(--label) !important;
        }

        :root.dark .form-control:focus,
        :root.dark select:focus,
        :root.dark textarea:focus {
            border-color: var(--accent) !important;
            box-shadow: 0 0 0 4px var(--accent-glow) !important;
            background: color-mix(in srgb, var(--accent) 12%, #0d1526) !important;
        }

        /* Button plain overrides */
        :root.dark .btn-plain {
            background: var(--surface2);
            border-color: var(--glass-border);
            color: var(--label);
        }
        :root.dark .btn-plain:hover {
            background: var(--surface-hover);
            color: var(--accent);
        }

        /* Sheets */
        :root.dark .sheet,
        :root.dark .sheet-header,
        :root.dark .sheet-footer {
            background: var(--surface2);
            border-color: var(--glass-border);
        }
        :root.dark .sheet {
            border-top-color: var(--accent);
        }

        /* Sheet overlay */
        :root.dark .sheet-overlay {
            background: rgba(0, 0, 0, 0.65);
        }

        /* Headings & typography */
        :root.dark h1,
        :root.dark h2,
        :root.dark h3 {
            color: var(--label);
        }
        :root.dark p {
            color: var(--label3);
        }

        /* Badges */
        :root.dark .badge {
            opacity: 0.9;
        }

        /* KPI cards */
        :root.dark .kpi-card {
            background: var(--surface2);
            border-color: var(--glass-border);
        }

        /* Scrollbars */
        :root.dark ::-webkit-scrollbar-track {
            background: var(--surface);
        }
        :root.dark ::-webkit-scrollbar-thumb {
            background: var(--surface-hover);
            border-color: var(--surface);
        }
        :root.dark ::-webkit-scrollbar-thumb:hover {
            background: color-mix(in srgb, var(--accent) 50%, var(--surface-hover));
        }

        /* Mode toggle card */
        :root.dark .mode-toggle-card {
            background: var(--surface2);
            border-color: var(--glass-border);
        }
