:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --white: #ffffff;

  --text: #1f2937;
  --muted: #6b7280;

  --line: #e5e7eb;
  --line-dark: #d1d5db;

  --dilawri-red: #ba0c2f;
  --dilawri-red-dark: #8f0923;
  --dilawri-red-light: #f8edf0;

  --success: #0f766e;

  --hover-bg: #f9fafb;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: system-ui, -apple-system, Montserrat, Roboto, sans-serif;
}

[hidden] {
  display: none !important;
}

.dilawri-header {
  position: sticky;
  top: 0;
  z-index: 999;
  height: 80px;
  display: flex;
  align-items: center;
  background: #333;
  border-bottom: 1px solid var(--line);
}

.dilawri-header-inner {
  width: 100%;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.dilawri-header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.dilawri-logo {
  width: auto;
  max-height: 70px;
}

.dilawri-nav-list {
  display: flex;
  align-items: center;
  gap: 20px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.dilawri-nav-link,
.dilawri-nav-list a {
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.75);
  padding: 6px 0;
  white-space: nowrap;
}

.dilawri-nav-link:hover,
.dilawri-nav-list a:hover,
.dilawri-nav-link.active,
.dilawri-nav-link[aria-current="page"] {
  color: #ffffff;
}

.dilawri-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.dilawri-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dilawri-user-icon {
  width: 20px;
  height: auto;
}

.dilawri-user-name {
  margin-right: 8px;
}

.dilawri-user-name,
.dilawri-logout,
.separator {
  color: rgba(255, 255, 255, 0.55);
  font-size: 16px;
}

.dilawri-logout {
  text-decoration: none;
  padding: 8px 16px;
  margin-right: 16px;
  font-weight: 600;
}

.dilawri-logout:hover {
  color: #ffffff;
  text-decoration: none;
}

.dilawri-logout:visited , .dilawri-logout:active, .dilawri-logout:focus {
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
}

.page {
  max-width: 2000px;
  margin: 0 auto;
  padding: 24px;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.summary,
.card,
.filters {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}

.summary-head {
  margin-bottom: 18px;
}

.summary-head h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.summary-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.summary-card {
  background: #ffffffa3;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi {
  display: flex;
  align-items: center;
  gap: 14px;
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #f9e9ed;
  font-size: 20px;
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
}

.kpi-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.guidelines-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guideline {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
}

.guideline-bullet {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dilawri-red);
  margin-top: 6px;
  flex-shrink: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.card-head h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.card-actions {
  white-space: nowrap;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.opps-table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  max-height: 320px;
}

.opps-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  background: var(--white);
}

.opps-table th,
.opps-table td {
  padding: 7px 8px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: middle;
}

.opps-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f9fafb;
}

.opps-table th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--text);
}

.opps-table tbody tr:hover td {
  background: #fafafa;
}

.opps-table tbody tr:last-child td {
  border-bottom: none;
}

.opp-row {
  cursor: pointer;
}

.advanced-row {
  cursor: pointer;
}

.vehicle-col {
  text-align: center;
}

.vehicle-cell {
  font-weight: 600;
}

.opps-table th.dom-col,
.opps-table td.dom-col {
  text-align: center !important;
}

.mileage-col,
.province-col,
.money-col,
.link-col {
  white-space: nowrap;
}

.money-col,
.opps-table th.money-col,
.opps-table td.money-col {
  text-align: center !important;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.center-col,
.opps-table th.center-col,
.opps-table td.center-col {
  text-align: center !important;
}

.opps-table th.link-col,
.opps-table td.link-col {
  text-align: center;
}

.gap-positive {
  color: var(--success);
}

.vehicle-image {
  width: 80px;
  height: 62px;
  object-fit: cover;
  display: block;
  margin: 0 auto;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  background: #f3f4f6;
}

.vehicle-image.placeholder {
  width: 84px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  background: #f3f4f6;
  color: #6b7280;
  font-size: 12px;
}

.pill {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef2f7;
  color: var(--text);
}

.pill-mileage {
  background: #eef2f7;
}

.info-pill {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #d4d4d4;
  font-size: 12px;
  font-weight: 700;
}

.info-pill--province {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #eef2f7;
  font-size: 12px;
  font-weight: 700;
}

.listing-link {
  color: var(--dilawri-red);
  text-decoration: none;
  font-weight: 600;
}

.listing-link:hover {
  color: var(--dilawri-red-dark);
  text-decoration: underline;
}

.no-link {
  color: #9ca3af;
}

.view-footnote,
.modal-footnote {
  margin-top: 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
  font-size: 13px;
  color: #6b7280;
}

.calc-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: default;
}

