/*
   AcuraONLY Inventory Screener — FinViz-Inspired Dense Table
   Utility over ornament. Every pixel earns its place.
*/

/* ═══ DESIGN TOKENS ═══════════════════════════════════════════ */
:root {
  /* Surface */
  --bg-body: #EAEAEE;
  --bg-header: #1D1D1F;
  --bg-filter: #2C2C2E;
  --bg-table: #FFFFFF;
  --bg-row-alt: #F7F7FA;
  --bg-hover: #EDF2FF;
  --bg-footer: #F5F5F7;

  /* Text */
  --text-hdr: #FFFFFF;
  --text-hdr-dim: #A1A1A6;
  --text-primary: #1D1D1F;
  --text-secondary: #636366;
  --text-muted: #8E8E93;

  /* Semantic */
  --green: #34C759;
  --green-bg: #E8F5E9;
  --green-text: #1B7A2E;
  --red: #FF3B30;
  --red-bg: #FFEBEE;
  --red-text: #C62828;
  --blue: #007AFF;
  --blue-bg: #E3F2FD;
  --blue-text: #1565C0;
  --gold: #FF9500;
  --gold-bg: #FFF8E1;
  --gold-text: #E65100;
  --gray-bg: #F2F2F7;

  /* Chrome */
  --border: #D1D1D6;
  --border-light: #E5E5EA;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 6px;

  /* Type */
  --font-ui: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Menlo', 'Consolas', monospace;
  --fs-data: 11.5px;
  --fs-header: 10px;
  --fs-small: 9.5px;
}

/* ═══ RESET ═══════════════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: var(--fs-data);
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ═══ HEADER ══════════════════════════════════════════════════ */
.screener-header {
  height: 44px;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  padding: 0 12px;
  position: sticky;
  top: 0;
  z-index: 200;
  gap: 12px;
}

.hdr-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.logo-mark {
  width: 24px;
  height: 24px;
  background: #E30000;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 12px;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  color: white;
  letter-spacing: -0.02em;
}

.logo-text span {
  color: #FF3B30;
}

.hdr-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
}

.hdr-label {
  font-size: 11px;
  color: var(--text-hdr-dim);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Search */
.hdr-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 0 10px;
  width: 100%;
  max-width: 340px;
  transition: all 0.2s;
}

.search-wrap:focus-within {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
}

.search-wrap svg {
  color: var(--text-hdr-dim);
  flex-shrink: 0;
}

.search-wrap input {
  background: none;
  border: none;
  outline: none;
  color: white;
  font-size: 12px;
  padding: 6px 0;
  width: 100%;
  font-family: var(--font-ui);
}

.search-wrap input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

/* Header right */
.hdr-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.hdr-stats {
  display: flex;
  gap: 6px;
}

.stat {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  color: var(--text-hdr-dim);
}

.stat-new {
  background: rgba(0, 122, 255, 0.15);
  color: #5AC8FA;
}

.stat-used {
  background: rgba(255, 255, 255, 0.08);
  color: #A1A1A6;
}

.stat-cpo {
  background: rgba(255, 149, 0, 0.15);
  color: #FFD60A;
}

.hdr-timestamp {
  font-size: 9px;
  color: var(--text-hdr-dim);
  white-space: nowrap;
}

.hdr-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-hdr-dim);
  width: 30px;
  height: 28px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.hdr-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: white;
}

.hdr-btn-fav.active {
  color: #FF3B30;
  background: rgba(255, 59, 48, 0.15);
  border-color: rgba(255, 59, 48, 0.3);
}

/* ═══ FILTER BAR ══════════════════════════════════════════════ */
.filter-bar {
  background: var(--bg-filter);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 44px;
  z-index: 190;
  overflow-x: auto;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.filter-bar::-webkit-scrollbar {
  height: 0;
}

.fb-group {
  display: flex;
  gap: 2px;
}

.pill {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-hdr-dim);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-family: var(--font-ui);
}

.pill:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.pill.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.fb-sep {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.fb-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #D1D1D6;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-ui);
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 18px;
  outline: none;
}

.fb-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
}

.fb-select option {
  background: #2C2C2E;
  color: #D1D1D6;
}

