/* ============================================
   VIEWER & MODALS STYLES
   3D Model Viewer, Forms, Modals (Camera Scan, Reflect Upload, Measurements)
   Shared across viewer.html and index.html (for modals)
   ============================================ */

/* Z-Index Hierarchy */
:root {
    --z-background: 0;
    --z-content: 10;
    --z-ui-elements: 100;
    --z-controls: 200;
    --z-modals: 1000;
    --z-tooltips: 2000;
    --z-errors: 9999;
}

body {
    margin: 0;
    overflow: hidden;
    background-color: #000;
    font-family: Arial, sans-serif;
}

canvas {
    display: block;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 1.2em;
    text-shadow: 0 0 10px rgba(0, 128, 255, 0.8);
}

#error {
    position: absolute;
    bottom: 10px;
    right: 10px;
    color: #ff4444;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 5px;
    font-family: sans-serif;
    display: none;
    z-index: var(--z-errors);
}

#controls-panel {
    position: absolute;
    top: 70px;
    right: 15px;
    background: rgba(0, 0, 0, 0.7);
    padding: 12px;
    border-radius: 12px;
    color: white;
    z-index: var(--z-controls);
    min-width: 120px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.control-group {
    margin-bottom: 12px;
}

.control-title {
    font-weight: bold;
    margin-bottom: 5px;
    color: #4da6ff;
}

button {
    background: #2c7bb6;
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    margin: 2px;
    transition: background 0.2s;
}

button:hover {
    background: #3498db;
}

button.active {
    background: #1e5799;
    box-shadow: 0 0 5px #4da6ff;
}

#model-info {
    position: absolute;
    bottom: 15px;
    right: 15px;
    background: transparent;
    padding: 0;
    border-radius: 8px;
    color: white;
    z-index: var(--z-ui-elements);
    max-width: 300px;
}

#back-button {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    z-index: var(--z-ui-elements);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#back-button:hover {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.9);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.4);
}

#back-button:active {
    transform: scale(1.05);
    transition: all 0.1s ease;
}

#logo {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 1.5em;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(0, 128, 255, 0.8);
    z-index: var(--z-ui-elements);
    white-space: nowrap;
    max-width: calc(100vw - 140px); /* Leave space for back button and logo */
    overflow: hidden;
    text-overflow: ellipsis;
}


#reflect-upload-button {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    border: none;
    padding: 16px 24px;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(17, 153, 142, 0.4);
    transition: all 0.3s ease;
    z-index: var(--z-ui-elements);
    display: none;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

#reflect-upload-button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 15px 35px rgba(17, 153, 142, 0.6);
    background: linear-gradient(135deg, #38ef7d 0%, #11998e 100%);
    border-color: rgba(255, 255, 255, 0.2);
}

#reflect-upload-button:active {
    transform: translateY(-1px) scale(1.02);
    transition: all 0.1s ease;
}

.modal {
    display: none;
    position: fixed;
    z-index: var(--z-modals);
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    margin: 5% auto;
    padding: 30px;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    color: white;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 2px solid #3498db;
}

.modal-title {
    font-size: 1.8em;
    font-weight: bold;
    color: #3498db;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close:hover {
    color: #fff;
}

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

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #ecf0f1;
    font-size: 15px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #34495e;
    border-radius: 10px;
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
    color: white;
    font-size: 15px;
    box-sizing: border-box;
    transition: all 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.4);
    transform: translateY(-1px);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    margin-bottom: 15px;
}

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

.height-picker {
    background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
    border-radius: 15px;
    padding: 25px;
    border: 2px solid #34495e;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
}

.height-picker label {
    text-align: center;
    margin-bottom: 20px;
    font-size: 16px;
    color: #3498db;
    font-weight: 600;
}

