/* ── Components: ปุ่ม, การ์ด, badge, modal, tabs, ตาราง, ฟอร์ม ───── */

/* ── ปุ่ม ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 10px var(--sp-5);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--fs-base);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
    color var(--t-fast), box-shadow var(--t-base), transform var(--t-fast), filter var(--t-fast);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn svg {
  width: 17px;
  height: 17px;
}

/* ส้ม = ปุ่มสั่งซื้อ/ยืนยัน — ปุ่มเดียวบนหน้าที่ควรเด่นที่สุด */
.btn--primary {
  background: var(--accent-grad);
  color: var(--on-accent);
  box-shadow: var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.btn--primary:hover:not(:disabled) {
  color: var(--on-accent);
  filter: brightness(1.07) saturate(1.05);
  box-shadow: 0 14px 32px -10px rgba(255, 107, 26, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn--secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

/* ทองขอบบาง — การกระทำรองที่ยังอยากให้ดูมีระดับ เช่น เพิ่มเข้าคลัง */
.btn--outline {
  background: transparent;
  color: var(--gold);
  border-color: var(--gold-line);
}

.btn--outline:hover:not(:disabled) {
  background: var(--gold-soft);
  border-color: var(--gold);
  color: var(--gold);
}

.btn--ghost {
  color: var(--text-muted);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn--danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.btn--danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn--sm {
  min-height: 36px;
  padding: 6px var(--sp-3);
  font-size: var(--fs-sm);
}

.btn--lg {
  min-height: 54px;
  padding: var(--sp-3) var(--sp-6);
  font-size: var(--fs-md);
  letter-spacing: 0.03em;
}

.btn--block {
  width: 100%;
}

/* ── Badge / chip ──────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.5;
  background: var(--bg-hover);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge--success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  color: var(--success);
}

.badge--warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 35%, transparent);
  color: var(--warning);
}

.badge--accent {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  color: var(--accent);
}

.badge--gold {
  background: var(--gold-soft);
  border-color: var(--gold-line);
  color: var(--gold);
}

/* จุดนำหน้าป้ายสถานะคลัง (พร้อมส่ง / เหลือน้อย / หมด) */
.badge--dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ป้าย rarity — สีมาจาก [data-rarity] */
.rarity-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.6;
  color: var(--rarity-ink, #fff);
  background: var(--rarity-color);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14) inset;
}

.rarity-badge--outline {
  background: color-mix(in srgb, var(--rarity-color) 16%, transparent);
  color: var(--rarity-color);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--rarity-color) 45%, transparent) inset;
}

.rarity-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--rarity-color);
  flex: none;
}

/* ระดับสูงสุด (SE ของ Kayou และ CR) เป็นป้ายสีรุ้ง */
[data-rarity='CR'] .rarity-badge,
.rarity-badge[data-rarity='CR'],
[data-rarity='SE'] .rarity-badge,
.rarity-badge[data-rarity='SE'] {
  background: linear-gradient(100deg, #f43f5e, #eab308, #22c55e, #3b82f6, #a855f7, #f43f5e);
  background-size: 300% 100%;
  animation: rainbow-slide 6s linear infinite;
}

@keyframes rainbow-slide {
  to {
    background-position: 300% 0;
  }
}

/* chip ตัวกรองที่เลือกอยู่ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 4px 6px 4px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: var(--fs-sm);
  color: var(--text);
}

.chip__remove {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: var(--text-faint);
  transition: background var(--t-fast), color var(--t-fast);
}

.chip__remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip__remove svg {
  width: 11px;
  height: 11px;
}

/* ── Panel / surface ───────────────────────────────────────────── */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow-inset);
}

.panel--flush {
  padding: 0;
  overflow: hidden;
}

.panel__title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: var(--sp-4);
}

/* ── การ์ด 1 ใบในกริด ──────────────────────────────────────────── */
.card-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--t-base), transform var(--t-base),
    box-shadow var(--t-base);
}

.card-tile:hover {
  border-color: var(--gold-line);
  transform: translateY(-4px);
  box-shadow: var(--shadow-gold);
}

