/*
 * 車両一覧の検索パネル（2026-11-10 車両検索の見直し）
 * 先方・社長のイメージ図（docs/evidence/search-panel-20261110/mockup.jpg）の配置。
 * ボデーカテゴリーのボタンは今までと同じ見た目（common.css の #search .body-shape-*）。
 * 今までの #search の指定は ID で書かれているので、ここも #search を付けて同じ強さにする。
 */
#search {
  --st-navy: var(--getruck-navy, #1d2a5b);
  --st-line: #dfe4ec;
  --st-panel: #f4f6fa;
  --st-ink: #1d2433;
  --st-sub: #6a7280;
  --st-red: var(--getruck-red, #c8102e);
}

#search .st-section {
  margin: 22px 0 0;
}

#search .st-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 10px;
  padding: 0;
  background: transparent;
  color: var(--st-ink);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
}

#search .st-heading:before {
  content: '';
  display: inline-block;
  flex: 0 0 auto;
  width: 5px;
  height: 1.6em;
  background: var(--st-navy);
}

/* ボデーカテゴリー：「すべて」は今までの ALL。アイコンの代わりに文字だけ */
#search .st-body-all {
  display: flex;
  align-items: center;
  justify-content: center;
}

#search .st-body-all .body-shape-label {
  justify-content: center;
  background: transparent;
  font-size: 0.95rem;
  font-weight: 800;
}

/*
 * 長いボディ名でも件数がはみ出さないよう、件数は名前の後ろで折り返す。
 * 折り返したときに件数が欠けないよう、名前の欄の高さは中身に合わせる（2026-11-17 表示QA。今までは高さ固定で2行目が切れていた）。
 * 同じ行のカードは高さが揃うので、名前の欄はカードの下に揃う。
 */
#search .body-shape-grid .body-shape-card {
  grid-template-rows: minmax(50px, 1fr) auto;
}

#search .body-shape-grid .body-shape-label {
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 2px;
  height: auto;
  min-height: 28px;
  box-sizing: border-box;
  /* 文字を大きくしているブラウザで、8列のときに名前がカードの幅に入らない場合だけ途中で折り返す（2026-11-17 表示QA） */
  overflow-wrap: anywhere;
}

#search .body-shape-card.is-empty {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 件数（ボタンの右に小さく） */
#search .st-count {
  display: inline-block;
  min-width: 1.6em;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e8ecf3;
  color: var(--st-sub);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1.6;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#search .is-selected .st-count,
#search .search-refine-option.is-current .st-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

/* 選んだボデーカテゴリーは薄い背景なので、件数は紺地に白 */
#search .body-shape-card.selected .st-count {
  background: var(--st-navy);
  color: #fff;
}

/* トンクラス・メーカー */
#search .st-row-panels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin: 12px 0 0;
}

#search .st-panel {
  padding: 14px 16px;
  border: 1px solid var(--st-line);
  border-radius: 8px;
  background: var(--st-panel);
}

#search .st-inline {
  display: flex;
  align-items: center;
  gap: 12px;
}

#search .st-inline-label {
  flex: 0 0 auto;
  min-width: 5.5em;
  color: var(--st-ink);
  font-size: 0.9rem;
  font-weight: 800;
}

#search .st-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#search .st-pill,
#search .st-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid #cfd6e2;
  background: #fff;
  color: var(--st-ink);
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
}

#search .st-pill {
  border-radius: 999px;
}

#search a.st-pill:hover,
#search a.st-option:hover {
  opacity: 1;
}

/* 枠の色はマウスのある機器だけ（タッチの機器は押した後も :hover が残るため。2026-11-23） */
@media (hover: hover) {
  #search a.st-pill:hover,
  #search a.st-option:hover {
    border-color: var(--st-navy);
  }
}

#search .st-pill.is-selected,
#search .st-option.is-selected {
  border-color: var(--st-navy);
  background: var(--st-navy);
  color: #fff;
}

#search .st-pill.is-empty,
#search .st-option.is-empty {
  border-color: #e3e7ee;
  background: #f1f3f6;
  color: #a7aeb9;
  cursor: not-allowed;
}

#search .search-refine-option.is-empty {
  border-color: #e3e7ee;
  background: #f1f3f6;
  color: #a7aeb9;
  cursor: not-allowed;
}

/*
 * 読み込み中（2026-11-17 連打の対策。car-search.js の is-loading・is-pending）
 * 読み込み中はパネルのボタンを押せない。押したボタンと画面下の該当台数に、くるくる回る印を出す。
 */
#search.is-loading a,
#search.is-loading button {
  pointer-events: none;
}

/* 押したボタンは白く覆ってくるくる回る印を出すので、common.css の薄くする指定（.cars #search a.is-pending）は打ち消す（0件のボタンと見分けがつかないため） */
.cars #search a.is-pending,
.cars #search .is-pending {
  position: relative;
  opacity: 1;
}

