/* ==========================================================================
   Components — buttons, forms, chips, badges, panels, cards, pagination,
   empty states, lightbox.
   ========================================================================== */

/* --- Buttons & links --------------------------------------------------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-h); padding: var(--space-2) var(--space-5);
  border: var(--border-strong) solid transparent; border-radius: var(--radius);
  font-family: var(--font-body); font-size: var(--fs-body); font-weight: var(--weight-semibold); line-height: 1.2;
  text-decoration: none; text-align: center; cursor: pointer;
  transition: background-color var(--duration-state) var(--ease), border-color var(--duration-state) var(--ease), color var(--duration-state) var(--ease);
}
.button:hover { text-decoration: none; }
.button--block { width: 100%; }
.button--small { min-height: var(--control-h-small); padding: var(--space-1) var(--space-3); font-size: var(--fs-small); }
.button--primary { background: var(--accent); color: var(--on-accent); }
.button--primary:hover { background: var(--accent-strong); }
.button--whatsapp { background: var(--whatsapp); color: var(--on-whatsapp); }
.button--whatsapp:hover { background: var(--whatsapp-strong); }
.button--dark { background: var(--ink-950); color: var(--text-on-dark); }
.button--dark:hover { background: var(--ink-800); }
.button--outline { background: transparent; color: var(--text); border-color: var(--text); }
.button--outline:hover { background: var(--text); color: var(--paper); }
.button--outline-on-dark { background: transparent; color: var(--text-on-dark); border-color: var(--ink-700); }
.button--outline-on-dark:hover { border-color: var(--text-on-dark); }

.icon-button {
  display: inline-grid; place-items: center; width: var(--control-h); height: var(--control-h);
  border: var(--hairline) solid var(--on-dark-hairline); border-radius: var(--radius);
  background: transparent; color: inherit; cursor: pointer;
}

.link-quiet { display: inline-flex; align-items: center; gap: var(--space-1); font-weight: var(--weight-semibold); text-decoration: none; }
.link-quiet .icon { width: var(--icon-small); height: var(--icon-small); }
.link-quiet:hover { text-decoration: underline; }
.link-quiet--on-dark { color: var(--text-on-dark); }

.pill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--control-h-small); padding: var(--space-1) var(--space-4);
  border-radius: var(--radius-pill); font-size: var(--fs-small); font-weight: var(--weight-semibold); text-decoration: none; white-space: nowrap;
}
.pill:hover { text-decoration: none; }
.pill--whatsapp { background: var(--whatsapp); color: var(--on-whatsapp); }
.pill--whatsapp:hover { background: var(--whatsapp-strong); }
.pill--on-dark { color: var(--text-on-dark); border: var(--hairline) solid var(--ink-700); }
.pill--on-dark:hover { border-color: var(--text-on-dark); }
.pill-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* --- Forms ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field__label { font-size: var(--fs-label); font-weight: var(--weight-semibold); line-height: var(--lh-snug); }
.field__hint { font-size: var(--fs-label); color: var(--text-muted); }
.field-error { margin-top: var(--space-3); color: var(--danger-text); font-weight: var(--weight-semibold); font-size: var(--fs-small); }
.panel-dark .field-error { color: var(--accent); }

.select { position: relative; }
.select::after {
  content: ''; position: absolute; right: var(--space-4); top: 50%;
  width: var(--space-2); height: var(--space-2); margin-top: calc(-1 * var(--space-1));
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg); pointer-events: none; opacity: 0.7;
}
.select__control, .text-input, .multiselect {
  width: 100%; min-height: var(--control-h);
  padding: var(--space-2) var(--space-10) var(--space-2) var(--space-3);
  border: var(--hairline) solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); appearance: none;
}
.text-input, .multiselect { padding-right: var(--space-3); }
.multiselect { min-height: calc(var(--control-h) * 2.5); }
.select__control:disabled, .multiselect:disabled { color: var(--text-muted); background: var(--paper-deep); cursor: not-allowed; }
.select--compact .select__control { min-height: var(--control-h-small); }

.panel-dark .select__control, .panel-dark .text-input { background: var(--ink-800); border-color: var(--ink-800); color: var(--text-on-dark); }
.panel-dark .select__control:disabled { background: var(--ink-900); border-color: var(--ink-800); color: var(--muted-on-dark); }
.panel-dark .field__label { color: var(--muted-on-dark); }

.checkbox { width: var(--icon); height: var(--icon); margin: 0; accent-color: var(--ink-950); flex: none; }
.field--check { flex-direction: row; align-items: center; gap: var(--space-2); font-size: var(--fs-small); }

.range-pair__controls { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: var(--space-2); margin-top: var(--space-1); }
.range-pair__separator { font-size: var(--fs-label); color: var(--text-muted); }
.panel-dark .range-pair__separator { color: var(--muted-on-dark); }
.range-pair legend { margin-bottom: var(--space-1); }

.check-group__list {
  display: grid; gap: var(--space-2); max-height: calc(var(--control-h) * 3.6); overflow-y: auto;
  margin-top: var(--space-2); padding: var(--space-3); border: var(--hairline) solid var(--line); border-radius: var(--radius); background: var(--surface);
}

/* Trim picker (built by search.js over the native multiselect) */
.trim-picker__search { margin-bottom: var(--space-2); }
.trim-picker__list { max-height: calc(var(--control-h) * 4); overflow-y: auto; border: var(--hairline) solid var(--line); border-radius: var(--radius); background: var(--surface); }
.trim-picker__option { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); font-size: var(--fs-small); cursor: pointer; }
.trim-picker__option:hover { background: var(--paper); }
.trim-picker__empty { padding: var(--space-2) var(--space-3); color: var(--text-muted); font-size: var(--fs-small); }
.trim-picker__chips { margin-top: var(--space-2); }

