/* ======================================================================
   MARKETPLACE — the hirer's search screen (js/screens/contractorSearch.js).

   Utility-first: the search widget and the category rail sit at the top,
   machines start near the fold, filters live in a rail (desktop) or a
   bottom sheet (phone), and every card ends in the two actions that make a
   hire happen. Light cool-grey canvas, white cards with a crisp 1px border.

   Component map
     .search-hero    the search module: title, three-segment widget, trust bar
     .pill-rail      category pills with counts
     .market         two-column body: .filter-rail + .catalog
     .filter-rail    sticky rail on desktop, bottom sheet on the phone
     .results-bar    count · active filter tags · sort · view toggle
     .machine-card   the listing card
   ====================================================================== */

:root {
  --line: #e5e7eb;
  --ok-600: #1e9e55;
  --wa-500: #25d366;
  --wa-600: #1faa53;
}

/* ---- Search hero -------------------------------------------------------- */
.search-hero { background: var(--color-surface); border-bottom: 1px solid var(--line); }
.search-hero-inner { padding: 12px 16px 14px; }
.search-hero .page-head { padding: 6px 0 10px; margin: 0; border: 0; display: block; }
.search-hero .page-title { font-size: 24px; line-height: 1.1; }
.search-hero .page-sub { font-size: 13px; margin-top: 4px; max-width: none; }

/* Phone: the keyword box on its own row, location and term side by side,
   the button full width - four rows, not five, so machines sit nearer the
   fold. */
.search-widget { display: grid; gap: 8px; margin-top: 6px; grid-template-columns: 1fr 1fr; }
.seg-query, .seg-go { grid-column: 1 / -1; }
.seg { position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.seg > label {
  font-family: var(--font-heading); font-size: 10.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--color-neutral-600);
}
.seg .input { min-height: 46px; font-size: 15px; background: var(--color-surface); }
.seg-location .row { gap: 6px; }
.seg-location .input { flex: 1; min-width: 0; }
.seg-location #fArea { flex: 1.2; }
.near-btn {
  flex: none; min-height: 46px; width: 46px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--color-surface); cursor: pointer;
  border-radius: var(--radius-md); color: var(--color-neutral-700);
}
.near-btn[aria-expanded="true"], .near-btn.set { border-color: var(--brand-500); color: var(--brand-700); background: var(--brand-100); }
.near-btn svg { width: 18px; height: 18px; }

.term-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.term-toggle button {
  min-height: 46px; padding: 0 14px; flex: 1; border: 0; background: var(--color-surface);
  font-family: var(--font-heading); font-weight: 600; font-size: 12px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--color-neutral-700); cursor: pointer;
}
.term-toggle button + button { border-left: 1px solid var(--line); }
.term-toggle button.on { background: var(--steel-900); color: var(--brand-300); }

.search-go { min-height: 46px; padding: 0 20px; font-size: 14px; gap: 8px; white-space: nowrap; }
.search-go svg { width: 17px; height: 17px; }

.search-widget-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; min-height: 22px; }
.query-hints { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--color-neutral-700); }
.query-hint { border: 1px dashed var(--color-neutral-400); padding: 2px 8px; border-radius: 999px; }
.query-hint b { color: var(--steel-900); font-weight: 600; }
.clear-all {
  margin-left: auto; font-size: 12px; text-decoration: underline; color: var(--brand-700);
  background: none; border: 0; cursor: pointer; padding: 2px 0; font-family: inherit;
}

/* Suggestions under the keyword box. */
.suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 25; margin-top: 4px;
  background: var(--color-surface); border: 1px solid var(--line); box-shadow: var(--shadow-md);
  max-height: 380px; overflow: auto; border-radius: var(--radius-md);
}
.suggest-group {
  padding: 9px 12px 3px; font-family: var(--font-heading); font-size: 10px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--color-neutral-600);
}
.suggest-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; font-size: 14px; cursor: pointer;
}
.suggest-item:hover, .suggest-item.active { background: var(--brand-100); }
.suggest-item small { color: var(--color-neutral-600); font-size: 11px; white-space: nowrap; }
.suggest-item .kbd { font-size: 10px; border: 1px solid var(--line); padding: 0 5px; color: var(--color-neutral-600); }