.card-tile--owned {
  border-color: color-mix(in srgb, var(--success) 40%, var(--border));
}

.card-tile--missing .card-tile__art {
  filter: grayscale(1) brightness(0.45);
}

.card-tile--selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
}

/* การ์ดวางบนพื้นเข้มโดยเว้นขอบรอบ ๆ ไว้ จึงเห็นการ์ดเต็มใบพร้อมมุมโค้งครบสี่มุม
   ไม่ถูกมุมกรอบตัดและไม่ชิดขอบกรอบ */
.card-tile__art {
  position: relative;
  padding: var(--sp-2);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-hover), var(--bg-sunken) 70%);
  transition: filter var(--t-base);
}

/* สัดส่วนการ์ดจริง 63:88 มุมโค้งเท่าการ์ดจริง (รัศมี 3 มม. บนการ์ด 63 × 88 มม.)
   ย่อให้พอดีทั้งใบ ไม่ครอปส่วนไหนทิ้ง */
.card-tile__art > svg,
.card-tile__art > img {
  width: 100%;
  height: auto;
  aspect-ratio: var(--card-ratio);
  object-fit: contain;
  border-radius: 4.8% / 3.4%;
}

.card-tile__link {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.card-tile__link span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* ป้ายและ checkbox ห่างจากมุมการ์ดเท่าเดิม — บวกขอบพื้นรอบการ์ด (sp-2) เข้าไปแล้ว */
.card-tile__rarity {
  position: absolute;
  top: var(--sp-4);
  inset-inline-start: var(--sp-4);
  z-index: 2;
  pointer-events: none;
}

.card-tile__check {
  position: absolute;
  top: var(--sp-4);
  inset-inline-end: var(--sp-4);
  z-index: 3;
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
  cursor: pointer;
}

.card-tile__body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--sp-3);
  flex: 1;
}

.card-tile__name {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.8em;
}

.card-tile__id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.02em;
}

.card-tile__price {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: auto;
  padding-top: var(--sp-2);
  font-size: var(--fs-sm);
}

.card-tile__price-label {
  color: var(--text-faint);
  font-size: var(--fs-xs);
  /* ท้ายแถวมีปุ่มตะกร้า ถ้าราคายาวจนที่ไม่พอ ป้ายนี้ย่อเป็น … แทนการดันปุ่มล้นกรอบ */
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-tile__price-value {
  font-weight: 700;
  color: var(--text);
}

.card-tile__owned-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-inline-start: auto;
  flex: none;
}

/* ปุ่มตะกร้าท้ายแถวราคา — ส้มเต็มปุ่มเพราะเป็นทางสั่งซื้อของการ์ดใบนี้
   (ปุ่มเพิ่มเข้าคลังด้านล่างเป็นทองขอบบาง จึงไม่แย่งกันเด่น) */
.card-tile__cart {
  flex: none;
  width: 36px;
  min-height: 36px;
  margin-inline-start: auto;
  padding: 0;
  background: var(--accent-grad);
  color: var(--on-accent);
  box-shadow: var(--accent-glow);
}

.card-tile__cart:hover:not(:disabled) {
  color: var(--on-accent);
  filter: brightness(1.08);
}

/* การ์ดที่ยังไม่มีประกาศขาย กดสั่งไม่ได้ — เหลือแค่กรอบ ไม่ให้ดูเหมือนปุ่มที่ใช้งานได้ */
.card-tile__cart:disabled {
  background: transparent;
  color: var(--text-faint);
  box-shadow: inset 0 0 0 1px var(--border);
  opacity: 1;
}

/* จุดเขียว "มีในคลังแล้ว" ดันตัวเองไปทางขวาอยู่แล้ว ปุ่มตะกร้าจึงต่อท้ายจุดได้เลย */
.card-tile__owned-dot + .card-tile__cart {
  margin-inline-start: 0;
}

.card-tile__action {
  margin-top: var(--sp-2);
}

/* มุมมอง list */
.card-grid--list .card-tile {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2);
}

.card-grid--list .card-tile:hover {
  transform: none;
}

