/* CSS variables for Theme Management */
:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --primary-gradient: linear-gradient(135deg, #667eea, #764ba2);
    
    /* Card Gradients */
    --grad-3d: linear-gradient(135deg, #4fc3f7, #29b6f6);
    --grad-live: linear-gradient(135deg, #ffb74d, #ffa726);
    --grad-pin: linear-gradient(135deg, #81c784, #66bb6a);
    --grad-files: linear-gradient(135deg, #b39ddb, #9575cd);
    
    /* Default Dark Mode Values */
    --bg-color: #1a1a2e;
    --surface-color: rgba(255, 255, 255, 0.05);
    --surface-border: rgba(255, 255, 255, 0.1);
    --surface-shadow: rgba(0, 0, 0, 0.3);
    --text-color: #ffffff;
    --text-secondary: #8c8c9e;
    --grid-unread: #2a2a40;
    --grid-unread-border: rgba(255, 255, 255, 0.05);
    --input-bg: rgba(255, 255, 255, 0.08);
}

body.light-mode {
    --bg-color: #f0f2f5;
    --surface-color: rgba(255, 255, 255, 0.85);
    --surface-border: rgba(0, 0, 0, 0.15);
    --surface-shadow: rgba(0, 0, 0, 0.1);
    --text-color: #1a1a2e;
    --text-secondary: #606070;
    --grid-unread: #e0e4eb;
    --grid-unread-border: rgba(0, 0, 0, 0.08);
    --input-bg: rgba(0, 0, 0, 0.05);
}

/* Base resets & typography */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

#app-container {
    width: 100%;
    max-width: 1200px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    padding-bottom: 75px; /* space for bottom nav */
}

/* Header style */
#main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--surface-color);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--surface-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo h1 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(90deg, #a5b4fc, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    background: rgba(0,0,0,0.2);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid var(--surface-border);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background-color: #00e676;
    box-shadow: 0 0 8px #00e676;
}

.status-dot.disconnected {
    background-color: #ff3d00;
    box-shadow: 0 0 8px #ff3d00;
}

/* Main content container */
#main-content {
    flex: 1;
    padding: 20px;
    position: relative;
}

/* SPA Page views styling */
.app-page {
    display: none;
    animation: fadeIn 0.3s ease-in-out forwards;
    width: 100%;
}

.app-page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
}

/* Welcome Banner */
.welcome-banner {
    background: var(--surface-color);
    border: 1px solid var(--surface-border);
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 25px;
    box-shadow: 0 4px 15px var(--surface-shadow);
    text-align: center;
}

.welcome-banner h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.welcome-banner p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Dashboard cards */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

.dashboard-card {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 20px;
    border-radius: 15px;
    color: white;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.dashboard-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.25);
}

.dashboard-card:active {
    transform: scale(0.97);
}

.card-3d-scan { background: var(--grad-3d); }
.card-live-scan { background: var(--grad-live); }
.card-pin-pointer { background: var(--grad-pin); }
.card-scan-files { background: var(--grad-files); }

.card-icon-wrapper {
    background: rgba(255, 255, 255, 0.15);
    padding: 12px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-info h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 5px;
}

.card-info p {
    font-size: 12px;
    opacity: 0.9;
}

/* Glassmorphism panels */
.glass-panel {
    background: var(--surface-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--surface-border);
    border-radius: 18px;
    padding: 20px;
    box-shadow: 0 8px 30px var(--surface-shadow);
    margin-bottom: 20px;
}

/* Form & Input controls */
.settings-group {
    margin-bottom: 20px;
}

.settings-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--text-color);
}

/* Custom Radio Toggle Buttons */
.radio-toggle {
    display: flex;
    background: var(--input-bg);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--surface-border);
}

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

.radio-toggle label {
    flex: 1;
    text-align: center;
    padding: 10px 5px;
    margin-bottom: 0;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.radio-toggle input[type="radio"]:checked + label {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.4);
}

/* Circular Counters */
.dimensions-inputs {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    flex-wrap: wrap; /* wrap on very small screens */
}

.dimension-box {
    flex: 1;
    min-width: 130px; /* prevent shrinking too far */
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    padding: 10px 8px;
    border-radius: 15px;
}

.dim-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-align: center;
    line-height: 1.3;
}

.counter-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-counter {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--surface-border);
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    touch-action: manipulation;
}

.btn-counter:hover {
    background: var(--primary-color);
    color: white;
}

.btn-counter:active {
    transform: scale(0.88);
    background: var(--primary-color);
    color: white;
}

