/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 20px;
}

header h1 {
    color: #2c3e50;
    font-size: 2rem;
    margin-bottom: 8px;
}

.subtitle {
    color: #7f8c8d;
    font-size: 1.1rem;
}

/* Upload Form */
.upload-form {
    background: white;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
}

.upload-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

@media (max-width: 768px) {
    .upload-group {
        grid-template-columns: 1fr;
    }
}

.upload-section {
    display: flex;
    flex-direction: column;
}

.upload-section label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 12px;
    font-size: 1rem;
}

.label-icon {
    font-size: 1.2rem;
}

.upload-section input[type="file"] {
    padding: 15px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    background: #fafafa;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.upload-section input[type="file"]:hover {
    border-color: #3498db;
    background: #f0f8ff;
}

.upload-section input[type="file"]:focus {
    outline: none;
    border-color: #3498db;
}

.file-name {
    margin-top: 8px;
    font-size: 0.9rem;
    color: #7f8c8d;
}

/* Mode Tabs */
.mode-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0;
    background: white;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.mode-tab {
    flex: 1;
    padding: 16px 24px;
    background: #f5f7fa;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 1rem;
    font-weight: 600;
    color: #7f8c8d;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.mode-tab:hover {
    background: #eef2f7;
    color: #2c3e50;
}

.mode-tab.active {
    background: white;
    color: #3498db;
    border-bottom-color: #3498db;
}

.mode-tab .tab-icon {
    font-size: 1.1rem;
}

.upload-form.with-tabs {
    border-radius: 0 0 12px 12px;
    margin-top: 0;
}

/* Input help text */
.input-help {
    margin-top: 8px;
    font-size: 0.85rem;
    color: #95a5a6;
}

/* Checkbox section */
.checkbox-section {
    background: #f8fafc;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
    font-weight: normal !important;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 2px;
    cursor: pointer;
    accent-color: #3498db;
}

.checkbox-text {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #2c3e50;
}

.checkbox-section .input-help {
    margin-left: 32px;
}

/* Submit Button */
.submit-btn {
    width: 100%;
    padding: 16px 32px;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
}

.submit-btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

.submit-btn .btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading p {
    color: #2c3e50;
    font-weight: 600;
}

.loading-detail {
    color: #7f8c8d;
    font-weight: normal !important;
    font-size: 0.9rem;
    margin-top: 8px;
}

/* Error */
.error {
    background: #fee;
    border: 1px solid #e74c3c;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
}

.error h3 {
    color: #c0392b;
    margin-bottom: 8px;
}

.error p {
    color: #e74c3c;
}

/* Results */
.results {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.results section {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
}

.results h2 {
    color: #2c3e50;
    font-size: 1.3rem;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
}

/* Summary Grid */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
}

.summary-card {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
}

.summary-card.ok {
    background: #e8f5e9;
    border-left: 4px solid #27ae60;
}

.summary-card.warning {
    background: #fff3e0;
    border-left: 4px solid #f39c12;
}

.summary-card.error {
    background: #ffebee;
    border-left: 4px solid #e74c3c;
}

.summary-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: #2c3e50;
}

.summary-card .label {
    font-size: 0.85rem;
    color: #7f8c8d;
    margin-top: 4px;
}

/* Line Comparisons */
.line-comparison {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}

.line-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #f8f9fa;
    cursor: pointer;
    transition: background-color 0.2s;
}

.line-header:hover {
    background: #f0f0f0;
}

.line-header.ok {
    border-left: 4px solid #27ae60;
}

.line-header.discrepancy {
    border-left: 4px solid #e74c3c;
}

.line-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.line-number {
    background: #e0e0e0;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
}

.line-description {
    color: #2c3e50;
    font-weight: 500;
}

.line-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.line-status.ok {
    background: #e8f5e9;
    color: #27ae60;
}

.line-status.discrepancy {
    background: #ffebee;
    color: #e74c3c;
}

.line-details {
    padding: 16px;
    border-top: 1px solid #e0e0e0;
    display: none;
}

.line-details.expanded {
    display: block;
}

.comparison-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
}

.comparison-row:last-child {
    border-bottom: none;
}

.comparison-label {
    font-weight: 600;
    color: #7f8c8d;
    font-size: 0.85rem;
}

.comparison-value {
    color: #2c3e50;
}

.comparison-value.diff {
    color: #e74c3c;
    font-weight: 600;
}

/* Discrepancies */
.discrepancies {
    margin-top: 16px;
    padding: 12px;
    background: #fff3e0;
    border-radius: 6px;
}

.discrepancy-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    font-size: 0.9rem;
}

.discrepancy-icon {
    color: #f39c12;
}

/* Dimension Adjustment Note */
.dimension-adjustment-note {
    margin-top: 12px;
    padding: 10px 12px;
    background: #e3f2fd;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #1565c0;
}

.adjustment-icon {
    font-size: 1rem;
}

/* Unmatched Section */
.unmatched-section h3 {
    color: #7f8c8d;
    font-size: 1rem;
    margin: 16px 0 12px;
}

.unmatched-list {
    list-style: none;
}

.unmatched-item {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    gap: 12px;
}

.unmatched-item .line-number {
    flex-shrink: 0;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-size: 0.9rem;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Confidence badge */
.confidence-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: #e0e0e0;
    color: #666;
}

