/* ===== DESIGN TOKENS ===== */

:root {
    --accent:          #059669;
    --accent-hover:    #047857;
    --accent-light:    #ecfdf5;
    --accent-mid:      #6ee7b7;

    --replace:         #6d28d9;
    --replace-light:   #f5f3ff;

    --danger:          #dc2626;
    --danger-light:    #fef2f2;

    --amber:           #d97706;
    --amber-light:     #fffbeb;

    --bg:              #ffffff;
    --surface:         #f9fafb;
    --border:          #e5e7eb;
    --border-strong:   #d1d5db;

    --text-primary:    #111827;
    --text-secondary:  #4b5563;
    --text-muted:      #9ca3af;

    --radius:          10px;
    --radius-sm:       6px;
    --radius-lg:       14px;

    --shadow-sm:       0 1px 3px rgba(0,0,0,0.08);
    --shadow-md:       0 4px 16px rgba(0,0,0,0.08);
}

/* ===== RESET & BASE ===== */

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

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: 600;
    line-height: 1.3;
}

p {
    margin: 0;
}

a {
    color: inherit;
}

/* ===== HEADER ===== */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-logo {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.3px;
    text-decoration: none;
    cursor: pointer;
}

.header-auth {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-email {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ===== BUTTONS ===== */

button {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    padding: 9px 18px;
    transition: background 0.15s, opacity 0.15s;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

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

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

.btn-ghost {
    background: none;
    border: 1px solid var(--border-strong);
    color: var(--text-secondary);
    padding: 6px 14px;
    font-size: 0.825rem;
}

.btn-ghost:hover {
    background: var(--surface);
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    padding: 0;
    font-size: inherit;
    font-weight: 500;
    text-decoration: underline;
    cursor: pointer;
}

.btn-sm {
    font-size: 0.8rem;
    padding: 5px 12px;
}

/* ===== UPLOAD FORM ===== */

main {
    max-width: 680px;
    margin: 0 auto;
    padding: 48px 24px 80px;
}

.flex-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 40px;
}

.flex-column label {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.flex-column input[type="file"] {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.mode-container {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.mode-container label {
    font-weight: 400;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.mode-container input[type="radio"] {
    accent-color: var(--accent);
    cursor: pointer;
}

.upload-btn {
    background: var(--accent);
    color: white;
    padding: 11px 32px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

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

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

.input-error {
    color: var(--danger);
    font-size: 0.825rem;
    min-height: 1em;
}

/* ===== RESULTS ===== */

.results > p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.error-message {
    color: var(--danger);
    font-size: 0.875rem;
}

/* Hero */

.results-hero {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 24px;
    align-items: start;
    padding: 28px 28px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
}

.hero-savings-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.hero-savings-amount {
    font-size: 2.25rem;
    font-weight: 700;
    letter-spacing: -1px;
    line-height: 1;
    margin-bottom: 10px;
}

.hero-savings-amount.positive { color: var(--accent); }
.hero-savings-amount.negative { color: var(--replace); }

.hero-spend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.hero-spend-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.hero-spend-new {
    font-weight: 600;
    color: var(--text-primary);
}

/* Score */

.score-block {
    text-align: right;
}

.score-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 6px;
}

.score-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.score-bar-track {
    width: 96px;
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
    margin-left: auto;
}

.score-bar-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 0.6s ease;
}

.score-bar-fill.score-low  { background: var(--danger); }
.score-bar-fill.score-mid  { background: var(--amber); }
.score-bar-fill.score-high { background: var(--accent); }

/* Summary */

.summary-block {
    padding: 20px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 32px;
}

.summary-block p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.65;
}

/* Section headings */

.results-section {
    margin-bottom: 32px;
}

.section-heading {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* Cards */

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 8px;
    background: var(--bg);
}

/* Remove card */

.remove-card {
    border-left: 3px solid var(--danger);
}

.remove-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 6px;
}

.remove-item-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.remove-savings {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--danger);
    white-space: nowrap;
}

.card-reason {
    font-size: 0.825rem;
    color: var(--text-muted);
    line-height: 1.55;
}

/* Replace card */

.replace-card {
    border-left: 3px solid var(--replace);
}

.item-swap {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.item-col {
    flex: 1;
    min-width: 0;
}

.item-col-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.item-col-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.swap-arrow {
    color: var(--text-muted);
    font-size: 1rem;
    padding-top: 16px;
    flex-shrink: 0;
}

.replace-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.suggested-price {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent);
}

.suggested-store {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.suggested-rating {
    font-size: 0.8rem;
    color: var(--amber);
}

.buy-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 16px;
    background: var(--accent);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 0.825rem;
    font-weight: 600;
    margin-bottom: 12px;
    transition: background 0.15s;
}

.buy-link:hover {
    background: var(--accent-hover);
}

/* Keep card */

.keep-card {
    border-left: 3px solid var(--border-strong);
}

.keep-item-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Reset button */

.reset-btn {
    display: block;
    width: 100%;
    padding: 12px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    margin-top: 8px;
    cursor: pointer;
}

.reset-btn:hover {
    background: var(--surface);
    border-color: var(--border-strong);
}

/* ===== SIGN-UP GATE ===== */

#signup-gate {
    min-height: calc(100vh - 56px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    background: var(--surface);
}

#signup-gate[hidden] {
    display: none;
}

.gate-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    max-width: 440px;
    width: 100%;
    box-shadow: var(--shadow-md);
}