.height-display {
    text-align: center;
    font-size: 2.5em;
    font-weight: bold;
    color: #ecf0f1;
    margin: 20px 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.height-slider {
    width: 100%;
    height: 8px;
    border-radius: 5px;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    outline: none;
    -webkit-appearance: none;
    margin: 20px 0;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.height-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3498db, #2ecc71);
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.height-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.height-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3498db, #2ecc71);
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.height-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.height-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.height-btn {
    background: linear-gradient(135deg, #34495e, #2c3e50);
    color: white;
    border: 2px solid #3498db;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.height-btn:hover {
    background: linear-gradient(135deg, #3498db, #2ecc71);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.required {
    color: #e74c3c;
    font-weight: bold;
}

.submit-btn {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    border: none;
    padding: 18px 32px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.3s ease;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.3);
}

.submit-btn:hover {
    background: linear-gradient(135deg, #5dade2, #3498db);
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(52, 152, 219, 0.4);
}

.submit-btn:disabled {
    background: #7f8c8d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: linear-gradient(135deg, #34495e, #2c3e50);
    border-radius: 10px;
    overflow: hidden;
    margin: 20px 0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3498db, #2ecc71);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 10px;
}

.results-panel {
    position: absolute;
    bottom: 80px;
    left: 20px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    border-radius: 12px;
    padding: 16px;
    z-index: var(--z-ui-elements);
    min-width: 280px;
    max-width: calc(100vw - 40px);
    display: none;
    text-align: left;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.results-panel h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #4da6ff;
}

.results-panel .status {
    font-size: 12px;
    color: #ddd;
    margin-bottom: 8px;
}

.measurements-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    transition: all 0.3s ease;
    margin-top: 8px;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    display: none;
}

.measurements-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.measurements-btn:active {
    transform: translateY(0);
    transition: all 0.1s ease;
}

.measurements-modal-content {
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    #back-button {
        top: 10px;
        left: 10px;
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    #logo {
        top: 10px;
        font-size: 1.1em;
        max-width: calc(100vw - 120px); /* Adjust for mobile */
    }
    
    #model-info {
        top: auto !important;     /* Override any top positioning */
        bottom: 15px !important;
        right: 10px;
        z-index: var(--z-ui-elements);
    }
    
    #controls-panel {
        top: 60px;
        right: 10px;
        min-width: 100px;
        padding: 8px;
    }
    
    #reflect-upload-button {
        bottom: 20px;
        left: 15px;
        padding: 14px 20px;
        font-size: 14px;
        max-width: calc(50vw - 25px); /* Half screen width, leave space for FIT:MATCH logo */
    }
    
    .results-panel {
        bottom: 80px;
        left: 15px;
        padding: 12px;
        min-width: 260px;
        max-width: calc(100vw - 30px);
    }
    
    .results-panel h3 {
        font-size: 14px;
        margin-bottom: 6px;
    }
    
    .results-panel .status {
        font-size: 11px;
        margin-bottom: 6px;
    }
    
    .measurements-btn {
        padding: 10px 16px;
        font-size: 12px;
        width: 100%;
    }
    
    #model-info {
        top: 10px;
        right: 10px;
    }
    
    #model-info img {
        height: 14px !important;
    }
}