#search .is-pending:before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.65);
}

#search .is-pending:after,
#search.is-loading .st-summary-total:before {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--st-navy);
  border-right-color: transparent;
  border-radius: 50%;
  box-sizing: border-box;
  animation: st-spin 0.7s linear infinite;
}

#search .is-pending:after {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  margin: -8px 0 0 -8px;
}

#search.is-loading .st-summary-total:before {
  margin: 0 6px 0 0;
  vertical-align: middle;
}

#search.is-loading .st-summary-total strong {
  opacity: 0.35;
}

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

@media (prefers-reduced-motion: reduce) {
  #search .is-pending:after,
  #search.is-loading .st-summary-total:before {
    animation-duration: 2s;
  }
}

#search .st-link:focus-visible {
  outline: 3px solid #f2b705;
  outline-offset: 2px;
}

/* 年式・走行距離・価格・寸法 */
#search .st-ranges {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 32px;
  padding: 18px 20px;
}

#search .st-range {
  display: flex;
  align-items: center;
  gap: 12px;
}

#search .st-range-label {
  flex: 0 0 5.5em;
  color: var(--st-ink);
  font-size: 0.9rem;
  font-weight: 800;
}

#search .st-range-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

#search .st-search input[type="text"],
#search .st-search select {
  height: 38px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
  color: var(--st-ink);
  font-family: inherit;
  font-size: 0.9rem;
}

#search .st-range-fields input[type="text"] {
  width: 96px;
  text-align: right;
}

#search .st-range-fields input.st-input-year {
  width: 52px;
  text-align: center;
}

#search .st-range-fields select {
  width: 64px;
}

#search .st-year-pair {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#search .st-unit,
#search .st-tilde {
  color: var(--st-sub);
  font-size: 0.86rem;
  white-space: nowrap;
}

/* 詳細カテゴリー（列ごとに縦に並べる） */
#search .st-detail-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 8px;
}

#search .st-detail-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 8px;
  border: 1px solid var(--st-line);
  border-radius: 8px;
  background: var(--st-panel);
}

#search .st-detail-title {
  margin: 0 0 2px;
  color: var(--st-ink);
  font-size: 0.84rem;
  font-weight: 800;
  text-align: center;
}

#search .st-option {
  flex-wrap: wrap;
  width: 100%;
  min-height: 34px;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 0.8rem;
  text-align: center;
  box-sizing: border-box;
}

#search .st-option .st-count {
  margin-left: 4px;
}

/* 名前は単語の途中で折り返さない（折り返す所は cars/index.php で <wbr> を入れている）。それでも入らないときだけ途中で折り返す */
#search .st-label {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* 枠の右下の「絞り込む」（2026-11-17 先方指定） */
#search .st-panel-actions {
  display: flex;
  grid-column: 1 / -1;
  justify-content: flex-end;
}

#search .st-refine {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 140px;
  min-height: 40px;
  padding: 0 24px;
  border: 0;
  border-radius: 999px;
  background: var(--st-navy);
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

@media (hover: hover) {
  #search .st-refine:hover {
    opacity: 0.88;
  }
}

#search .st-refine:focus-visible,
#search .st-submit:focus-visible {
  outline: 3px solid #f2b705;
  outline-offset: 2px;
}

/* 指やマウスで押した後に、差し替えたボタンへフォーカスを戻したときは枠を出さない（Safari は戻しただけで枠を出す。car-search.js） */
#search .is-pointer-focus:focus,
#search .is-pointer-focus:focus-visible {
  outline: none;
}

/* その他の条件（管理番号・型式・ボディ長・新古車・キーワード） */
#search .st-others {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 24px;
  align-items: center;
  padding: 18px 20px;
}

#search .st-other {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#search .st-other input[type="text"],
#search .st-other select {
  flex: 1 1 auto;
  min-width: 0;
}

#search .st-other-check {
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 700;
}

#search .st-other-keyword {
  flex-wrap: wrap;
  grid-column: 1 / -1;
}

#search .st-other-keyword input[type="text"] {
  flex: 0 1 360px;
}

#search .st-other-keyword .search-keyword-tags {
  flex: 1 0 100%;
  margin: 0;
}

/*
 * 選択中の条件・該当台数・条件をクリア・この条件で検索する
 * パネルを見ている間は画面の下に固定する（car-search.js が is-floating を付ける）。
 * サイト全体の body が overflow: hidden なので sticky は使えない。
 * 固定している間は元の場所に同じ高さの空きを残す（holder の min-height。下の内容が跳ねないように）。
 */
#search .st-summary-holder {
  margin: 22px 0 0;
}

#search .st-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border: 2px solid var(--st-navy);
  border-radius: 10px;
  background: #fff;
  box-sizing: border-box;
}

#search .st-summary.is-floating {
  position: fixed;
  bottom: 12px;
  left: 50%;
  z-index: 50;
  width: min(1200px, calc(100% - 32px));
  transform: translateX(-50%);
  box-shadow: 0 -4px 18px rgba(23, 49, 101, 0.16);
}