.fb-results {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-hdr-dim);
  font-weight: 500;
  flex-shrink: 0;
}

/* ═══ MAIN TABLE ══════════════════════════════════════════════ */
.screener-main {
  padding: 8px;
}

.table-wrap {
  background: var(--bg-table);
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 110px);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 1200px;
}

/* Column widths */
.th-rank {
  width: 34px;
}

.th-fixed {
  min-width: 90px;
}

.th-num {
  text-align: right !important;
}

.th-actions {
  width: 80px;
  text-align: center !important;
}

.th-tactic {
  width: 90px;
  text-align: center !important;
}

.th-fav {
  width: 32px;
  text-align: center !important;
}

/* Header cells */
th {
  background: #F8F8FA;
  padding: 7px 8px;
  text-align: left;
  font-size: var(--fs-header);
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  letter-spacing: 0.04em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 20;
  transition: all 0.15s;
  resize: horizontal;
  overflow: hidden;
}

th[draggable="true"] {
  cursor: grab;
}

th[draggable="true"]:active {
  cursor: grabbing;
}

th.drag-over-left {
  border-left: 2px solid var(--blue) !important;
}

th.drag-over-right {
  border-right: 2px solid var(--blue) !important;
}

th:hover {
  color: var(--text-primary);
}

th.sorted {
  color: var(--blue);
}

.sa {
  font-size: 8px;
  margin-left: 2px;
  opacity: 0.4;
  vertical-align: middle;
}

th.sorted .sa {
  opacity: 1;
}

/* Data cells */
td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-light);
  font-size: var(--fs-data);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

tr:nth-child(even) td {
  background: var(--bg-row-alt);
}

tr:hover td {
  background: var(--bg-hover) !important;
}

/* Rank column */
.td-rank {
  text-align: center;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
}

/* UUID column */
.td-uuid {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--blue);
}

/* Stock & VIN columns */
.td-stock,
.td-vin {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

/* Vehicle column */
.td-vehicle {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 180px;
}

/* Type badges */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-new {
  background: var(--blue-bg);
  color: var(--blue-text);
}

.badge-used {
  background: var(--gray-bg);
  color: var(--text-muted);
}

.badge-cpo {
  background: var(--gold-bg);
  color: var(--gold-text);
}

/* Numeric cells */
.td-num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
}

.td-price {
  font-weight: 700;
}

.td-msrp {
  color: var(--text-muted);
}

/* Delta (price change) */
.td-delta {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
}

.td-delta.positive {
  color: var(--green-text);
  background: var(--green-bg) !important;
}

.td-delta.negative {
  color: var(--red-text);
  background: var(--red-bg) !important;
}

tr:hover .td-delta.positive {
  background: var(--green-bg) !important;
}

tr:hover .td-delta.negative {
  background: var(--red-bg) !important;
}

/* Color swatch */
.color-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--border);
  margin-right: 4px;
  vertical-align: middle;
}

/* Owner (dealer) cell */
.td-owner {
  cursor: pointer;
  position: relative;
}

.owner-alias {
  font-weight: 600;
  color: var(--text-secondary);
}

.owner-name {
  display: none;
  font-weight: 600;
  color: var(--text-primary);
}

.td-owner.revealed .owner-alias {
  display: none;
}

.td-owner.revealed .owner-name {
  display: inline;
}

.owner-city {
  font-size: 9px;
  color: var(--text-muted);
  display: block;
}

/* Age cell coloring */
.td-age-low {
  color: var(--green-text);
}

.td-age-mid {
  color: var(--text-secondary);
}

.td-age-high {
  color: var(--red-text);
  background: var(--red-bg) !important;
}

tr:hover .td-age-high {
  background: var(--red-bg) !important;
}

/* Score cell */
.td-score {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 800;
}

.td-score.score-hot {
  color: var(--green-text);
  background: var(--green-bg) !important;
}

.td-score.score-warm {
  color: var(--blue);
}

.td-score.score-cold {
  color: var(--text-muted);
}

tr:hover .td-score.score-hot {
  background: var(--green-bg) !important;
}

/* Contact icons */
.td-contact {
  text-align: center;
}

