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

:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --header-bg: #1a1d23;
    --header-text: #f0f0f0;
    --accent: #4f7df9;
    --accent-hover: #3b66e0;
    --text: #2c2c2c;
    --text-secondary: #6b7280;
    --border: #e2e5ea;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 4px 14px rgba(0,0,0,.10);
}

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

/* ===== Header ===== */
header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 18px 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.header-content {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: baseline;
    gap: 16px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 0.85rem;
    color: #9ca3af;
}

/* ===== Main ===== */
main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
}

/* ===== Upload ===== */
.upload-section { margin-bottom: 24px; }

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    background: var(--card);
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--accent);
    background: #f0f4ff;
}

.dropzone-content svg {
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.dropzone-text {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
}

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

/* Preview row */
.preview-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.preview-thumb {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.preview-thumb img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.file-name {
    font-size: 0.88rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-analyze {
    padding: 10px 28px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    white-space: nowrap;
}

.btn-analyze:hover { background: var(--accent-hover); }
.btn-analyze:disabled { opacity: .5; cursor: not-allowed; }

.btn-clear {
    padding: 10px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background .15s;
}

.btn-clear:hover { background: #f3f4f6; }

/* ===== Loading ===== */
.loading-section {
    text-align: center;
    padding: 48px 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-text {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 4px;
}

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

/* ===== Error ===== */
.error-banner {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: var(--danger);
    padding: 12px 16px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.error-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--danger);
    padding: 0 4px;
}

/* ===== Results ===== */
.results-section { margin-top: 8px; }

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.results-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.results-meta { display: flex; gap: 8px; }

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    background: #e8f0fe;
    color: var(--accent);
}

.badge-secondary {
    background: #f3f4f6;
    color: var(--text-secondary);
}

/* Grid: debug image left, table right */
.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
}

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

.image-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.image-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 10px 14px 0;
}

.image-container {
    padding: 8px;
    cursor: zoom-in;
}

.image-container img {
    width: 100%;
    height: auto;
    border-radius: 6px;
    display: block;
}

/* Table */
.table-panel {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    align-self: start;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

thead {
    background: #f8f9fb;
}

th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 11px 14px;
    border-bottom: 1px solid #f0f1f3;
}

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

tr:hover { background: #fafbfc; }

.price-cell {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.confidence-bar {
    display: inline-block;
    height: 6px;
    border-radius: 3px;
    background: var(--accent);
    vertical-align: middle;
    margin-right: 6px;
}

.promo-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.promo-yes { background: #fef3c7; color: #92400e; }
.promo-no { background: #f3f4f6; color: #9ca3af; }

.no-results {
    padding: 32px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ===== Lightbox ===== */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 4px;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    z-index: 1001;
}

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