﻿/* Virtual Lab CSS - extracted for embedding in chemistry.html */
/* Scoped under #virtual-lab-view */

#virtual-lab-view {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding-top: 0;
    margin-top: -8px;
}
        .virtual-lab-container {
            display: grid;
            grid-template-columns: 220px 1fr 320px;
            grid-template-rows: 1fr;
            height: calc(100vh - 74px);
            gap: 0;
            overflow: hidden;
            transition: grid-template-columns 0.4s ease;
        }

        .virtual-lab-container.plot-expanded {
            grid-template-columns: 220px 1fr 480px;
        }

        /* Header */
        .lab-header {
            background: linear-gradient(90deg, #2c3e50 0%, #34495e 100%);
            color: white;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 14px;
            height: 32px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
            z-index: 100;
        }

        .lab-header h1 {
            font-size: 14px;
            font-weight: 600;
            letter-spacing: 0.4px;
            margin: 0;
        }

        .lab-header .back-btn {
            background: rgba(255,255,255,0.1);
            border: 1px solid rgba(255,255,255,0.3);
            color: white;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;
        }

        .lab-header .back-btn:hover {
            background: rgba(255,255,255,0.2);
            transform: translateY(-2px);
        }

        .help-icon {
            background: rgba(255,255,255,0.1);
            border: 1px solid rgba(255,255,255,0.3);
            color: white;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            cursor: pointer;
            font-size: 13px;
            font-weight: bold;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
            margin-left: 8px;
        }

        .help-icon:hover {
            background: rgba(255,255,255,0.2);
            transform: scale(1.1);
        }

        /* Quick Start Guide */
        .quick-guide {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            color: white;
            padding: 10px 30px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 2px 8px rgba(0,0,0,0.2);
            animation: slideDown 0.5s ease;
        }

        .quick-guide.hidden {
            display: none;
        }

        @keyframes slideDown {
            from {
                transform: translateY(-100%);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        .guide-steps {
            display: flex;
            gap: 30px;
            align-items: center;
            flex-wrap: wrap;
        }

        .guide-step {
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 14px;
        }

        .guide-step-num {
            background: rgba(255,255,255,0.3);
            width: 24px;
            height: 24px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 12px;
        }

        .guide-close {
            background: none;
            border: none;
            color: white;
            font-size: 24px;
            cursor: pointer;
            padding: 5px;
            opacity: 0.8;
            transition: opacity 0.3s ease;
        }

        .guide-close:hover {
            opacity: 1;
        }

        /* Left Sidebar - Equipment & Reagents */
        .equipment-sidebar {
            background: rgba(255,255,255,0.95);
            padding: 12px;
            overflow-y: auto;
            box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        }

        .sidebar-section {
            margin-bottom: 15px;
        }

        .sidebar-section h3 {
            color: #2c3e50;
            font-size: 13px;
            font-weight: 600;
            margin-bottom: 10px;
            border-bottom: 2px solid #3498db;
            padding-bottom: 5px;
        }

        .equipment-item, .reagent-item {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            border: 1px solid #bdc3c7;
            border-radius: 6px;
            padding: 8px 10px;
            margin-bottom: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            font-size: 12px;
            gap: 10px;
        }

        .equipment-item:hover, .reagent-item:hover {
            transform: translateX(5px);
            box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
            border-color: #3498db;
        }

        .equipment-item.active, .reagent-item.active {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            color: white;
            border-color: #2980b9;
        }

        .equipment-icon {
            font-size: 18px;
        }

        /* Reagent Controls */
        .reagent-row {
            margin-bottom: 12px;
        }

        .reagent-row label {
            display: block;
            font-size: 13px;
            font-weight: 600;
            color: #2c3e50;
            margin-bottom: 6px;
        }

        .reagent-select-group {
            display: flex;
            gap: 6px;
            align-items: center;
        }

        .reagent-select {
            flex: 1;
            padding: 8px 10px;
            border: 1px solid #bdc3c7;
            border-radius: 6px;
            font-size: 13px;
            background: white;
            cursor: pointer;
            min-width: 0;
        }

        .reagent-select:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }

        .conc-input {
            width: 60px;
            padding: 8px 6px;
            border: 1px solid #bdc3c7;
            border-radius: 6px;
            font-size: 13px;
            text-align: center;
            font-weight: 600;
        }

        .conc-input:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }

        /* Hide default number input spinners and add custom styling */
        .conc-input::-webkit-inner-spin-button,
        .conc-input::-webkit-outer-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }
        .conc-input[type=number] {
            -moz-appearance: textfield;
        }

        .unit-label {
            font-size: 13px;
            color: #2c3e50;
            font-weight: 600;
            align-self: center;
        }

        /* Titration Mode Toggle */
        .mode-toggle-group {
            display: flex;
            width: 100%;
            gap: 4px;
        }

        .mode-btn {
            flex: 1;
            padding: 8px 10px;
            font-size: 12px;
            font-weight: 600;
            border: 2px solid #bdc3c7;
            background: linear-gradient(135deg, #f5f7fa 0%, #e8ecef 100%);
            color: #5a6c7d;
            cursor: pointer;
            transition: all 0.3s ease;
            border-radius: 6px;
        }

        .mode-btn:hover {
            border-color: #3498db;
            color: #2980b9;
        }

        .mode-btn.active {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            color: white;
            border-color: #2980b9;
            box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
        }

        /* pKa/pKb Input Rows */
        .pka-row, .pkb-row {
            background: linear-gradient(135deg, #fef9e7 0%, #fdebd0 100%);
            border: 1px solid #f39c12;
            border-radius: 6px;
            padding: 8px 10px;
            margin-top: -5px;
        }

        .pka-label {
            font-size: 12px;
            color: #8e6e00;
            font-weight: 600;
        }

        .pka-input-group {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-top: 5px;
        }

        .pka-input {
            flex: 1;
            padding: 6px 8px;
            border: 1px solid #f39c12;
            border-radius: 4px;
            font-size: 13px;
            font-weight: 600;
            text-align: center;
            background: white;
            color: #2c3e50;
        }

        .pka-input:focus {
            outline: none;
            border-color: #e67e22;
            box-shadow: 0 0 0 2px rgba(243, 156, 18, 0.2);
        }

        .pka-info {
            font-size: 16px;
            color: #f39c12;
            cursor: pointer;
            padding: 2px 6px;
            border-radius: 4px;
            transition: all 0.2s ease;
        }

        .pka-info:hover {
            background: #f39c12;
            color: white;
        }

        .pka-row.modified, .pkb-row.modified {
            background: linear-gradient(135deg, #e8f8f5 0%, #d1f2eb 100%);
            border-color: #1abc9c;
        }

        .pka-row.modified .pka-label,
        .pkb-row.modified .pka-label {
            color: #0e6655;
        }

        .pka-row.modified .pka-input,
        .pkb-row.modified .pka-input {
            border-color: #1abc9c;
        }

        .indicator-toggle {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 12px;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            border: 1px solid #bdc3c7;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 13px;
        }

        .indicator-toggle:hover {
            border-color: #3498db;
        }

        .indicator-toggle.active {
            background: linear-gradient(135deg, #e91e63 0%, #c2185b 100%);
            color: white;
            border-color: #c2185b;
        }

        .indicator-toggle input[type="checkbox"] {
            display: none;
        }

        .toggle-switch {
            width: 40px;
            height: 20px;
            background: #bdc3c7;
            border-radius: 10px;
            position: relative;
            transition: background 0.3s ease;
            flex-shrink: 0;
        }

        .toggle-switch::after {
            content: '';
            position: absolute;
            width: 16px;
            height: 16px;
            background: white;
            border-radius: 50%;
            top: 2px;
            left: 2px;
            transition: left 0.3s ease;
            box-shadow: 0 1px 3px rgba(0,0,0,0.2);
        }

        .indicator-toggle.active .toggle-switch {
            background: #ff69b4;
        }

        .indicator-toggle.active .toggle-switch::after {
            left: 22px;
        }

        /* Central Workbench */
        .workbench {
            background: linear-gradient(180deg, #ecf0f1 0%, #bdc3c7 100%);
            position: relative;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: space-between;
            padding: 10px;
            gap: 10px;
            overflow: hidden;
            min-height: 0;
        }

        #labCanvas {
            background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
            border: 2px solid #34495e;
            border-radius: 8px;
            box-shadow: inset 0 2px 10px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 480px;
            height: auto;
            max-height: calc(100% - 92px);
            flex: 1;
            min-height: 0;
        }

        .controls-panel {
            background: rgba(255,255,255,0.95);
            padding: 10px 15px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.15);
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 15px;
            flex-shrink: 0;
            margin-top: auto;
            width: min(100%, 560px);
            justify-content: center;
        }

        .status-message {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
            color: white;
            padding: 12px 24px;
            border-radius: 8px;
            box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
            font-weight: 600;
            font-size: 14px;
            z-index: 50;
            animation: fadeInOut 3s ease;
            display: none;
        }

        .status-message.show {
            display: block;
        }

        .status-message.warning {
            background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
            box-shadow: 0 4px 15px rgba(243, 156, 18, 0.3);
        }

        .status-message.success {
            background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
            box-shadow: 0 4px 15px rgba(155, 89, 182, 0.3);
        }

        @keyframes fadeInOut {
            0%, 100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
            10%, 90% { opacity: 1; transform: translateX(-50%) translateY(0); }
        }

        .control-group {
            display: flex;
            flex-direction: column;
            gap: 5px;
        }

        .control-group.horizontal {
            flex-direction: row;
            align-items: center;
            gap: 15px;
        }

        .control-group label {
            font-size: 13px;
            font-weight: 600;
            color: #2c3e50;
            white-space: nowrap;
        }

        .control-hint {
            font-size: 10px;
            color: #7f8c8d;
            font-weight: 400;
            font-style: italic;
            display: block;
        }

        .slider-container {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        input[type="range"] {
            width: 120px;
            height: 8px;
            border-radius: 4px;
            background: linear-gradient(to right, #e74c3c, #f39c12, #27ae60);
            outline: none;
            cursor: pointer;
        }

        input[type="range"]::-webkit-slider-thumb {
            appearance: none;
            width: 18px;
            height: 18px;
            border-radius: 50%;
            background: #3498db;
            cursor: pointer;
        }

        .control-group [title] {
            cursor: help;
        }

        .quick-demo-btn {
            background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
            color: white;
            border: none;
            padding: 10px 16px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 13px;
            font-weight: 600;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            white-space: nowrap;
        }

        .quick-demo-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(155, 89, 182, 0.4);
        }

        .valve-status {
            font-size: 12px;
            color: #7f8c8d;
            font-weight: 500;
            min-width: 60px;
            text-align: right;
        }

        .valve-status.open {
            color: #27ae60;
            font-weight: 700;
        }

        .action-btn {
            background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
            color: white;
            border: none;
            padding: 10px 16px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 13px;
            font-weight: 600;
            transition: all 0.3s ease;
            white-space: nowrap;
        }

        .action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(39, 174, 96, 0.4);
        }

        .action-btn:disabled {
            background: #95a5a6;
            cursor: not-allowed;
            transform: none;
        }

        .reset-btn {
            background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
        }

        .reset-btn:hover {
            box-shadow: 0 4px 15px rgba(231, 76, 60, 0.4);
        }

        /* Right Panel - Data & Graph */
        .data-panel {
            background: rgba(255,255,255,0.95);
            padding: 12px;
            overflow-y: auto;
            box-shadow: -2px 0 10px rgba(0,0,0,0.1);
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        .data-panel h3 {
            color: #2c3e50;
            font-size: 14px;
            font-weight: 600;
            border-bottom: 2px solid #3498db;
            padding-bottom: 10px;
        }

        #titrationPlot {
            width: 100%;
            height: 240px;
            border: 1px solid #ddd;
            border-radius: 6px;
            transition: height 0.4s ease;
            margin-bottom: 8px;
            position: relative;
            z-index: 1;
        }

        .plot-expanded #titrationPlot {
            height: 470px;
        }

        .data-panel > div:first-child {
            flex-shrink: 0;
        }

        .data-readout {
            background: #f8f9fa;
            padding: 10px;
            border-radius: 6px;
            border: 1px solid #dee2e6;
            transition: all 0.3s ease;
        }

        .plot-expanded .data-readout {
            display: none;
        }

        .expand-plot-btn {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 11px;
            font-weight: 600;
            transition: all 0.3s ease;
            margin-left: auto;
        }

        .expand-plot-btn:hover {
            transform: scale(1.05);
            box-shadow: 0 2px 8px rgba(52, 152, 219, 0.4);
        }

        .plot-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 8px;
        }

        .plot-header h3 {
            border-bottom: none;
            padding-bottom: 0;
            margin-bottom: 0;
        }

        .data-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 4px;
            padding: 4px 0;
            border-bottom: 1px solid #e9ecef;
            font-size: 12px;
        }

        .data-row:last-child {
            border-bottom: none;
        }

        .data-label {
            font-weight: 600;
            color: #495057;
            font-size: 11px;
        }

        .data-value {
            color: #3498db;
            font-weight: 700;
            font-size: 11px;
        }

        .indicator-status {
            background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
            color: white;
            padding: 5px 8px;
            border-radius: 6px;
            text-align: center;
            font-weight: 600;
            font-size: 10px;
            position: relative;
            z-index: 4;
            margin-top: 2px;
            align-self: flex-start;
            width: auto;
            max-width: 100%;
            line-height: 1.2;
        }

        .indicator-status.pink {
            background: linear-gradient(135deg, #e91e63 0%, #c2185b 100%);
        }

        .indicator-status.red {
            background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
        }

        .indicator-status.orange {
            background: linear-gradient(135deg, #f39c12 0%, #d35400 100%);
        }

        .indicator-status.yellow {
            background: linear-gradient(135deg, #f1c40f 0%, #f39c12 100%);
            color: #2c3e50;
        }

        .indicator-status.green {
            background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
        }

        .indicator-status.blue {
            background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
        }

        .indicator-status.purple {
            background: linear-gradient(135deg, #9b59b6 0%, #8e44ad 100%);
        }

        .equivalence-inline {
            display: none;
            font-size: 10px;
            font-weight: 600;
            color: #d35400;
            line-height: 1.2;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            flex: 1;
            min-width: 0;
        }

        .equivalence-inline.show {
            display: block;
        }

        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }

        /* Full Curve Section */
        .full-curve-section {
            margin-top: 6px;
            padding-top: 6px;
            border-top: 1px solid rgba(255,255,255,0.15);
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .full-curve-btn {
            width: auto;
            padding: 6px 10px;
            background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 11px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s ease;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            position: relative;
            z-index: 3;
            flex-shrink: 0;
        }

        .full-curve-btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(142,68,173,0.4);
        }

        .full-curve-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

        .curve-results {
            margin-top: 8px;
            padding: 8px;
            background: rgba(142,68,173,0.15);
            border-radius: 6px;
            border: 1px solid rgba(142,68,173,0.3);
            width: 100%;
        }

        .curve-results h4 {
            font-size: 11px;
            color: #9b59b6;
            margin: 0 0 6px 0;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        /* Advanced Options Toggle & Panel */
        .advanced-toggle {
            cursor: pointer;
            user-select: none;
            transition: color 0.2s;
        }

        .advanced-toggle:hover {
            color: #3498db;
        }

        .advanced-panel {
            padding-top: 6px;
        }

        .compact-pair-row {
            margin-bottom: 10px;
        }

        .compact-pair-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 6px;
        }

        .compact-pair-labels {
            margin-bottom: 4px;
        }

        .compact-pair-labels label {
            margin-bottom: 0;
            font-size: 12px;
        }

        .compact-pair-inputs .conc-input {
            width: 100%;
            box-sizing: border-box;
            text-align: center;
        }

        .stoich-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 6px;
            width: 100%;
        }

        .stoich-label-row {
            margin-bottom: 4px;
        }

        .stoich-grid-label {
            font-size: 11px;
            color: #7f8c8d;
            font-weight: 600;
        }

        .stoich-input-row .conc-input {
            width: 100%;
            box-sizing: border-box;
        }

        .derived-info {
            margin-top: 6px;
            padding: 6px 8px;
            background: rgba(52,152,219,0.1);
            border-radius: 4px;
            font-size: 10px;
            color: #3498db;
            line-height: 1.4;
        }

        .derived-info:empty {
            display: none;
        }

        .curve-note {
            margin-top: 8px;
            padding: 6px 8px;
            font-size: 10px;
            line-height: 1.35;
            color: #5d6d7e;
            background: rgba(149, 165, 166, 0.12);
            border-radius: 4px;
        }

        .advanced-actions-row {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 8px;
            margin-top: 8px;
        }

        .advanced-actions-row .action-btn,
        .advanced-actions-row .quick-demo-btn {
            width: 100%;
            padding: 8px 10px;
            font-size: 12px;
            justify-content: center;
        }

        .advanced-compare-btn {
            background: linear-gradient(135deg, #f39c12 0%, #d68910 100%);
        }

        .advanced-compare-btn:hover {
            box-shadow: 0 4px 15px rgba(243, 156, 18, 0.35);
        }

        /* Responsive Design */
        @media (max-width: 1200px) {
            .virtual-lab-container {
                grid-template-columns: 180px 1fr 280px;
            }
            
            #labCanvas {
                width: 100%;
                max-width: 600px;
                height: auto;
            }
        }

        /* Tablet Portrait */
        @media (max-width: 900px) {
            .virtual-lab-container {
                grid-template-columns: 1fr;
                grid-template-rows: auto auto auto auto;
                height: auto;
                min-height: calc(100vh - 74px);
                overflow-y: auto;
            }

            #virtual-lab-view {
                overflow-y: auto;
                height: auto;
            }

            .equipment-sidebar, .data-panel {
                max-height: 220px;
            }

            .controls-panel {
                flex-wrap: wrap;
                justify-content: center;
            }
            
            #labCanvas {
                width: 100%;
                max-width: 500px;
            }

            .lab-header h1 {
                font-size: 14px;
            }
        }

        /* Mobile Landscape & Small Tablets */
        @media (max-width: 768px) {
            .virtual-lab-container {
                grid-template-rows: auto auto auto auto;
            }

            .lab-header {
                padding: 0 10px;
                height: 30px;
            }

            .lab-header h1 {
                font-size: 12px;
            }

            .lab-header .back-btn {
                padding: 6px 12px;
                font-size: 12px;
            }

            .help-icon {
                width: 22px;
                height: 22px;
                font-size: 12px;
            }

            .quick-guide {
                padding: 10px 15px;
                flex-direction: column;
                gap: 10px;
            }

            .guide-steps {
                flex-direction: column;
                gap: 8px;
            }

            .guide-step {
                font-size: 12px;
            }

            .equipment-sidebar {
                padding: 8px;
            }

            .sidebar-section h3 {
                font-size: 12px;
            }

            .equipment-item, .reagent-item {
                padding: 6px 8px;
                font-size: 11px;
            }

            .equipment-icon {
                font-size: 16px;
            }

            .reagent-select {
                font-size: 12px;
                padding: 6px 8px;
            }

            .mode-btn {
                padding: 6px 8px;
                font-size: 11px;
            }

            .controls-panel {
                padding: 8px 10px;
                gap: 10px;
            }

            .control-group label {
                font-size: 11px;
            }

            input[type="range"] {
                width: 80px;
            }

            .action-btn, .reset-btn, .quick-demo-btn {
                padding: 8px 12px;
                font-size: 11px;
            }

            .data-panel {
                padding: 8px;
                gap: 8px;
            }

            #titrationPlot {
                height: 200px;
            }

            .data-row {
                font-size: 11px;
            }
        }

        /* Mobile Portrait - Primary Android Phone Optimization */
        @media (max-width: 480px) {
            #virtual-lab-view {
                overflow-y: auto;
                height: auto;
                min-height: calc(100vh - 50px);
                margin-top: -4px;
            }

            .virtual-lab-container {
                display: flex;
                flex-direction: column;
                height: auto;
                min-height: calc(100vh - 50px);
                gap: 0;
            }

            .lab-header {
                flex-shrink: 0;
                padding: 6px 8px;
                min-height: 30px;
                height: 30px;
            }

            .lab-header h1 {
                font-size: 10px;
                letter-spacing: 0.3px;
            }

            .lab-header .back-btn {
                padding: 5px 10px;
                font-size: 11px;
            }

            .help-icon {
                width: 20px;
                height: 20px;
                font-size: 11px;
                margin-left: 6px;
            }

            .quick-guide {
                padding: 8px 12px;
            }

            .guide-step {
                font-size: 11px;
                gap: 6px;
            }

            .guide-step-num {
                width: 20px;
                height: 20px;
                font-size: 10px;
            }

            /* Equipment Sidebar - Collapsible on Mobile */
            .equipment-sidebar {
                order: 2;
                max-height: none;
                padding: 10px;
                overflow-y: visible;
            }

            .sidebar-section {
                margin-bottom: 10px;
            }

            .sidebar-section h3 {
                font-size: 11px;
                padding-bottom: 4px;
                margin-bottom: 6px;
            }

            .equipment-item, .reagent-item {
                padding: 8px;
                font-size: 12px;
                gap: 8px;
            }

            .equipment-icon {
                font-size: 18px;
            }

            .reagent-row {
                margin-bottom: 8px;
            }

            .reagent-row label {
                font-size: 11px;
                margin-bottom: 4px;
            }

            .reagent-select-group {
                flex-wrap: wrap;
            }

            .reagent-select {
                font-size: 14px; /* Larger for touch */
                padding: 10px 8px;
                min-height: 44px; /* Touch-friendly height */
            }

            .compact-pair-grid {
                gap: 8px;
            }

            .conc-input {
                width: 55px;
                padding: 10px 6px;
                font-size: 14px;
                min-height: 44px;
            }

            .advanced-actions-row {
                gap: 10px;
            }

            .advanced-actions-row .action-btn,
            .advanced-actions-row .quick-demo-btn {
                min-height: 44px;
                font-size: 13px;
            }

            .mode-toggle-group {
                flex-direction: column;
                gap: 6px;
            }

            .mode-btn {
                padding: 10px 12px;
                font-size: 12px;
                min-height: 44px;
            }

            .indicator-toggle {
                padding: 10px;
                font-size: 12px;
                min-height: 44px;
            }

            /* Workbench Area */
            .workbench {
                order: 3;
                padding: 8px;
                min-height: 280px;
            }

            #labCanvas {
                width: 100%;
                max-width: 320px;
                height: auto;
                touch-action: manipulation;
            }

            .controls-panel {
                flex-direction: column;
                width: 100%;
                padding: 10px;
                gap: 12px;
            }

            .control-group {
                width: 100%;
            }

            .control-group.horizontal {
                flex-direction: column;
                align-items: stretch;
                gap: 8px;
            }

            .slider-container {
                width: 100%;
                justify-content: space-between;
            }

            input[type="range"] {
                flex: 1;
                width: auto;
                height: 12px; /* Larger touch target */
            }

            input[type="range"]::-webkit-slider-thumb {
                width: 24px;
                height: 24px;
            }

            .action-btn, .reset-btn, .quick-demo-btn {
                width: 100%;
                padding: 12px 16px;
                font-size: 14px;
                min-height: 48px;
                justify-content: center;
            }

            .valve-status {
                text-align: center;
                width: 100%;
            }

            /* Data Panel */
            .data-panel {
                order: 4;
                padding: 10px;
                gap: 10px;
            }

            .data-panel h3 {
                font-size: 13px;
            }

            #titrationPlot {
                height: 180px;
                min-height: 180px;
            }

            .data-readout {
                padding: 8px;
            }

            .data-row {
                padding: 6px 0;
                font-size: 12px;
            }

            .data-label, .data-value {
                font-size: 12px;
            }

            .indicator-status {
                padding: 10px;
                font-size: 12px;
            }

            .equivalence-alert {
                padding: 10px;
                font-size: 12px;
            }

            /* Better touch targets for buttons */
            button, .equipment-item, .reagent-item, select, input {
                -webkit-tap-highlight-color: rgba(52, 152, 219, 0.3);
            }

            /* Prevent zoom on double-tap */
            * {
                touch-action: manipulation;
            }
        }

        /* Very Small Screens (older phones) */
        @media (max-width: 360px) {
            .lab-header h1 {
                font-size: 10px;
            }

            .lab-header .back-btn {
                padding: 4px 8px;
                font-size: 10px;
            }

            .equipment-item, .reagent-item {
                font-size: 11px;
            }

            #labCanvas {
                max-width: 280px;
            }

            #titrationPlot {
                height: 160px;
            }
        }

        /* Landscape mode optimization for phones */
        @media (max-width: 900px) and (orientation: landscape) {
            .virtual-lab-container {
                display: grid;
                grid-template-columns: 200px 1fr;
                grid-template-rows: auto;
                height: calc(100vh - 90px);
                overflow: hidden;
            }

            .equipment-sidebar {
                grid-row: 2;
                max-height: none;
                overflow-y: auto;
            }

            .workbench {
                grid-row: 2;
            }

            .data-panel {
                display: none; /* Hide on landscape to save space, or make it a toggle */
            }

            #labCanvas {
                max-width: 400px;
            }
        }

        /* High DPI / Retina displays */
        @media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
            .equipment-icon {
                image-rendering: -webkit-optimize-contrast;
            }
        }

        /* Accessibility - Reduced Motion */
        @media (prefers-reduced-motion: reduce) {
            *, *::before, *::after {
                animation-duration: 0.01ms !important;
                animation-iteration-count: 1 !important;
                transition-duration: 0.01ms !important;
            }
        }

        /* Dark mode support for OLED screens (battery saving) */
        @media (prefers-color-scheme: dark) {
            #virtual-lab-view {
                background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            }
        }
