/* ── Reset & Base ────────────────────────────────────────────────── */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Surface palette */
    --bg-primary: #0a0a0b;
    --bg-secondary: #111113;
    --bg-card: #141416;
    --bg-card-hover: #1a1a1d;
    --bg-elevated: #1e1e21;

    /* Border palette */
    --border-subtle: #1e1e22;
    --border-default: #2a2a2e;
    --border-strong: #3a3a3f;

    /* Text palette */
    --text-primary: #e8e8ec;
    --text-secondary: #9a9aa0;
    --text-tertiary: #6a6a70;
    --text-inverse: #0a0a0b;

    /* Accent — warm amber/gold */
    --accent: #d4a853;
    --accent-muted: rgba(212, 168, 83, 0.15);
    --accent-glow: rgba(212, 168, 83, 0.08);

    /* Score gradient stops */
    --score-high: #4ade80;
    --score-mid: #d4a853;
    --score-low: #6a6a70;

    /* Dimensions */
    --max-width: 1400px;
    --header-height: 56px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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


/* ── Status Bar ──────────────────────────────────────────────────── */

.status-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 11, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    height: var(--header-height);
}

.status-bar-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.status-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.status-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
}

.status-logo svg {
    color: var(--accent);
    flex-shrink: 0;
}

.status-logo h1 {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.status-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    transition: all var(--duration-normal) var(--ease-out);
}

.status-pill.loading {
    color: var(--accent);
}

.status-pill.ready {
    color: var(--score-high);
    border-color: rgba(74, 222, 128, 0.15);
    background: rgba(74, 222, 128, 0.06);
}

.status-pill.empty {
    color: var(--text-tertiary);
}

.btn-reindex {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.btn-reindex:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

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

.btn-reindex.loading svg {
    animation: spin 1s linear infinite;
}

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


/* ── Container ───────────────────────────────────────────────────── */

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 32px 24px 64px;
}


/* ── Upload Zone ─────────────────────────────────────────────────── */

.upload-section {
    margin-bottom: 40px;
}

.upload-zone {
    position: relative;
    border: 2px dashed var(--border-default);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    background: var(--bg-secondary);
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover {
    border-color: var(--border-strong);
    background: var(--bg-card);
}

.upload-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-glow);
    box-shadow: 0 0 0 4px var(--accent-muted);
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.upload-icon {
    color: var(--text-tertiary);
    transition: color var(--duration-normal) var(--ease-out);
}

.upload-zone:hover .upload-icon {
    color: var(--text-secondary);
}

.upload-zone.drag-over .upload-icon {
    color: var(--accent);
}

.upload-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.upload-subtitle {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

.upload-preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-preview img {
    max-height: 160px;
    max-width: 100%;
    border-radius: var(--radius-md);
    object-fit: contain;
}

.btn-clear {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border-default);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.btn-clear:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-strong);
}


/* ── Loading ─────────────────────────────────────────────────────── */

.loading-section {
    display: flex;
    justify-content: center;
    padding: 48px 0;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.loader p {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.loader-ring {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-subtle);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}


/* ── Results ─────────────────────────────────────────────────────── */

.results-section {
    animation: fadeIn var(--duration-slow) var(--ease-out);
}

.results-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 24px;
}

.results-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.results-count {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
    font-weight: 400;
}

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

@media (max-width: 1200px) {
    .results-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 900px) {
    .results-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
    .results-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
    .results-grid { grid-template-columns: 1fr; }
}


/* ── Product Card ────────────────────────────────────────────────── */

.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: all var(--duration-normal) var(--ease-out);
    animation: cardIn var(--duration-slow) var(--ease-out) both;
}

.product-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-default);
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.card-image-wrap {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-secondary);
    overflow: hidden;
}

.card-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--duration-slow) var(--ease-out);
}

.product-card:hover .card-image-wrap img {
    transform: scale(1.03);
}

.card-image-wrap a {
    display: block;
    width: 100%;
    height: 100%;
}

/* Score badge */
.score-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.score-value {
    padding: 3px 8px;
    border-radius: 100px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.score-value.high {
    background: rgba(74, 222, 128, 0.18);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.2);
}

.score-value.mid {
    background: rgba(212, 168, 83, 0.18);
    color: #d4a853;
    border: 1px solid rgba(212, 168, 83, 0.2);
}

.score-value.low {
    background: rgba(106, 106, 112, 0.18);
    color: #9a9aa0;
    border: 1px solid rgba(106, 106, 112, 0.2);
}

.score-bar {
    width: 48px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width var(--duration-slow) var(--ease-out);
}

/* Rank indicator */
.rank-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 700;
    background: rgba(10, 10, 11, 0.7);
    color: var(--text-secondary);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.06);
}


