/* Premium Camera Popup Styles */
.camera-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 2147483647;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', sans-serif;
    color: #fff;
    overflow: hidden;
}

.camera-popup.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.camera-preview-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 500px;
    /* Limit width on desktop */
    aspect-ratio: 9 / 16;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

#camera_video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scaleX(1);
    /* Default, can be mirrored for front camera */
}

#camera_video.mirrored {
    transform: scaleX(-1);
}

.camera-popup-controls {
    position: absolute;
    bottom: 50px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    padding: 0 20px;
    z-index: 10;
}

.camera-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50% !important;
    width: 60px !important;
    height: 60px !important;
    min-width: 60px !important;
    min-height: 60px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: background-color 0.2s ease, transform 0.2s ease;
    box-shadow: var(--shadow-lg);
    flex: none !important;
    padding: 0 !important;
}

.camera-btn:active {
    transform: scale(0.9);
}

.camera-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.capture-btn {
    width: 80px !important;
    height: 80px !important;
    min-width: 80px !important;
    min-height: 80px !important;
    background: #fff;
    border: 4px solid rgba(255, 255, 255, 0.3);
}

.capture-btn i {
    color: #000;
}

.capture-btn:hover {
    background: #f0f0f0;
}

.close-camera-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    border: none;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 11;
    backdrop-filter: blur(5px);
}

/* Aspect Ratio Overlay */
.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-sizing: border-box;
}

.camera-overlay::before,
.camera-overlay::after {
    content: '';
    position: absolute;
    border-color: rgba(255, 255, 255, 0.5);
    border-style: solid;
    width: 20px;
    height: 20px;
}

.camera-overlay::before {
    top: 20px;
    left: 20px;
    border-width: 2px 0 0 2px;
}

.camera-overlay::after {
    bottom: 20px;
    right: 20px;
    border-width: 0 2px 2px 0;
}

/* Preview Image */
#camera_captured_preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: none;
    z-index: 5;
}

.preview-mode .capture-btn {
    display: none;
}


.confirm-btn {
    display: none;
    background: #2ecc71;
    color: #fff;
}

.retake-btn {
    display: none;
    background: #e74c3c;
    color: #fff;
}

.preview-mode .confirm-btn,
.preview-mode .retake-btn {
    display: flex;
}

.toggle-doc-btn {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.toggle-doc-btn.active {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
    border-color: #fbbf24 !important;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.4);
    animation: pulse-gold 2s infinite;
}

.preview-mode .toggle-doc-btn {
    display: none;
}

@keyframes pulse-gold {
    0% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(245, 158, 11, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
    }
}

/* Loading Spinner */
.camera-loading {
    position: absolute;
    display: none;
    color: #fff;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Inline Camera Controls (Form Buttons) */
.camera-controls {
    display: flex;
    gap: 12px;
    margin: 18px 0;
    width: 100%;
    flex-wrap: nowrap;
    /* Prevent wrapping to keep them side by side */
    position: relative;
    justify-content: space-between;
    align-items: stretch;
}

.camera-controls button {
    flex: 1;
    width: 50%;
    /* Explicit half width */
    display: flex;
    flex-direction: column;
    /* Stack icon and text vertically for a modern look */
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 15px 10px !important;
    border-radius: 14px !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    background: #2a2a2a !important;
    color: #ffffff !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25) !important;
    white-space: nowrap;
    line-height: 1.2;
    margin: 0 !important;

}

.camera-controls button:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

.camera-controls button i {
    font-size: 22px !important;
    margin: 0 !important;
}

/* Primary Color for Camera Button - Premium Vibrant Blue */
.camera-controls button[id*="open_camera_btn"] {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%) !important;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3) !important;
}

.camera-controls button[id*="open_camera_btn"]:hover {
    background: linear-gradient(135deg, #60a5fa 0%, #2563eb 100%) !important;
}

/* Secondary Color for File Button - Sleek Dark Slate */
.camera-controls button[id*="choose_file_btn"] {
    background: #334155 !important;
    color: #f1f5f9 !important;
}

.camera-controls button[id*="choose_file_btn"]:hover {
    background: #475569 !important;
}

/* Red Color for Retake Button */
.camera-controls button[id*="retake_btn"] {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%) !important;
    width: 100% !important;
    /* Retake usually shows alone, so make it full width */
    max-width: 100% !important;
}

/* Override for Retake button to be full width when alone */
.camera-controls button[id*="retake_btn"]:only-child {
    width: 100% !important;
    max-width: 100% !important;
}

/* Animation for buttons */
@keyframes pulse-blue {
    0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
}

.camera-controls button[id*="open_camera_btn"] {
    animation: pulse-blue 2s infinite;
}

/* RTL Support - Keep vertical stack but ensure font is correct */
[dir="rtl"] .camera-controls button {
    font-family: 'Tajawal', sans-serif;
    /* Example for Arabic font if available */
}

/* Optical Stabilizer & Visual Aids */
.camera-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    pointer-events: none;
    z-index: 1;
}

.camera-grid div {
    border: 0.5px solid rgba(255, 255, 255, 0.1);
}

.stabilizer-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    pointer-events: none;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.3s ease, background 0.3s ease, width 0.3s ease, height 0.3s ease;
}

.stabilizer-indicator::before,
.stabilizer-indicator::after {
    content: "";
    position: absolute;
    background: rgba(255, 255, 255, 0.5);
}

.stabilizer-indicator::before {
    width: 20px;
    height: 1px;
}

.stabilizer-indicator::after {
    width: 1px;
    height: 20px;
}

.stabilizer-indicator.steady {
    border-color: #2ecc71;
    background: rgba(46, 204, 113, 0.1);
    width: 80px;
    height: 80px;
}

.stabilizer-indicator.steady::before,
.stabilizer-indicator.steady::after {
    background: #2ecc71;
}

.steady-badge {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 15px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    border-radius: 20px;
    font-size: 12px;
    color: #fff;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: opacity 0.3s ease;
}

.steady-badge.active {
    color: #2ecc71;
}

.scan-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(to right, transparent, #3498db, transparent);
    box-shadow: 0 0 15px #3498db;
    z-index: 2;
    display: none;
    animation: scanMove 3s linear infinite;
}

/* Detection Overlay Styles */
.camera-detection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

.detection-svg {
    width: 100%;
    height: 100%;
}

.detection-svg.detecting line {
    stroke: #2ecc71;
    stroke-width: 3;
    stroke-dasharray: none;
    filter: drop-shadow(0 0 5px #2ecc71);
    animation: pulse-green 1.5s infinite;
}

.cropper-svg.detecting line {
    stroke: #2ecc71;
    stroke-width: 3;
    stroke-dasharray: none;
    filter: drop-shadow(0 0 5px #2ecc71);
    animation: pulse-green 1.5s infinite;
}

.cropper-point.detected {
    background: #2ecc71;
    border-color: #fff;
    width: 12px;
    height: 12px;
}

@keyframes pulse-green {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

@keyframes scanMove {
    0% {
        top: 0;
    }

    100% {
        top: 100%;
    }
}

.camera-popup.active .scan-line {
    display: block;
}

.preview-mode .camera-grid,
.preview-mode .stabilizer-indicator,
.preview-mode .steady-badge,
.preview-mode .scan-line {
    display: none !important;
}