/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
    font-weight: 300;
}

/* Main content */
main {
    flex: 1;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

section {
    padding: 40px;
}

/* Upload section */
.upload-area {
    border: 3px dashed #ddd;
    border-radius: 12px;
    padding: 60px 20px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: #fafafa;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: #667eea;
    background: #f0f4ff;
    transform: translateY(-2px);
}

.upload-content .upload-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

.upload-content h3 {
    font-size: 1.5em;
    margin-bottom: 10px;
    color: #333;
}

.upload-content p {
    color: #666;
    margin-bottom: 10px;
}

.file-info {
    font-size: 0.9em;
    color: #999;
}

.upload-btn, .primary-btn, .secondary-btn, .process-btn, .toggle-btn, .remove-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.upload-btn, .primary-btn, .process-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    margin-top: 20px;
}

.upload-btn:hover, .primary-btn:hover, .process-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.secondary-btn, .toggle-btn {
    background: #f8f9fa;
    color: #666;
    border: 2px solid #e9ecef;
}

.secondary-btn:hover, .toggle-btn:hover {
    background: #e9ecef;
    color: #333;
}

.remove-btn {
    background: #dc3545;
    color: white;
    padding: 8px 12px;
    font-size: 0.9em;
}

.remove-btn:hover {
    background: #c82333;
}

/* Image preview */
.image-preview {
    margin-top: 30px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background: white;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.preview-header h4 {
    margin: 0;
    color: #333;
}

#previewImg {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    display: block;
}

.file-details {
    padding: 15px 20px;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
    font-size: 0.9em;
    color: #666;
}

.process-btn {
    width: 100%;
    margin: 0;
    border-radius: 0;
}

/* Loading section */
.loading-section {
    text-align: center;
    background: #f8f9fa;
}

.loading-content h3 {
    margin-bottom: 10px;
    color: #333;
}

.loading-step {
    color: #666;
    margin-bottom: 30px;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 30px;
}

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

.progress-bar {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    margin: 0 auto;
    overflow: hidden;
}

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

/* Results section */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.results-header h2 {
    color: #333;
    font-size: 1.8em;
}

.confidence-badge {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
    color: white;
}

.confidence-high {
    background: #28a745;
}

.confidence-medium {
    background: #ffc107;
}

.confidence-low {
    background: #dc3545;
}

/* Cards */
.info-card, .items-card, .totals-card, .validation-card, .ocr-section {
    background: #f8f9fa;
    border-radius: 12px;
    margin-bottom: 25px;
    overflow: hidden;
    border: 1px solid #e9ecef;
}

.info-card h3, .items-card h3, .totals-card h3, .validation-card h3 {
    background: white;
    padding: 20px;
    margin: 0;
    color: #333;
    border-bottom: 1px solid #e9ecef;
}

.info-grid, .totals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    padding: 20px;
}

.info-item, .total-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #e9ecef;
}

.info-item:last-child, .total-item:last-child {
    border-bottom: none;
}

.info-item label, .total-item label {
    font-weight: 600;
    color: #666;
}

.info-item span, .total-item span {
    color: #333;
    font-weight: 500;
}

.total-final {
    background: white;
    margin: 10px -20px -20px;
    padding: 20px;
    font-size: 1.1em;
    border-top: 2px solid #667eea;
}

.total-final label, .total-final span {
    font-weight: 700;
    color: #333;
}

/* Table */
.table-container {
    overflow-x: auto;
    padding: 20px;
}

#itemsTable {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#itemsTable th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
}

#itemsTable td {
    padding: 12px;
    border-bottom: 1px solid #e9ecef;
}

#itemsTable tr:last-child td {
    border-bottom: none;
}

#itemsTable tr:nth-child(even) {
    background: #f8f9fa;
}

#itemsTable tr:hover {
    background: #e3f2fd;
}

/* Validation notes */
#validationNotes {
    padding: 20px;
    list-style: none;
}

#validationNotes li {
    padding: 8px 12px;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    margin-bottom: 8px;
    color: #856404;
}

#validationNotes li:last-child {
    margin-bottom: 0;
}

/* OCR section */
.ocr-section {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}

.toggle-btn {
    margin: 20px;
    margin-bottom: 0;
}

.ocr-text {
    margin: 20px;
    margin-top: 15px;
}

#ocrContent {
    background: #2d3748;
    color: #e2e8f0;
    padding: 20px;
    border-radius: 8px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 400px;
    overflow-y: auto;
}

/* Action buttons */
.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 30px;
}

/* Error section */
.error-section {
    text-align: center;
    background: #f8f9fa;
}

.error-content .error-icon {
    font-size: 4em;
    margin-bottom: 20px;
}

.error-content h3 {
    color: #dc3545;
    margin-bottom: 15px;
}

.error-message {
    color: #666;
    margin-bottom: 30px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 20px 20px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9em;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2em;
    }
    
    section {
        padding: 30px 20px;
    }
    
    .upload-area {
        padding: 40px 20px;
    }
    
    .info-grid, .totals-grid {
        grid-template-columns: 1fr;
    }
    
    .results-header {
        text-align: center;
    }
    
    .action-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .action-buttons button {
        width: 100%;
        max-width: 300px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.8em;
    }
    
    .subtitle {
        font-size: 1em;
    }
    
    section {
        padding: 20px 15px;
    }
    
    .upload-area {
        padding: 30px 15px;
    }
    
    .upload-content .upload-icon {
        font-size: 3em;
    }
    
    #itemsTable th, #itemsTable td {
        padding: 8px 6px;
        font-size: 0.9em;
    }
}