/**
 * Camera interface styles
 * Provides styling for camera modal, video preview, and controls
 */

/* Camera Modal */
.camera-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.camera-modal--show {
    opacity: 1;
    visibility: visible;
}

.camera-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.camera-modal__content {
    position: relative;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    max-height: 90vh;
    width: 600px;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.camera-modal--show .camera-modal__content {
    transform: scale(1);
}

/* Camera Modal Header */
.camera-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e0e0e0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    flex-shrink: 0;
}

.camera-modal__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.title-icon {
    font-size: 1.5rem;
}

.camera-modal__close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.camera-modal__close:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.camera-modal__close:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.camera-modal__close-icon {
    line-height: 1;
}

/* Camera Modal Body */
.camera-modal__body {
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
}

/* Custom scrollbar styling */
.camera-modal__body::-webkit-scrollbar {
    width: 8px;
}

.camera-modal__body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.camera-modal__body::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.camera-modal__body::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Integrated Controls Bar */
.controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.controls-bar__left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.controls-bar__right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Face Selector */
.face-selector__label {
    font-weight: 500;
    color: #333;
    margin: 0;
}

.face-selector__dropdown {
    padding: 0.5rem 0.75rem;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.95rem;
    background: white;
    color: #333;
    cursor: pointer;
    transition: border-color 0.2s ease;
    min-width: 150px;
}

.face-selector__dropdown:hover {
    border-color: #667eea;
}

.face-selector__dropdown:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Progress Indicator */
.progress-text {
    font-size: 0.9rem;
    color: #666;
    white-space: nowrap;
}

.progress-count {
    color: #667eea;
    font-weight: 600;
}

.progress-bar {
    width: 100px;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* Camera Preview */
.camera-preview {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    aspect-ratio: 4/3;
}

.camera-preview__video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transform: scaleX(-1); /* Mirror the video for natural interaction */
}

/* Captured Image Preview */
.camera-preview__captured {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 10;
}

.captured-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.captured-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.camera-preview__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-preview__guide {
    text-align: center;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.camera-preview__instruction {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    font-weight: 500;
}

.face-name {
    color: #007bff;
    font-weight: 600;
    text-transform: capitalize;
}

.camera-preview__frame {
    width: 300px;
    height: 300px;
    margin: 0 auto;
    position: relative;
}

/* Frame Corner Markers */
.frame-corner {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.9);
}

.frame-corner--tl {
    top: 0;
    left: 0;
    border-right: none;
    border-bottom: none;
    border-top-left-radius: 8px;
}

.frame-corner--tr {
    top: 0;
    right: 0;
    border-left: none;
    border-bottom: none;
    border-top-right-radius: 8px;
}

.frame-corner--bl {
    bottom: 0;
    left: 0;
    border-right: none;
    border-top: none;
    border-bottom-left-radius: 8px;
}

.frame-corner--br {
    bottom: 0;
    right: 0;
    border-left: none;
    border-top: none;
    border-bottom-right-radius: 8px;
}

/* 3x3 Sampling Grid */
.sampling-grid {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    gap: 60px;
    width: 100%;
    height: 100%;
    align-content: center;
    justify-content: center;
}

.sampling-grid__row {
    display: contents;
}

.sampling-cell {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background-color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
}

