:root {
  --bg: #0b0b0e;
  --card-bg: #16161a;
  --border: #282830;
  --accent: #00adef;
  --text: #ffffff;
  --muted: #9e9ea8;
  --diff-bg: rgba(0, 173, 239, 0.08);
  --color-plus: #4cd964;
  --color-minus: #ff3b30;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', 'Noto Sans Thai', sans-serif; }
html, body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-anchor: none; /* ป้องกัน browser ปรับตำแหน่ง scroll เองตอนความสูงการ์ดรถเปลี่ยน (เคยทำให้เลื่อนจอแล้วเด้งกลับ) */
}
body { padding-bottom: 60px; }

header {
  background: #111114;
  padding: 14px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
header h1 { font-weight: 300; letter-spacing: 2px; color: #e0e0e0; font-size: 1.1rem; text-transform: uppercase; }

.container { max-width: 1200px; margin: 0 auto; padding: 10px; }

/* ===== Vehicle selection ===== */
.selection-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.selection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.select-group { display: flex; flex-direction: column; gap: 6px; width: 100%; min-width: 0; }
.select-group label { font-size: 0.75rem; font-weight: 700; color: var(--accent); letter-spacing: 0.5px; }
.select-row { display: flex; gap: 6px; width: 100%; min-width: 0; }

select {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: #202026;
  border: 1px solid var(--border);
  color: #fff;
  padding: 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  outline: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
select:focus { border-color: var(--accent); }

/* ===== Feature Filter Panel ===== */
.feature-filter-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.feature-filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.feature-filter-header h4 {
  font-size: 0.78rem;
  color: var(--accent);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  font-weight: 700;
}
.feature-filter-header .ff-arrow {
  font-size: 0.75rem;
  color: var(--muted);
  transition: transform 0.3s;
  flex-shrink: 0;
  margin-left: 10px;
}
.feature-filter-header.open .ff-arrow { transform: rotate(180deg); }
.feature-filter-body { display: none; margin-top: 10px; }
.feature-filter-body.open { display: block; }
.feature-search-wrap { position: relative; }
#featureSearchInput {
  width: 100%;
  background: #202026;
  border: 1px solid var(--border);
  color: #fff;
  padding: 9px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
}
#featureSearchInput:focus { border-color: var(--accent); }
.feature-autocomplete {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #1a1a20;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 60;
  display: none;
  box-shadow: 0 10px 20px rgba(0,0,0,0.35);
}
.feature-autocomplete.open { display: block; }
.feature-autocomplete-item {
  padding: 9px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  color: #d0d0d8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  white-space: pre-line;
}
.feature-autocomplete-item:last-child { border-bottom: none; }
.feature-autocomplete-item:hover { background: rgba(0,173,239,0.12); color: #fff; }
.feature-autocomplete-item .cat-tag {
  color: var(--muted);
  font-size: 0.66rem;
  white-space: nowrap;
  background: #101014;
  padding: 2px 6px;
  border-radius: 4px;
}
.feature-autocomplete-empty {
  padding: 12px;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.feature-chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.feature-chip {
  background: rgba(0,173,239,0.15);
  border: 1px solid rgba(0,173,239,0.4);
  color: #fff;
  padding: 5px 8px 5px 10px;
  border-radius: 14px;
  font-size: 0.76rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.feature-chip .chip-remove { cursor: pointer; color: var(--muted); font-weight: 800; padding: 0 2px; }
.feature-chip .chip-remove:hover { color: var(--color-minus); }
.feature-limit-note { font-size: 0.7rem; color: var(--muted); margin-top: 6px; }

.popular-features-row { margin-top: 12px; }
.popular-features-row .pf-label { font-size: 0.7rem; color: var(--muted); margin-bottom: 6px; letter-spacing: 0.3px; }
.pf-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #1d1d24;
  border: 1px solid var(--border);
  color: #c8c8d2;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.73rem;
  cursor: pointer;
  margin: 2px 5px 2px 0;
  transition: all 0.2s;
}
.pf-chip:hover { border-color: var(--accent); color: #fff; }
.pf-chip .pf-count {
  color: var(--accent);
  font-weight: 700;
  background: rgba(0,173,239,0.15);
  padding: 0 5px;
  border-radius: 8px;
  font-size: 0.68rem;
}
.pf-chip.disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.filter-results { margin-top: 14px; }
.filter-results-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 8px; }
.filter-result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.filter-car-card {
  background: #1a1a20;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  text-align: center;
}
.filter-car-card img {
  width: 100%;
  height: 80px;
  object-fit: contain;
  background: #08080a;
  border-radius: 5px;
  margin-bottom: 6px;
}
.filter-car-card .fc-name { font-size: 0.76rem; color: #fff; line-height: 1.25; min-height: 30px; }
.filter-car-card .fc-my { color: var(--muted); font-size: 0.68rem; }
.filter-car-card .fc-price { font-size: 0.8rem; color: var(--accent); font-weight: 700; margin: 4px 0 6px; }
.filter-car-card .fc-btns { display: flex; gap: 4px; }
.filter-car-card .fc-btn {
  flex: 1;
  font-size: 0.68rem;
  padding: 6px 3px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: #202026;
  color: #c8c8d2;
  cursor: pointer;
  font-weight: 600;
}
.filter-car-card .fc-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-empty { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 14px 0; grid-column: 1 / -1; }

/* ===== Sticky car header ===== */
.sticky-wrapper {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 999;
  background: var(--bg);
  padding: 6px 0;
  border-bottom: 2px solid var(--border);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.car-display-grid { display: grid; gap: 10px; }
.grid-1-col { grid-template-columns: 1fr; }
.grid-2-col { grid-template-columns: 1fr 1fr; }

/* การ์ดสองใบสูงเท่ากันอยู่แล้ว (grid stretch) จัดเป็น flex column แล้วดันราคาลงล่างสุด
   ราคาของทั้งสองคันจึงอยู่ระดับเดียวกันเสมอ แม้ชื่อรุ่นจะยาวไม่เท่ากัน */
.car-card-header {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.25s ease;
}
.car-card-header .price { margin-top: auto; padding-top: 6px; }

.img-wrapper {
  position: relative;
  width: 100%;
  max-height: 220px;
  opacity: 1;
  background: #08080a;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: max-height 0.4s ease, opacity 0.3s ease, margin 0.4s ease, border-width 0.4s ease;
}
.img-wrapper img {
  width: 100%;
  height: 100%;
  max-height: 220px;
  object-fit: contain;
  display: block;
}

.car-card-header h3 {
  font-size: 1.05rem;
  margin-top: 6px;
  color: #fff;
  line-height: 1.25;
  transition: all 0.25s ease;
}
.car-card-header .my-badge {
  display: inline-block;
  background: #252530;
  color: var(--muted);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 4px;
  transition: all 0.25s ease;
}
.car-card-header .price {
  color: var(--accent);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  text-shadow: 0 0 10px rgba(0, 173, 239, 0.2);
  transition: all 0.25s ease;
}

.controls-bar {
  padding: 8px 0 2px 0;
  display: flex;
  gap: 8px;
}
.btn-action {
  background: #1d1d24;
  border: 1px solid var(--border);
  color: #d0d0d8;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.2s;
}
.btn-action:hover { border-color: var(--accent); color: #fff; }
.btn-action.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.icon-plus { color: var(--color-plus); font-weight: 800; font-size: 0.95rem; }
.icon-minus { color: var(--color-minus); font-weight: 800; font-size: 0.95rem; }

/* ตอนการ์ดรถติดขอบบนจอ: ย่อรูปลงแบบนุ่มนวล (ใช้ max-height แทน display:none เพื่อให้ transition ทำงาน) */
.sticky-wrapper.is-scrolled .img-wrapper {
  max-height: 0;
  opacity: 0;
  margin: 0;
  border-width: 0;
  pointer-events: none;
}
.sticky-wrapper.is-scrolled .car-card-header {
  padding: 6px 10px;
  background: #181820;
  border-color: rgba(0, 173, 239, 0.3);
}
.sticky-wrapper.is-scrolled h3 { font-size: 1.05rem; font-weight: 700; margin-top: 0; }
.sticky-wrapper.is-scrolled .my-badge { font-size: 0.68rem; margin-top: 2px; background: #20202a; }
.sticky-wrapper.is-scrolled .price { font-size: 1.05rem; padding-top: 2px; }

/* ===== AI summary ===== */
.ai-box {
  background: linear-gradient(135deg, #121924 0%, #0c0f17 100%);
  border: 1px solid rgba(0, 173, 239, 0.4);
  border-radius: 8px;
  margin: 12px 0;
  overflow: hidden;
  box-shadow: 0 0 15px rgba(0, 173, 239, 0.15);
}
.ai-header {
  padding: 12px 15px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: rgba(0, 173, 239, 0.05);
  user-select: none;
}
.ai-title {
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #00adef, #00ffcc, #00adef);
  background-size: 200% auto;
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  animation: shine 3s linear infinite;
}
@keyframes shine { to { background-position: 200% center; } }
.ai-arrow { font-size: 0.75rem; color: var(--accent); transition: transform 0.3s; }
.ai-header.open .ai-arrow { transform: rotate(180deg); }

.ai-body {
  display: none;
  padding: 16px 18px;
  border-top: 1px solid rgba(0, 173, 239, 0.2);
  word-break: break-word;
}
.ai-body.open { display: block; }
#aiSummaryContent { font-size: 0.98rem; line-height: 1.75; color: #f1f5f9; }
#aiSummaryContent strong { color: #fff; }

/* ===== Spec table ===== */
#specContainer { min-height: 75vh; padding-bottom: 40px; }
.cat-accordion {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-bg);
}
.cat-header {
  background: #1a1a20;
  padding: 12px 15px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--accent);
  user-select: none;
}
.cat-header .arrow { transition: transform 0.3s; font-size: 0.75rem; color: var(--muted); }
.cat-header.open .arrow { transform: rotate(180deg); }
.cat-body { display: none; }
.cat-body.open { display: block; }

.spec-row {
  display: grid;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid rgba(255,255,255,0.04);
  align-items: center;
  font-size: 0.8rem;
}
.spec-row.grid-1-col { grid-template-columns: 130px 1fr; }
.spec-row.grid-2-col { grid-template-columns: 110px 1fr 1fr; }
.spec-row.is-diff { background: var(--diff-bg); }
.spec-name {
  color: #d6d6de;
  font-weight: 600;
  word-break: break-word;
  white-space: pre-line;
}
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 0.6rem;
  font-style: italic;
  font-weight: 700;
  margin-left: 5px;
  cursor: pointer;
  vertical-align: middle;
  transition: all 0.2s;
}
.info-icon:hover { background: var(--accent); color: #fff; }
.spec-val { text-align: center; font-weight: 600; word-break: break-word; white-space: pre-line; }
.badge-true { color: #4cd964; }
.badge-false { color: #ff3b30; opacity: 0.4; }
.diff-badge {
  background: rgba(0,173,239,0.2);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.68rem;
  font-weight: 400;
}
.pdf-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0,173,239,0.2);
}
.spec-thumbs { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.spec-thumb {
  width: 110px;
  height: 75px;
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  background: #000;
}
.spec-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ===== Modals ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(5px);
}
.modal-overlay.open { display: flex; }
.modal-content { position: relative; max-width: 90vw; max-height: 85vh; text-align: center; }
.modal-img-wrapper {
  width: 90vw;
  height: 80vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 0 20px rgba(0, 173, 239, 0.3);
  background: #000;
}
.modal-content img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
  cursor: grab;
}
.modal-content img.is-panning { cursor: grabbing; }
.modal-zoom-hint { margin-top: 8px; color: var(--muted); font-size: 0.72rem; }
.modal-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  z-index: 5;
  transition: background 0.2s;
}
.modal-nav-btn:hover { background: rgba(0,173,239,0.5); }
.modal-nav-prev { left: -6px; }
.modal-nav-next { right: -6px; }
.hidden { display: none !important; }
.modal-counter { margin-top: 6px; color: var(--accent); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.5px; }
.modal-title { margin-top: 10px; color: #fff; font-size: 0.95rem; font-weight: 600; }
.modal-close {
  position: absolute;
  top: -35px;
  right: 0;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  font-weight: bold;
}

.info-modal-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  max-width: 340px;
  width: 88vw;
  text-align: left;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.info-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.info-modal-title { color: var(--accent); font-weight: 700; font-size: 0.92rem; line-height: 1.4; }
.info-modal-close { color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; flex-shrink: 0; }
.info-modal-close:hover { color: #fff; }
.info-modal-body { color: #e2e8f0; font-size: 0.85rem; line-height: 1.7; white-space: pre-line; }

/* ===== Status ===== */
.init-loading, .init-error { text-align: center; padding: 40px 20px; color: var(--muted); font-size: 0.9rem; }
.init-error { color: #ff3b30; }
.init-error .btn-action { margin: 12px auto 0; }
.warn-note { text-align: center; color: var(--muted); font-size: 0.78rem; margin-top: 6px; }
.mock-banner {
  background: #2a2410;
  color: #f5d76e;
  border: 1px solid #5a4a1a;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.75rem;
  margin-bottom: 10px;
  text-align: center;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #1d1d24;
  border: 1px solid var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 2000;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  /* ปุ่มทั้ง 4 แบ่งความกว้างเท่ากันในบรรทัดเดียว และใช้ชื่อสั้น */
  .controls-bar { gap: 6px; }
  .controls-bar .btn-action { flex: 1 1 0; min-width: 0; padding: 8px 4px; font-size: 0.74rem; gap: 4px; }
  .lbl-extra { display: none; }
  .spec-row.grid-2-col { grid-template-columns: 90px 1fr 1fr; font-size: 0.76rem; }
  .car-card-header h3 { font-size: 0.92rem; }
  .car-card-header .price { font-size: 1rem; }
}