.calc-help-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: #d4d4d4;
  font-size: 12px;
  font-weight: 700;
}

.calc-tooltip {
  position: absolute;
  left: 0.3125rem;
  right: 0;
  bottom: calc(100% + 10px);
  width: 320px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: 0.18s ease;
  z-index: 20;
}

.calc-help:hover .calc-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.filters-head {
  margin-bottom: 16px;
}

.filters-head h3 {
  margin: 0 0 4px;
  font-size: 20px;
}

.filters-sub {
  color: var(--muted);
  font-size: 14px;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select,
.combo-input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.field input:focus,
.field select:focus,
.combo-input:focus {
  border-color: var(--dilawri-red);
}

.range {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}

.range-sep {
  color: var(--muted);
  font-size: 14px;
}

.error-message {
  font-size: 12px;
  color: var(--dilawri-red);
}

.input-error {
  border-color: var(--dilawri-red) !important;
}

.combo {
  position: relative;
}

.combo-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
  padding: 8px;
}

.filters-actions {
  margin-top: 18px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn {
  height: 42px;
  padding: 0 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid transparent;
}

.primary-btn {
  background: var(--dilawri-red);
  color: var(--white);
  border: none;
}

.primary-btn:hover {
  background: var(--dilawri-red-dark);
}

.secondary-btn {
  background: #fff;
  color: var(--text);
  border-color: var(--line-dark);
}

.secondary-btn:hover {
  background: #f9fafb;
}

.table-loader,
.page-loader {
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-loader {
  flex-direction: column;
  gap: 10px;
  padding: 28px 0;
}

.page-loader {
  position: fixed;
  inset: 0;
  z-index: 1900;
  background: rgba(17, 24, 39, 0.18);
}

.page-loader-card {
  background: #fff;
  border-radius: 16px;
  padding: 24px 28px;
  min-width: 240px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.14);
}

.loader-spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 10px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--dilawri-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loader-text {
  font-size: 14px;
  color: var(--muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 12px;
}

.modal.modal-top {
  z-index: 2100;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.28);
  backdrop-filter: none;
}

.modal-panel {
  position: relative;
  width: min(1120px, calc(100vw - 24px));
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  outline: none;
  display: flex;
  flex-direction: column;
  z-index: 9999;
  height: auto;
  max-height: 80vh;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
  flex: 0 0 auto;
}

.modal-head-text {
  min-width: 0;
  flex: 1 1 auto;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.modal-subtitle {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.modal-close {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--line-dark);
  background: #f9fafb;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.modal-close:hover {
  background: #f3f4f6;
}

.modal-body {
  padding: 18px 16px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.modal-open {
  overflow: hidden;
}

.province-table-wrap,
.modal .opps-table-wrap,
.listings-table-wrap {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.modal .province-table-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
}

.modal .opps-table,
.listings-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #fff;
  table-layout: fixed;
}

.modal .opps-table thead th,
.listings-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: center;
  font-size: 12px;
  padding: 14px;
  background: #f9fafb;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  color: #111827;
}

.modal .opps-table td,
.listings-table td {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  text-align: center;
  vertical-align: middle;
}

.modal .opps-table tbody tr:hover td,
.listings-table tbody tr:hover td {
  background: #fafafa;
}

.modal .opps-table tbody tr:last-child td,
.listings-table tbody tr:last-child td {
  border-bottom: none;
}

.province-table-wrap .opps-table {
  width: 100%;
  border-collapse: collapse;
}

.province-table-wrap .opps-table thead th {
  border-bottom: 1px solid var(--line) !important;
}

.province-table-wrap .opps-table tbody td {
  border-bottom: 1px solid var(--line) !important;
}

.province-table-wrap .opps-table tbody tr:last-child td {
  border-bottom: none !important;
}

.listings-table th,
.listings-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.listings-table th:nth-child(1),
.listings-table td:nth-child(1) {
  width: 130px;
}

.listings-table th:nth-child(2),
.listings-table td:nth-child(2) {
  width: 120px;
}

.listings-table th:nth-child(3),
.listings-table td:nth-child(3) {
  width: 190px;
}

.listings-table th:nth-child(4),
.listings-table td:nth-child(4) {
  width: 260px;
  text-align: center !important;
}

.listings-table th:nth-child(5),
.listings-table td:nth-child(5) {
  width: 100px;
}

.listings-table th:nth-child(6),
.listings-table td:nth-child(6) {
  width: 90px;
}

.th-with-help {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.spread-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.spread-help-icon {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #eef2f7;
  border: 1px solid #d1d5db;
  color: #6b7280;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.spread-tooltip {
  position: absolute;
  left: 50%;
  top: calc(100% + 10px);
  bottom: auto;
  transform: translateX(-50%) translateY(-4px);
  width: 320px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #111827;
  color: #ffffff;
  font-size: 12px;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  opacity: 0;
  visibility: hidden;
  transition: 0.18s ease;
  z-index: 9999;
  white-space: normal;
  font-weight: 400;
}

.spread-sub {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.8);
}

.spread-help:hover .spread-tooltip,
.spread-help:focus-within .spread-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.prov-drill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 36px;
  padding: 0 14px;
  border: transparent;
  border-radius: 11px;
  background: #f5f5f4;
  color: #111827;
  font-weight: 500;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}