/* Mobile Form Styles */
@media (max-width: 768px) {
    .modal-content {
        position: absolute;
        top: 4vh;              /* Smaller padding on all sides */
        left: 4vw;
        right: 4vw;
        bottom: 4vh;
        width: auto;
        height: auto;
        max-width: none;
        max-height: none;
        margin: 0;
        padding: 20px;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        overflow-y: auto;
    }
    
    .modal-header {
        margin-bottom: 20px;
        padding-bottom: 12px;
    }
    
    .modal-title {
        font-size: 1.4em;
    }
    
    .close {
        font-size: 32px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .form-group {
        margin-bottom: 12px;
    }
    
    .form-group label {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .form-group input,
    .form-group select {
        padding: 12px 14px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    .height-picker {
        padding: 20px;
    }
    
    .height-display {
        font-size: 2.5em;
        margin-bottom: 15px;
    }
    
    .height-slider {
        margin: 15px 0;
    }
    
    .height-buttons {
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .height-btn {
        padding: 12px 16px;
        font-size: 14px;
        min-width: 60px;
    }
    
    .submit-btn {
        padding: 14px 24px;
        font-size: 15px;
        margin-top: 20px;
    }
}

@media (max-width: 375px) {
    #back-button {
        width: 36px;
        height: 36px;
        font-size: 16px;
        top: 8px;
        left: 8px;
    }
    
    #logo {
        font-size: 1em;
        top: 8px;
        max-width: calc(100vw - 100px); /* Even tighter on small screens */
    }
    
    #model-info {
        top: auto !important;     /* Override any top positioning */
        bottom: 15px !important;
        right: 8px;
    }
    
    #controls-panel {
        top: 50px;
        right: 8px;
        min-width: 90px;
        padding: 6px;
    }
    
    #reflect-upload-button {
        padding: 12px 18px;
        font-size: 13px;
        bottom: 20px;
        left: 10px;
        max-width: calc(50vw - 20px); /* Half screen width, leave space for FIT:MATCH logo */
    }
    
    .results-panel {
        bottom: 75px;
        left: 10px;
        padding: 10px;
        min-width: 240px;
        max-width: calc(100vw - 20px);
    }
    
    .results-panel h3 {
        font-size: 13px;
    }
    
    .measurements-btn {
        padding: 8px 14px;
        font-size: 11px;
    }
    
    /* Form adjustments for very small screens */
    .modal-content {
        top: 4vh;              /* Small padding on all sides */
        left: 4vw;
        right: 4vw;
        bottom: 4vh;
        padding: 15px;
    }
    
    .modal-title {
        font-size: 1.2em;
    }
    
    .height-picker {
        padding: 15px;
    }
    
    .height-display {
        font-size: 2em;
    }
    
    .height-btn {
        padding: 10px 12px;
        font-size: 13px;
        min-width: 55px;
    }
    
    .submit-btn {
        padding: 12px 20px;
        font-size: 14px;
    }
}

.measurements-content {
    padding: 20px 0;
}

.measurements-table-container {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    border-radius: 15px;
    padding: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.measurements-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    color: white;
}

.measurements-table th {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    border-radius: 8px 8px 0 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 13px;
}

.measurements-table td {
    padding: 10px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: background 0.2s ease;
}

.measurements-table tr:hover td {
    background: rgba(52, 152, 219, 0.1);
}

.measurements-table td:first-child {
    color: #9ecbff;
    font-weight: 600;
    width: 60%;
}

.measurements-table td:last-child {
    color: #ecf0f1;
    text-align: right;
    font-weight: 500;
}

.measurements-table tr.section-header th {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: #3498db;
    font-size: 16px;
    padding: 15px;
    text-align: center;
    border-radius: 8px;
    margin: 10px 0;
}

/* Custom scrollbar styling for modals */
.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #3498db, #2ecc71);
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #2ecc71, #3498db);
}

/* Mobile scrollbar - more visible on iOS */
@media (max-width: 768px) {
    .modal-content::-webkit-scrollbar {
        width: 6px;
    }
    
    .modal-content::-webkit-scrollbar-thumb {
        background: rgba(52, 152, 219, 0.8);
        border-radius: 3px;
    }
    
    /* iOS scroll indicator */
    .modal-content {
        scrollbar-width: thin;
        scrollbar-color: rgba(52, 152, 219, 0.8) rgba(255, 255, 255, 0.1);
    }
}

/* FIT:MATCH Logo Styling */
#model-info a {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    text-decoration: none;
}

#model-info a:hover {
    background: rgba(0, 0, 0, 0.6);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#model-info img {
    transition: all 0.3s ease;
}

#model-info a:hover img {
    transform: scale(1.1);
}