/* --- Chips, badges, pills on media ------------------------------------ */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chips--scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: var(--space-1); scrollbar-width: thin; }
.chips--scroll > li { flex: none; }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--control-h-small); padding: var(--space-1) var(--space-3);
  border: var(--hairline) solid var(--line-strong); border-radius: var(--radius-pill); background: var(--surface);
  font-size: var(--fs-small); font-weight: var(--weight-medium); text-decoration: none; white-space: nowrap; color: var(--text);
}
.chip:hover { border-color: var(--text); text-decoration: none; }
button.chip { cursor: pointer; font-family: inherit; }
.chip--reset { border-color: transparent; background: transparent; text-decoration: underline; }
.chip--quiet { background: transparent; }

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill);
  font-size: var(--fs-label); font-weight: var(--weight-semibold); line-height: var(--lh-snug);
}
.badge .icon { width: var(--icon-small); height: var(--icon-small); }
.badge--success { background: var(--success-bg); color: var(--success-text); }
.badge--sold { background: var(--ink-950); color: var(--text-on-dark); }
.media-pill {
  display: inline-flex; align-items: center; padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill); background: var(--scrim); color: var(--text-on-dark);
  font-size: var(--fs-label); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums;
}

.accident { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill); font-size: var(--fs-small); font-weight: var(--weight-semibold); }
.accident .icon { width: var(--icon-small); height: var(--icon-small); }
.accident--success { background: var(--success-bg); color: var(--success-text); }
.accident--attention { background: var(--danger-bg); color: var(--danger-text); }
.accident--neutral { background: var(--paper-deep); color: var(--text-muted); }

.checklist { display: grid; gap: var(--space-2); font-size: var(--fs-small); }
.checklist li { display: flex; gap: var(--space-2); align-items: flex-start; }
.checklist .icon { width: var(--icon-small); height: var(--icon-small); margin-top: var(--space-1); }

.note { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-8); font-size: var(--fs-small); color: var(--text-muted); }
.note .icon { width: var(--icon-small); height: var(--icon-small); }

/* --- Panels ------------------------------------------------------------ */
.panel-dark {
  padding: var(--space-5); border: var(--hairline) solid var(--ink-800); border-radius: var(--radius);
  color: var(--text-on-dark); background-color: var(--ink-900); background-image: var(--grain);
}
@media (min-width: 48rem) { .panel-dark { padding: var(--space-6); } }

.contact-card { display: grid; gap: var(--space-5); }
.contact-card__title { font-size: var(--fs-h3); font-weight: var(--weight-semibold); }
.contact-list { display: grid; gap: var(--space-3); font-size: var(--fs-small); }
.contact-list__row { display: grid; grid-template-columns: minmax(6rem, auto) 1fr; gap: var(--space-3); padding-bottom: var(--space-3); border-bottom: var(--hairline) solid var(--on-dark-hairline); }
.contact-list__row:last-child { border-bottom: 0; padding-bottom: 0; }
.contact-list dt { color: var(--muted-on-dark); }
.contact-list dd { overflow-wrap: anywhere; }
.contact-list a { text-decoration: none; }
.contact-list a:hover { text-decoration: underline; }

