/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #222632;
    --border: #2a2e3b;
    --text: #e4e6eb;
    --text-muted: #8b8fa3;
    --primary: #4f8cff;
    --primary-hover: #3a7af0;
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
    --orange: #fb923c;
    --radius: 12px;
    --glass-bg: rgba(26, 29, 39, 0.85);
    --glass-border: rgba(255, 255, 255, 0.06);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.container { max-width: 1280px; margin: 0 auto; padding: 0 20px; }

/* ── Glass Card ── */
.glass-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
}

/* ── Header ── */
.header {
    background: rgba(15, 17, 23, 0.9);
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}
.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.logo { font-size: 1.4rem; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.last-updated { color: var(--text-muted); font-size: 0.8rem; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-close {
    background: none; border: none; color: var(--text-muted);
    font-size: 1.5rem; cursor: pointer; line-height: 1;
}
.btn-close:hover { color: var(--text); }

/* ── Form Controls ── */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
input, select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
}
.modal-wide { max-width: 900px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 1.2rem; }
.modal-body { display: flex; flex-direction: column; gap: 16px; }
.modal-body h3 { margin-top: 8px; font-size: 1rem; color: var(--primary); }
.modal-footer { margin-top: 20px; text-align: right; }

/* ── Summary Row ── */
.summary-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin: 24px 0;
}
.summary-card { padding: 20px; text-align: center; }
.summary-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; }
.summary-value { font-size: 1.6rem; font-weight: 700; }
.summary-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; word-break: break-word; }

/* ── Alert Area ── */
.alert-area { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.alert-deal { background: rgba(52, 211, 153, 0.12); border: 1px solid rgba(52, 211, 153, 0.3); color: var(--green); }
.alert-threshold { background: rgba(251, 191, 36, 0.12); border: 1px solid rgba(251, 191, 36, 0.3); color: var(--yellow); }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}
.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Filter Bar ── */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    padding: 16px;
    margin-bottom: 20px;
}
.results-count { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }

/* ── Listings Grid ── */
.listings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}
.listing-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
}
.listing-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.listing-card.below-threshold { border-color: var(--green); }

.listing-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: var(--surface);
}
.listing-body { padding: 16px; }
.listing-heading {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.listing-price-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
}
.listing-price { font-size: 1.3rem; font-weight: 700; color: var(--green); }
.listing-msrp { font-size: 0.85rem; color: var(--text-muted); text-decoration: line-through; }
.listing-msrp.no-discount { text-decoration: none; }
.listing-savings { font-size: 0.8rem; color: var(--yellow); font-weight: 600; }
.listing-no-savings .listing-price { color: var(--orange); }

.listing-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.listing-meta span { display: flex; align-items: center; gap: 4px; }
.listing-dealer {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.listing-dealer strong { color: var(--text); font-weight: 500; }

/* ── Compare Table ── */
.compare-table-wrap { overflow-x: auto; padding: 4px; }
.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.compare-table th {
    text-align: left;
    padding: 12px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.compare-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.compare-table tr:hover td { background: var(--surface-hover); }
.compare-table a { color: var(--primary); text-decoration: none; }
.compare-table a:hover { text-decoration: underline; }
.savings-positive { color: var(--green); font-weight: 600; }
.savings-negative { color: var(--red); font-weight: 600; }

/* ── Chart ── */
.chart-container { padding: 20px; margin-bottom: 20px; }
.chart-container h3 { font-size: 1rem; margin-bottom: 16px; }

/* ── Loading ── */
.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    font-size: 0.9rem;
}

/* ── Detail Modal ── */
.detail-gallery {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
}
.detail-gallery img {
    height: 180px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}
.detail-specs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 0.9rem;
}
.detail-specs dt { color: var(--text-muted); }
.detail-specs dd { font-weight: 500; }
.detail-actions { margin-top: 16px; display: flex; gap: 12px; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .header-content { flex-wrap: wrap; gap: 12px; }
    .filter-bar { flex-wrap: wrap; }
    .listings-grid { grid-template-columns: 1fr; }
    .summary-row { grid-template-columns: 1fr 1fr; }
    .detail-specs { grid-template-columns: 1fr; }
}
