/* CSS Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 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);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.tagline {
    font-size: 1rem;
    opacity: 0.9;
    margin-top: 0.5rem;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Sections */
section {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-md);
}

section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

section h3 svg {
    color: var(--primary-color);
}

/* Upload Section */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--background);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
}

.upload-icon {
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.upload-area:hover .upload-icon,
.upload-area.dragover .upload-icon {
    color: var(--primary-color);
}

.upload-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

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

.upload-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--background);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-capture {
    background: var(--success-color);
    color: white;
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

.btn-capture:hover:not(:disabled) {
    background: #059669;
}

.btn-cancel {
    background: var(--secondary-color);
    color: white;
}

.btn-cancel:hover:not(:disabled) {
    background: #4b5563;
}

.btn-remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--danger-color);
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
}

.btn-remove:hover:not(:disabled) {
    background: #dc2626;
}

.btn-export {
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
}

.btn-export:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn-scan {
    width: 100%;
    margin-top: 1rem;
    padding: 1rem;
    font-size: 1.125rem;
}

.btn-new-scan {
    width: 100%;
    margin-top: 1.5rem;
}

/* Camera Section */
.camera-section {
    padding: 0;
    overflow: hidden;
}

.camera-container {
    position: relative;
}

#cameraVideo {
    width: 100%;
    max-height: 400px;
    object-fit: cover;
    display: block;
    background: #000;
}

.camera-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.8);
}

/* Preview Section */
.preview-container {
    position: relative;
    display: inline-block;
    width: 100%;
}

#previewImage {
    max-width: 100%;
    max-height: 400px;
    display: block;
    margin: 0 auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

/* Processing Section */
.processing-section {
    text-align: center;
    padding: 3rem 1.5rem;
}

.processing-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

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

/* Results Section */
.amounts-container,
.text-container,
.export-container {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.amounts-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.amount-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, var(--success-color) 0%, #059669 100%);
    color: white;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
}

.amount-tag.total {
    background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
    font-size: 1.25rem;
    padding: 0.75rem 1.25rem;
}

.amount-label {
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.9;
}

.text-content {
    background: var(--background);
    border-radius: var(--radius-md);
    padding: 1rem;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
}

.export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Footer */
.footer {
    background: var(--text-primary);
    color: var(--background);
    padding: 1.5rem;
    text-align: center;
    font-size: 0.875rem;
}

.footer a {
    color: #93c5fd;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: #bfdbfe;
    text-decoration: underline;
}

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

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 1rem);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* Responsive Design */
@media (max-width: 640px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

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

    .tagline {
        font-size: 0.875rem;
    }

    .main-content {
        padding: 1rem;
    }

    section {
        padding: 1rem;
        border-radius: var(--radius-lg);
    }

    .upload-area {
        padding: 2rem 1rem;
    }

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

    .upload-text {
        font-size: 1rem;
    }

    .upload-buttons {
        flex-direction: column;
    }

    .upload-buttons .btn {
        width: 100%;
    }

    .btn {
        padding: 0.875rem 1.25rem;
    }

    .export-buttons {
        flex-direction: column;
    }

    .export-buttons .btn {
        width: 100%;
    }

    .amounts-list {
        flex-direction: column;
    }

    .amount-tag {
        justify-content: center;
    }

    .camera-controls {
        flex-direction: column;
        padding: 1rem;
    }

    .camera-controls .btn {
        width: 100%;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .main-content {
        max-width: 700px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #111827;
        --surface: #1f2937;
        --text-primary: #f9fafb;
        --text-secondary: #9ca3af;
        --border-color: #374151;
    }

    .upload-area {
        background: rgba(255, 255, 255, 0.05);
    }

    .upload-area:hover,
    .upload-area.dragover {
        background: rgba(79, 70, 229, 0.15);
    }

    .btn-secondary {
        background: var(--surface);
        border-color: var(--border-color);
    }

    .btn-export {
        background: var(--surface);
        border-color: var(--border-color);
    }

    .text-content {
        background: rgba(0, 0, 0, 0.3);
    }

    .footer {
        background: #000;
    }
}

/* Print styles */
@media print {
    .header,
    .upload-section,
    .camera-section,
    .preview-section,
    .processing-section,
    .export-container,
    .btn-new-scan,
    .footer {
        display: none !important;
    }

    .results-section {
        box-shadow: none;
        padding: 0;
    }

    .text-content {
        max-height: none;
        overflow: visible;
    }
}