.card-grid--list .card-tile__art {
  width: 52px;
  flex: none;
  aspect-ratio: var(--card-ratio);
  padding: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.card-grid--list .card-tile__rarity {
  position: static;
}

.card-grid--list .card-tile__body {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-4);
  flex: 1;
  padding: 0 var(--sp-2);
  min-width: 0;
}

.card-grid--list .card-tile__name {
  flex: 1;
  min-height: 0;
  -webkit-line-clamp: 1;
}

.card-grid--list .card-tile__price {
  margin-top: 0;
  padding-top: 0;
}

.card-grid--list .card-tile__action {
  margin: 0;
}

/* ── การ์ดเซ็ต ─────────────────────────────────────────────────── */
.set-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
  transition: border-color var(--t-base), transform var(--t-base);
}

.set-card:hover {
  border-color: var(--gold-line);
  transform: translateY(-4px);
  box-shadow: var(--shadow-gold);
}

.set-card--pending {
  opacity: 0.72;
}

.set-card__cover {
  position: relative;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--set-accent, var(--accent)) 55%, #0a0a0a),
    #0a0a0a
  );
  color: #fff;
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  letter-spacing: 0.1em;
}

.set-card__region {
  position: absolute;
  top: var(--sp-3);
  inset-inline-start: var(--sp-3);
}

.set-card__soon {
  position: absolute;
  top: var(--sp-3);
  inset-inline-end: var(--sp-3);
}

.set-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  flex: 1;
}

/* ป้ายแบรนด์ใช้ทองทุกแบรนด์ — สีประจำแบรนด์ (เช่นน้ำเงินของบันได) ไม่อยู่ในพาเลตต์ของเว็บ */
.set-card__brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.set-card__brand:hover {
  color: var(--gold-hover);
  text-decoration: underline;
}

.set-card__brand-type {
  padding: 0 7px;
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-pill);
  background: var(--gold-soft);
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
}

.set-card__name {
  font-family: var(--font-body);
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: 1.4;
}

.set-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* ── การ์ดสินค้า: กล่อง / คาร์ตัน ──────────────────────────────── */
.product-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
  transition: border-color var(--t-base), transform var(--t-base), box-shadow var(--t-base);
}

.product-card:hover {
  border-color: var(--gold-line);
  transform: translateY(-4px);
  box-shadow: var(--shadow-gold);
}

/* ของหมดให้จางลง แต่ยังอ่านออก เพราะยังต้องใช้เทียบราคา */
.product-card--soldout {
  opacity: 0.66;
}

/* เวทีภาพสินค้าเป็นพื้นดำมีแสงทองจาง ๆ ทุกชิ้น — สีของกล่องเป็นสีสินค้า ส่วนกรอบคงพาเลตต์ของเว็บ */
.product-card__art {
  position: relative;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  background:
    radial-gradient(90% 75% at 50% 18%, var(--gold-soft), transparent 70%),
    var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}

.product-card__art svg {
  width: 100%;
  height: 100%;
  transition: transform var(--t-base);
}

/* ภาพเป็นลิงก์ไปหน้าสั่งซื้อ — ขยายเล็กน้อยตอนชี้ ให้รู้ว่ากดได้ */
.product-card__art:hover svg {
  transform: scale(1.05);
}

.product-card__art:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

/* ป้ายประเภท (กล่อง/คาร์ตัน) เป็นกระจกดำตัวอักษรทอง อ่านออกบนภาพทุกสี */
.product-card__type {
  position: absolute;
  top: var(--sp-3);
  inset-inline-start: var(--sp-3);
  background: rgba(0, 0, 0, 0.55);
  border-color: var(--gold-line);
  color: var(--gold);
  backdrop-filter: blur(6px);
}

:root[data-theme='light'] .product-card__type {
  background: rgba(255, 255, 255, 0.8);
}

.product-card__new {
  position: absolute;
  top: var(--sp-3);
  inset-inline-end: var(--sp-3);
}

.product-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  flex: 1;
}

.product-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: auto;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.product-card__price {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 600;
  line-height: 1.1;
  color: var(--gold);
  font-variant-numeric: lining-nums tabular-nums;
}