.trust-bar {
  display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px;
  font-size: 12px; color: var(--color-neutral-700);
}
.trust-bar span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.trust-bar span::before { content: "✔"; color: var(--ok-600); font-weight: 700; }

/* ---- Category pills ----------------------------------------------------- */
.pill-rail { padding: 10px 16px 0; }
.pill-rail .chip {
  border-radius: 999px; background: var(--color-surface); border-color: var(--line);
  padding: 7px 13px; font-size: 12px; color: var(--color-neutral-800);
}
.pill-rail .chip:hover { border-color: var(--brand-500); color: var(--brand-700); }
.pill-rail .chip.on { background: var(--steel-900); border-color: var(--steel-900); color: var(--brand-300); }
.chip-count { opacity: .62; margin-left: 4px; font-size: 11px; letter-spacing: 0; }
.pill-rail .chips-note { padding: 0; margin-top: 6px; }

/* ---- Two-column body ---------------------------------------------------- */
.market { display: grid; gap: 14px; padding: 12px 16px 0; align-items: start; }
.catalog { min-width: 0; }

/* ---- Filter rail -------------------------------------------------------- */
.filter-rail {
  background: var(--color-surface); border: 1px solid var(--line); padding: 14px 16px;
  border-radius: var(--radius-md);
}
.rail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.rail-head h2 { font-size: 16px; margin: 0; letter-spacing: .04em; text-transform: uppercase; }
.rail-close { display: none; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--color-neutral-600); }
.rail-section { padding: 12px 0; border-top: 1px solid var(--line); }
.rail-section:first-of-type { border-top: 0; }
.rail-title {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-family: var(--font-heading); font-weight: 600; font-size: 12px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--steel-900); margin-bottom: 8px;
}
.rail-title small { font-family: var(--font-body); font-size: 11px; color: var(--color-neutral-600); text-transform: none; letter-spacing: 0; }
.rail-section .field + .field { margin-top: 10px; }
.rail-section .field > label { font-size: 12px; }
.rail-section .input { min-height: 38px; font-size: 13px; }
.rail-check { display: flex; align-items: center; gap: 9px; font-size: 13px; padding: 5px 0; cursor: pointer; }
.rail-check input { width: 16px; height: 16px; accent-color: var(--brand-500); margin: 0; }
.rail-foot {
  display: flex; gap: 8px; padding-top: 12px; margin-top: 4px;
  position: sticky; bottom: 0; background: var(--color-surface);
}
.rail-foot .btn { flex: 1; min-height: 42px; font-size: 13px; }