.counter-val {
    font-size: 22px;
    font-weight: 700;
    min-width: 28px;
    text-align: center;
    font-family: monospace;
}

/* Action Button styling */
.btn-action {
    display: block;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    color: white;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.btn-action:hover {
    transform: translateY(-2px);
}

.btn-action:active {
    transform: scale(0.98);
}

.primary-gradient {
    background: var(--primary-gradient);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.primary-gradient:hover {
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--surface-border);
    color: var(--text-color);
}

.secondary-btn:hover {
    background: var(--surface-color);
}

/* Custom Select Dropdown */
.styled-select {
    display: block;
    width: 100%;
    padding: 12px;
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    color: var(--text-color);
    border-radius: 12px;
    font-size: 14px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.styled-select:focus {
    border-color: var(--primary-color);
}

/* Scan page details */
.scan-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.scan-meta {
    font-family: monospace;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    gap: 15px;
    background: rgba(0,0,0,0.2);
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--surface-border);
}

.grid-outer-container {
    width: 100%;
    overflow: auto; /* both axes */
    background: rgba(0, 0, 0, 0.15);
    border-radius: 15px;
    padding: 15px;
    border: 1px solid var(--surface-border);
    display: grid;
    place-items: safe center;
    place-content: safe center;
    min-height: 250px;
    max-height: calc(100vh - 320px); /* limit height to viewport so cell stays visible */
    margin-bottom: 25px;
    -webkit-overflow-scrolling: touch; /* smooth momentum scroll on iOS */
    scroll-behavior: smooth;
    cursor: grab;
    user-select: none;
    direction: ltr; /* Force LTR scroll coordinates to align with scan-grid and fix auto-scroll direction */
}

.grid-outer-container.dragging {
    cursor: grabbing;
    scroll-behavior: auto; /* disable smooth scroll during drag */
}

.scan-grid {
    display: grid;
    gap: 4px;
    margin: auto;
    direction: ltr; /* always LTR so column 0 = physical left regardless of page RTL */
}

.grid-cell {
    background: var(--grid-unread);
    border: 1px solid var(--grid-unread-border);
    border-radius: 6px;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    font-family: monospace;
    color: rgba(255,255,255,0.7);
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
    cursor: default;
    user-select: none;
}

.grid-cell.active {
    border: 2px solid var(--primary-color);
    box-shadow: 0 0 12px var(--primary-color);
    z-index: 5;
    animation: activeGlow 1.5s infinite alternate;
}

@keyframes activeGlow {
    0% { box-shadow: 0 0 5px var(--primary-color); }
    100% { box-shadow: 0 0 18px var(--primary-color); }
}

.grid-cell.read {
    border-color: rgba(0,0,0,0.15);
}

/* Floating Action Button */
.fab-btn {
    position: fixed;
    bottom: 90px;
    right: 25px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
    z-index: 90;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: fabPulse 2s infinite;
}

.fab-btn:hover {
    transform: scale(1.05);
}

.fab-btn:active {
    transform: scale(0.92);
}

@keyframes fabPulse {
    0% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(102, 126, 234, 0); }
    100% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0); }
}

.post-scan-actions {
    margin-top: 25px;
    animation: slideUp 0.3s ease forwards;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.post-scan-actions h3 {
    text-align: center;
    color: #00e676;
    margin-bottom: 15px;
}

.post-scan-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 20px;
}

.post-scan-row label {
    font-size: 14px;
    font-weight: 600;
}