/* ปุ่มสั่งซื้อเต็มความกว้างท้ายการ์ด — ไม่ต้องเดาว่าต้องกดที่รูป */
.product-card__buy {
  margin-top: var(--sp-1);
}

/* ── แถบความคืบหน้า ────────────────────────────────────────────── */
.progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress__head {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.progress__value {
  font-weight: 700;
  color: var(--text);
}

.progress__track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--gold-grad);
  transition: width var(--t-slow);
}

.progress--success .progress__bar {
  background: linear-gradient(90deg, var(--success), #6ee7a8);
}

.progress--rarity .progress__bar {
  background: var(--rarity-color);
}

/* ── แผงกรอง ───────────────────────────────────────────────────── */
.filter-panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.filter-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
}

.filter-group__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.filter-group[open] .filter-group__toggle {
  color: var(--gold);
}

.filter-group__toggle svg {
  width: 15px;
  height: 15px;
  color: var(--text-faint);
  transition: transform var(--t-base);
}

.filter-group[open] .filter-group__toggle svg {
  transform: rotate(180deg);
}

.filter-group__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--sp-3) var(--sp-3);
  max-height: 280px;
  overflow-y: auto;
}

.filter-option {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-2);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}

.filter-option:hover {
  background: var(--bg-hover);
}

.filter-option input {
  accent-color: var(--gold);
  width: 15px;
  height: 15px;
  cursor: pointer;
  flex: none;
}

.filter-option__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-option__count {
  color: var(--text-faint);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

.filter-range {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-2);
}

.filter-range__inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--sp-2);
}

.filter-range__sliders {
  position: relative;
  height: 20px;
}

.filter-range__sliders input[type='range'] {
  position: absolute;
  inset: 0;
  width: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
  accent-color: var(--gold);
  -webkit-appearance: none;
  appearance: none;
}

.filter-range__sliders input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
}

.filter-range__sliders input[type='range']::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
}

.filter-range__sliders input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg-elevated);
  pointer-events: auto;
  cursor: pointer;
}

.filter-range__sliders input[type='range']::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg-elevated);
  pointer-events: auto;
  cursor: pointer;
}

.filter-actions {
  display: flex;
  gap: var(--sp-2);
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

/* ── แถบเครื่องมือ ─────────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.toolbar__count {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.view-toggle {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.view-toggle__btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 26px;
  border-radius: 5px;
  color: var(--text-faint);
  transition: background var(--t-fast), color var(--t-fast);
}

.view-toggle__btn:hover {
  color: var(--text);
}

.view-toggle__btn.is-active {
  background: var(--gold-soft);
  color: var(--gold);
}

.view-toggle__btn svg {
  width: 15px;
  height: 15px;
}

/* ── ฟอร์ม ─────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
}

.field__hint {
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--t-fast), background var(--t-fast);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--gold);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.select {
  cursor: pointer;
  appearance: none;
  padding-inline-end: var(--sp-6);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.select--inline {
  width: auto;
  padding-block: var(--sp-2);
  font-size: var(--fs-sm);
}

.textarea {
  resize: vertical;
  min-height: 84px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
}

/* ── ช่องค้นหา + autocomplete ─────────────────────────────────── */
.search-bar {
  position: relative;
  flex: 1;
  max-width: 230px;
}

.search-bar__input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: var(--fs-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

html[dir='ltr'] .search-bar__input {
  padding-inline: 40px var(--sp-3);
}

.search-bar__input:hover {
  border-color: var(--border-strong);
}

.search-bar__input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.search-bar__icon {
  position: absolute;
  top: 50%;
  inset-inline-start: var(--sp-3);
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}

.search-bar__results {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline: 0;
  z-index: var(--z-modal);
  max-height: 380px;
  overflow-y: auto;
  padding: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-pop);
}

/* ── แถบค้นหาบน header: กดใช้งานแล้วยืดยาวขึ้น ─────────────────
   ยืดไปทางขวาโดยหักด้วย margin ติดลบ พื้นที่รวมบน header จึงเท่าเดิม
   เมนูกับปุ่มฝั่งขวาไม่ขยับตาม ส่วนไอคอนกับกล่องผลลัพธ์อิงกล่องนี้อยู่แล้ว */
.site-header .search-bar {
  --search-w: 230px;
  --search-open-w: clamp(260px, 26vw, 420px);
  flex: none;
  width: var(--search-w);
  max-width: none;
  transition: width var(--t-base), margin-inline-end var(--t-base);
}

.site-header .search-bar:focus-within {
  width: var(--search-open-w);
  margin-inline-end: calc(var(--search-w) - var(--search-open-w));
}

/* จอแคบ ๆ ตอนยืดออกอาจไปทับปุ่มฝั่งขวา ใส่เงาไว้ให้แยกชั้นกันออก */
.site-header .search-bar:focus-within .search-bar__input {
  box-shadow: 0 0 0 3px var(--gold-soft), var(--shadow-pop);
}

.search-result {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  transition: background var(--t-fast);
}

.search-result:hover,
.search-result.is-active {
  background: var(--bg-hover);
  color: var(--text);
}

.search-result__art {
  width: 30px;
  aspect-ratio: var(--card-ratio);
  border-radius: 4px;
  overflow: hidden;
  flex: none;
}

.search-result__art svg {
  width: 100%;
  height: 100%;
}

.search-result__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result__id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
}