#search .st-summary-conditions {
  min-width: 0;
  font-size: 0.86rem;
}

#search .st-summary-label {
  display: block;
  margin: 0 0 2px;
  color: var(--st-ink);
  font-weight: 800;
}

#search .st-summary-list {
  color: var(--st-sub);
  line-height: 1.5;
}

#search .st-summary-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
}

#search .st-summary-total,
#search .st-summary-total:visited {
  margin: 0;
  color: var(--st-ink);
  font-size: 0.95rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

#search .st-summary-total strong {
  color: var(--st-red);
  font-size: 1.7rem;
  font-variant-numeric: tabular-nums;
}

#search .st-clear,
#search .st-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 22px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}

#search .st-clear,
#search .st-clear:visited {
  border: 1px solid #cfd6e2;
  background: #fff;
  color: var(--st-ink);
}

#search .st-submit {
  border: 0;
  background: var(--st-navy);
  color: #fff;
}

@media (hover: hover) {
  #search .st-submit:hover {
    opacity: 0.88;
  }
}

/*
 * タッチの機器（iPhone 等）では、押した後のボタンを薄くしない（2026-11-23）
 * サイト全体の a:hover（common.css。マウスを乗せると薄くする）は、Safari では最後に押した所に残るので、
 * ページ遷移せずに一覧を差し替えた後も、押したボタンが薄いままに見えていた。
 */
@media (hover: none) {
  #search a:hover {
    opacity: 1;
  }
}

@media screen and (max-width: 1199px) {
  #search .st-detail-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media screen and (max-width: 960px) {
  #search .st-row-panels,
  #search .st-ranges {
    grid-template-columns: minmax(0, 1fr);
  }

  #search .st-others {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media screen and (max-width: 667px) {
  #search .st-inline {
    flex-direction: column;
    align-items: flex-start;
  }

  #search .st-ranges,
  #search .st-others {
    padding: 14px;
  }

  #search .st-range,
  #search .st-other:not(.st-other-check) {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  #search .st-range-label {
    flex: 0 0 auto;
  }

  /* 16px の文字で上限の7桁まで入れても切れないよう、内側の余白を詰める（2026-11-17 表示QA） */
  #search .st-range-fields input[type="text"] {
    width: 88px;
    padding: 0 6px;
  }

  /*
   * iPhone の Safari は、文字が 16px より小さい入力欄を押すと画面を拡大し、そのまま戻らない（2026-11-17 シミュレーターで確認）。
   * スマホでは入力欄・選択欄の文字を 16px にする。
   */
  #search .st-search input[type="text"],
  #search .st-search select {
    font-size: 16px;
  }

  /* 年式は「元号・年 〜 元号・年」を1行に収める（2026-11-17 表示QA。年の欄が 88px になり2行に崩れていた） */
  #search .st-range-fields input.st-input-year {
    width: 48px;
  }

  #search .st-range-fields select {
    width: 60px;
  }

  /* キーワード欄は縦に並べると高さが 360px になっていた（flex の基準の大きさが高さに効く。2026-11-17 表示QA） */
  #search .st-other-keyword input[type="text"] {
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
  }

  #search .st-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /*
   * スマホ：1行目に「選択中の条件」と「該当○台」、2行目に「条件をクリア」と「この条件で検索する」を並べる。
   * 該当台数と2つのボタンを1行にしていたときは、幅 375〜430px 前後でボタンが欄の枠から飛び出していた（2026-11-17 指摘）。
   * ボタンの並び（.st-summary-actions）は display: contents にして、4つを欄の格子に直接並べる。
   */
  #search .st-summary {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
  }

  #search .st-summary.is-floating {
    bottom: 8px;
    width: calc(100% - 16px);
  }

  #search .st-summary-actions {
    display: contents;
  }

  #search .st-summary-conditions {
    display: flex;
    grid-column: 1 / 3;
    grid-row: 1;
    gap: 8px;
    min-width: 0;
    font-size: 0.8rem;
  }

  #search .st-summary-label {
    flex: 0 0 auto;
    margin: 0;
  }

  #search .st-summary-list {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #search .st-summary-total {
    grid-column: 3;
    grid-row: 1;
    font-size: 0.8rem;
  }

  #search .st-summary-total strong {
    font-size: 1.3rem;
  }

  #search .st-clear,
  #search .st-submit {
    grid-row: 2;
    min-width: 0;
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.82rem;
  }

  #search .st-clear {
    grid-column: 1;
  }

  #search .st-submit {
    grid-column: 2 / 4;
  }
}

/* 画面の下に固定しているとき（パソコン・タブレット）：選択中の条件は2行まで（条件が多いと欄が高くなり、パネルを覆うため） */
@media screen and (min-width: 668px) {
  #search .st-summary.is-floating .st-summary-list {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}
