:root {
    --primary: #0066ff;
    --primary-hover: #0052cc;
    --bg-dark: #0d1117;
    --bg-card: #161b22;
    --bg-card-2: #1c2333;
    --text-main: #e6edf3;
    --text-muted: #7d8590;
    --accent-green: #2ea043;
    --accent-orange: #f0a030;
    --accent-red: #da3633;
    --border-color: rgba(255,255,255,0.08);
    --border-hover: rgba(255,255,255,0.2);
    --radius: 12px;
    --shadow: 0 8px 24px rgba(0,0,0,0.4);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
}

/* ── HEADER ── */
header {
    background: linear-gradient(180deg, rgba(0,102,255,0.12) 0%, transparent 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 2.5rem 1rem 2rem;
    text-align: center;
    animation: fadeIn 0.7s ease-out;
}

.logo-container h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -1px;
    background: linear-gradient(135deg, #fff 40%, var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    margin-top: 0.5rem;
}

/* ── MAIN LAYOUT ── */
main {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
}

/* ── UPLOAD CARD ── */
.upload-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow);
    margin-bottom: 2.5rem;
    animation: fadeIn 0.5s ease-out;
}

/* ── TABS ── */
.input-tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.45rem 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    border-radius: 6px;
}

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

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s; }

/* ── UPLOAD AREA ── */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 1.3rem 1rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.upload-area:hover, .upload-area.drag-over {
    border-color: var(--primary);
    background: rgba(0,102,255,0.05);
}

.upload-icon {
    font-size: 1.8rem;
    margin-bottom: 0.4rem;
}

/* ── TEXTAREA ── */
.modern-textarea {
    width: 100%;
    height: 140px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-main);
    padding: 1rem;
    font-size: 0.95rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

.modern-textarea:focus { border-color: var(--primary); }

/* ── PRE-PROCESS SETTINGS ── */
.pre-process-settings {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding: 1rem 1.2rem;
    background: rgba(255,255,255,0.025);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    gap: 1rem;
}

.input-inline { display: flex; align-items: center; gap: 0.6rem; font-size: 0.9rem;}

.small-input {
    width: 75px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: white;
    padding: 0.5rem;
    border-radius: 8px;
    text-align: center;
    font-size: 0.9rem;
}

/* ── BUTTONS ── */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.7rem 1.6rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0,102,255,0.35);
}

.btn-primary:disabled {
    background: #30363d;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-outline {
    border: 1px solid var(--primary);
    color: var(--primary);
    text-decoration: none;
    text-align: center;
    padding: 0.55rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: block;
}

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

.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 0.7rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-text {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

/* ── LOADING STAGES ── */
.loading-container {
    display: none;
    margin-top: 1.5rem;
    padding: 1.2rem 1.5rem;
    background: rgba(255,255,255,0.025);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.stage {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
    opacity: 0.35;
    transition: opacity 0.3s;
}

.stage.active { opacity: 1; color: var(--primary); }
.stage.done { opacity: 1; color: var(--accent-green); }

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

.stage.active .dot { animation: pulse 1.5s infinite; }

/* ── RESULTS SECTION ── */
#results-container {
    display: none;
    animation: fadeIn 0.5s ease-out;
}

.item-group { margin-bottom: 2.5rem; }

.item-header {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.2rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.item-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}

.offers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.2rem;
}

/* ── OFFER CARD ── */
.offer-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: all 0.2s;
    position: relative;
}

.offer-card:hover { border-color: var(--border-hover); }

.offer-card.best-price { border-color: var(--accent-green); }

/* ★ State: Selected */
.offer-card.is-selected {
    border-color: var(--primary);
    background: rgba(0,102,255,0.08);
    box-shadow: 0 0 0 1px var(--primary);
}

.store-name {
    font-size: 0.72rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.offer-title {
    font-size: 0.9rem;
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.offer-price {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.price-badge {
    font-size: 1rem;
    font-weight: 700;
}

.sale-price { color: var(--accent-green); }

.shipping-info {
    font-size: 0.8rem;
    color: var(--accent-orange);
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.btn-select {
    flex: 1;
    padding: 0.55rem;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-select:hover { border-color: var(--primary); color: var(--primary); }

.btn-select.selected {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ── BUDGET DASHBOARD ── */
#budget-calculator {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    margin-top: 2.5rem;
    margin-bottom: 4rem;
    box-shadow: var(--shadow);
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.8rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.dashboard-header h2 { font-size: 1.15rem; font-weight: 700; }

.summary-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem;
    margin-bottom: 2rem;
}

.stat-card {
    padding: 1.3rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: var(--bg-card-2);
}

.stat-card.highlight {
    background: linear-gradient(135deg, var(--primary), #0044cc);
    border: none;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 0.4rem;
}

.stat-card.highlight .stat-label { color: rgba(255,255,255,0.65); }
.stat-value { font-size: 1.5rem; font-weight: 800; }
.text-green { color: var(--accent-green); }

/* ── TABLE ── */
.table-responsive { overflow-x: auto; border-radius: var(--radius); }

.modern-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card-2);
    font-size: 0.9rem;
}

.modern-table thead tr {
    background: rgba(255,255,255,0.04);
}

.modern-table th {
    padding: 0.9rem 1rem;
    text-align: left;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
}

.modern-table td {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

/* ── MODAL ── */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0; top: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(6px);
}

.modal-content {
    background: var(--bg-card);
    margin: 8% auto;
    padding: 2.5rem;
    border-radius: 16px;
    max-width: 580px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    animation: fadeIn 0.3s ease-out;
}

.modal-content h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.2rem;
    margin: 1.5rem 0;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    color: white;
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus { border-color: var(--primary); }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.8rem;
    margin-top: 1.5rem;
}

/* ── TOAST ── */
#toast {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 0.9rem 1.6rem;
    border-radius: 10px;
    font-size: 0.9rem;
    z-index: 1100;
    animation: fadeIn 0.3s ease;
    max-width: 320px;
}

/* ── RESPONSIVE ── */
@media (max-width: 700px) {
    header { padding: 1.5rem 1rem; }
    .logo-container h1 { font-size: 1.6rem; }
    main { padding: 1.5rem 1rem 3rem; }
    .summary-stats-grid { grid-template-columns: 1fr 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .pre-process-settings { flex-direction: column; align-items: flex-start; }
}
