:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2d3a;
    --text: #e4e4e7;
    --text-muted: #9ca3af;
    --accent: #3b82f6;
    --green: #22c55e;
    --yellow: #eab308;
    --red: #ef4444;
    --orange: #f97316;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* === Header & Tabs === */
header { text-align: center; padding: 24px 0 0; }
header h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 16px; }

.tab-nav { display: flex; justify-content: center; gap: 4px; margin-bottom: 24px; }
.tab-btn {
    padding: 10px 24px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); background: var(--border); }
.tab-btn.active { color: var(--accent); background: var(--bg); border-bottom: 2px solid var(--accent); font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* === Stats bar === */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin: 24px 0;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* === Filters (shared) === */
.filters, .data-filters {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
}
.filters select, .filters button,
.data-filters select, .data-filters button, .data-filters input {
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
}
.data-filters input[type="number"] { width: 110px; }
.filters button, .data-filters button {
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}
.filters button:hover, .data-filters button:hover { opacity: 0.9; }
.slider-group { display: flex; flex-direction: column; gap: 2px; }
.slider-group label { font-size: 0.8rem; color: var(--text-muted); }
.slider-group input[type="range"] { width: 140px; }

/* === Tables === */
h2 { margin-bottom: 16px; font-size: 1.2rem; }
h3 { margin: 20px 0 12px; font-size: 1rem; color: var(--text-muted); }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}
thead th {
    background: var(--border);
    padding: 12px 14px;
    text-align: left;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
tbody tr:hover { background: rgba(59, 130, 246, 0.05); }

/* === Deal colors === */
.deal-great { color: var(--green); font-weight: 700; }
.deal-good { color: var(--yellow); font-weight: 600; }
.deal-neutral { color: var(--text-muted); }
.deal-bad { color: var(--red); }
.row-great { border-left: 3px solid var(--green); }
.row-good { border-left: 3px solid var(--yellow); }
.row-bad { border-left: 3px solid var(--red); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px;
}
.pagination button {
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }
#page-info { color: var(--text-muted); font-size: 0.9rem; }

/* === Models grid === */
.models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.model-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.model-card h3 { font-size: 1rem; margin-bottom: 8px; text-transform: capitalize; color: var(--text); }
.model-card .metric { display: flex; justify-content: space-between; padding: 4px 0; font-size: 0.85rem; }
.model-card .metric-label { color: var(--text-muted); }
.model-card .metric-value { font-weight: 600; }

/* === Scraper form === */
.scraper-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
}
.checkbox-group { display: flex; gap: 20px; padding-top: 4px; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.pred-option {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
}
.pred-option input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }

.btn-primary {
    padding: 12px 32px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-large { width: 100%; }

/* === Job cards === */
.job-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.job-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.job-header .job-id { font-family: monospace; color: var(--text-muted); font-size: 0.85rem; }
.job-status {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.job-status.running { background: rgba(59, 130, 246, 0.2); color: var(--accent); }
.job-status.completed { background: rgba(34, 197, 94, 0.2); color: var(--green); }
.job-status.failed { background: rgba(239, 68, 68, 0.2); color: var(--red); }
.job-status.starting { background: rgba(249, 115, 22, 0.2); color: var(--orange); }

.job-details { font-size: 0.85rem; color: var(--text-muted); }
.job-details span { margin-right: 16px; }
.job-results {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 6px;
    vertical-align: middle;
}

/* === Data Explorer === */
.data-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.data-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.data-panel h3 { margin: 0 0 12px; font-size: 0.95rem; color: var(--text); }

/* Mini bar charts (CSS-only) */
.bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.85rem;
}
.bar-label { min-width: 100px; text-align: right; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 20px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; min-width: 2px; }
.bar-count { min-width: 50px; font-weight: 600; font-size: 0.8rem; }

/* Nested brand/model tree */
.brand-group { margin-bottom: 12px; }
.brand-header {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.brand-header:hover { color: var(--accent); }
.brand-models { padding-left: 16px; }
.model-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* === Sub-tabs (within Models tab) === */
.sub-tab-nav {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.sub-tab-btn {
    padding: 8px 20px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.sub-tab-btn:hover { color: var(--text); }
.sub-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.sub-tab-content { display: none; }
.sub-tab-content.active { display: block; }

/* === Train form === */
.train-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 24px;
}
.train-form .form-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: end;
}
.train-form .btn-primary { white-space: nowrap; }

/* === Legend === */
.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}
.legend-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.legend-card h3 { font-size: 0.95rem; margin: 0 0 8px; color: var(--text); }
.legend-card p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 8px; }
.legend-card code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--accent);
}
.legend-scale {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}
.legend-item {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 0;
}