.gate-logo {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 24px;
}

.gate-title {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
    letter-spacing: -0.3px;
}

.gate-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.65;
    margin-bottom: 28px;
}

#gate-step-email,
#gate-step-code {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.gate-card input[type="email"],
.gate-card input[type="text"] {
    font-family: inherit;
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    color: var(--text-primary);
    background: var(--bg);
    transition: border-color 0.15s;
}

.gate-card input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

#gate-code {
    font-size: 1.5rem;
    letter-spacing: 10px;
    text-align: center;
}

.gate-card button[id="gate-send-btn"],
.gate-card button[id="gate-verify-btn"] {
    background: var(--accent);
    color: white;
    padding: 11px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    width: 100%;
}

.gate-card button[id="gate-send-btn"]:hover:not(:disabled),
.gate-card button[id="gate-verify-btn"]:hover:not(:disabled) {
    background: var(--accent-hover);
}

.gate-code-msg {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.gate-footer {
    margin-top: 20px;
    font-size: 0.825rem;
    color: var(--text-muted);
}

.auth-error {
    color: var(--danger);
    font-size: 0.825rem;
    min-height: 1.1em;
}

/* ===== AUTH MODAL ===== */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}

.modal[hidden] { display: none; }

.modal-content {
    background: var(--bg);
    padding: 36px 32px;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: var(--shadow-md);
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.modal-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.modal-close:hover {
    background: var(--surface);
    color: var(--text-primary);
}

#otp-step-email,
#otp-step-code {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-content input[type="email"],
.modal-content input[type="text"] {
    font-family: inherit;
    width: 100%;
    padding: 10px 13px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: border-color 0.15s;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.12);
}

#auth-code {
    font-size: 1.4rem;
    letter-spacing: 10px;
    text-align: center;
}

.modal-content button[id="send-code-btn"],
.modal-content button[id="verify-code-btn"] {
    background: var(--accent);
    color: white;
    padding: 10px;
    font-size: 0.875rem;
    font-weight: 600;
    width: 100%;
    border-radius: var(--radius-sm);
}

.modal-content button[id="send-code-btn"]:hover:not(:disabled),
.modal-content button[id="verify-code-btn"]:hover:not(:disabled) {
    background: var(--accent-hover);
}

/* ===== HISTORY PANEL ===== */

.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 360px;
    max-width: 100vw;
    background: var(--bg);
    border-left: 1px solid var(--border);
    z-index: 90;
    display: flex;
    flex-direction: column;
}

.side-panel[hidden] { display: none; }

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 600;
}

.panel-header h2 {
    font-size: 0.95rem;
}

#history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 40px 0;
    font-size: 0.875rem;
}

.history-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.history-item:hover {
    border-color: var(--accent);
}

.history-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.mode-badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 99px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.mode-save    { background: var(--accent-light); color: var(--accent); }
.mode-quality { background: var(--replace-light); color: var(--replace); }
.mode-value   { background: var(--amber-light); color: var(--amber); }

.history-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.history-item-body {
    display: flex;
    justify-content: space-between;
    font-size: 0.825rem;
    margin-bottom: 4px;
}

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

.history-savings {
    color: var(--accent);
    font-weight: 600;
}

