/* === RESET & BASE === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f0f14;
    --bg-secondary: #1a1a24;
    --bg-card: #22222e;
    --bg-card-hover: #2a2a38;
    --bg-glass: rgba(30, 30, 42, 0.85);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(139, 92, 246, 0.3);
    
    --text-primary: #f0f0f5;
    --text-secondary: #9898a8;
    --text-muted: #6b6b7d;
    
    --accent-primary: #8b5cf6;
    --accent-secondary: #6366f1;
    --accent-gradient: linear-gradient(135deg, #8b5cf6, #6366f1, #3b82f6);
    --accent-glow: rgba(139, 92, 246, 0.25);
    
    --green: #22c55e;
    --green-bg: rgba(34, 197, 94, 0.12);
    --yellow: #eab308;
    --yellow-bg: rgba(234, 179, 8, 0.12);
    --red: #ef4444;
    --red-bg: rgba(239, 68, 68, 0.12);
    --blue: #3b82f6;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);
}

html {
    font-size: 16px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* === APP CONTAINER === */
.app-container {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
}

/* === HEADER === */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 2rem;
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.db-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-card);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--yellow);
    animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.online {
    background: var(--green);
    animation: none;
}

.status-dot.offline {
    background: var(--red);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* === TAB NAVIGATION === */
.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
}

.tab-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: var(--shadow-glow);
}

.tab-icon {
    font-size: 1.1rem;
}

/* === TAB CONTENT === */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === CAMERA === */
.camera-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 12px;
}

.camera-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.camera-overlay.hidden {
    display: none;
}

.camera-placeholder {
    text-align: center;
    color: var(--text-muted);
}

.placeholder-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
    opacity: 0.5;
}

.camera-placeholder p {
    font-size: 0.85rem;
}

.captured-preview {
    position: absolute;
    inset: 0;
    z-index: 5;
}

.captured-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 30px var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-glow);
}

.btn-capture {
    padding: 16px 32px;
    font-size: 1rem;
}

/* === UPLOAD ZONE === */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    background: var(--bg-secondary);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 16px;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
    box-shadow: inset 0 0 30px rgba(139, 92, 246, 0.05);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.7;
}

.upload-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.upload-subtext {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.upload-formats {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.upload-preview-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.upload-preview-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    animation: fadeIn 0.3s ease;
}

.upload-preview-thumb {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.upload-preview-info {
    flex: 1;
    min-width: 0;
}

.upload-preview-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-preview-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.upload-preview-btn {
    padding: 8px 16px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.upload-preview-btn:hover {
    transform: scale(1.05);
}

.upload-preview-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* === LOADING === */
.loading-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px;
    gap: 16px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* === RESULTS === */
.results-section {
    margin-top: 16px;
    animation: fadeIn 0.4s ease;
}

.results-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.results-query {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: auto;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Result Card */
.result-card {
    display: flex;
    align-items: stretch;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: all 0.3s ease;
    animation: slideIn 0.4s ease;
    animation-fill-mode: both;
}

.result-card:nth-child(1) { animation-delay: 0ms; }
.result-card:nth-child(2) { animation-delay: 80ms; }
.result-card:nth-child(3) { animation-delay: 160ms; }
.result-card:nth-child(4) { animation-delay: 240ms; }
.result-card:nth-child(5) { animation-delay: 320ms; }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-16px); }
    to { opacity: 1; transform: translateX(0); }
}

.result-card:hover {
    border-color: var(--border-glow);
    background: var(--bg-card-hover);
    transform: translateX(4px);
}

.result-card.top-match {
    border-color: var(--green);
    box-shadow: 0 0 16px rgba(34, 197, 94, 0.15);
}

.result-rank {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
    flex-shrink: 0;
}

.result-card.top-match .result-rank {
    color: var(--green);
    background: var(--green-bg);
}

.result-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    flex-shrink: 0;
    margin: 8px 0;
    border-radius: var(--radius-sm);
}

.result-info {
    flex: 1;
    padding: 12px 16px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.result-sku {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    word-break: break-all;
}

.result-filename {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    flex-shrink: 0;
    min-width: 80px;
}

.result-score {
    font-size: 1.3rem;
    font-weight: 800;
}

.result-score.high { color: var(--green); }
.result-score.medium { color: var(--yellow); }
.result-score.low { color: var(--red); }

.result-score-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* Score bar */
.score-bar {
    width: 100%;
    height: 3px;
    background: var(--bg-card);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s ease;
}

.score-bar-fill.high { background: var(--green); }
.score-bar-fill.medium { background: var(--yellow); }
.score-bar-fill.low { background: var(--red); }

/* === RESPONSIVE === */
@media (max-width: 480px) {
    .app-container {
        padding: 8px;
    }
    
    .app-header {
        padding: 12px 14px;
    }
    
    .logo-text h1 {
        font-size: 1.05rem;
    }
    
    .tab-label {
        font-size: 0.8rem;
    }
    
    .result-image {
        width: 60px;
        height: 60px;
    }
    
    .result-sku {
        font-size: 0.8rem;
    }
    
    .btn-capture {
        padding: 14px 24px;
        font-size: 0.9rem;
    }
}

/* === FORM === */
.form-input {
    width: 100%;
    padding: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
/* === IMAGE MODAL === */
.image-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    padding-top: 60px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
}

.modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 80vh;
    border-radius: var(--radius-md);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
    from { transform: scale(0.7); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.modal-close:hover {
    color: var(--accent-primary);
}

.modal-caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: var(--text-primary);
    padding: 20px 0;
    font-weight: 500;
}