        :root {
            --bg: #090e17;
            --panel: rgba(20, 28, 43, 0.8);
            --border: rgba(255, 255, 255, 0.1);
            --teal: #2dd4bf;
            --emerald: #10b981;
            --text: #f8fafc;
            --text-dim: #94a3b8;
            --danger: #ef4444;
            --glass: blur(24px);
            --focus-ring: 0 0 0 3px rgba(45, 212, 191, 0.25);
        }

        html { background-color: var(--bg); }
        
        * { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', -apple-system, sans-serif; }
        body { 
            background: radial-gradient(circle at top right, #1e292b, #0f172a); 
            color: var(--text); 
            min-height: 100vh; 
            padding: 4vh 1rem 2rem 1rem; /* Fixed top margin instead of dynamic auto-centering */
            display: flex; 
            flex-direction: column; 
            align-items: center; 
        }

                .container { 
            width: 100%; max-width: 1200px; margin: 0 auto;
            animation: fadeIn 0.4s ease-out; 
            display: grid; grid-template-columns: 240px 1fr; gap: 2rem; align-items: start;
        }
        @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

        .sidebar { display: flex; flex-direction: column; gap: 1.5rem; align-self: center; z-index: 50; }
        
        .top-bar { 
            width: 100%; max-width: 1200px; margin: 0 auto 1.5rem auto; 
            display: flex; justify-content: space-between; align-items: center; 
            animation: fadeIn 0.4s ease-out;
        }
        .logo { display: flex; align-items: center; gap: 1rem; }
        h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; color: #fff;}
        .subtitle { font-size: 0.85rem; color: var(--text-dim); font-weight: 500;}

        .controls-row { display: flex; gap: 0.5rem; }
        .mobile-menu-btn { display: none; } /* Hidden on desktop */

        /* Vertical Tab Bar */
        .nav-menu { 
            display: flex; flex-direction: column; gap: 0.25rem;
            background: rgba(0,0,0,0.15); padding: 0.5rem; border-radius: 12px; border: 1px solid var(--border); 
        }

        .tab { 
            padding: 0.75rem 1rem; border-radius: 8px; cursor: pointer; 
            font-weight: 600; font-size: 0.9rem; transition: all 0.2s ease; 
            border: 1px solid transparent; /* Replaces border: none so layout doesn't shift when active adds a 1px border */
            background: transparent; color: var(--text-dim); 
            display: flex; align-items: center; justify-content: flex-start; gap: 0.75rem;
            width: 100%; text-align: left;
            outline: none; /* Prevents Safari default white flash focus ring */
            -webkit-tap-highlight-color: transparent; /* Prevents iOS gray highlight */
        }
        .tab svg { stroke-width: 2.5px; width: 18px; height: 18px; flex-shrink: 0; }
        .tab:hover:not(.active) { color: var(--text); background: rgba(255,255,255,0.05); }
        .tab.active { background: rgba(45, 212, 191, 0.1); color: var(--teal); box-shadow: 0 2px 10px rgba(0,0,0,0.2); border: 1px solid rgba(45, 212, 191, 0.2); }

        .main-content {
            display: flex; flex-direction: column; justify-content: center;
            min-height: calc(100vh - 160px);
        }

        .panel { 
            background: var(--panel); backdrop-filter: var(--glass); 
            border: 1px solid var(--border); border-radius: 20px; 
            padding: 2rem; box-shadow: 0 24px 60px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05); 
            animation: fadeInTab 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
        }
        @keyframes fadeInTab {
            from { opacity: 0; transform: translateY(8px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .grid { 
            display: flex; flex-wrap: wrap; justify-content: flex-start;
            gap: 1.5rem; margin-bottom: 1.5rem; 
            background: rgba(0,0,0,0.2); padding: 1.25rem; border-radius: 12px; 
            border: 1px solid rgba(255,255,255,0.05);
        }
        .field { display: flex; flex-direction: column; justify-content: flex-end; gap: 0.5rem; flex: 1 1 140px; max-width: 250px; }
        label { font-size: 0.7rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
        
        input { 
            background: rgba(0,0,0,0.3); border: 1px solid var(--border); 
            border-radius: 8px; padding: 0.6rem 0.75rem; color: var(--text); 
            font-size: 1rem; 
            transition: all 0.2s ease; outline: none; width: 100%; 
            color-scheme: dark; 
        }
        input:focus { border-color: var(--teal); background: rgba(0,0,0,0.5); box-shadow: var(--focus-ring); }
        input::placeholder { font-weight: 400; font-size: 0.85rem; opacity: 0.7; }

        /* Error States & Solved Highlights */
        .has-error { border-color: var(--danger) !important; box-shadow: 0 0 0 1px var(--danger); background: rgba(239, 68, 68, 0.08) !important; color: #ff9999 !important;}
        .solved-value { color: var(--teal) !important; font-weight: 700 !important; border-color: rgba(45, 212, 191, 0.4) !important; background: rgba(45, 212, 191, 0.05) !important;}

        /* Globally remove UP/DOWN arrows from all number inputs */
        input[type="number"]::-webkit-inner-spin-button,
        input[type="number"]::-webkit-outer-spin-button { 
            -webkit-appearance: none !important; 
            margin: 0 !important; 
            display: none !important; 
        }
        input[type="number"] { 
            -moz-appearance: textfield !important; 
            appearance: textfield !important; 
        }

        /* Scrollable table with sticky headers */
        .table-wrap { 
            overflow-x: auto; margin-bottom: 1.5rem; border-radius: 10px; 
            border: 1px solid var(--border); max-height: 500px; overflow-y: auto;
        }
        table { width: 100%; border-collapse: collapse; min-width: 750px; }
        thead { position: sticky; top: 0; z-index: 10; background: var(--bg); }
        th { 
            text-align: center; padding: 1rem; color: var(--text-dim); 
            font-size: 0.85rem; font-weight: 600; border-bottom: 2px solid var(--border); 
            vertical-align: middle; 
        }
        td { padding: 0.6rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.05); text-align: center; }
        
        .table-wrap td input { text-align: center; max-width: 180px; margin: 0 auto; padding: 0.6rem; font-size: 1rem; font-weight: 500; }
        
        .th-wrap { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; text-align: center; }
        .th-controls { display: flex; flex-wrap: nowrap; gap: 6px; margin-top: 0; justify-content: center; }

        .header-select {
            background: rgba(0,0,0,0.4); color: var(--teal); border: 1px solid var(--border);
            border-radius: 6px; font-size: 0.75rem; padding: 4px 8px;
            outline: none; cursor: pointer; font-weight: 700; transition: 0.2s;
            color-scheme: dark; text-align: center; text-align-last: center;
        }
        .header-select:hover { border-color: var(--teal); background: rgba(0,0,0,0.6); }
        .header-select option { background: var(--bg); color: var(--text); }

        .res { font-family: 'SF Mono', 'Monaco', 'Consolas', monospace; font-weight: 700; font-size: 1.1rem; white-space: nowrap; text-align: center; }
        .teal { color: var(--teal); }
        .emerald { color: var(--emerald); }

        .btn { padding: 0.6rem 1.2rem; border-radius: 10px; font-weight: 600; cursor: pointer; border: none; display: flex; align-items: center; justify-content: center; gap: 0.6rem; transition: 0.2s; font-size: 0.9rem; }
        .btn-p { background: var(--emerald); color: #000; padding: 0.35rem 0.8rem; font-size: 0.75rem; border-radius: 6px; gap: 0.4rem; }
        .btn-p:hover { transform: translateY(-2px); }
        
        .btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); padding: 0.5rem 1rem; font-size: 0.85rem; border-radius: 8px; gap: 0.5rem;}
        .btn-outline:hover { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.3); }

        .btn-g { background: rgba(45, 212, 191, 0.08); color: var(--teal); margin: 0.5rem auto 0 auto; padding: 0.75rem 1.5rem; width: fit-content; border: 1px dashed rgba(45, 212, 191, 0.3);}
        .btn-g:hover { background: rgba(45, 212, 191, 0.15); border-color: var(--teal); }
        .btn-d { background: transparent; color: rgba(255,255,255,0.2); font-size: 1.25rem; padding: 0.4rem; border-radius: 6px; }
        .btn-d:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }

        /* Tools Input Group CSS - CENTERED & RESTRICTED WIDTH */
        .tool-wrap { max-width: 600px; margin: 0 auto; }
        
        .tool-wrap .grid { 
            display: flex; 
            flex-direction: column; 
            align-items: center; 
            gap: 1.25rem; 
            background: transparent; 
            border: none; 
            padding: 0; 
            margin-bottom: 0;
        }
        .tool-wrap .field { 
            flex: 0 0 auto; 
            width: 100%; 
            max-width: 360px; 
        }

        .equation { text-align: center; font-family: 'SF Mono', monospace; font-size: 0.95rem; color: var(--teal); margin-bottom: 2rem; padding: 1rem; background: rgba(45, 212, 191, 0.05); border-radius: 12px; border: 1px dashed rgba(45, 212, 191, 0.2); }
        .input-group { display: flex; align-items: stretch; background: rgba(0,0,0,0.3); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; transition: 0.2s; }
        .input-group:focus-within { border-color: var(--teal); box-shadow: var(--focus-ring); }
        
        .input-group input { 
            flex: 1; min-width: 0; border: none; background: transparent; border-radius: 0; 
            font-family: 'SF Mono', monospace; font-weight: 600; font-size: 1.1rem;
            padding: 0.5rem 0.6rem;
        }
        .input-group input:focus { box-shadow: none; background: transparent; }
        .input-group input::placeholder { font-weight: 400; font-size: 0.85rem; font-family: 'Inter', -apple-system, sans-serif; opacity: 0.7; }
        
        .copy-btn { display: none; align-items: center; justify-content: center; flex: 0 0 auto; background: rgba(45, 212, 191, 0.1); color: var(--teal); border: none; border-left: 1px solid var(--border); padding: 0 0.6rem; cursor: pointer; transition: 0.2s; }
        .copy-btn:hover { background: rgba(45, 212, 191, 0.3); color: #fff; }
        .copy-btn.show { display: flex; }

        .input-group select { 
            flex: 0 0 92px; width: 92px; /* Fixed width stops unaligned jagged borders */
            border: none; background: rgba(255,255,255,0.05); color: var(--text); 
            outline: none; padding: 0.5rem 0.4rem; font-weight: 600; font-size: 0.9rem;
            cursor: pointer; border-left: 1px solid var(--border); transition: 0.2s; 
            color-scheme: dark; 
            text-align: center; text-align-last: center; 
        }
        .input-group select:focus { background: rgba(255,255,255,0.1); }
        .input-group select option { background: var(--bg); color: var(--text); }
        
        .fixed-unit { 
            flex: 0 0 92px; width: 92px; /* Match select fixed width */
            padding: 0.5rem 0.6rem; font-weight: 600; 
            border-left: 1px solid var(--border); background: rgba(255,255,255,0.02); 
            color: var(--text-dim); display: flex; align-items: center; justify-content: center;
            font-size: 0.9rem; text-align: center;
        }

        /* --- Floating Lab Timer (Draggable FAB & Modal) --- */
        .timer-fab {
            position: fixed; bottom: 20px; right: 20px; z-index: 999;
            width: 48px; height: 48px; border-radius: 24px;
            background: var(--panel); border: 1px solid var(--border); backdrop-filter: var(--glass);
            box-shadow: 0 6px 16px rgba(0,0,0,0.6);
            display: flex; align-items: center; justify-content: center;
            cursor: pointer; transition: width 0.3s, background 0.2s, border 0.2s; color: var(--text-dim);
            user-select: none; touch-action: none;
        }
        .timer-fab:hover { border-color: var(--teal); color: var(--teal); background: rgba(30, 41, 59, 0.95); }
        .timer-fab.running { width: auto; padding: 0 16px; font-family: 'SF Mono', monospace; font-weight: 700; color: var(--teal); border-color: rgba(45, 212, 191, 0.5); }
        .timer-fab.ringing { color: #fff; background: var(--danger); border-color: var(--danger); animation: pulse 0.8s infinite; }
        @keyframes pulse { 0% { opacity: 1; transform: scale(1); } 50% { opacity: 0.8; transform: scale(1.05); } 100% { opacity: 1; transform: scale(1); } }

        .timer-modal {
            position: fixed; top: 0; left: 0; right: 0; bottom: 0;
            background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
            display: none; align-items: center; justify-content: center; z-index: 1000;
        }
        .timer-modal.show { display: flex; animation: fadeIn 0.2s; }
        .timer-modal-content {
            background: var(--bg); border: 1px solid var(--border);
            padding: 1.5rem 2rem; border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
            display: flex; flex-direction: column; gap: 1.25rem; align-items: center;
        }
        .timer-modal-title { font-weight: 700; color: var(--text); font-size: 1.1rem; }
        .timer-inputs { display: flex; align-items: center; gap: 0.5rem; font-size: 1.5rem; font-weight: bold; color: var(--text-dim); }
        .timer-inputs input { width: 70px; text-align: center; font-size: 1.5rem; padding: 0.5rem; border-radius: 8px; }
        .timer-actions { display: flex; gap: 0.5rem; width: 100%; }
        .timer-actions button { flex: 1; padding: 0.6rem; border-radius: 8px; font-weight: 600; cursor: pointer; border: none; transition: 0.2s; font-size: 0.95rem;}
        .btn-cancel { background: transparent; color: var(--text-dim); border: 1px solid var(--border) !important; }
        .btn-cancel:hover { background: rgba(255,255,255,0.05); color: var(--text); }
        .btn-start { background: var(--teal); color: #000; }
        .btn-start:hover { filter: brightness(1.1); }

        /* Toast Notification */
        #toast {
            position: fixed; bottom: 30px; left: 50%; transform: translate(-50%, 100px);
            background: rgba(15, 23, 42, 0.95); color: #fff; padding: 0.8rem 1.25rem;
            border-radius: 30px; border: 1px solid var(--teal); box-shadow: 0 10px 30px rgba(0,0,0,0.5);
            font-weight: 600; font-size: 0.9rem; opacity: 0; z-index: 1000;
            transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s;
            backdrop-filter: blur(10px); display: flex; align-items: center; gap: 0.6rem;
            white-space: nowrap;
        }
        #toast.show { transform: translate(-50%, 0); opacity: 1; }

        .credit { margin-top: 2rem; padding-bottom: 1rem; text-align: center; font-size: 0.8rem; color: rgba(255,255,255,0.3); font-weight: 500;}
        .credit a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 0.5rem; transition: color 0.3s; }
        .credit a:hover { color: var(--teal); }

        tr:hover { background: rgba(255,255,255,0.02); }

        /* Empty State Icon */
        .empty-icon { opacity: 0.2; margin-bottom: 0.5rem; display: block; margin-left: auto; margin-right: auto;}

        /* --- Mobile Optimizations --- */
        @media (max-width: 800px) {
            .container { display: flex; flex-direction: column; gap: 1rem; padding: 0.5rem; }
            .sidebar { position: relative; gap: 1rem; align-self: stretch; }
            
            .top-bar { flex-direction: column; align-items: flex-start; gap: 1rem; margin-bottom: 0.5rem; padding: 0 0.5rem; }
            .top-bar .controls-row { width: 100%; justify-content: space-between; }
            .top-bar .controls-row button { flex: 1; justify-content: center; }
            
            .logo h1 { font-size: 1.3rem; }
            .logo .subtitle { display: none; } /* Save space on mobile */

            .mobile-menu-btn {
                display: flex; justify-content: space-between; align-items: center;
                background: var(--panel); backdrop-filter: var(--glass); 
                border: 1px solid var(--border); border-radius: 12px;
                padding: 1rem 1.25rem; font-size: 0.95rem; font-weight: 600; color: var(--text);
                cursor: pointer; width: 100%; transition: all 0.2s ease;
                box-shadow: 0 8px 24px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.05);
            }
            .mobile-menu-btn:active { transform: scale(0.98); }

            .nav-menu {
                display: none; 
                position: absolute; top: calc(100% - 3.5rem); left: 0; right: 0;
                background: rgba(15, 23, 42, 0.95); backdrop-filter: blur(24px);
                border: 1px solid rgba(255,255,255,0.1); border-radius: 16px;
                padding: 0.5rem; flex-direction: column; gap: 0.25rem;
                box-shadow: 0 20px 40px rgba(0,0,0,0.5); z-index: 100;
                animation: slideDown 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
            }
            .nav-menu.show { display: flex; }
            
            @keyframes slideDown { 
                from { opacity: 0; transform: translateY(-10px); } 
                to { opacity: 1; transform: translateY(0); } 
            }
            
            .main-content { margin-top: 0.5rem; }
            .panel { padding: 1rem; border-radius: 16px; }
            .grid { gap: 0.75rem; padding: 0.85rem; margin-bottom: 1rem; }
        }

        @media (max-width: 600px) {
            .panel { padding: 1rem; border-radius: 16px; }
            .grid { gap: 0.75rem; padding: 0.85rem; margin-bottom: 1rem; }
            .top-bar { margin-bottom: 0.75rem; gap: 0.5rem; }
            h1 { font-size: 1.25rem; }
            .subtitle { font-size: 0.75rem; }
            .controls-row { gap: 0.6rem; margin-bottom: 0.75rem; }
            .tab { padding: 0.5rem 0.8rem; font-size: 0.85rem; gap: 0.4rem; }
            .tab svg { width: 16px; height: 16px; }
            
            /* Forces Passaging & Glucose grids to fit perfectly on a single row */
            .main-calc-grid { flex-wrap: nowrap; gap: 0.4rem; padding: 0.75rem 0.5rem; }
            .main-calc-grid .field { flex: 1 1 0; min-width: 0; max-width: none; }
            .main-calc-grid .field label { font-size: 0.55rem; letter-spacing: 0; text-align: center; }
            .main-calc-grid .field label span { white-space: normal !important; display: inline !important; }
            .main-calc-grid input { padding: 0.4rem 0.2rem; text-align: center; font-size: 0.95rem; }
            
            table { min-width: 550px; } 
            th { padding: 0.6rem 0.3rem; font-size: 0.75rem; }
            td { padding: 0.5rem 0.3rem; }
            .table-wrap td input { padding: 0.4rem 0.3rem; font-size: 0.95rem; max-width: 100%; }
            
            .header-select { font-size: 0.7rem; padding: 2px 4px; }
            .equation { margin-bottom: 1rem; padding: 0.75rem; font-size: 0.85rem; }
            .btn-p, .btn-outline { padding: 0.4rem 0.6rem; font-size: 0.8rem; gap: 0.3rem; }

            /* Constrains single-tool calculators so they don't stretch edge-to-edge on mobile */
            .tool-wrap .field { max-width: 280px; }
        }

        /* --- Print Friendly Mode --- */
        @media print {
            body { background: #fff; color: #000; padding: 0; }
            .container { max-width: 100%; animation: none; }
            .panel { background: none; border: none; box-shadow: none; padding: 0; }
            header .header-actions, .controls-row, .btn, .btn-p, .btn-g, .btn-d, .timer-fab, .timer-modal, #toast, .credit, .copy-btn { display: none !important; }
            input, select, .header-select { background: none !important; border: 1px solid #ccc !important; color: #000 !important; }
            .grid { background: #f8f9fa; border: 1px solid #dee2e6; color: #000; break-inside: avoid; }
            label, th, .th-wrap span { color: #444; }
            .table-wrap { overflow: visible; border: none; max-height: none; }
            table { min-width: 100%; border-collapse: collapse; }
            th, td { border: 1px solid #dee2e6; padding: 8px; color: #000; }
            .res.teal, .res.emerald, .solved-value { color: #000 !important; font-weight: bold; background: none !important;}
            * { text-shadow: none !important; box-shadow: none !important; }
        }