.prov-drill:hover {
  background: #e7e5e4;
  cursor: pointer;
}

.info-note {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #6b7280;
}

.info-note-icon {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #eef2f7;
  border: 1px solid #d1d5db;
  color: #6b7280;
  font-size: 11px;
  font-weight: 700;
  flex: 0 0 18px;
}

.dilawri-footer {
  margin-top: 28px;
  border-top: 1px solid var(--line);
  background: var(--card);
}

.dilawri-footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.dilawri-footer-sep {
  color: var(--line-dark);
}

.combo-option {
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.combo-option:hover {
  background: #f9fafb;
}

.combo-option[aria-selected="true"] {
  background: rgba(186, 12, 47, 0.08);
  color: var(--dilawri-red);
  font-weight: 600;
}

.combo-option:last-child {
  border-bottom: none;
}

.field-error,
.combo-hint {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--dilawri-red);
  background: rgba(186, 12, 47, 0.06);
  border: 1px solid rgba(186, 12, 47, 0.14);
  border-radius: 10px;
  padding: 8px 10px;
  display: inline-block;
  white-space: normal;
}

.footnote-extra:empty {
  display: none;
}

.market-filters-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.filters-card,
.filter-summary-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.filters-head h3,
.summary-head h3 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
  color: var(--dilawri-red);
}

.filters-sub,
.summary-head p {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 180px;
  flex: 1 1 180px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select,
.combo-input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line-dark);
  border-radius: 10px;
  padding: 0 10px;
  font-size: 14px;
  background: var(--white);
  color: var(--text);
}

.field input:focus,
.field select:focus,
.combo-input:focus {
  border-color: var(--dilawri-red);
  box-shadow: 0 0 0 2px rgba(186, 12, 47, 0.1);
}

.range {
  display: flex;
  gap: 6px;
  align-items: center;
}

.range-sep {
  font-weight: 600;
  color: var(--muted);
}

.filters-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.filter-summary-inner {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.summary-block {
  background: var(--hover-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.summary-title {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.summary-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.summary.summary--top,
.card.card--top {
  background: #f1f1f1;
  border: 1px solid #fffff05e;
}

.info-pill.info-pill--top,
.calc-help-icon.calc-help-icon--top {
  background: white;
}

.field-min-listings input {
  width: 30%;
}

.filters-card,
.filter-summary-card,
#advancedSection {
  background: #fcfcfc;
  border: 1px solid #b2abab45;
}

.advanced-table-title {
  margin: 0 0 6px;
  font-size: 18px !important;
  font-weight: 600;
  color: var(--dilawri-red);
}

.card-head h3.advanced-table-title {
  font-size: 18px !important;
}

.vehicle-img-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

@media (max-width: 1100px) {
  .summary-row {
    grid-template-columns: 1fr;
  }

  .filters-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .market-filters-grid {
    grid-template-columns: 1fr;
  }

  .filter-summary-inner {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .filters-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .dilawri-header-inner,
  .dilawri-header-left,
  .dilawri-header-right {
    flex-wrap: wrap;
  }

  .page {
    padding: 16px;
  }

  .card,
  .summary,
  .filters {
    padding: 16px;
  }

  .card-head,
  .view-footnote,
  .modal-footnote {
    flex-direction: column;
    align-items: flex-start;
  }

  .filters-grid {
    grid-template-columns: 1fr;
  }

  .calc-tooltip {
    left: 0;
    right: auto;
    width: 280px;
  }

  .modal .opps-table,
  .listings-table {
    min-width: 700px;
  }
}