/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.container {
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    min-height: 700px;
    display: flex;
    flex-direction: column;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Logo Section */
.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    background: var(--surface);
    min-height: 100px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.logo {
    width: 80px;
    height: 80px;
    max-width: 100%;
    max-height: 100px;
    object-fit: contain;
    display: block;
}

/* Step Sections */
.step-section {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    transition: all 0.3s ease;
}

.step-section.active {
    opacity: 1;
    pointer-events: auto;
}

.step-section.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.step-number {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.step-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Camera Zone */
.camera-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.camera-icon-wrapper {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: var(--shadow);
}

.camera-icon-wrapper:hover,
.camera-icon-wrapper:active {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

/* Camera Icon Animation States */
.camera-icon-wrapper.fade-out {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
    transition: opacity 300ms ease-out, transform 300ms ease-out;
}

.camera-zone.photo-captured .camera-icon-wrapper {
    display: none;
}

.camera-zone.photo-captured .camera-instruction {
    display: none;
}

.camera-icon {
    width: 50px;
    height: 50px;
    color: white;
}

.camera-instruction {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Thumbnail Styles */
.thumbnail-container {
    position: relative;
    width: 100px;
    /* Matching size */
    height: 100px;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--border);
    margin-top: 1rem;
}

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

.retake-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.375rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s ease;
    backdrop-filter: blur(4px);
}

.retake-button:hover {
    background: rgba(0, 0, 0, 0.85);
}

.retake-button svg {
    width: 14px;
    height: 14px;
}

/* Thumbnails Grid */
.thumbnails-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.5rem;
    margin-top: 1rem;
}

.thumbnail-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 6px;
    overflow: hidden;
    background: var(--border);
    border: 2px solid transparent;
    transition: border-color 0.2s ease;
}

.thumbnail-item:hover {
    border-color: var(--primary);
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-item .remove-button {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: var(--error);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: background 0.2s ease;
}

.thumbnail-item .remove-button:hover {
    background: #dc2626;
}

.add-more-button {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    border: 2px dashed var(--border);
    border-radius: 8px;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.add-more-button:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

.add-more-button svg {
    width: 16px;
    height: 16px;
}

/* Processing Status */
.processing-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem 1rem;
    text-align: center;
}

.processing-icon {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.processing-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.processing-subtext {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Progress Bar for OCR Download */
.progress-bar-container {
    width: 100%;
    max-width: 280px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* Local Processing Icon (Phone) */
.processing-icon.local-icon {
    color: var(--success);
    animation: pulse 1.5s ease-in-out infinite;
}

.processing-icon.local-icon svg {
    width: 48px;
    height: 48px;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.05);
    }
}

/* OCR Source Badge */
.ocr-source-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6366f1;
    margin-bottom: 1rem;
}

.ocr-source-badge.ai-fallback {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(239, 68, 68, 0.1));
    border-color: rgba(245, 158, 11, 0.3);
    color: var(--warning);
}

.ocr-source-icon {
    font-size: 1rem;
}

/* Extracted Data */
.extracted-data {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.data-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.data-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.data-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.confidence-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--warning);
    color: white;
}

.confidence-badge.high {
    background: var(--success);
}

.confidence-badge.low {
    background: var(--error);
}

/* Edit Icon Styles */
.edit-icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    margin-left: 0.5rem;
    color: var(--text-secondary);
    opacity: 0.6;
    transition: opacity 0.2s, color 0.2s;
    vertical-align: middle;
}

.edit-icon-btn:hover,
.edit-icon-btn:focus {
    opacity: 1;
    color: var(--primary);
}

.edit-icon-btn svg {
    width: 16px;
    height: 16px;
}

.data-value.editing { display: none; }

.data-value-input {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--primary);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    width: 100%;
    max-width: 250px;
}

.data-value-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.invoice-numbers-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.invoice-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.invoice-number-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.invoice-number-text.editing {
    display: none;
}

.invoice-number-input {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--surface);
    border: 1px solid var(--primary);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    width: 100%;
}

.invoice-number-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Submit Button */
.submit-button {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: var(--shadow);
}

.submit-button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.action-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    width: 100%;
}

.action-buttons button {
    flex: 1;
}

.secondary-button {
    padding: 1rem;
    background-color: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.primary-button {
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
}

.submit-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.button-loader {
    display: flex;
    align-items: center;
}

.spinner {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

.spinner circle {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: 0;
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

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

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }

    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }

    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

/* Success Message */
.success-message {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    gap: 1.5rem;
}

.success-icon {
    width: 80px;
    height: 80px;
    background: var(--success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: scaleIn 0.5s ease;
}

.success-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

@keyframes scaleIn {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.success-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.success-text {
    color: var(--text-secondary);
    font-size: 1rem;
}

.submitted-data {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--background);
    border-radius: 8px;
}

.data-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.data-row-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.data-row-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.new-entry-button {
    padding: 1rem 2rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.new-entry-button:hover {
    background: var(--primary-dark);
}

/* Error Message */
.error-message {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    gap: 1.5rem;
}

.error-icon {
    width: 80px;
    height: 80px;
    background: var(--error);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-icon svg {
    width: 40px;
    height: 40px;
    color: white;
}

.error-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.error-text {
    color: var(--text-secondary);
    font-size: 1rem;
}

.retry-button {
    padding: 1rem 2rem;
    background: var(--error);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.retry-button:hover {
    background: #dc2626;
}

/* Responsive Design */
@media (max-width: 480px) {
    body {
        padding: 0;
    }

    .container {
        border-radius: 0;
        min-height: 100vh;
    }

    .logo-container {
        padding: 1rem 0.75rem;
        min-height: 80px;
    }

    .logo {
        width: 60px;
        height: 60px;
    }

    .step-section {
        padding: 1rem;
    }

    .camera-icon-wrapper {
        width: 80px;
        height: 80px;
    }

    .camera-icon {
        width: 40px;
        height: 40px;
    }

    .thumbnails-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

*:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}