.search-result__empty {
  padding: var(--sp-4);
  text-align: center;
  color: var(--text-faint);
  font-size: var(--fs-sm);
}

/* ── ตาราง ─────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table {
  font-size: var(--fs-sm);
  min-width: 540px;
}

.table th,
.table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: start;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

html[lang='th'] .table th {
  text-transform: none;
  letter-spacing: 0;
}

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

.table tbody tr:hover td {
  background: var(--bg-hover);
}

.table__num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* ── แท็บ ──────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tabs__btn {
  position: relative;
  padding: var(--sp-3) var(--sp-4);
  color: var(--text-muted);
  font-size: var(--fs-base);
  font-weight: 600;
  white-space: nowrap;
  transition: color var(--t-fast);
}

.tabs__btn:hover {
  color: var(--text);
}

.tabs__btn.is-active {
  color: var(--gold);
}

.tabs__btn.is-active::after {
  content: '';
  position: absolute;
  inset-inline: var(--sp-3);
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--gold-grad);
}

.tabs__panel {
  padding-top: var(--sp-4);
}

/* ── Modal ─────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  animation: fade-in var(--t-base);
}

.modal__box {
  width: min(520px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  padding: var(--sp-5);
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-pop);
  animation: pop-in var(--t-slow);
}

.modal__box--wide {
  width: min(880px, 100%);
}

.modal__box--bare {
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  width: auto;
  max-width: 100%;
  /* ภาพซูมกำหนดขนาดให้พอดีจอเองแล้ว ไม่ต้องเป็นกล่องเลื่อน (และเงาของภาพจะได้ไม่ถูกตัด) */
  overflow: visible;
}

.modal__head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.modal__title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 600;
}

.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

/* ── ภาพซูมเต็มจอ (imageModal) ─────────────────────────────────── */
/* พื้นหลังรอบภาพและปุ่ม X = กดแล้วออก จึงใช้เคอร์เซอร์วงกลมสีแดง
   (เบราว์เซอร์ที่ใช้เคอร์เซอร์รูปนี้ไม่ได้จะเป็นรูปมือแทน) */
.modal--zoom,
.zoom-view__close {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='13' fill='%23e5484d' stroke='%23fff' stroke-width='2'/%3E%3Cpath d='M11.5 11.5l9 9m0-9-9 9' stroke='%23fff' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") 16 16, pointer;
}

.zoom-view {
  position: relative;
  /* สัดส่วนการ์ดจริง 63:88 — กว้างไม่เกินภาพต้นฉบับ (600px) และสูงไม่เกินจอ */
  width: min(600px, 92vw, calc(86vh * 63 / 88));
  aspect-ratio: var(--card-ratio);
  margin-inline: auto;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-pop);
  cursor: default;
}