/* Dual-thumb range: two native sliders stacked, tracks shared, thumbs live. */
.range-dual { position: relative; height: 26px; margin: 4px 2px 0; }
.range-dual::before {
  content: ""; position: absolute; left: 0; right: 0; top: 11px; height: 4px;
  background: var(--color-neutral-300); border-radius: 2px;
}
.range-dual .range-fill { position: absolute; top: 11px; height: 4px; background: var(--brand-500); border-radius: 2px; }
.range-dual input[type="range"] {
  position: absolute; inset: 0; width: 100%; height: 26px; margin: 0;
  appearance: none; -webkit-appearance: none; background: transparent; pointer-events: none;
}
.range-dual input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.range-dual input[type="range"]::-moz-range-track { height: 4px; background: transparent; }
.range-dual input[type="range"]::-webkit-slider-thumb {
  pointer-events: auto; appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; border-radius: 50%; margin-top: -7px; cursor: pointer;
  background: var(--brand-500); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--steel-900);
}
.range-dual input[type="range"]::-moz-range-thumb {
  pointer-events: auto; width: 14px; height: 14px; border-radius: 50%; cursor: pointer;
  background: var(--brand-500); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--steel-900);
}
.range-values { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.range-values .input { min-height: 34px; font-size: 13px; padding: 4px 8px; }
.range-values span { font-size: 12px; color: var(--color-neutral-600); }

/* ---- Results bar -------------------------------------------------------- */
.results-bar { margin-bottom: 10px; }
.results-count { font-size: 13px; font-weight: 600; color: var(--steel-900); }
.results-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.results-bar .input-compact { min-height: 36px; background: var(--color-surface); }
.active-tags { display: flex; gap: 6px; flex-wrap: wrap; flex-basis: 100%; }
.active-tags:empty { display: none; }
.tag-filter {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px;
  border: 1px solid var(--line); background: var(--color-surface); font-size: 12px;
  color: var(--color-neutral-800); cursor: pointer; border-radius: 999px;
}
.tag-filter:hover { border-color: var(--brand-500); }
.tag-filter b { font-weight: 600; color: var(--steel-900); }
.tag-filter .x { color: var(--color-neutral-600); font-size: 13px; }
.view-toggle { display: inline-flex; border: 1px solid var(--line); background: var(--color-surface); border-radius: var(--radius-md); overflow: hidden; }
.view-toggle button {
  width: 38px; height: 36px; border: 0; background: transparent; cursor: pointer;
  color: var(--color-neutral-600); display: grid; place-items: center;
}
.view-toggle button + button { border-left: 1px solid var(--line); }
.view-toggle button.on { background: var(--steel-900); color: var(--brand-300); }
.view-toggle svg { width: 16px; height: 16px; }
.filter-btn { min-height: 36px; padding: 0 14px; font-size: 12px; gap: 6px; background: var(--color-surface); }
.filter-btn svg { width: 15px; height: 15px; }

/* ---- Cards -------------------------------------------------------------- */
.machine-card {
  padding: 0; overflow: hidden; background: var(--color-surface);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: none;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.machine-card:hover, .machine-card:focus-within {
  transform: translateY(-2px); border-color: var(--color-neutral-400);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--steel-900) 10%, transparent);
}
.card-media { position: relative; background: var(--color-neutral-100); }
.card-media .card-photo { aspect-ratio: 16 / 9; margin: 0; border: 0; border-bottom: 1px solid var(--line); }
.card-badges { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-family: var(--font-heading); font-weight: 600; font-size: 10.5px; letter-spacing: .06em;
  text-transform: uppercase; padding: 4px 8px; border-radius: 3px; line-height: 1.2;
}
.badge-live { background: var(--ok-600); color: #fff; }
.badge-verified { background: var(--brand-500); color: var(--brand-ink); }
.badge-hire { background: var(--steel-800); color: #fff; }
.badge-unconfirmed { background: #fff; color: var(--color-neutral-800); border: 1px solid var(--line); }

.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-heading {
  margin: 0; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap;
  font-family: var(--font-heading); font-weight: 600; font-size: 17px; line-height: 1.15; letter-spacing: .01em;
}
.card-year { color: var(--color-neutral-600); font-weight: 500; }
.card-heading .card-title { font-size: inherit; }
.card-owner { font-size: 12.5px; color: var(--color-neutral-700); }
.card-loc { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--color-neutral-700); }
.card-loc svg { width: 14px; height: 14px; flex: none; color: var(--brand-600); }
.card-loc .card-note { margin: 0; font-size: inherit; color: inherit; }
.card-specs { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.spec {
  font-size: 11.5px; padding: 3px 8px; border-radius: 3px; white-space: nowrap;
  background: var(--color-neutral-100); border: 1px solid var(--line); color: var(--color-neutral-800);
}
.spec-cert { border-color: var(--brand-300); background: var(--brand-100); color: var(--brand-700); }
.spec-tool { border-color: var(--steel-700); background: var(--steel-900); color: var(--brand-300); }
.card-price-block { margin-top: auto; padding-top: 10px; border-top: 1px dashed var(--line); }
.card-price-block .card-price { font-size: 18px; }
.card-price-block .card-price small { font-size: 11px; }
.card-price-alt { display: block; font-size: 12px; color: var(--color-neutral-600); margin-top: 1px; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions .btn { flex: 1; min-height: 40px; font-size: 12.5px; letter-spacing: .04em; text-transform: uppercase; gap: 6px; }
.card-actions svg { width: 16px; height: 16px; }
.btn-whatsapp { background: var(--wa-500); border-color: var(--wa-500); color: #fff; font-weight: 700; }
.btn-whatsapp:hover { background: var(--wa-600); border-color: var(--wa-600); }

/* Empty state: the message the tests know, then a way out. */
.feed-empty-wrap { grid-column: 1 / -1; text-align: center; padding: 36px 16px; }
.feed-empty-wrap .feed-empty { font-size: 13px; color: var(--color-neutral-700); }
.feed-empty-actions { margin-top: 10px; }

/* ======================================================================
   PHONE — the rail is a bottom sheet.
   ====================================================================== */
@media (max-width: 1023px) {
  .filter-rail {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    max-height: 86dvh; overflow: auto; border-radius: 14px 14px 0 0; border: 0;
    box-shadow: var(--shadow-lg); padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .rail-close { display: block; }
  .sheet-backdrop { position: fixed; inset: 0; z-index: 59; background: color-mix(in srgb, var(--steel-900) 45%, transparent); }
  .search-hero .page-head { padding-top: 10px; }
}

/* ======================================================================
   DESKTOP — inline widget, sticky rail, three-column grid.
   ====================================================================== */
@media (min-width: 1024px) {
  .ph { background: var(--color-bg); }
  .search-hero-inner { max-width: var(--content-max); margin: 0 auto; padding: 24px var(--content-gutter) 18px; }
  .search-hero .page-title { font-size: 30px; }
  .search-hero .page-sub { font-size: 14px; }
  .search-widget {
    grid-template-columns: minmax(0, 1fr) 380px auto auto; align-items: end; gap: 10px;
    background: var(--color-neutral-100); border: 1px solid var(--line); padding: 10px;
    border-radius: 8px; margin-top: 10px;
  }
  .seg-query, .seg-go { grid-column: auto; }
  .seg .input { min-height: 48px; }
  .term-toggle button, .near-btn, .search-go { min-height: 48px; }
  .search-go { padding: 0 24px; font-size: 15px; }
  .search-widget-foot { margin-top: 8px; }

  /* width:100% - an auto cross-axis margin on a flex item otherwise shrinks
     the rail to its content and centres it. */
  .pill-rail { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 12px var(--content-gutter) 0; }

  .market {
    grid-template-columns: 280px minmax(0, 1fr); gap: 20px;
    max-width: var(--content-max); margin: 12px auto 0; padding: 0 var(--content-gutter);
    width: 100%;
  }
  .filter-rail {
    position: sticky; top: calc(var(--nav-h) + 12px); align-self: start;
    max-height: calc(100vh - var(--nav-h) - 24px); overflow: auto;
  }
  .sheet-backdrop { display: none !important; }
  /* The rail is always open on desktop, so the toggle has nothing to do. */
  .filter-btn { display: none; }

  /* Count and controls on one line; active-filter tags on their own row
     beneath (desktop.css sets nowrap for the old toolbar - undo it here). */
  .results-bar { flex-wrap: wrap; }
  .results-count { flex: none; }

  .catalog .feed { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

  /* List view: one machine per row, photo on the left. The media slot is a
     fixed-size box the photo fills, so the row's height comes from the
     text, not from whatever shape the photo happens to be. */
  .catalog .feed.feed-list { grid-template-columns: 1fr; }
  .feed-list .machine-card { flex-direction: row; }
  .feed-list .card-media { width: 300px; flex: none; position: relative; min-height: 220px; }
  .feed-list .card-media .card-photo {
    position: absolute; inset: 0; width: 100%; height: 100%; aspect-ratio: auto;
    border-bottom: 0; border-right: 1px solid var(--line);
  }
  .feed-list .card-body { padding: 14px 18px; }
  .feed-list .card-actions { max-width: 360px; }
}
@media (min-width: 1700px) {
  .catalog .feed { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
