:root {
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --yellow-bg: #fef9c3;
  --yellow: #ca8a04;
  --blue-bg: #eff6ff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); padding: 16px; font-size: 13px; }
.container { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* Header */
header { background: var(--card-bg); padding: 14px 20px; border: 1px solid var(--border); border-radius: 8px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
h1 { font-size: 18px; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* Card */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px 18px; }

/* Split Top Sections */
.top-sections { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .top-sections { grid-template-columns: 1fr; } }

.section-title { font-size: 13px; font-weight: 700; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 3px; }
label { font-size: 11px; font-weight: 600; color: #475569; }
input[type="number"], input[type="text"], select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px; font-size: 12px; background: #fff; }
input:focus, select:focus { outline: none; border-color: var(--primary); }
.help { font-size: 10px; color: var(--muted); }

.model-prices-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.model-prices-title { font-size: 11px; font-weight: 700; color: var(--primary); margin-bottom: 6px; text-transform: uppercase; }
.model-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 6px; }

/* Location & Transfer Fee Box */
.location-box { background: var(--blue-bg); border: 1px solid #bfdbfe; border-radius: 6px; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.location-box strong { font-size: 12px; color: #1e40af; }

.checkbox-row { display: flex; flex-wrap: wrap; gap: 12px; padding-top: 6px; border-top: 1px dashed var(--border); font-size: 12px; align-items: center; }
.checkbox-row label { font-size: 12px; font-weight: 500; color: var(--text); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }

/* Summary Stats */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.stat-box { padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.stat-val { font-size: 19px; font-weight: 700; }
.stat-val.good { color: var(--green); }

/* Column Filter Bar */
.filter-section { display: flex; flex-direction: column; gap: 10px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; align-items: end; }
.range-inputs { display: flex; gap: 4px; align-items: center; }
.range-inputs input { width: 50%; }

/* Buttons */
.btn { padding: 5px 12px; border: 1px solid var(--border); background: #fff; border-radius: 5px; cursor: pointer; font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.btn:hover { background: #f8fafc; }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { opacity: 0.9; }
.btn-live { background: #059669; color: #fff; border-color: #059669; font-weight: 600; }
.btn-live:hover { background: #047857; }

/* Table Container with Max-Height & Sticky Header */
.table-card { padding: 0; overflow: hidden; }
.table-container { max-height: 540px; overflow: auto; position: relative; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; }
thead th { 
  position: sticky; 
  top: 0; 
  z-index: 10; 
  background: #edf2f7; 
  padding: 9px 10px; 
  font-weight: 600; 
  border-bottom: 2px solid var(--border); 
  cursor: pointer; 
  user-select: none; 
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
thead th:hover { background: #e2e8f0; }
thead th.sorted { color: var(--primary); }
thead th.non-sortable { cursor: default; }
thead th.non-sortable:hover { background: #edf2f7; }
td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:nth-child(even) { background: #fafbfc; }
tr:hover { background: #f1f5f9; }

/* Pagination Bar */
.pagination-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; background: #f8fafc; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.page-controls { display: flex; gap: 4px; align-items: center; }
.page-btn { padding: 3px 8px; font-size: 11px; border: 1px solid var(--border); background: #fff; border-radius: 4px; cursor: pointer; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Badges & Tags */
.badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; white-space: nowrap; }
.badge-great { background: var(--green-bg); color: var(--green); }
.badge-fair { background: var(--yellow-bg); color: var(--yellow); }
.badge-over { background: var(--red-bg); color: var(--red); }
.delta-good { color: var(--green); font-weight: 700; font-size: 13px; }
.delta-bad { color: var(--red); font-weight: 700; font-size: 13px; }
.fee-badge { font-weight: 600; color: #475569; }
.fee-zero { color: var(--green); font-weight: 700; }

.tag { display: inline-block; padding: 1px 5px; border-radius: 3px; font-size: 10px; font-weight: 500; margin-right: 3px; background: #e2e8f0; }
.tag-clean { background: #dcfce7; color: #15803d; font-weight: 600; }
.tag-salvage { background: #fee2e2; color: #b91c1c; font-weight: 700; }
.tag-awd { background: #dbeafe; color: #1d4ed8; }
.tag-perf { background: #fef3c7; color: #b45309; }
.tag-fsd { background: #f3e8ff; color: #7e22ce; }
.btn-link { display: inline-block; padding: 3px 8px; background: var(--primary); color: #fff; text-decoration: none; border-radius: 4px; font-size: 11px; font-weight: 500; }
.btn-link:hover { opacity: 0.9; }
.formula-box { font-size: 11px; color: var(--muted); background: #f1f5f9; padding: 10px 14px; border-radius: 6px; }
.save-indicator { font-size: 11px; color: var(--green); font-weight: 600; opacity: 0; transition: opacity 0.3s ease; }
.save-indicator.show { opacity: 1; }

/* Live Status Banner */
.live-status-banner { font-size: 11px; padding: 8px 12px; border-radius: 6px; display: none; margin-bottom: 4px; align-items: center; justify-content: space-between; }
.live-status-banner.info { display: flex; background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.live-status-banner.success { display: flex; background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.live-status-banner.warning { display: flex; background: #fef9c3; color: #854d0e; border: 1px solid #fef08a; }
