/* ==========================================================================
   Spark Your AI Workflows — Buy Now（txt 串接）
   搭配 js/spark-buynow.js：區塊內的產品卡片（.spark-bn）與經銷商彈窗（.spark-bn-pop）
   ========================================================================== */

/* ---------- 區塊內的產品卡片 ---------- */
.spark-bn {
  --spark-bn-gap: clamp(12px, 1.4vw, 20px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--spark-bn-gap);
  max-width: 1080px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
  animation: spark-bn-rise 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.spark-bn__item {
  display: flex;
  flex: 0 1 calc((100% - 2 * var(--spark-bn-gap)) / 3);
  flex-direction: column;
  align-items: center;
  min-width: 0;
  padding: clamp(18px, 1.8vw, 24px) clamp(16px, 1.6vw, 22px) clamp(18px, 1.6vw, 22px);
  border: 1px solid rgba(255, 255, 255, 0.95);
  border-radius: 18px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.66));
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 12px 30px -16px rgba(30, 70, 150, 0.3);
  text-align: center;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.45s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.45s;
}

.spark-bn__media {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: clamp(110px, 10vw, 150px);
  margin: 0 0 14px;
}
.spark-bn__media img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.spark-bn__name {
  margin: 0 0 8px;
  font-size: clamp(16px, 1.25vw, 19px);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.005em;
  color: #18213a;
}

.spark-bn__specs {
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  font-size: 14px;
  line-height: 1.6;
  color: #5a6578;
}

.spark-bn__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 220px;
  margin-top: auto;
  padding: 11px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #4f8fff, #2563eb);
  box-shadow: 0 10px 22px -12px rgba(37, 99, 235, 0.8);
  color: #ffffff;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: box-shadow 0.3s, filter 0.3s;
}
.spark-bn__btn svg,
.spark-bn-shop__cta svg {
  flex: none;
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.spark-bn__btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}

@media (hover: hover) {
  .spark-bn__item:hover {
    transform: translateY(-5px);
    border-color: rgba(150, 195, 255, 0.95);
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 22px 40px -18px rgba(37, 99, 235, 0.4);
  }
  .spark-bn__btn:hover {
    filter: brightness(1.06);
    box-shadow: 0 14px 26px -12px rgba(37, 99, 235, 0.9);
  }
  .spark-bn__btn:hover svg {
    transform: translateX(3px);
  }
}

/* 平板：一列兩張 */
@media (max-width: 1023px) {
  .spark-bn__item {
    flex-basis: calc((100% - var(--spark-bn-gap)) / 2);
  }
}

/* 手機：橫向卡片，一列一張 */
@media (max-width: 767px) {
  .spark-bn {
    --spark-bn-gap: 12px;
  }
  .spark-bn__item {
    display: grid;
    flex-basis: 100%;
    grid-template-columns: 80px minmax(0, 1fr);
    grid-template-areas:
      "media name"
      "media specs"
      "btn btn";
    align-items: start;
    column-gap: 14px;
    padding: 14px 14px 16px;
    border-radius: 16px;
    text-align: left;
  }
  .spark-bn__media {
    grid-area: media;
    height: 76px;
    margin: 0;
  }
  .spark-bn__name {
    grid-area: name;
    margin: 4px 0 4px;
    font-size: 15px;
  }
  .spark-bn__specs {
    grid-area: specs;
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
  }
  .spark-bn__btn {
    grid-area: btn;
    max-width: none;
    margin-top: 14px;
  }
}

/* ---------- 經銷商彈窗 ---------- */
html.spark-bn-open {
  overflow: hidden;
}

.spark-bn-pop {
  width: min(640px, 100% - 32px);
  max-width: none;
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: #121a2b;
  font-family: "motiva-sans", sans-serif;
  overflow: visible;
}
.spark-bn-pop::backdrop {
  background: rgba(8, 16, 38, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.spark-bn-pop[open],
.spark-bn-pop[open]::backdrop {
  animation: spark-bn-fade 0.3s ease-out;
}
.spark-bn-pop[open] .spark-bn-pop__panel {
  animation: spark-bn-rise 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.spark-bn-pop.is-closing,
.spark-bn-pop.is-closing::backdrop {
  animation: spark-bn-fade-out 0.2s ease-in forwards;
}

.spark-bn-pop__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 32px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 40px 100px -30px rgba(5, 20, 60, 0.6);
  overflow: hidden;
}

.spark-bn-pop__close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(18, 26, 43, 0.06);
  color: #18213a;
  cursor: pointer;
  transition: background 0.25s;
}
.spark-bn-pop__close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
.spark-bn-pop__close:hover {
  background: rgba(18, 26, 43, 0.12);
}
.spark-bn-pop__close:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.spark-bn-pop__head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 18px;
  padding: 26px 66px 20px 26px;
  border-bottom: 1px solid #e6ebf3;
  background: linear-gradient(180deg, #f2f7fd, #ffffff);
}
.spark-bn-pop__thumb {
  display: flex;
  flex: 0 0 96px;
  align-items: center;
  justify-content: center;
  height: 80px;
  margin: 0;
}
.spark-bn-pop__thumb[hidden] {
  display: none;
}
.spark-bn-pop__thumb img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}
.spark-bn-pop__heading {
  min-width: 0;
}
.spark-bn-pop__eyebrow {
  margin: 0 0 6px;
  font-family: "new-science", sans-serif;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #2563eb;
}
.spark-bn-pop__title {
  margin: 0 0 4px;
  font-size: clamp(18px, 1.6vw, 22px);
  font-weight: 700;
  line-height: 1.25;
  color: #121a2b;
}
.spark-bn-pop__specs {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: #5a6578;
}