/* ภาพต้องเต็มกรอบพอดี — <img> จาก cardArt มี height="880" ติดมา ถ้าไม่ตั้งตรงนี้ภาพจะถูกยืดสูง */
.zoom-view__art,
.zoom-view__art > *,
.zoom-view__art img,
.zoom-view__art svg {
  width: 100%;
  height: 100%;
}

.zoom-view__art img {
  object-fit: cover;
}

/* ปุ่ม X ใส ๆ มุมขวาบนของภาพ — พื้นกระจกเข้มโปร่งแสง เห็นชัดทั้งบนภาพสว่างและภาพมืด */
.zoom-view__close {
  position: absolute;
  top: var(--sp-3);
  inset-inline-end: var(--sp-3);
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(6px);
  color: #fff;
  transition: background var(--t-fast);
}

.zoom-view__close:hover {
  background: rgba(0, 0, 0, 0.45);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

/* ── Toast ─────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed;
  bottom: var(--sp-5);
  inset-inline-end: var(--sp-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  max-width: 340px;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  animation: toast-in var(--t-slow);
  pointer-events: auto;
}

.toast--success {
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
}

.toast--error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.toast__icon {
  width: 17px;
  height: 17px;
  flex: none;
}

.toast--success .toast__icon {
  color: var(--success);
}

.toast--error .toast__icon {
  color: var(--danger);
}

.toast.is-leaving {
  animation: toast-out var(--t-base) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(24px);
  }
}

/* ── สถานะว่าง / โหลด ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  color: var(--text-faint);
  opacity: 0.6;
}

.empty-state__title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
}

/* ── Breadcrumb ────────────────────────────────────────────────── */
.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--text-faint);
}

.crumbs a {
  color: var(--text-muted);
}

.crumbs a:hover {
  color: var(--gold);
}

/* ── กล่องราคา ─────────────────────────────────────────────────── */
.price-box {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--border);
  overflow: hidden;
}

.price-box__cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--sp-4);
  background: var(--bg-elevated);
}

.price-box__label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.price-box__value {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 600;
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: 0.02em;
}

.price-box__cell--primary .price-box__value {
  color: var(--gold);
}

.trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.trend--up {
  color: var(--success);
}

.trend--down {
  color: var(--danger);
}

.trend--flat {
  color: var(--text-faint);
}

.trend svg {
  width: 11px;
  height: 11px;
}

/* ── กราฟราคา ──────────────────────────────────────────────────── */
.price-chart {
  position: relative;
}

.price-chart__svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.price-chart__line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.price-chart__area {
  fill: url(#priceGradient);
}

.price-chart__grid {
  stroke: var(--border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.price-chart__axis-label {
  fill: var(--text-faint);
  font-size: 10px;
  font-family: var(--font-mono);
}

.price-chart__dot {
  fill: var(--bg-elevated);
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.price-chart__cursor {
  stroke: var(--text-faint);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  vector-effect: non-scaling-stroke;
}

.price-chart__tooltip {
  position: absolute;
  z-index: 4;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-xs);
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -125%);
}

.price-chart__stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-5);
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

.price-chart__stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.price-chart__stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.price-chart__stat-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── หมายเหตุข้อมูลจำลอง ───────────────────────────────────────── */
.demo-note {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--gold-line);
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  color: var(--gold);
  font-size: var(--fs-xs);
}

.demo-note svg {
  width: 14px;
  height: 14px;
  flex: none;
}

/* ── ดาวเรตติ้ง ────────────────────────────────────────────────── */
.stars {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-xs);
  color: var(--gold);
  font-weight: 700;
}

.stars svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

/* ── ส่วนที่เพิ่งได้ข้อมูลใหม่ (ใช้กับ flash() ใน dom.js) ───────── */
.is-updated {
  animation: live-highlight 1.2s ease-out 1;
}

@keyframes live-highlight {
  0% {
    box-shadow: 0 0 0 2px var(--gold);
  }
  60% {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 45%, transparent);
  }
  100% {
    box-shadow: 0 0 0 2px transparent;
  }
}