/* --- Car card (photo first) ------------------------------------------- */
.card-grid { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 48rem) { .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-6); } }
@media (min-width: 90rem) { .card-grid--results { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 64rem) { .card-grid--related { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.car-card { position: relative; height: 100%; }
.car-card__link {
  display: flex; flex-direction: column; height: 100%; overflow: hidden;
  border: var(--hairline) solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-1); text-decoration: none;
  transition: box-shadow var(--duration-state) var(--ease);
}
.car-card__media { position: relative; overflow: hidden; aspect-ratio: 4 / 3; background: var(--paper-deep); }
.car-card__image { width: 100%; height: 100%; object-fit: cover; transition: scale var(--duration-state) var(--ease); }
.car-card__image--placeholder { object-fit: contain; padding: var(--space-8); }
.car-card__badge { position: absolute; top: var(--space-3); left: var(--space-3); }
.car-card__photos { position: absolute; bottom: var(--space-3); left: var(--space-3); }
.car-card__body { display: flex; flex-direction: column; flex: 1; gap: var(--space-2); padding: var(--space-4) var(--space-4) var(--space-5); }
.car-card__title {
  font-size: var(--fs-card-title); font-weight: var(--weight-semibold); line-height: var(--lh-snug);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.car-card__price { margin-top: auto; padding-top: var(--space-3); transition: color var(--duration-state) var(--ease); }
/* The report link sits outside the card link, under the price; the body reserves its height. */
.car-card__report { position: absolute; left: var(--space-4); bottom: var(--space-4); z-index: 1; }
.car-card:has(.car-card__report) .car-card__body { padding-bottom: calc(var(--control-h-small) + var(--space-8)); }

@media (hover: hover) {
  .car-card__link:hover { box-shadow: var(--shadow-2); }
  .car-card__link:hover .car-card__image { scale: var(--hover-scale); }
  .car-card__link:hover .car-card__title { text-decoration: underline; text-decoration-thickness: var(--hairline); }
  .car-card__link:hover .price { color: var(--price-hover); }
}

.spec-row { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); font-size: var(--fs-small); color: var(--text-muted); }
.spec-row__item { display: inline-flex; align-items: center; gap: var(--space-1); }
.spec-row__item .icon { width: var(--icon-small); height: var(--icon-small); }

/* --- Pagination -------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-top: var(--space-10); }
.pagination__list { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-1); }
.pagination__page, .pagination__step {
  display: inline-grid; place-items: center; min-width: var(--control-h); height: var(--control-h); padding-inline: var(--space-2);
  border: var(--hairline) solid var(--line); border-radius: var(--radius); background: var(--surface);
  font-weight: var(--weight-semibold); text-decoration: none; font-variant-numeric: tabular-nums;
}
.pagination__page:hover, .pagination__step:hover { border-color: var(--text); }
.pagination__page.is-current { background: var(--ink-950); border-color: var(--ink-950); color: var(--text-on-dark); }
.pagination__gap { display: inline-grid; place-items: center; min-width: var(--space-6); color: var(--text-muted); }

/* --- Empty state ------------------------------------------------------- */
.empty-state {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); justify-items: start;
  padding: var(--space-8) var(--space-6); border: var(--hairline) dashed var(--line-strong); border-radius: var(--radius); background: var(--surface);
}
.empty-state__icon { width: var(--icon-large); height: var(--icon-large); color: var(--text-muted); }
.empty-state__title { font-size: var(--fs-h3); }
.empty-state__text { max-width: var(--measure); color: var(--text-muted); }
.empty-state__subtitle { margin-top: var(--space-4); font-family: var(--font-body); font-size: var(--fs-label); letter-spacing: 0; color: var(--text-muted); }

/* --- Status list (warranty) ------------------------------------------- */
.status-list { display: grid; gap: var(--space-5); }
.status-list__item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.status-list__title { font-size: var(--fs-card-title); font-weight: var(--weight-semibold); margin-bottom: var(--space-1); }
.status-list__text { color: var(--text-muted); }
.status-icon { display: inline-grid; place-items: center; width: var(--timeline-dot); height: var(--timeline-dot); border-radius: var(--radius-pill); }
.status-icon .icon { width: var(--icon-small); height: var(--icon-small); }
.status-icon--success { background: var(--success-bg); color: var(--success-text); }
.status-icon--neutral { background: var(--paper-deep); color: var(--text-muted); }

/* --- Lightbox (built by lightbox.js) ---------------------------------- */
.lightbox { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0; border: 0; background: var(--scrim-strong); color: var(--text-on-dark); }
.lightbox::backdrop { background: var(--scrim-strong); }
.lightbox__stage { position: absolute; inset: var(--space-16) 0 calc(var(--thumb-w) + var(--space-8)); display: grid; place-items: center; touch-action: pan-y; }
.lightbox__image { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox__close, .lightbox__arrow {
  position: absolute; display: inline-grid; place-items: center; width: var(--control-h); height: var(--control-h);
  border: var(--hairline) solid var(--on-dark-hairline); border-radius: var(--radius); background: var(--scrim); color: var(--text-on-dark); cursor: pointer;
}
.lightbox__close { top: var(--space-3); right: var(--space-3); }
.lightbox__arrow { top: 50%; translate: 0 -50%; }
.lightbox__arrow--prev { left: var(--space-3); }
.lightbox__arrow--next { right: var(--space-3); }
.lightbox__counter { position: absolute; top: var(--space-5); left: var(--space-4); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.lightbox__thumbs { position: absolute; inset-inline: 0; bottom: var(--space-3); display: flex; gap: var(--space-2); overflow-x: auto; padding-inline: var(--gutter); }
.lightbox__thumb { flex: none; width: var(--thumb-w); padding: 0; border: 2px solid transparent; border-radius: var(--radius); overflow: hidden; background: none; cursor: pointer; opacity: 0.6; }
.lightbox__thumb.is-current { border-color: var(--text-on-dark); opacity: 1; }
.lightbox__thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