.spark-bn-pop__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 18px 26px 26px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.spark-bn-pop__loading,
.spark-bn-pop__empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 120px;
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
  color: #5a6578;
}
.spark-bn-pop__empty {
  font-size: 17px;
  font-weight: 700;
  color: #18213a;
}
.spark-bn-pop__spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(37, 99, 235, 0.18);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spark-bn-spin 0.8s linear infinite;
}

/* 經銷商清單 */
.spark-bn-pop__list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.spark-bn-shop__link {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 12px 14px 12px 16px;
  border: 1px solid #e3e9f2;
  border-radius: 14px;
  background: #ffffff;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.25s, box-shadow 0.25s, transform 0.25s;
}
.spark-bn-shop__link:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
.spark-bn-shop__logo {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 40px;
}
.spark-bn-shop__logo img {
  display: block;
  max-width: 128px;
  max-height: 40px;
  width: auto;
  height: auto;
  object-fit: contain;
}
.spark-bn-shop__name {
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: #18213a;
  text-overflow: ellipsis;
}
.spark-bn-shop__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.spark-bn-shop__stock {
  font-size: 13px;
  line-height: 1.3;
  color: #16834a;
}
.spark-bn-shop.is-oos .spark-bn-shop__stock {
  color: #8590a6;
}
.spark-bn-shop.is-oos .spark-bn-shop__logo {
  opacity: 0.6;
}
.spark-bn-shop__cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid rgba(37, 99, 235, 0.22);
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.06);
  color: #2563eb;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.25s, color 0.25s, border-color 0.25s;
}

@media (hover: hover) {
  .spark-bn-shop__link:hover {
    border-color: #9cc0ff;
    box-shadow: 0 12px 26px -16px rgba(37, 99, 235, 0.45);
    transform: translateY(-2px);
  }
  .spark-bn-shop__link:hover .spark-bn-shop__cta {
    border-color: transparent;
    background: linear-gradient(135deg, #4f8fff, #2563eb);
    color: #ffffff;
  }
  .spark-bn-shop__link:hover .spark-bn-shop__cta svg {
    transform: translateX(3px);
  }
}

@media (max-width: 767px) {
  .spark-bn-pop {
    width: calc(100% - 24px);
    max-height: calc(100dvh - 24px);
  }
  .spark-bn-pop__panel {
    max-height: calc(100dvh - 24px);
    border-radius: 20px;
  }
  .spark-bn-pop__head {
    gap: 12px;
    padding: 18px 58px 16px 16px;
  }
  .spark-bn-pop__thumb {
    flex-basis: 52px;
    height: 48px;
  }
  .spark-bn-pop__title {
    font-size: 17px;
  }
  .spark-bn-pop__specs {
    font-size: 13px;
  }
  .spark-bn-pop__body {
    padding: 14px 14px 18px;
  }
  .spark-bn-shop__link {
    grid-template-columns: 96px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px 10px 10px 12px;
  }
  .spark-bn-shop__logo img {
    max-width: 96px;
    max-height: 34px;
  }
  /* 手機只留箭頭，庫存文字有足夠空間 */
  .spark-bn-shop__cta {
    padding: 8px 10px;
  }
  .spark-bn-shop__cta span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

/* ---------- 動畫 ---------- */
@keyframes spark-bn-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes spark-bn-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes spark-bn-rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
@keyframes spark-bn-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spark-bn,
  .spark-bn-pop[open],
  .spark-bn-pop[open]::backdrop,
  .spark-bn-pop[open] .spark-bn-pop__panel,
  .spark-bn-pop.is-closing,
  .spark-bn-pop.is-closing::backdrop {
    animation: none;
  }
  .spark-bn__item,
  .spark-bn-shop__link {
    transition: none;
  }
}