/* === Brand checkboxes grid === */
.brand-checkboxes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 6px;
    margin-bottom: 8px;
}
.brand-checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}
.brand-checkbox-label:hover { border-color: var(--accent); }
.brand-checkbox-label:has(input:checked) {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}
.brand-checkbox-label input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; }
.brand-select-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.btn-small {
    padding: 4px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-small:hover { color: var(--text); border-color: var(--accent); }

/* === Scraper job progress pills === */
.job-progress {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.progress-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.progress-waiting { background: rgba(156, 163, 175, 0.15); color: var(--text-muted); }
.progress-listing { background: rgba(234, 179, 8, 0.2); color: var(--yellow); }
.progress-detail { background: rgba(59, 130, 246, 0.2); color: var(--accent); }
.progress-done { background: rgba(34, 197, 94, 0.2); color: var(--green); }

/* === Overall progress bar === */
.job-progress-bar-wrapper {
    margin-top: 10px;
    margin-bottom: 6px;
}
.job-progress-bar-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}
.job-progress-bar-track {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.job-progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.4s ease;
}

/* === Job detail modal === */
.job-detail-summary p {
    font-size: 0.95rem;
    line-height: 1.6;
}
.job-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.job-detail-error {
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--red);
    border-radius: var(--radius);
    color: var(--red);
    font-size: 0.85rem;
}
.job-detail-table {
    width: 100%;
    margin-top: 8px;
}
.job-detail-table tfoot td {
    border-top: 2px solid var(--border);
    font-weight: 700;
}
.job-card[style*="cursor"] {
    transition: border-color 0.15s;
}
.job-card[style*="cursor"]:hover {
    border-color: var(--accent);
}

/* === Multi-brand result pills === */
.job-results .result-brand {
    display: inline-block;
    margin-right: 12px;
    padding: 2px 0;
}
.job-results .result-total {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(34, 197, 94, 0.15);
    border-radius: 8px;
    color: var(--green);
    font-size: 0.8rem;
}

/* === Tracker tab === */
.tracker-subtitle { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 16px; }
.tracker-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}
.tracker-actions .btn-primary { white-space: nowrap; }
.tracker-status-text { font-size: 0.85rem; color: var(--text-muted); }
.empty-msg { color: var(--text-muted); font-size: 0.9rem; padding: 24px; text-align: center; }
.price-down { color: var(--green); font-weight: 600; }
.price-up { color: var(--red); font-weight: 600; }

/* === URL status indicators === */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.status-dot.active { background: var(--green); }
.status-dot.removed { background: var(--red); }
.status-dot.unknown { background: var(--text-muted); }
.link-removed {
    color: var(--text-muted);
    text-decoration: line-through;
    opacity: 0.6;
}

/* === Pipeline tab === */
.pipeline-section {
    margin-bottom: 24px;
}
.pipeline-section h3 {
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 12px;
}
.pipeline-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.scheduler-status-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.scheduler-info {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    font-size: 0.9rem;
    margin-bottom: 12px;
}
.scheduler-next-runs {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.next-run-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
}

/* Pipeline steps indicator */
.pipeline-steps {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.pipeline-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.pipeline-step .step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--border);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}
.pipeline-step .step-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}
.pipeline-step.completed .step-num {
    background: var(--green);
    border-color: var(--green);
    color: white;
}
.pipeline-step.completed .step-label { color: var(--green); }
.pipeline-step.active .step-num {
    border-color: var(--accent);
    color: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}
.pipeline-step.active .step-label { color: var(--accent); font-weight: 600; }
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(59, 130, 246, 0); }
}
.step-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    min-width: 20px;
    margin: 0 4px;
    margin-bottom: 18px;
}
.pipeline-detail {
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* === Export button === */
.btn-export {
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--green);
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-export:hover { background: rgba(34, 197, 94, 0.3); }

/* === Chart button (inline) === */
.btn-chart {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 4px;
    vertical-align: middle;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.btn-chart:hover { opacity: 1; }

/* === Duplicate groups === */
.duplicate-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}
.duplicate-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--border);
    font-size: 0.85rem;
}
.duplicate-group-id { font-weight: 700; font-family: monospace; }
.duplicate-match-type {
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    background: rgba(59, 130, 246, 0.2);
    color: var(--accent);
}
.duplicate-count { color: var(--text-muted); margin-left: auto; }
.duplicate-table { border-radius: 0; }
.duplicate-table thead th { background: transparent; }