.action-buttons-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Live scan page details */
.live-background-container {
    width: 100%;
    min-height: calc(100vh - 180px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    transition: background 0.3s ease;
    padding: 10px;
    /* Force dark theme properties inside the live scan area so that colors pop in light mode */
    background-color: #0b0f19;
    color: #ffffff;
    --text-color: #ffffff;
    --text-secondary: #8c8c9e;
    --surface-color: rgba(255, 255, 255, 0.05);
    --surface-border: rgba(255, 255, 255, 0.1);
    --surface-shadow: rgba(0, 0, 0, 0.3);
    --input-bg: rgba(255, 255, 255, 0.08);
}

.live-scan-card {
    width: 100%;
    max-width: 400px;
}

.value-display-large {
    font-size: 64px;
    font-weight: 800;
    font-family: monospace;
    margin: 20px 0;
    text-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.calibrated-status {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.live-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.btn-circle-control {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 1px solid var(--surface-border);
    background: var(--input-bg);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-circle-control:hover {
    background: var(--surface-color);
}

.btn-circle-control.sound-off {
    color: #ff3d00;
    border-color: rgba(255, 61, 0, 0.4);
}

.btn-circle-control.sensitive-on {
    color: #a855f7;
    border-color: rgba(168, 85, 247, 0.4);
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.2) inset, 0 0 10px rgba(168, 85, 247, 0.15);
}

/* Pin pointer page elements */
.pin-pointer-container {
    width: 100%;
    max-width: 450px;
    margin: auto;
    padding: 30px 20px;
}

/* Circular Gauge Visual */
.gauge-wrapper {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.gauge {
    position: relative;
    width: 250px;
    height: 125px; /* half circle */
    overflow: hidden;
}

.gauge-arc {
    width: 250px;
    height: 250px;
    border-radius: 50%;
    background: conic-gradient(
        from 180deg at 50% 50%,
        #0000ff 0deg,
        #00ffff 45deg,
        #00ad00 90deg,
        #ffff00 135deg,
        #ff0000 180deg
    );
    transform: rotate(90deg);
    mask: radial-gradient(circle, transparent 65%, black 66%);
    -webkit-mask: radial-gradient(circle, transparent 65%, black 66%);
}

.gauge-labels {
    position: absolute;
    width: 100%;
    bottom: 5px;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-color);
    direction: ltr;
}

.label-cavity {
    color: #3b82f6; /* Blue */
}
.label-neutral {
    color: #10b981; /* Green */
}
.label-metal {
    color: #ef4444; /* Red */
}

.gauge-needle {
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 4px;
    height: 100px;
    background: #ffffff;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
    border-radius: 4px 4px 0 0;
    transform-origin: bottom center;
    transform: translateX(-50%) rotate(0deg); /* 0deg is neutral center (straight up) */
    transition: transform 0.15s cubic-bezier(0.1, 0.8, 0.3, 1);
    z-index: 10;
}

.gauge-center {
    position: absolute;
    bottom: -15px;
    left: 50%;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--text-color);
    transform: translateX(-50%);
    z-index: 15;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

/* Modern Range Slider for Calibration */
.modern-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    transition: all 0.2s ease;
}

/* Chrome/Safari/Webkit Thumb */
.modern-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.5), 0 0 0 3px var(--primary-color);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.modern-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.6), 0 0 0 4px var(--primary-color);
}

.modern-slider::-webkit-slider-thumb:active {
    transform: scale(0.92);
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.4), 0 0 0 2px var(--primary-color);
}

/* Firefox Thumb */
.modern-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.5), 0 0 0 3px var(--primary-color);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.modern-slider::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.6), 0 0 0 4px var(--primary-color);
}

.modern-slider::-moz-range-thumb:active {
    transform: scale(0.92);
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.4), 0 0 0 2px var(--primary-color);
}

/* Reset Calibration Button */
.reset-calib-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    color: var(--text-secondary);
    margin-top: 10px;
    font-size: 13px;
    padding: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 10px;
    transition: all 0.25s ease;
    width: 100%;
}

.reset-calib-btn:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
    transform: translateY(-1px);
}

.reset-calib-btn:active {
    transform: scale(0.98);
}

/* 3D WebGL Viewer Page Layout */
.viewer-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.three-container {
    width: 100%;
    height: 350px;
    background-color: #0b0b16;
    border-radius: 18px;
    border: 1px solid var(--surface-border);
    position: relative;
    overflow: hidden;
}

.viewer-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.control-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-row label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
}

.control-row-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    background: rgba(0,0,0,0.15);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--surface-border);
}

.stat-item {
    font-size: 11px;
    color: var(--text-secondary);
}

.stat-item span {
    font-family: monospace;
    font-weight: 700;
    color: var(--text-color);
}

.checkbox-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Custom Checkbox */
.custom-checkbox {
    display: flex;
    align-items: center;
    position: relative;
    padding-right: 30px;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
    min-height: 20px;
}

/* Hide original browser checkbox */
.custom-checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