.confidence-badge.high {
    background: #e8f5e9;
    color: #27ae60;
}

.confidence-badge.medium {
    background: #fff3e0;
    color: #f39c12;
}

.confidence-badge.low {
    background: #ffebee;
    color: #e74c3c;
}

.confidence-badge.potential {
    background: #fff3cd;
    color: #856404;
    border: 1px dashed #ffc107;
}

/* AI Metrics Card */
.summary-card.ai-metrics {
    background: #e8f4fd;
    border-left: 4px solid #3498db;
}

.summary-card.ai-metrics .value {
    font-size: 1.4rem;
    color: #2980b9;
}

.summary-card.ai-metrics .label {
    color: #3498db;
}

.summary-card.saved-to-db {
    background: #d4edda;
    border-left: 4px solid #28a745;
}

.summary-card.saved-to-db .value {
    color: #28a745;
}

.summary-card.saved-to-db .label {
    color: #155724;
}

/* Approve Button */
.approve-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
}

.approve-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #27ae60, #219a52);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}

.approve-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(39, 174, 96, 0.3);
}

.approve-btn:disabled {
    background: #bdc3c7;
    cursor: wait;
}

/* Cache Badge */
.cache-badge {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.cache-badge.small {
    padding: 2px 8px;
    font-size: 0.7rem;
    margin-left: 8px;
}

.cache-indicator {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.approve-success {
    color: #27ae60;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Conversion Indicators */
.conversion-note {
    font-size: 0.85em;
    color: #666;
    font-style: italic;
}

.comparison-value.converted {
    background-color: #fff3cd;
    border-left: 3px solid #ffc107;
    padding-left: 8px;
    margin-left: -8px;
}

/* Section header with Save All button */
.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #f0f0f0;
}

.section-header-row h2 {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

/* Save All Button */
.save-all-container {
    flex-shrink: 0;
}

.save-all-btn {
    padding: 10px 24px;
    background: linear-gradient(135deg, #27ae60, #219a52);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.save-all-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.4);
}

.save-all-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

.save-all-btn.saved {
    background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

/* Delivery Line Selector */
.delivery-selector-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0 14px;
    margin-bottom: 10px;
    border-bottom: 1px dashed #e0e0e0;
}

.delivery-selector-label {
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.85rem;
    white-space: nowrap;
}

.delivery-selector {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.85rem;
    background: white;
    color: #2c3e50;
    cursor: pointer;
    max-width: 500px;
}

.delivery-selector:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

/* Header Comparison Section */
.header-comparison-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 600;
    margin-bottom: 16px;
}

.header-comparison-status.ok {
    background: #e8f5e9;
    color: #27ae60;
    border-left: 4px solid #27ae60;
}

.header-comparison-status.discrepancy {
    background: #ffebee;
    color: #e74c3c;
    border-left: 4px solid #e74c3c;
}

.header-status-icon {
    font-size: 1.2rem;
}

.header-discrepancies {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header-discrepancy-item {
    background: #fff3e0;
    border-radius: 8px;
    padding: 14px 16px;
    border-left: 4px solid #f39c12;
}

.header-disc-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.header-disc-detail {
    font-size: 0.9rem;
    color: #2c3e50;
    padding-left: 28px;
}

.address-compare {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.address-item {
    display: flex;
    gap: 8px;
}

.address-label {
    font-weight: 600;
    color: #7f8c8d;
    min-width: 90px;
}

/* No Match Status */
.line-header.no-match {
    border-left: 4px solid #95a5a6;
    background: #f5f5f5;
}

.line-status.no-match {
    background: #ecf0f1;
    color: #7f8c8d;
}

.no-match-value {
    color: #95a5a6;
    font-style: italic;
}

.no-match-text {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #95a5a6;
}

.no-match-text::before {
    content: "—";
    color: #bdc3c7;
}

/* Header Field Comparisons (always shown) */
.header-field-comparisons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.header-field-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 14px 16px;
    border-left: 4px solid #e0e0e0;
}

.header-field-item.ok {
    background: #e8f5e9;
    border-left-color: #27ae60;
}

.header-field-item.discrepancy {
    background: #ffebee;
    border-left-color: #e74c3c;
}

.header-field-item.missing {
    background: #fff3e0;
    border-left-color: #f39c12;
}

.header-field-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.header-field-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.8rem;
}

.header-field-icon.ok {
    background: #27ae60;
    color: white;
}

.header-field-icon.discrepancy {
    background: #e74c3c;
    color: white;
}

.header-field-icon.missing {
    background: #f39c12;
    color: white;
}

.header-field-detail {
    font-size: 0.9rem;
    color: #2c3e50;
    padding-left: 28px;
}

.header-field-value {
    display: inline-block;
    margin-right: 16px;
}

.header-field-diff {
    color: #e74c3c;
    font-weight: 600;
}

/* API Key Authentication Overlay */
.auth-overlay {
    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: 10000;
}

.auth-overlay.hidden {
    display: none;
}

.auth-card {
    background: white;
    border-radius: 12px;
    padding: 40px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.auth-card h2 {
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 1.4rem;
}

.auth-card p {
    color: #7f8c8d;
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.auth-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 12px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.auth-input:focus {
    outline: none;
    border-color: #3498db;
}

.auth-btn {
    width: 100%;
    margin-top: 8px;
}

.auth-error {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.auth-error.hidden {
    display: none;
}