/* === Price History Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 560px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-header h3 {
    font-size: 1rem;
    color: var(--text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80%;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* === SVG Price Chart === */
.price-chart-svg {
    width: 100%;
    height: auto;
}
.chart-line {
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
}
.chart-dot {
    fill: var(--accent);
    stroke: var(--surface);
    stroke-width: 2;
    cursor: pointer;
}
.chart-dot:hover { fill: var(--green); r: 6; }
.chart-label {
    font-size: 9px;
    fill: var(--text-muted);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.chart-grid {
    stroke: var(--border);
    stroke-width: 0.5;
    stroke-dasharray: 4 4;
}

/* === Light theme === */
[data-theme="light"] {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --border: #d1d5db;
    --text: #1f2937;
    --text-muted: #6b7280;
    --accent: #2563eb;
    --green: #16a34a;
    --yellow: #ca8a04;
    --red: #dc2626;
    --orange: #ea580c;
}
[data-theme="light"] .chart-label { fill: var(--text-muted); }
[data-theme="light"] .chart-grid { stroke: var(--border); }

/* === Login overlay === */
.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 90%;
    max-width: 360px;
    text-align: center;
}
.login-card h2 { font-size: 1.4rem; margin-bottom: 8px; }
.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

/* === Header row === */
.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-badge {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 600;
    padding: 4px 10px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 12px;
}

/* === Deal thumbnail + title cell === */
.deal-title-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}
.deal-thumb {
    width: 48px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
    background: var(--bg);
}

/* === Favorite button === */
.btn-fav {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 4px;
    color: var(--text-muted);
    vertical-align: middle;
    transition: color 0.15s;
}
.btn-fav:hover { color: var(--red); }
.btn-fav.fav-active { color: var(--red); }

/* === Compare checkbox === */
.compare-cb {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    vertical-align: middle;
    margin-left: 6px;
    cursor: pointer;
}

/* === Compare modal (wide) === */
.modal-wide {
    max-width: 900px;
}

/* === Change password modal (narrow) === */
.modal-narrow {
    max-width: 380px;
}
.change-pw-form {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.change-pw-form input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
}
.compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}
.compare-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.compare-card h4 {
    font-size: 0.95rem;
    margin-bottom: 12px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Toast notifications === */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    color: #fff;
    pointer-events: auto;
    animation: toast-in 0.3s ease-out;
    max-width: 380px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.toast.toast-hide {
    animation: toast-out 0.3s ease-in forwards;
}
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--accent); }
@keyframes toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* === Loading states === */
.section-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.section-loading .spinner {
    width: 20px;
    height: 20px;
}

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

/* === Inline style replacements === */
.filters-secondary { margin-top: -16px; padding-top: 8px; }
.predict-form { max-width: 600px; }
.predict-result { margin-top: 24px; }
.text-error { color: var(--red); }
.text-success { color: var(--green); }
.text-muted { color: var(--text-muted); }
.text-orange { color: var(--orange); }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.mt-8 { margin-top: 8px; }
.trend-panel-wide { grid-column: span 2; }
.form-group-flex { display: flex; align-items: flex-end; }

/* === Scrollable tab nav === */
.tab-nav-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 24px;
    scrollbar-width: none;
}
.tab-nav-wrapper::-webkit-scrollbar { display: none; }
.tab-nav-wrapper .tab-nav {
    margin-bottom: 0;
    flex-wrap: nowrap;
    justify-content: flex-start;
    min-width: max-content;
}

/* === Table wrapper for horizontal scroll === */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
}

/* === Responsive === */
@media (max-width: 768px) {
    .filters, .data-filters { flex-direction: column; }
    .form-row { grid-template-columns: 1fr; }
    .data-grid { grid-template-columns: 1fr; }
    table { font-size: 0.8rem; }
    thead th, tbody td { padding: 8px; }
    .tab-btn { padding: 8px 16px; font-size: 0.8rem; }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 1.2rem; }
    .stat-label { font-size: 0.7rem; }
    .trend-panel-wide { grid-column: span 1; }
    .toast-container { left: 16px; right: 16px; bottom: 16px; }
    .toast { max-width: 100%; }
}