/* Custom checkmark circle */
.checkmark {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    height: 20px;
    width: 20px;
    background-color: var(--input-bg);
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.custom-checkbox:hover input ~ .checkmark {
    background-color: var(--surface-color);
}

.custom-checkbox input:checked ~ .checkmark {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Add checkmark icon */
.checkmark:after {
    content: "";
    position: absolute;
    display: none;
}

.custom-checkbox input:checked ~ .checkmark:after {
    display: block;
}

.custom-checkbox .checkmark:after {
    left: 7px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* Align checkbox checkmark in English mode (left to right) */
html[dir="ltr"] .custom-checkbox {
    padding-right: 0;
    padding-left: 30px;
}
html[dir="ltr"] .checkmark {
    right: auto;
    left: 0;
}

/* Color Ramp Legend at bottom */
.color-ramp-wrapper {
    margin-top: 15px;
    padding: 12px;
}

.color-ramp-bar {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #0000ff, #00ffff, #00ad00, #ffff00, #ff0000);
    margin-bottom: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.color-ramp-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-secondary);
    font-weight: 600;
    direction: ltr !important;
}

/* Settings Form styles */
.settings-divider {
    height: 1px;
    background: var(--surface-border);
    margin: 25px 0;
}

h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 15px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 600;
}

.form-group input {
    width: 100%;
    padding: 12px;
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    color: var(--text-color);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary-color);
}

/* Files Upload View */
.file-upload-zone {
    border: 2px dashed var(--surface-border);
    border-radius: 15px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    background: rgba(0,0,0,0.1);
}

.file-upload-zone:hover {
    border-color: var(--primary-color);
    background: rgba(102, 126, 234, 0.05);
}

.file-upload-zone svg {
    color: var(--text-secondary);
    transition: color 0.2s;
}

.file-upload-zone:hover svg {
    color: var(--primary-color);
}

.file-upload-zone p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.files-list-header {
    margin: 25px 0 10px 0;
}

.files-list-header h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-color);
}

.local-scans-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.no-files {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 20px;
}

.file-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    padding: 10px 15px;
}

.file-item-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.file-item-name {
    font-size: 13px;
    font-weight: 700;
}

.file-item-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

.file-item-actions {
    display: flex;
    gap: 8px;
}

.btn-file-action {
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-file-load {
    background: var(--primary-color);
    color: white;
}

.btn-file-delete {
    background: rgba(255, 61, 0, 0.1);
    color: #ff3d00;
}

.btn-file-delete:hover {
    background: #ff3d00;
    color: white;
}

/* Bottom Navigation Bar */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 1200px;
    height: 65px;
    background: var(--surface-color);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-top: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 99;
}

.nav-item {
    flex: 1;
    height: 100%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 600;
    transition: color 0.2s ease, transform 0.2s;
}

.nav-item svg {
    transition: stroke 0.2s ease, transform 0.2s;
}

.nav-item:hover {
    color: var(--text-color);
}

.nav-item:active {
    transform: scale(0.95);
}

.nav-item.active {
    color: var(--primary-color);
}

.nav-item.active svg {
    stroke: var(--primary-color);
    transform: scale(1.1);
}

/* Notifications / Toast alert */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: rgba(10, 10, 20, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--primary-color);
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    opacity: 1;
    pointer-events: none;
    text-align: center;
}

.toast.hidden {
    transform: translateX(-50%) translateY(30px);
    opacity: 0;
}

/* Micro-animations */
.pulse-icon {
    animation: pulseGlow 2.5s infinite;
}

@keyframes pulseGlow {
    0% { transform: scale(1); filter: drop-shadow(0 0 1px var(--primary-color)); }
    50% { transform: scale(1.05); filter: drop-shadow(0 0 8px var(--primary-color)); }
    100% { transform: scale(1); filter: drop-shadow(0 0 1px var(--primary-color)); }
}

.text-center {
    text-align: center;
}

.hidden {
    display: none !important;
}

/* Language Alignment Overrides */
html[dir="rtl"] {
    text-align: right;
}

html[dir="ltr"] {
    text-align: left;
}

/* RESPONSIVE BREAKPOINTS */

/* Tablet and larger screens */
@media (min-width: 768px) {
    #main-content {
        padding: 30px;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
    
    .viewer-panel {
        flex-direction: row;
        gap: 20px;
    }
    
    .three-container {
        flex: 2;
        height: 450px;
    }
    
    .viewer-controls {
        flex: 1;
        justify-content: flex-start;
    }
    
    .page-title {
        font-size: 26px;
    }
}

/* Desktop and wide screens */
@media (min-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .three-container {
        height: 500px;
    }
    
    #app-container {
        border-left: 1px solid var(--surface-border);
        border-right: 1px solid var(--surface-border);
        box-shadow: 0 0 50px rgba(0,0,0,0.5);
    }
}