.sampling-cell--center {
    border-color: rgba(102, 126, 234, 0.9);
    border-width: 3px;
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

.sampling-cell--detecting {
    animation: pulse-cell 0.6s ease-in-out;
    border-color: #ffd700;
}

.sampling-cell--detected {
    animation: pop-cell 0.3s ease-out;
    border-color: rgba(255, 255, 255, 0.9);
    border-width: 3px;
}

.cell-color-label {
    font-size: 0.85rem;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    color: white;
}

@keyframes pulse-cell {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

@keyframes pop-cell {
    0% {
        transform: scale(0.8);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    margin-top: 1.5rem;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
    justify-content: center;
}

.action-btn--primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.action-btn--primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.action-btn--primary:active {
    transform: translateY(0);
}

.action-btn--secondary {
    background: #28a745;
    color: white;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}

.action-btn--secondary:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(40, 167, 69, 0.4);
}

.action-btn--secondary:active {
    transform: translateY(0);
}

.action-btn--tertiary {
    background: #6c757d;
    color: white;
}

.action-btn--tertiary:hover {
    background: #5a6268;
    transform: translateY(-1px);
}

.action-btn--tertiary:active {
    transform: translateY(0);
}

.action-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.action-btn__icon {
    font-size: 1.2rem;
}

.action-btn__text {
    font-weight: 500;
}

/* Camera Modal Status */
.camera-modal__status {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 60px;
    flex-shrink: 0;
}

.status-indicator {
    font-size: 0.75rem;
    line-height: 1;
}

.status-indicator--ready {
    color: #28a745;
}

.status-indicator--capturing {
    color: #17a2b8;
}

.status-indicator--processing {
    color: #ffc107;
}

.status-indicator--success {
    color: #28a745;
}

.status-indicator--error {
    color: #dc3545;
}

.status-text {
    margin: 0;
    color: #666;
    font-size: 0.9rem;
}

.status-spinner {
    display: none;
    align-items: center;
    justify-content: center;
    margin-left: 0.5rem;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e0e0e0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Camera Error Modal */
.camera-error-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.camera-error-modal--show {
    opacity: 1;
    visibility: visible;
}

.camera-error-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.camera-error-modal__content {
    position: relative;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    width: 400px;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.camera-error-modal--show .camera-error-modal__content {
    transform: scale(1);
}

.camera-error-modal__header {
    padding: 1.5rem 1.5rem 1rem 1.5rem;
    border-bottom: 1px solid #e0e0e0;
}

.camera-error-modal__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #dc3545;
}

.camera-error-modal__body {
    padding: 1rem 1.5rem;
}

.camera-error-modal__message {
    margin: 0;
    color: #666;
    line-height: 1.5;
}

.camera-error-modal__footer {
    padding: 1rem 1.5rem 1.5rem 1.5rem;
    text-align: right;
}

.camera-error-modal__ok {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.camera-error-modal__ok:hover {
    background: #0056b3;
}

.camera-error-modal__ok:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .camera-modal__content {
        width: 95vw;
        margin: 1rem;
    }
    
    .camera-modal__header,
    .camera-modal__body,
    .camera-modal__status {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .controls-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .controls-bar__left,
    .controls-bar__right {
        justify-content: space-between;
        width: 100%;
    }
    
    .face-selector__dropdown {
        flex: 1;
    }
    
    .progress-bar {
        flex: 1;
    }
    
    .camera-preview {
        aspect-ratio: 1;
    }
    
    .camera-preview__frame {
        width: 240px;
        height: 240px;
    }
    
    .sampling-grid {
        grid-template-columns: repeat(3, 36px);
        grid-template-rows: repeat(3, 36px);
        gap: 24px;
    }
    
    .sampling-cell {
        width: 36px;
        height: 36px;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .action-btn {
        width: 100%;
        min-width: auto;
    }
    
    .camera-error-modal__content {
        width: 90vw;
        margin: 1rem;
    }
}

@media (max-width: 480px) {
    .camera-modal__title {
        font-size: 1.1rem;
    }
    
    .title-icon {
        font-size: 1.25rem;
    }
    
    .camera-preview__instruction {
        font-size: 0.85rem;
    }
    
    .camera-preview__frame {
        width: 180px;
        height: 180px;
    }
    
    .sampling-grid {
        grid-template-columns: repeat(3, 30px);
        grid-template-rows: repeat(3, 30px);
        gap: 18px;
    }
    
    .sampling-cell {
        width: 30px;
        height: 30px;
    }
    
    .cell-color-label {
        font-size: 0.75rem;
    }
    
    .action-btn {
        padding: 0.625rem 1rem;
        font-size: 0.9rem;
    }
    
    .face-selector__dropdown {
        font-size: 0.85rem;
    }
    
    .progress-text {
        font-size: 0.85rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .camera-modal__overlay {
        background: rgba(0, 0, 0, 0.9);
    }
    
    .camera-preview__frame {
        border-color: #ffffff;
        border-width: 4px;
    }
    
    .camera-btn--capture {
        border: 2px solid #ffffff;
    }
    
    .camera-btn--cancel {
        border: 2px solid #ffffff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .camera-modal,
    .camera-modal__content,
    .camera-error-modal,
    .camera-error-modal__content,
    .camera-btn {
        transition: none;
    }
    
    .camera-preview__frame {
        animation: none;
    }
}


/* Success Animation */
.camera-modal__content--success {
    animation: success-bounce 0.6s ease-out;
}

@keyframes success-bounce {
    0% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.05);
    }
    50% {
        transform: scale(0.98);
    }
    75% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

/* Success state styling */
.status-indicator--success {
    animation: success-pulse 1s ease-in-out infinite;
}

@keyframes success-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.2);
    }
}
