/* =========================================================
   SIAMTECH SURIN — Shortlist add-on styles (plan Package 12)
   Load after assets/app.css. Uses app.css tokens only
   (--gold, --panel, --line, --glass, --f-mono, ...) so both
   :root (dark) and :root[data-theme="light"] work unchanged.
   ========================================================= */

/* page scroll lock while the sheet is open (body.locked belongs to app.js) */
html.sl-open { overflow: hidden; }

/* ---------- dock button + badge ---------- */
#dock.sl-has { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }
.sl-btn { color: var(--gold); }
.sl-btn .sl-ico-bm { fill: rgba(var(--gold-rgb), .2); }
.sl-badge {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; display: grid; place-items: center;
  font: 600 11px/1 var(--f-mono); letter-spacing: 0;
  background: var(--gold); color: #17120a; box-shadow: 0 0 0 3px var(--bg);
}
:root[data-theme="light"] .sl-badge { color: #fff; }
.sl-btn.bump { animation: slBump .5s var(--ease); }
@keyframes slBump { 0% { transform: scale(1); } 35% { transform: scale(1.16); } 100% { transform: scale(1); } }

/* ---------- bookmark button on cards (sibling of the card link) ---------- */
.card.sl-has-save { position: relative; }
.sl-save {
  position: absolute; z-index: 5; top: 9px; right: 10px;
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(6, 8, 11, .55); border: 1px solid rgba(255, 255, 255, .18); color: #fff;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform .35s var(--ease), background .3s, color .3s, border-color .3s;
}
.sl-save svg { width: 16px; height: 16px; }
.sl-save:active { transform: scale(.86); }
.sl-save[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #17120a; }
:root[data-theme="light"] .sl-save[aria-pressed="true"] { color: #fff; }
[aria-pressed="true"] > .sl-ico-bm { fill: currentColor; }
.card.sl-has-save .tag.vid { right: 52px; }

/* ---------- detail: per-model save button in .cta-stack ---------- */
.sl-cta-wrap { display: grid; gap: 4px; }
.sl-cta .sl-ico-bm { width: 17px; height: 17px; }
.sl-cta-ok { display: none; }
.sl-cta[aria-pressed="true"] { border-color: rgba(var(--gold-rgb), .65); color: var(--gold); background: rgba(var(--gold-rgb), .09); }
.sl-cta[aria-pressed="true"] .sl-cta-t { display: none; }
.sl-cta[aria-pressed="true"] .sl-cta-ok { display: inline; }
.sl-cta-open {
  justify-self: center; padding: 4px 10px; border-radius: 999px;
  font-size: 13px; color: var(--gold); transition: background .3s, color .3s;
}

/* ---------- product list: 'ถาม' links ---------- */
.product-list li.sl-has-ask { grid-template-columns: 40px 1fr auto; }
.sl-p-act { display: flex; gap: 6px; align-self: center; }
.sl-ask {
  height: 30px; padding: 0 11px 0 9px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
  border: 1px solid rgba(6, 199, 85, .45); color: var(--line-green); background: rgba(6, 199, 85, .06);
  transition: background .3s, color .3s, border-color .3s, opacity .3s;
}
.sl-ask svg { width: 14px; height: 14px; }
:root[data-theme="light"] .sl-ask { color: #04873a; border-color: rgba(4, 135, 58, .4); background: rgba(4, 135, 58, .05); }

/* ---------- empty-search fallback ---------- */
.sl-empty-alt {
  margin: 26px auto 0; max-width: 640px; display: grid; gap: 12px; justify-items: center;
  text-align: left; animation: pop .45s var(--ease);
}
.sl-ea-h { margin: 0; display: grid; gap: 6px; justify-items: center; text-align: center; color: var(--text-2); font-size: 14.5px; }
.sl-ea-list { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 6px; }
.sl-ea-list li {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 10px 10px 10px 14px; border-radius: var(--r-md);
  background: var(--glass-2); border: 1px solid var(--line);
}
.sl-ea-n { font-family: var(--f-mono); font-size: 12px; color: var(--gold); }
.sl-ea-t { min-width: 0; }
.sl-ea-t b { display: block; font-weight: 500; color: var(--text); line-height: 1.4; }
.sl-ea-t small { display: block; font-family: var(--f-mono); font-size: 11px; letter-spacing: .03em; color: var(--muted); line-height: 1.45; }
.sl-ea-send { margin-top: 4px; }

/* ---------- shortlist sheet (dialog) ---------- */
.sl-sheet {
  position: fixed; inset: 0; z-index: 330; display: grid; place-items: center; padding: 16px;
  background: rgba(3, 4, 6, .6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  overscroll-behavior: contain; animation: fade .25s ease;
}
:root[data-theme="light"] .sl-sheet { background: rgba(17, 25, 35, .38); }
.sl-panel {
  position: relative; width: min(640px, 100%);
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--r-xl); padding: 24px; border: 1px solid var(--line-2); box-shadow: var(--shadow);
  background: radial-gradient(90% 80% at 100% 0%, rgba(var(--gold-rgb), .14), transparent 60%), var(--panel);
  animation: pop .45s var(--ease);
}
.sl-grab { display: none; }
.sl-head { flex: none; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.sl-head h2 { margin: 8px 0 0; font-size: clamp(24px, 3vw, 32px); font-weight: 600; line-height: 1.25; }
.sl-sub { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.sl-head .icon-btn { flex: none; }

.sl-list {
  list-style: none; margin: 18px -6px; padding: 2px 6px; flex: 1 1 auto; min-height: 0;
  display: grid; gap: 8px; align-content: start; overflow-y: auto; overscroll-behavior: contain;
}
.sl-row {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border-radius: 16px; background: var(--glass-2); border: 1px solid var(--line);
  transition: border-color .3s; animation: pop .45s var(--ease) both;
}
.sl-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; border-radius: 10px; }
.sl-thumb {
  flex: none; width: 72px; height: 54px; border-radius: 10px; overflow: hidden;
  background: var(--panel-2); display: grid; place-items: center;
}
.sl-thumb img { width: 100%; height: 100%; object-fit: cover; }
.sl-thumb img.white { object-fit: contain; background: var(--white-media); padding: 4px; }
.sl-ph { font-family: var(--f-mono); font-size: 13px; color: var(--gold); }
.sl-txt { min-width: 0; display: grid; gap: 1px; }
.sl-txt small {
  font-family: var(--f-mono); font-size: 11px; letter-spacing: .06em; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sl-txt b {
  font-weight: 600; line-height: 1.35; transition: color .3s;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.sl-txt em { font-style: normal; font-size: 13px; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sl-rm { flex: none; }
.sl-in {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-size: 14px; color: var(--gold); background: rgba(var(--gold-rgb), .12);
}
.sl-empty {
  display: grid; justify-items: center; gap: 6px; padding: 34px 16px; text-align: center;
  color: var(--muted); border: 1px dashed var(--line-2); border-radius: 16px;
}
.sl-empty svg { width: 28px; height: 28px; color: var(--gold); }
.sl-empty b { color: var(--text); font-weight: 600; }
.sl-empty span { font-size: 14px; max-width: 40ch; }

.sl-foot {
  flex: none; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding-top: 16px; border-top: 1px dashed var(--line-2);
}
.sl-foot .btn { flex: 1 1 170px; }
.sl-foot #sl-line { flex: 2 1 220px; }
.sl-foot .btn svg { width: 18px; height: 18px; }
.sl-foot .btn-gold .sl-ico-bm { fill: currentColor; }
.sl-foot .btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
#sl-line.is-disabled { opacity: .45; pointer-events: none; filter: grayscale(.4); box-shadow: none; }
.sl-clear {
  flex: 1 1 100%; height: 34px; border-radius: 999px;
  font-size: 13px; color: var(--muted); transition: color .3s, background .3s;
}
.sl-clear.armed { color: #ff8a7a; background: rgba(255, 120, 100, .1); }
:root[data-theme="light"] .sl-clear.armed { color: #b3261e; background: rgba(179, 38, 30, .08); }

/* ---------- hover only on real pointers ---------- */
@media (hover: hover) and (pointer: fine) {
  .sl-save:hover { background: rgba(6, 8, 11, .8); border-color: rgba(var(--gold-rgb), .7); color: var(--gold-hi); }
  .sl-save[aria-pressed="true"]:hover { background: var(--gold-hi); border-color: var(--gold-hi); color: #17120a; }
  .sl-cta-open:hover { background: rgba(var(--gold-rgb), .1); }
  .product-list .sl-p-act { opacity: .45; }
  .product-list li:hover .sl-p-act, .product-list li:focus-within .sl-p-act { opacity: 1; }
  .sl-ask:hover { background: var(--line-green); border-color: transparent; color: #fff; }
  .sl-row:hover { border-color: rgba(var(--gold-rgb), .4); }
  .sl-link:hover b { color: var(--gold-hi); }
  :root[data-theme="light"] .sl-link:hover b { color: var(--gold-lo); }
  .sl-rm:hover { color: #ff8a7a; border-color: rgba(255, 120, 100, .5); }
  :root[data-theme="light"] .sl-rm:hover { color: #b3261e; border-color: rgba(179, 38, 30, .4); }
  .sl-clear:hover { color: var(--text); background: var(--glass-2); }
}

/* ---------- phones: bottom sheet ---------- */
@media (max-width: 640px) {
  .sl-sheet { place-items: end stretch; padding: 0; }
  .sl-panel {
    width: 100%; max-height: 90vh; max-height: 90dvh;
    border-radius: 26px 26px 0 0; border-bottom: 0;
    padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
    animation: sheetIn .45s var(--ease);
  }
  .sl-grab { display: block; flex: none; width: 40px; height: 4px; margin: 0 auto 12px; border-radius: 4px; background: var(--line-2); }
  .sl-head h2 { font-size: 24px; }
  .sl-list { margin: 14px -6px; }
  .sl-thumb { width: 60px; height: 46px; }
  .sl-link { gap: 12px; }
  .sl-foot #sl-line { flex-basis: 100%; }
  /* no min-width:0 here: .btn is nowrap, so long labels ('อยู่ในรายการของคุณแล้ว') must wrap to their own row, not overflow */
  .sl-foot .btn-glass, .sl-foot .btn-gold { flex: 1 1 0; padding: 0 12px; font-size: 14px; }
  .sl-save { width: 32px; height: 32px; top: 8px; right: 8px; }
  .card.sl-has-save .tag.vid { right: 46px; }
  .related .card.sl-has-save .tag.vid { display: none; }
  .sl-ea-list li { grid-template-columns: 28px minmax(0, 1fr) auto; padding: 10px; }
}
/* 40px+ touch target on coarse pointers (after the 640px block so it wins) */
@media (pointer: coarse) {
  .sl-save { width: 40px; height: 40px; top: 6px; right: 6px; }
  .card.sl-has-save .tag.vid { right: 52px; }
  .sl-ask { height: 36px; padding: 0 13px 0 11px; }
  .sl-cta-open { padding: 10px 14px; }
}
