/* General Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
    padding: 5px;
    overflow-x: hidden;
}

/* Step Caption */
.step-caption {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #3498db;
    margin-bottom: 10px;
    padding: 5px;
    background-color: #f1f2f6;
    border-radius: 8px;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 10px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

@media (min-width: 768px) {
    body {
        padding: 20px;
    }
    
    .container {
        max-width: 1000px;
        padding: 20px;
    }
}

h1 {
    text-align: center;
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 24px;
}

h2, h3 {
    color: #2c3e50;
    margin: 10px 0;
    font-size: 20px;
}

/* Camera Container */
.camera-container {
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f1f2f6;
    border-radius: 8px;
}

.view-container {
    width: 100%;
}

.video-container, .captured-image-view {
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0 auto 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background-color: #000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    /* Square aspect ratio */
    aspect-ratio: 1/1;
}

#video, #canvas, #previewImage {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover; /* Changed from contain to cover to fill the square */
    object-position: center; /* Center the image */
}

/* Camera error message */
.camera-error, .error-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    text-align: center;
    padding: 20px;
    z-index: 20;
}

.camera-error p, .error-message p {
    margin: 10px 0;
    font-size: 16px;
    line-height: 1.5;
}

.error-message {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    max-width: 80%;
    color: #333;
}

.error-message p:first-child {
    color: #d9534f;
    font-weight: bold;
}

/* Rotation Controls */
.rotation-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 10px 0 15px;
    gap: 15px;
}

.rotation-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    width: 100%;
    margin-bottom: 15px;
}

.rotation-buttons .btn {
    min-width: 120px;
    font-size: 16px;
    padding: 10px 15px;
}

.rotate-icon {
    font-style: normal;
    font-size: 18px;
    display: inline-block;
}

/* Circular Rotation Interface */
.circular-rotation-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    position: relative;
    z-index: 2000;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.rotation-dial {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background-color: #f1f2f6;
    border: 3px solid #3498db;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    transition: box-shadow 0.3s;
    z-index: 2000;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: none;
}

.rotation-dial:hover {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.rotation-dial::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 80%;
    height: 80%;
    border-radius: 50%;
    background-color: #fff;
    transform: translate(-50%, -50%);
    z-index: 1;
}

.rotation-handle {
    position: absolute;
    top: 10px;
    left: 50%;
    width: 20px;
    height: 20px;
    background-color: #3498db;
    border-radius: 50%;
    transform: translateX(-50%);
    z-index: 2001;
    cursor: grab;
    pointer-events: auto;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: none;
}

.rotation-handle:active {
    cursor: grabbing;
}

.rotation-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 40%;
    background-color: #3498db;
    transform-origin: bottom center;
    transform: translate(-50%, -100%);
    z-index: 2000;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.rotation-value {
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
    margin: 10px auto;
    z-index: 2000;
    background-color: #f1f2f6;
    padding: 5px 15px;
    border-radius: 4px;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    caret-color: transparent;
    display: block;
    text-align: center;
    width: fit-content;
}

@media (min-width: 768px) {
    .rotation-dial {
        width: 150px;
        height: 150px;
    }
}

@media (min-width: 768px) {
    .camera-container {
        padding: 20px;
        margin-bottom: 30px;
    }
    
    .video-container, .captured-image-view {
        max-width: 640px;
        margin: 0 auto 20px;
    }
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.reference-guide {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 100px;
    height: 20px;
    border: 2px dashed #fff;
    opacity: 0.7;
}

/* Workflow Controls */
.workflow-controls {
    margin-bottom: 20px;
    width: 100%;
}

.button-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
}

.button-row .btn {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 16px;
}

@media (min-width: 768px) {
    .button-row {
        justify-content: center;
        gap: 15px;
    }
    
    .button-row .btn {
        flex: 0 1 auto;
        min-width: 120px;
        max-width: 200px;
    }
}

.btn {
    padding: 12px 20px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
    width: 100%;
    text-align: center;
    min-height: 48px; /* Minimum touch target size */
}

.btn:hover {
    background-color: #2980b9;
}

.btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

@media (min-width: 768px) {
    .controls {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 15px;
    }
    
    .btn {
        width: auto;
    }
}

/* Reference Container */
.reference-container {
    display: none; /* Hidden by default, shown when needed */
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    width: 100%;
}

/* Reference Size Input */
.reference-size {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
    width: 100%;
}

.reference-size label {
    margin-right: 10px;
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
}

.reference-size input {
    width: 80px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 8px;
    text-align: center;
    font-size: 16px;
}

/* Reference Buttons */
.reference-buttons {
    display: none; /* Hide these buttons as they're replaced by workflow buttons */
}

.btn-small {
    padding: 8px 12px;
    font-size: 14px;
    min-height: 40px;
}

.help-text {
    font-size: 14px;
    color: #7f8c8d;
    margin-top: 5px;
    text-align: center;
}

.reference-active {
    color: #00AA00;
    font-weight: bold;
}

/* Result Container */
.result-container {
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f1f2f6;
    border-radius: 8px;
    display: none; /* Hidden by default, shown after measurements */
}

.polygon-instructions {
    text-align: center;
    font-size: 14px;
    color: #2c3e50;
    margin: 10px 0;
    font-style: italic;
    padding: 8px;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.polygon-canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
}

.polygon-canvas {
    cursor: crosshair;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: auto;
}

.measurements {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.measurement-item {
    background-color: #fff;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.label {
    font-weight: bold;
    font-size: 14px;
    color: #555;
    margin-bottom: 5px;
}

.value {
    font-size: 18px;
    color: #2c3e50;
    font-weight: 600;
}

.unit {
    margin-left: 2px;
    color: #7f8c8d;
    font-size: 14px;
}

@media (min-width: 768px) {
    .result-container {
        padding: 15px;
    }
    
    .measurements {
        grid-template-columns: repeat(4, 1fr);
        gap: 15px;
    }
    
    .measurement-item {
        padding: 15px;
    }
}

/* Instructions */
.instructions {
    background-color: #f1f2f6;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
}

.instructions h3 {
    margin-bottom: 15px;
    font-size: 18px;
    color: #2c3e50;
    text-align: center;
}

.instructions ol {
    padding-left: 25px;
}

.instructions li {
    margin-bottom: 12px;
    font-size: 15px;
    line-height: 1.5;
}

@media (min-width: 768px) {
    .instructions {
        padding: 20px;
    }
    
    .instructions h3 {
        font-size: 20px;
    }
    
    .instructions li {
        font-size: 16px;
    }
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
    }
    
    .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .measurements {
        grid-template-columns: 1fr;
    }
}