/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --success: #4ade80;
    --error: #f87171;
    --warning: #fbbf24;
    --border: #2d3748;
    --shadow: rgba(0, 0, 0, 0.3);
}

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

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    padding: 30px 0;
    position: relative;
}

.version-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(135deg, var(--accent), #ff9a8b);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--accent), #ff9a8b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 10px;
}

.tab {
    padding: 12px 24px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    border-radius: 8px 8px 0 0;
    transition: all 0.3s ease;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.tab.active {
    color: var(--accent);
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--accent);
    margin-bottom: -12px;
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Forms */
.form {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-hint {
    display: block;
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.form-hint code {
    background: var(--bg-tertiary);
    padding: 2px 4px;
    border-radius: 4px;
    color: var(--accent);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="password"],
textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

textarea {
    resize: vertical;
    min-height: 80px;
    font-family: 'Courier New', monospace;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

/* MongoDB Paste Section */
.mongo-paste-section {
    margin-bottom: 20px;
}

.mongo-paste-section h3 {
    margin-bottom: 16px;
    color: var(--accent);
}

/* Checkbox styling */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Index Stats */
.index-stats {
    display: flex;
    gap: 24px;
    background: var(--bg-tertiary);
    padding: 16px 20px;
    border-radius: 8px;
    margin-top: 16px;
    margin-bottom: 16px;
}

.index-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.index-stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.index-stat-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-primary);
}

.index-stat-value.highlight {
    color: var(--accent);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

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

.btn-danger:hover:not(:disabled) {
    background: #ef4444;
}

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

.button-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Status Messages */
.status-message {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.status-message.success {
    background: rgba(74, 222, 128, 0.2);
    border: 1px solid var(--success);
    color: var(--success);
}

.status-message.error {
    background: rgba(248, 113, 113, 0.2);
    border: 1px solid var(--error);
    color: var(--error);
}

.status-message.warning {
    background: rgba(251, 191, 36, 0.2);
    border: 1px solid #fbbf24;
    color: #fbbf24;
}

/* Progress */
.progress-container {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.progress-bar {
    flex: 1;
    height: 24px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #ff9a8b);
    border-radius: 12px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-weight: bold;
    min-width: 50px;
}

.progress-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: bold;
}

.stat-value.success {
    color: var(--success);
}

.stat-value.error {
    color: var(--error);
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    text-transform: uppercase;
}

.status-badge.processing {
    background: rgba(251, 191, 36, 0.2);
    color: var(--warning);
}

.status-badge.completed {
    background: rgba(74, 222, 128, 0.2);
    color: var(--success);
}

.status-badge.failed, .status-badge.cancelled {
    background: rgba(248, 113, 113, 0.2);
    color: var(--error);
}

/* Error Log */
.error-log {
    margin-top: 20px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
}

.error-log summary {
    padding: 12px 16px;
    cursor: pointer;
    background: rgba(248, 113, 113, 0.1);
    color: var(--error);
}

.error-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 12px;
}

.error-item {
    padding: 8px;
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.drop-icon {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.drop-hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.divider {
    text-align: center;
    color: var(--text-secondary);
    margin: 20px 0;
    position: relative;
}

.divider::before, .divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.divider::before { left: 0; }
.divider::after { right: 0; }

.url-input-group {
    display: flex;
    gap: 12px;
}

.url-input-group input {
    flex: 1;
}

/* Preview */
.preview-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    border: 2px solid var(--border);
}

/* Results */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.search-time {
    color: var(--text-secondary);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.result-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.result-card:hover {
    transform: translateY(-4px);
}

.result-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    background: var(--bg-tertiary);
}

.result-info {
    padding: 12px;
}

.result-name {
    font-weight: bold;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-id {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.result-confidence {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.confidence-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    background: var(--success);
    border-radius: 3px;
}

.confidence-text {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--success);
}

/* Score breakdown (OCR) */
.score-breakdown {
    margin-top: 6px;
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.score-breakdown .visual-score {
    color: var(--accent);
}

.score-breakdown .text-score {
    color: #60a5fa;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    text-align: center;
}

.stat-card-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent);
}

.stat-card-label {
    color: var(--text-secondary);
    margin-top: 8px;
}

/* OCR Stats Section */
.ocr-stats-section {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
}

.ocr-stats-section h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.ocr-stats-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ocr-progress-bar {
    height: 24px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.ocr-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #ff9a8b);
    border-radius: 12px;
    transition: width 0.5s ease;
}

.ocr-stats-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.ocr-stats-details .ocr-count {
    color: var(--accent);
    font-weight: 600;
}

/* Health Status */
.health-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 20px;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.status-indicator.healthy {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.status-indicator.degraded {
    background: var(--warning);
    box-shadow: 0 0 10px var(--warning);
}

.status-indicator.unhealthy {
    background: var(--error);
    box-shadow: 0 0 10px var(--error);
}

.actions-section {
    display: flex;
    gap: 12px;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
}

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

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
}

.modal-content h3 {
    margin-bottom: 12px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

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

/* Bulk Section */
.section-desc {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.bulk-drop-zone {
    min-height: 180px;
}

.bulk-file-list {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-top: 20px;
}

.bulk-file-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.bulk-files-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.bulk-file-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-tertiary);
}

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

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

.bulk-file-item:hover .remove-file {
    opacity: 1;
}

.bulk-actions {
    margin-top: 20px;
    text-align: center;
}

.btn-large {
    padding: 16px 48px;
    font-size: 1.1rem;
}

.bulk-timer {
    margin-top: 20px;
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
}

.timer-display {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 8px;
}

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

.timer-value {
    font-size: 2.5rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: var(--accent);
}

.timer-stats {
    color: var(--text-secondary);
}

.bulk-results {
    margin-top: 24px;
}

.bulk-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.bulk-results-stats {
    display: flex;
    gap: 16px;
    color: var(--text-secondary);
}

.bulk-results-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bulk-result-row {
    display: grid;
    grid-template-columns: 100px 40px 1fr;
    gap: 12px;
    align-items: center;
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 12px;
}

.bulk-query-image {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--border);
}

.bulk-arrow {
    color: var(--text-secondary);
    font-size: 1.5rem;
    text-align: center;
}

.bulk-match-info {
    display: flex;
    gap: 12px;
    align-items: center;
}

.bulk-match-image {
    width: 80px;
    height: 80px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--bg-tertiary);
}

.bulk-match-details {
    flex: 1;
}

.bulk-match-name {
    font-weight: bold;
    margin-bottom: 4px;
}

.bulk-match-id {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.bulk-match-confidence {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bulk-result-error {
    color: var(--error);
    font-size: 0.9rem;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab {
        flex: 1;
        text-align: center;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .url-input-group {
        flex-direction: column;
    }

    .bulk-result-row {
        grid-template-columns: 80px 30px 1fr;
    }

    .bulk-query-image {
        width: 80px;
        height: 80px;
    }

    .bulk-match-info {
        flex-direction: column;
        align-items: flex-start;
    }

    .timer-value {
        font-size: 2rem;
    }
}