/* === Badge & Hints === */
.badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    vertical-align: middle;
}
.badge-muted {
    background: var(--border);
    color: var(--text-muted);
    font-weight: 400;
    text-transform: uppercase;
    font-size: 0.7rem;
}
.form-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 4px;
    line-height: 1.4;
}

/* === Range slider === */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    margin: 8px 0;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    border: none;
    cursor: pointer;
}

/* === Skeleton loading === */
@keyframes skeleton-pulse {
    0% { opacity: 0.6; }
    50% { opacity: 0.3; }
    100% { opacity: 0.6; }
}
.skeleton {
    background: var(--border);
    border-radius: 4px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-row {
    display: flex;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.skeleton-cell {
    height: 14px;
    background: var(--border);
    border-radius: 4px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.skeleton-line {
    height: 12px;
    background: var(--border);
    border-radius: 4px;
    margin-bottom: 8px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-80 { width: 80%; }
.skeleton-line.w-100 { width: 100%; }
.skeleton-line.h-20 { height: 20px; }

/* === Sortable table headers === */
thead th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 22px;
}
thead th.sortable:hover {
    color: var(--text);
    background: rgba(59, 130, 246, 0.1);
}
thead th.sortable::after {
    content: "\2195";
    position: absolute;
    right: 6px;
    opacity: 0.4;
    font-size: 0.7rem;
}
thead th.sortable.sort-asc::after { content: "\2191"; opacity: 1; color: var(--accent); }
thead th.sortable.sort-desc::after { content: "\2193"; opacity: 1; color: var(--accent); }

/* === Confirm dialog === */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3500;
}
.confirm-dialog {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}
.confirm-dialog h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--text);
}
.confirm-dialog p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.confirm-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}
.btn-danger {
    padding: 10px 24px;
    border-radius: var(--radius);
    border: none;
    background: var(--red);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-danger:hover { opacity: 0.9; }
.btn-cancel {
    padding: 10px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
}
.btn-cancel:hover { background: var(--border); }

/* === Tab notification badges === */
.tab-btn { position: relative; }
.tab-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--red);
}
.tab-badge-count {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    background: var(--red);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* === Compare winner highlight === */
.compare-winner {
    color: var(--green) !important;
    font-weight: 700 !important;
}
.compare-loser {
    color: var(--text-muted) !important;
}

/* === Deal score badge === */
.deal-score {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}
.deal-score.score-a { background: var(--green); }
.deal-score.score-b { background: #4ade80; }
.deal-score.score-c { background: var(--yellow); }
.deal-score.score-d { background: var(--orange); }
.deal-score.score-f { background: var(--red); }

/* === Models search === */
.models-search-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: center;
}
.models-search-bar input {
    flex: 1;
    max-width: 300px;
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
}
.models-search-bar .result-count {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* === Infinite scroll sentinel === */
.scroll-sentinel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* === Keyboard shortcut hints === */
.kbd {
    display: inline-block;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* === Error retry === */
.error-retry {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 16px;
    color: var(--text-muted);
}
.error-retry p { font-size: 0.9rem; }
.btn-retry {
    padding: 8px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-retry:hover { border-color: var(--accent); color: var(--accent); }

/* === Deal alerts panel === */
.alert-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.alert-panel h4 {
    font-size: 0.9rem;
    margin-bottom: 8px;
}
.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.alert-item:last-child { border-bottom: none; }

/* === Duplicate indicator in deals table === */
.dup-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    background: rgba(249, 115, 22, 0.2);
    color: var(--orange);
    margin-left: 4px;
    vertical-align: middle;
}

/* === Text color classes for JS-generated HTML === */
.text-yellow { color: var(--yellow); }
.text-accent { color: var(--accent); }

/* === Quick filter presets (#1) === */
.quick-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.quick-filter-btn {
    padding: 6px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.quick-filter-btn:hover, .quick-filter-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

/* === Deal detail expand row (#2) === */
.deal-expand-row td {
    padding: 0 !important;
    border-bottom: 2px solid var(--accent);
}
.deal-detail-panel {
    background: var(--bg);
    padding: 16px 20px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    animation: slideDown 0.2s ease-out;
}
@keyframes slideDown {
    from { max-height: 0; opacity: 0; }
    to { max-height: 500px; opacity: 1; }
}
.deal-detail-section h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.deal-detail-section .metric {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 0.85rem;
}

/* === Sparkline (#3) === */
.sparkline-cell {
    display: inline-block;
    vertical-align: middle;
    margin-left: 6px;
}
.sparkline-svg {
    width: 60px;
    height: 20px;
}
.sparkline-line {
    stroke: var(--accent);
    stroke-width: 1.5;
    fill: none;
    stroke-linejoin: round;
}
.sparkline-down .sparkline-line { stroke: var(--green); }
.sparkline-up .sparkline-line { stroke: var(--red); }

/* === Price range display (#4) === */
.price-range {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}
.price-range-bar {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    position: relative;
}
.price-range-fill {
    position: absolute;
    height: 100%;
    background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
    border-radius: 4px;
}
.price-range-marker {
    position: absolute;
    top: -4px;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border: 2px solid var(--surface);
    border-radius: 50%;
    transform: translateX(-50%);
}
.predict-range-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 4px;
}

/* === Similar deals (#5) === */
.similar-deals {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 0;
}
.similar-deal-card {
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-size: 0.8rem;
    flex-shrink: 0;
}
.similar-deal-card h5 {
    font-size: 0.85rem;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}
.similar-deal-card .deal-great { color: var(--green); font-weight: 700; }

/* === Deal expand actions === */
.deal-expand-actions {
    display: flex;
    gap: 8px;
    padding: 8px 20px 16px;
    background: var(--bg);
}

/* === Dashboard summary (#7) === */
.dashboard-summary {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}
.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.summary-section h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.summary-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.85rem;
}
.summary-item .value { font-weight: 600; }
.top-deals-list {
    list-style: none;
    padding: 0;
}
.top-deals-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}
.top-deals-list li:last-child { border-bottom: none; }

/* === Watchlist tags (#9) === */
.tag-input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.tag-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 500;
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent);
    cursor: pointer;
    transition: all 0.15s;
}
.tag-pill:hover { background: rgba(59, 130, 246, 0.3); }
.tag-pill.active {
    background: var(--accent);
    color: #fff;
}