.history-summary {
    font-size: 0.775rem;
    color: var(--text-muted);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 80;
}

.overlay[hidden] { display: none; }

/* ===== VIEW MANAGEMENT ===== */

#main-content.state-upload section { display: none; }
#main-content.state-results form.flex-column { display: none; }
#main-content.state-results #file-preview-wrap { display: none; }

/* ===== LOGO ===== */

.header-logo {
    display: flex;
    align-items: center;
    gap: 7px;
}

.header-logo svg {
    width: 20px;
    height: 20px;
    color: var(--accent);
}

/* ===== SUMMARY CARD ===== */

.summary-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease both;
}

.summary-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.hero-savings-sub {
    font-size: 0.825rem;
    color: var(--text-muted);
    margin-top: 2px;
    margin-bottom: 14px;
}

.spend-old {
    text-decoration: line-through;
    color: var(--text-muted);
}

.summary-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 14px;
    font-size: 0.8rem;
}

.count-dot {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.dot-circle {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.keep-dot .dot-circle    { background: var(--accent); }
.replace-dot .dot-circle { background: var(--amber); }
.remove-dot .dot-circle  { background: var(--danger); }

.summary-divider {
    height: 1px;
    background: var(--border);
    margin: 22px 0;
}

.ai-insight-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.ai-insight-label svg { width: 12px; height: 12px; }

.ai-insight-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.65;
    margin-bottom: 14px;
}

.insight-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.insight-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.775rem;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
}

.insight-badge svg { width: 12px; height: 12px; }
.insight-badge.good { background: var(--accent-light);  color: var(--accent); }
.insight-badge.warn { background: var(--amber-light);   color: var(--amber); }
.insight-badge.bad  { background: var(--danger-light);  color: var(--danger); }

/* ===== YOUR CART CARD ===== */

.your-cart-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    overflow: hidden;
    animation: fadeIn 0.3s ease 0.06s both;
}

.your-cart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 18px;
    background: none;
    border: none;
    border-radius: 0;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.your-cart-header:hover { background: var(--surface); }

.your-cart-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    pointer-events: none;
}

.your-cart-title svg { width: 14px; height: 14px; }

.cart-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.show-items-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.775rem;
    color: var(--text-muted);
    pointer-events: none;
}

.show-items-label svg {
    width: 14px;
    height: 14px;
    transition: transform 0.2s;
}

.your-cart-header[aria-expanded="true"] .show-items-label svg {
    transform: rotate(180deg);
}

.your-cart-items {
    border-top: 1px solid var(--border);
}

.cart-item-replaced .cart-item-name,
.cart-item-replaced .cart-item-price {
    color: var(--text-muted);
    font-style: italic;
}

.cart-item-removed .cart-item-name {
    text-decoration: line-through;
    color: var(--text-muted);
}

.cart-item-removed .cart-item-price { color: var(--text-muted); }

/* ===== REPLACE CARD (NEW) ===== */

.replace-card-new {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 12px;
    animation: cardIn 0.28s ease var(--delay, 0ms) both;
    transition: box-shadow 0.18s;
}

.replace-card-new:hover { box-shadow: var(--shadow-md); }

.replace-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--border);
}

.replace-panel {
    padding: 20px;
}

.current-panel {
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.suggested-panel { background: var(--bg); }

.panel-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.panel-img-wrap {
    width: 76px;
    height: 76px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--border);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.panel-img-wrap.img-error,
.keep-img-wrap.img-error {
    background: var(--surface);
}

.img-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    opacity: 0.4;
}

.img-placeholder svg { width: 28px; height: 28px; }

.panel-item-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.panel-price {
    font-size: 0.9rem;
    font-weight: 700;
    margin-top: 4px;
}

.panel-price.current-price   { color: var(--text-muted); text-decoration: line-through; }
.panel-price.suggested-price { color: var(--accent); }

.replace-footer {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.replace-reason {
    padding: 12px 20px 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.55;
    margin: 0;
}

/* ===== KEEP CARD (NEW) ===== */

.keep-card-new {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    animation: cardIn 0.28s ease var(--delay, 0ms) both;
    transition: transform 0.18s, box-shadow 0.18s;
}

.keep-card-new:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.keep-img-wrap {
    width: 100%;
    height: 156px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.keep-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 14px;
}

.keep-img-wrap .img-placeholder svg { width: 36px; height: 36px; }

.keep-card-body { padding: 14px 16px 16px; }

.keep-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 6px;
}