.contact-icons {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.c-icon {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  text-decoration: none;
  transition: all 0.15s;
  border: 1px solid transparent;
}

.c-icon:hover {
  transform: scale(1.15);
}

.c-email {
  background: #E3F2FD;
}

.c-phone {
  background: #E8F5E9;
}

.c-chat {
  background: #E8F5E9;
}

/* Tactic cell */
.td-tactic {
  text-align: center;
}

.tactic-pill {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 8.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--blue-bg);
  color: var(--blue-text);
  cursor: default;
  margin: 0 1px;
}

.tactic-pill.t-flip {
  background: #E8F5E9;
  color: #2E7D32;
}

.tactic-pill.t-sell {
  background: #E3F2FD;
  color: #1565C0;
}

.tactic-pill.t-finance {
  background: #FFF3E0;
  color: #E65100;
}

.tactic-pill.t-repair {
  background: #FBE9E7;
  color: #BF360C;
}

.tactic-pill.t-partout {
  background: #F3E5F5;
  color: #7B1FA2;
}

.tactic-pill.t-liquidate {
  background: #FFEBEE;
  color: #C62828;
}

.tactic-pill.t-consign {
  background: #E0F7FA;
  color: #00695C;
}

.tactic-pill.t-option {
  background: #F1F8E9;
  color: #33691E;
}

.tactic-pill.t-accessorize {
  background: #FCE4EC;
  color: #AD1457;
}

.tactic-pill.t-report {
  background: #ECEFF1;
  color: #455A64;
}

.tactic-pill.t-news {
  background: #FFF9C4;
  color: #F57F17;
}

.tactic-add {
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  width: 20px;
  height: 18px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.tactic-add:hover {
  border-color: var(--blue);
  color: var(--blue);
}

/* Fav cell */
.td-fav {
  text-align: center;
}

.fav-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--border);
  transition: all 0.15s;
  padding: 2px;
}

.fav-btn:hover {
  color: #FF3B30;
  transform: scale(1.2);
}

.fav-btn.is-fav {
  color: #FF3B30;
}

/* Loading state */
.td-loading {
  text-align: center;
  padding: 60px 20px !important;
  color: var(--text-muted);
  font-size: 13px;
}

/* ═══ FOOTER ══════════════════════════════════════════════════ */
.screener-footer {
  background: var(--bg-footer);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.screener-footer a {
  color: var(--blue);
  text-decoration: none;
}

.foot-sep {
  color: var(--border);
}

/* ═══ OVERLAY (Reports) ══════════════════════════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
}

.overlay.open {
  display: flex;
}

.overlay-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 480px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.ov-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
}

.ov-title {
  font-size: 15px;
  font-weight: 600;
}

.ov-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
}

.ov-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.ov-empty {
  color: var(--text-muted);
  font-size: 12px;
}

.ov-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
}

.ov-btn {
  background: var(--blue);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.15s;
}

.ov-btn:hover {
  opacity: 0.9;
}

/* Report items */
.report-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}

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

.report-info {
  font-size: 12px;
  font-weight: 500;
}

.report-date {
  font-size: 10px;
  color: var(--text-muted);
}

.report-btns {
  display: flex;
  gap: 4px;
}

.report-load,
.report-del {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.report-load:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.report-del:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ═══ TACTIC PICKER ═══════════════════════════════════════════ */
.tactic-picker {
  position: fixed;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  padding: 6px;
  z-index: 600;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 240px;
}

.tactic-picker button {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: white;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.12s;
  font-family: var(--font-ui);
}

.tactic-picker button:hover {
  background: var(--blue-bg);
  color: var(--blue);
  border-color: var(--blue);
}

/* ═══ RESPONSIVE ══════════════════════════════════════════════ */
@media (max-width: 768px) {
  .screener-header {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 10px;
    gap: 8px;
  }

  .hdr-center {
    order: 3;
    flex-basis: 100%;
  }

  .search-wrap {
    max-width: 100%;
  }

  .hdr-stats {
    display: none;
  }

  .hdr-timestamp {
    display: none;
  }

  .filter-bar {
    top: auto;
    position: relative;
  }

  .screener-main {
    padding: 4px;
  }

  table {
    min-width: 900px;
  }
}