/* ===== Small mobile screens (max-width: 400px) ===== */
@media (max-width: 400px) {
    #main-content {
        padding: 12px;
    }

    .glass-panel {
        padding: 14px;
        border-radius: 14px;
    }

    .page-title {
        font-size: 18px;
        margin-bottom: 14px;
    }

    /* Scan settings: make dimensions inputs stack vertically if screen too narrow */
    .dimensions-inputs {
        flex-direction: column;
        gap: 10px;
    }

    .dimension-box {
        min-width: unset;
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        padding: 10px 14px;
    }

    .dim-label {
        margin-bottom: 0;
        font-size: 12px;
    }

    .counter-control {
        gap: 12px;
    }

    .btn-counter {
        width: 38px;
        height: 38px;
        font-size: 22px;
    }

    .counter-val {
        font-size: 20px;
        min-width: 30px;
    }

    /* Scan grid: tighten padding on mobile */
    .grid-outer-container {
        padding: 8px;
        max-height: calc(100vh - 280px);
    }

    .scan-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .scan-meta {
        font-size: 12px;
        gap: 8px;
    }

    /* FAB button position on small screens */
    .fab-btn {
        width: 62px;
        height: 62px;
        bottom: 85px;
        right: 15px;
    }

    /* Radio toggle compact */
    .radio-toggle label {
        padding: 8px 3px;
        font-size: 12px;
    }
}

/* 2D Grid Mode Toggles */
.grid-view-toggles {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.btn-grid-toggle {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--surface-border);
    color: var(--text-secondary);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-grid-toggle svg {
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-grid-toggle:hover {
    background: var(--surface-color);
    color: var(--text-color);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-grid-toggle.active {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-grid-toggle.active svg {
    opacity: 1;
}

/* Advanced Analysis CSS */
.analysis-section {
    animation: slideUp 0.4s ease forwards;
}

.analysis-banner {
    padding: 15px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 14px;
    text-align: center;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    line-height: 1.4;
}

/* Class 1 styling: Gold/flashing red */
.banner-class-1 {
    background: rgba(212, 175, 55, 0.1);
    border-color: rgba(212, 175, 55, 0.4);
    color: #ffd700;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.2);
    animation: goldPulse 2s infinite alternate;
}

@keyframes goldPulse {
    0% { box-shadow: 0 0 5px rgba(212, 175, 55, 0.2); border-color: rgba(212, 175, 55, 0.3); }
    100% { box-shadow: 0 0 20px rgba(212, 175, 55, 0.5); border-color: rgba(212, 175, 55, 0.8); }
}

/* Class 2 styling: Orange */
.banner-class-2 {
    background: rgba(255, 152, 0, 0.1);
    border-color: rgba(255, 152, 0, 0.4);
    color: #ffb74d;
}

/* Class 3 styling: Grey */
.banner-class-3 {
    background: rgba(158, 158, 158, 0.08);
    border-color: rgba(158, 158, 158, 0.25);
    color: #b0bec5;
}

.anomaly-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    padding: 12px 15px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.anomaly-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 13px;
}

.anomaly-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.anomaly-action {
    font-size: 11px;
    color: #81c784;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
}

.metric-item {
    margin-bottom: 15px;
}

.metric-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
}

.metric-bar-outer {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.metric-bar-inner {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: 3px;
    transition: width 0.5s ease-out;
}

.warning-box {
    background: rgba(239, 68, 68, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 10px;
    padding: 12px;
    font-size: 12px;
    line-height: 1.5;
    color: #fca5a5;
}

.warning-box.gas-warning {
    background: rgba(255, 152, 0, 0.05);
    border-color: rgba(255, 152, 0, 0.2);
    color: #ffcc80;
}

.warning-box.legal-warning {
    background: rgba(33, 150, 243, 0.05);
    border-color: rgba(33, 150, 243, 0.2);
    color: #90caf9;
}

@media (min-width: 768px) {
    .analysis-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}


/* Sensitive mode active value styling (purple glow) */
.value-display-large.sensitive-active {
    color: #c084fc !important;
    text-shadow: 0 0 20px rgba(168, 85, 247, 0.8) !important;
    opacity: 0.95 !important;
}

/* 3D Scan Mode Tabs styling */
.scan-tab-btn {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
}

.scan-tab-btn.active {
    background: var(--primary-gradient) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

/* Pulsing red animation for active column recording */
@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.btn-pulse-active {
    background: #ef4444 !important;
    color: #ffffff !important;
    border-color: #ef4444 !important;
    animation: pulse-red 1.5s infinite;
}