/* Card body */
.card-body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.card-item-no {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.card-description {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-price {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
    margin-top: 2px;
}

.card-details {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.card-detail {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.card-source {
    font-size: 0.6875rem;
    color: var(--text-tertiary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ── Message Section ─────────────────────────────────────────────── */

.message-section {
    text-align: center;
    padding: 48px 24px;
}

.message-section p {
    font-size: 0.9375rem;
    color: var(--text-tertiary);
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.6;
}


/* ── Animations ──────────────────────────────────────────────────── */

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

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

/* Staggered card entrance */
.product-card:nth-child(1) { animation-delay: 0ms; }
.product-card:nth-child(2) { animation-delay: 40ms; }
.product-card:nth-child(3) { animation-delay: 80ms; }
.product-card:nth-child(4) { animation-delay: 120ms; }
.product-card:nth-child(5) { animation-delay: 160ms; }
.product-card:nth-child(6) { animation-delay: 200ms; }
.product-card:nth-child(7) { animation-delay: 240ms; }
.product-card:nth-child(8) { animation-delay: 280ms; }
.product-card:nth-child(9) { animation-delay: 320ms; }
.product-card:nth-child(10) { animation-delay: 360ms; }


/* ── Reindex Modal/Toast ─────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: toastIn var(--duration-normal) var(--ease-out);
    z-index: 200;
    max-width: 360px;
}

.toast.success {
    border-color: rgba(74, 222, 128, 0.2);
}

.toast.error {
    border-color: rgba(239, 68, 68, 0.2);
}

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


/* ── Responsive adjustments ──────────────────────────────────────── */

@media (max-width: 640px) {
    .status-bar-inner {
        padding: 0 16px;
    }

    .status-logo h1 {
        font-size: 0.875rem;
    }

    .container {
        padding: 20px 16px 48px;
    }

    .upload-zone {
        padding: 32px 16px;
        min-height: 140px;
    }

    .results-grid {
        gap: 12px;
    }
}


/* ── Comparison Modal ────────────────────────────────────────────── */

.compare-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn var(--duration-normal) var(--ease-out);
}

.compare-overlay.active {
    display: flex;
}

.compare-modal {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    max-width: 960px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);
    animation: modalIn var(--duration-slow) var(--ease-out);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.compare-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.compare-close:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.compare-header {
    padding: 24px 28px 0;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.compare-header .compare-item-no {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}

.compare-header .compare-score-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
}

.compare-header .compare-score-pill.high {
    background: rgba(74, 222, 128, 0.12);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.18);
}

.compare-header .compare-score-pill.mid {
    background: rgba(212, 168, 83, 0.12);
    color: #d4a853;
    border: 1px solid rgba(212, 168, 83, 0.18);
}

.compare-header .compare-score-pill.low {
    background: rgba(106, 106, 112, 0.12);
    color: #9a9aa0;
    border: 1px solid rgba(106, 106, 112, 0.18);
}

.compare-header .compare-price {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--accent);
    margin-left: auto;
}

/* Compare body — side by side */
.compare-body {
    display: flex;
    align-items: stretch;
    gap: 0;
    padding: 20px 28px 24px;
}

.compare-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.compare-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
}

.compare-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    flex-shrink: 0;
}

.compare-vs {
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--text-tertiary);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 100px;
    padding: 6px 10px;
    letter-spacing: 0.1em;
}

/* Zoom container */
.compare-zoom-wrap {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    cursor: zoom-in;
    aspect-ratio: 1;
}

.compare-zoom-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transition: opacity var(--duration-fast) ease;
}

/* Zoom lens — magnifying glass following cursor */
.zoom-lens {
    position: absolute;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    box-shadow: 0 0 0 4px rgba(212, 168, 83, 0.15), 0 8px 32px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -50%);
    background-repeat: no-repeat;
    background-color: var(--bg-primary);
    transition: opacity var(--duration-fast) ease;
    z-index: 5;
}

.compare-zoom-wrap:hover .zoom-lens {
    opacity: 1;
}

.compare-zoom-wrap:hover {
    cursor: none;
}

/* Footer — product details */
.compare-footer {
    padding: 0 28px 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.compare-footer .compare-detail-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 100px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.compare-footer .compare-detail-chip .chip-label {
    color: var(--text-tertiary);
    font-weight: 400;
}

.compare-footer .compare-detail-chip .chip-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Responsive: stack on mobile */
@media (max-width: 640px) {
    .compare-body {
        flex-direction: column;
        gap: 16px;
        padding: 16px 16px 20px;
    }

    .compare-divider {
        padding: 4px 0;
    }

    .compare-header {
        padding: 20px 16px 0;
    }

    .compare-footer {
        padding: 0 16px 20px;
    }

    .compare-modal {
        border-radius: var(--radius-lg);
    }

    .zoom-lens {
        width: 120px;
        height: 120px;
    }
}

/* Make product card images clickable (no <a> tag) */
.card-image-wrap {
    cursor: pointer;
}
