/* ===========================================
   Shared Scan Modal Base Styles
   Used by: ScanFoodItemModal, ScanNutritionLabelModal, ScanReceiptModal
   =========================================== */

/* Modal Backdrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    padding: 1rem;
    overscroll-behavior: contain;
}

/* Modal Container */
.scan-modal {
    background: var(--card-bg);
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Modal Header */
.scan-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.scan-modal .modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.scan-modal .modal-header h2 span:not(.bi) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scan-modal .btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    transition: color 0.2s;
}

@media (hover: hover) {
    .scan-modal .btn-close:hover {
        color: var(--text-primary);
    }
}

/* Modal Body */
.scan-modal .modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Processing State */
.scan-modal .processing-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 0;
    text-align: center;
}

.scan-modal .processing-section h3 {
    margin: 1.5rem 0 0.5rem;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.scan-modal .processing-hint {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
}

.scan-modal .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: scan-modal-spin 1s linear infinite;
}

@keyframes scan-modal-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Success State */
.scan-modal .success-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.scan-modal .success-icon {
    font-size: 3rem;
    color: var(--success, #10b981);
    margin-bottom: 1rem;
}

.scan-modal .success-section h3 {
    margin: 0 0 0.75rem;
    color: var(--text-primary);
    font-size: 1.25rem;
}

/* Error State */
.scan-modal .error-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 2rem 0;
}

.scan-modal .error-icon {
    font-size: 3rem;
    color: var(--danger, #ef4444);
    margin-bottom: 1rem;
}

.scan-modal .error-section h3 {
    margin: 0 0 0.5rem;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.scan-modal .error-description,
.scan-modal .error-message {
    color: var(--text-secondary);
    margin: 0 0 1.5rem;
    font-size: 1rem;
    line-height: 1.5;
}

/* Scanned Data Preview */
.scan-modal .scanned-data-preview {
    width: 100%;
    background: var(--body-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.scan-modal .data-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.scan-modal .data-item:last-child {
    border-bottom: none;
}

.scan-modal .data-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.scan-modal .data-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Modal Actions */
.scan-modal .modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    width: 100%;
}

.scan-modal .modal-actions .btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
}

.scan-modal .modal-actions .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.scan-modal .modal-actions .btn-secondary {
    background: var(--border-color);
    color: var(--text-primary);
}

@media (hover: hover) {
    .scan-modal .modal-actions .btn-secondary:hover:not(:disabled) {
        background: var(--text-tertiary);
    }
}

.scan-modal .modal-actions .btn-primary {
    background: var(--accent-primary);
    color: white;
}

@media (hover: hover) {
    .scan-modal .modal-actions .btn-primary:hover:not(:disabled) {
        background: var(--accent-secondary);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    }
}

/* Responsive - Tablet */
@media (max-width: 768px) {
    .scan-modal {
        max-width: 95%;
    }
}

/* Mobile Fullscreen Modal */
@media (max-width: 576px) {
    .modal-backdrop {
        padding: 0;
        align-items: stretch;
        touch-action: none;
    }

    .scan-modal {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
    }

    .scan-modal .modal-header {
        padding: calc(env(safe-area-inset-top, 0px) + 1rem) 1rem 1rem;
        flex-shrink: 0;
    }

    .scan-modal .btn-close {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .scan-modal .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 1rem;
    }

    .scan-modal .modal-actions {
        flex-direction: column;
        padding: 1rem;
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    }

    .scan-modal .modal-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }
}

/* ===========================================
   Discard Button Styles
   =========================================== */

.scan-modal .modal-actions .btn-outline-danger {
    background: transparent;
    color: var(--danger, #ef4444);
    border: 2px solid var(--danger, #ef4444);
}

@media (hover: hover) {
    .scan-modal .modal-actions .btn-outline-danger:hover:not(:disabled) {
        background: var(--danger, #ef4444);
        color: white;
    }
}

/* ===========================================
   Scan Button Loading States
   Used on page buttons (not modal buttons)
   =========================================== */

/* Base scan button - add spinner support */
.scan-btn {
    position: relative;
    transition: all 0.3s ease;
}

/* Processing state - button has active scan */
.scan-btn.processing {
    opacity: 0.9;
    pointer-events: auto;
}

.scan-btn.processing .spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 2px;
}

/* Has result state - button has pending result */
.scan-btn.has-result {
    background: linear-gradient(135deg, var(--success, #10b981) 0%, var(--accent-primary) 100%);
    animation: scan-btn-pulse 2s ease-in-out infinite;
}

@keyframes scan-btn-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
    }
}

/* Spinner animation for buttons */
.scan-btn .spinner-border {
    animation: spinner-border 0.75s linear infinite;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}