/* === Outlier warning (#10) === */
.outlier-warning {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
    margin-left: 4px;
    vertical-align: middle;
}

/* === Model performance chart (#11) === */
.perf-chart-container {
    margin-top: 16px;
}
.perf-mini-chart {
    width: 100%;
    height: 120px;
    background: var(--bg);
    border-radius: var(--radius);
    overflow: hidden;
}

/* === Map view (#12) === */
.map-container {
    width: 100%;
    height: 400px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg);
    position: relative;
}
.map-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.9rem;
    gap: 8px;
}

/* === Live mode indicator (#14) === */
.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
}
.live-indicator.live-on {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
}
.live-indicator.live-off {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* === A/B dataset comparison (#13) === */
.ab-compare-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 16px;
    align-items: start;
}
.ab-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.ab-card h4 {
    font-size: 0.9rem;
    margin-bottom: 12px;
}
.ab-vs {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-muted);
    padding-top: 40px;
}
.ab-diff-positive { color: var(--green); }
.ab-diff-negative { color: var(--red); }

/* Search history */
.search-history {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}
.search-history:empty { display: none; }
.search-history-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}
.search-history-pill {
    font-size: 0.7rem !important;
    padding: 2px 8px !important;
    opacity: 0.8;
}

/* Undo button in toast */
.btn-undo {
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.btn-undo:hover { opacity: 0.8; }

/* Colorblind-friendly deal labels */
.deal-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    opacity: 0.7;
    letter-spacing: 0.5px;
}

/* Mobile filter toggle */
.mobile-filter-toggle { display: none; }
.filters-panel.collapsed { display: none; }

@media (max-width: 768px) {
    .mobile-filter-toggle { display: block; margin-bottom: 8px; width: 100%; }
    .deal-detail-panel { grid-template-columns: 1fr; }
    .summary-grid { grid-template-columns: 1fr; }
    .ab-compare-grid { grid-template-columns: 1fr; }
    .ab-vs { padding: 8px 0; }
}