.keep-badge svg { width: 12px; height: 12px; }

/* Override old keep-card styles that no longer apply */
.keep-item-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== CART ITEMS LIST ===== */

.cart-items-list {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.cart-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 11px 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.cart-item-row:last-child {
    border-bottom: none;
}

.cart-item-row:nth-child(even) {
    background: var(--surface);
}

.cart-item-name {
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cart-item-price {
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* Replace card price comparison */

.item-col-price {
    font-size: 0.85rem;
    font-weight: 700;
    margin-top: 3px;
}

.item-col-price.current-price {
    color: var(--text-muted);
    text-decoration: line-through;
}

.item-col-price.suggested-price {
    color: var(--accent);
}

.suggested-store {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.suggested-store svg {
    width: 11px;
    height: 11px;
}

/* ===== FILE PREVIEW ===== */

#file-preview-wrap {
    width: 100%;
    max-width: 320px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

#file-preview-img {
    display: block;
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    border-radius: var(--radius);
}

/* ===== PROGRESS BAR ===== */

.progress-wrap {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    animation: fadeIn 0.25s ease both;
}

.progress-thumb {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.progress-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 4px;
}

.progress-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.prog-track {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
}

.prog-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 99px;
    transition: width 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-step-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

@media (max-width: 400px) {
    .progress-wrap {
        flex-direction: column;
        gap: 14px;
    }

    .progress-thumb {
        width: 100%;
        height: 120px;
    }
}

/* ===== ICONS ===== */

.section-heading {
    display: flex;
    align-items: center;
    gap: 6px;
}

.section-heading svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.btn-ghost svg {
    width: 14px;
    height: 14px;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.buy-link svg {
    width: 12px;
    height: 12px;
}

.swap-arrow {
    display: flex;
    align-items: center;
}

.swap-arrow svg {
    width: 14px;
    height: 14px;
}

.suggested-rating {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.suggested-rating svg {
    width: 12px;
    height: 12px;
    fill: var(--amber);
    color: var(--amber);
}

.upload-icon-wrap {
    color: var(--accent);
    margin-bottom: 4px;
}

.upload-icon-wrap svg {
    width: 36px;
    height: 36px;
    stroke-width: 1.5;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.upload-btn svg {
    width: 16px;
    height: 16px;
}

.reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.reset-btn svg {
    width: 14px;
    height: 14px;
}

/* ===== ANIMATIONS ===== */

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

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

.upload-btn:disabled svg {
    animation: spin 1s linear infinite;
}

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

.results-hero {
    animation: fadeIn 0.3s ease both;
}

.summary-block {
    animation: fadeIn 0.3s ease 0.08s both;
}

.results-section {
    animation: fadeIn 0.3s ease 0.12s both;
}

.card {
    animation: cardIn 0.28s ease var(--delay, 0ms) both;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ===== RESPONSIVE GRID ===== */

.cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

/* Replace cards: 1 col on mobile, 2 col on tablet+ */
.cards-grid.wide {
    grid-template-columns: 1fr;
}

/* ===== RESPONSIVE LAYOUT ===== */

main {
    max-width: 680px;
}

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

    .cards-grid.wide {
        grid-template-columns: repeat(2, 1fr);
    }

    main {
        max-width: 760px;
    }
}

@media (min-width: 1024px) {
    .cards-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .cards-grid.wide {
        grid-template-columns: repeat(2, 1fr);
    }

    main {
        max-width: 960px;
    }
}

/* Remove per-card bottom margin when in grid */
.cards-grid .card {
    margin-bottom: 0;
}

/* ===== MOBILE HEADER ===== */

@media (max-width: 480px) {
    .user-email {
        display: none;
    }

    .app-header {
        padding: 0 16px;
    }

    main {
        padding: 32px 16px 64px;
    }

    .flex-column {
        padding: 28px 20px;
    }

    .mode-container {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .results-hero {
        grid-template-columns: 1fr;
    }

    .score-block {
        text-align: left;
    }

    .score-bar-track {
        margin-left: 0;
    }
}

/* ===== AFFILIATE FOOTER ===== */

.affiliate-footer {
    text-align: center;
    padding: 24px 16px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    max-width: 640px;
    margin: 0 auto;
    line-height: 1.5;
    opacity: 0.7;
}
