/* 線上客服（前台浮動視窗 bsc-widget 與客服中心頁 bsc-page 共用） */
.bsc {
  --bsc-ink: #1a2947;
  --bsc-gold: #d4af37;
  --bsc-line: rgba(26, 41, 71, 0.12);
  --bsc-soft: #f6f7f9;
  --bsc-muted: rgba(26, 41, 71, 0.72); /* 灰色說明文字：淺灰底上對比度仍達 4.5:1 */
  font-family: var(--font-sans, 'Inter', system-ui, sans-serif);
  color: var(--bsc-ink);
  box-sizing: border-box;
}
.bsc *, .bsc *::before, .bsc *::after { box-sizing: border-box; }
.bsc button { font-family: inherit; }
.bsc svg { flex: none; }

/* ---------- 浮動按鈕 ---------- */
.bsc-fab {
  position: fixed; right: 28px; bottom: 28px; z-index: 9998; width: 56px; height: 56px;
  border: 1px solid var(--bsc-gold); background: #fff; color: var(--bsc-ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 24px rgba(26, 41, 71, 0.16);
  transition: transform 0.2s, background 0.2s;
}
@media (hover: hover) { .bsc-fab:hover { transform: translateY(-2px); background: var(--bsc-ink); color: #fff; } }
.bsc-fab.is-open { background: var(--bsc-ink); color: #fff; }
.bsc-fab-badge {
  position: absolute; top: -7px; right: -7px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: #c0392b; color: #fff; font-size: 0.7rem; font-weight: 700; display: none; align-items: center; justify-content: center;
}
.bsc-fab-badge.show { display: flex; }
/* 手機：捲動或輸入時暫時滑出畫面（support-chat.js autoHideFab） */
.bsc-tucked .bsc-fab { transform: translateX(calc(100% + 32px)); pointer-events: none; }
@media (prefers-reduced-motion: reduce) { .bsc-tucked .bsc-fab { transition: none; } }

/* ---------- 視窗 ---------- */
.bsc-panel {
  position: fixed; right: 28px; bottom: 96px; z-index: 9997; width: 390px; height: 620px;
  max-height: calc(100% - 120px); max-width: calc(100% - 32px);
  background: #fff; border: 1px solid var(--bsc-ink); box-shadow: 0 20px 50px rgba(26, 41, 71, 0.22);
  display: none; flex-direction: column; overflow: hidden;
}
.bsc-panel.open { display: flex; }
.bsc-page {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); border: 1px solid var(--bsc-line); background: #fff;
  height: min(78vh, 760px); min-height: 520px;
}
.bsc-page .bsc-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.bsc-page .bsc-side { border-right: 1px solid var(--bsc-line); display: flex; flex-direction: column; min-height: 0; }
.bsc-side-head { padding: 14px 16px; border-bottom: 1px solid var(--bsc-line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bsc-side-head h2 { font-size: 0.86rem; letter-spacing: 0.08em; text-transform: uppercase; margin: 0; font-weight: 700; }
.bsc-side-list { flex: 1; overflow-y: auto; }

/* ---------- 標頭 ---------- */
.bsc-head { background: var(--bsc-ink); color: #fff; padding: 12px 14px; display: flex; align-items: center; gap: 10px; flex: none; }
.bsc-head-avatar { width: 36px; height: 36px; border: 1px solid var(--bsc-gold); display: flex; align-items: center; justify-content: center; color: var(--bsc-gold); font-family: var(--font-serif, serif); font-weight: 700; flex: none; }
.bsc-head-text { flex: 1; min-width: 0; }
.bsc-only-mobile { display: none !important; }
.bsc-head-title { font-size: 0.9rem; font-weight: 700; letter-spacing: 0.04em; display: flex; align-items: center; gap: 8px; }
.bsc-head-sub { font-size: 0.72rem; opacity: 0.7; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bsc-icon-btn {
  width: 32px; height: 32px; border: 0; background: rgba(255, 255, 255, 0.12); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; position: relative;
}
.bsc-icon-btn:hover { background: rgba(255, 255, 255, 0.24); }
.bsc-icon-btn .dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: #e74c3c; display: none; }
.bsc-icon-btn .dot.show { display: block; }
.bsc-tag { display: inline-block; padding: 1px 7px; font-size: 0.68rem; font-weight: 600; border: 1px solid currentColor; letter-spacing: 0.02em; white-space: nowrap; }
.bsc-head .bsc-tag { color: var(--bsc-gold); }

/* ---------- 訊息區 ---------- */
.bsc-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px 14px 6px; background: var(--bsc-soft); min-height: 0; position: relative; }
.bsc-day { text-align: center; margin: 10px 0; font-size: 0.7rem; color: var(--bsc-muted); }
.bsc-day span { background: var(--bsc-soft); padding: 0 8px; }
.bsc-msg { display: flex; flex-direction: column; margin-bottom: 10px; max-width: 82%; }
.bsc-msg.is-user { margin-left: auto; align-items: flex-end; }
.bsc-msg.is-admin { align-items: flex-start; }
.bsc-sender { font-size: 0.68rem; color: var(--bsc-muted); margin: 0 2px 3px; }
.bsc-bubble { background: #fff; border: 1px solid var(--bsc-line); padding: 9px 12px; font-size: 0.88rem; line-height: 1.6; word-break: break-word; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 8px; }
.bsc-msg.is-user .bsc-bubble { background: var(--bsc-ink); color: #fff; border-color: var(--bsc-ink); }
.bsc-text a { color: inherit; text-decoration: underline; }
.bsc-text { white-space: pre-wrap; }
.bsc-meta { font-size: 0.68rem; color: var(--bsc-muted); margin: 3px 2px 0; display: flex; gap: 6px; }
.bsc-msg.is-pending { opacity: 0.6; }
.bsc-msg.is-failed .bsc-bubble { border-color: #c0392b; }
.bsc-img { display: block; max-width: 220px; max-height: 260px; border: 1px solid var(--bsc-line); background: #fff; cursor: zoom-in; }
.bsc-img img { display: block; max-width: 100%; max-height: 258px; object-fit: contain; }

/* 附件卡片（訂單、商品） */
.bsc-card { display: flex; gap: 10px; align-items: center; background: #fff; color: var(--bsc-ink); border: 1px solid var(--bsc-line); padding: 8px; text-decoration: none !important; min-width: 220px; max-width: 280px; }
.bsc-card:hover { border-color: var(--bsc-gold); }
.bsc-card-img { width: 48px; height: 48px; flex: none; background: var(--bsc-soft) center/cover no-repeat; border: 1px solid var(--bsc-line); display: flex; align-items: center; justify-content: center; color: var(--bsc-muted); }
.bsc-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bsc-card-kicker { font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--bsc-gold); font-weight: 700; }
.bsc-card-title { font-size: 0.84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bsc-card-sub { font-size: 0.74rem; color: var(--bsc-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bsc-card-price { font-size: 0.82rem; font-weight: 700; }
.bsc-status { display: inline-block; font-size: 0.66rem; font-weight: 700; padding: 0 6px; background: rgba(212, 175, 55, 0.16); color: #7a5c00; margin-left: 4px; }

/* 歡迎與主題 */
.bsc-welcome { text-align: center; padding: 18px 8px 8px; }
.bsc-welcome h2, .bsc-welcome h3 { font-family: var(--font-serif, serif); font-size: 1.15rem; margin: 0 0 6px; font-weight: 600; }
.bsc-welcome p { font-size: 0.82rem; color: var(--bsc-muted); margin: 0 0 14px; line-height: 1.6; }
.bsc-topics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; }
.bsc-topic { border: 1px solid var(--bsc-line); background: #fff; padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; color: var(--bsc-ink); transition: border-color 0.15s; }
.bsc-topic:hover, .bsc-topic.active { border-color: var(--bsc-ink); }
.bsc-topic.active { background: var(--bsc-ink); color: #fff; }
.bsc-topic strong { font-size: 0.84rem; }
.bsc-topic span { font-size: 0.72rem; opacity: 0.65; }
.bsc-notice { margin: 8px 0; padding: 10px 12px; font-size: 0.8rem; background: rgba(212, 175, 55, 0.1); border: 1px solid rgba(212, 175, 55, 0.5); display: flex; align-items: center; gap: 10px; }
.bsc-notice span { flex: 1; }

/* ---------- 輸入區 ---------- */
.bsc-compose { border-top: 1px solid var(--bsc-line); background: #fff; padding: 8px 10px 10px; flex: none; }
.bsc-attach-chip { display: flex; align-items: center; gap: 8px; border: 1px dashed var(--bsc-gold); padding: 6px 8px; margin-bottom: 8px; font-size: 0.78rem; }
.bsc-attach-chip img { width: 36px; height: 36px; object-fit: cover; border: 1px solid var(--bsc-line); }
.bsc-attach-chip .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bsc-attach-chip button { border: 0; background: none; cursor: pointer; color: var(--bsc-muted); font-size: 1rem; }
.bsc-row { display: flex; align-items: flex-end; gap: 6px; }
.bsc-row textarea {
  flex: 1; border: 1px solid var(--bsc-line); padding: 9px 11px; font-size: 0.9rem; resize: none; min-height: 40px; max-height: 120px;
  font-family: inherit; outline: none; line-height: 1.5; color: var(--bsc-ink); background: #fff;
}
.bsc-row textarea:focus { border-color: var(--bsc-ink); }
.bsc-tool { width: 40px; height: 40px; border: 1px solid var(--bsc-line); background: #fff; color: var(--bsc-ink); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.bsc-tool:hover { border-color: var(--bsc-ink); }
.bsc-send { width: 40px; height: 40px; border: 1px solid var(--bsc-ink); background: var(--bsc-ink); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.bsc-send:disabled { opacity: 0.4; cursor: not-allowed; }
.bsc-hint { font-size: 0.68rem; color: var(--bsc-muted); margin-top: 5px; display: flex; justify-content: space-between; gap: 8px; }
.bsc-menu { position: absolute; bottom: 58px; left: 10px; background: #fff; border: 1px solid var(--bsc-ink); box-shadow: 0 10px 24px rgba(26, 41, 71, 0.18); z-index: 3; display: none; min-width: 180px; }
.bsc-menu.open { display: block; }
.bsc-menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 14px; border: 0; background: none; cursor: pointer; font-size: 0.85rem; color: var(--bsc-ink); text-align: left; }
.bsc-menu button:hover { background: var(--bsc-soft); }
.bsc-compose-wrap { position: relative; }

/* ---------- 選擇訂單／商品、歷史對話 ---------- */
.bsc-sheet { position: absolute; inset: 0; background: #fff; z-index: 4; display: none; flex-direction: column; }
.bsc-sheet.open { display: flex; }
.bsc-sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--bsc-line); }
.bsc-sheet-head h4 { flex: 1; margin: 0; font-size: 0.9rem; font-weight: 700; }
.bsc-sheet-head button { border: 0; background: none; cursor: pointer; font-size: 1.1rem; color: var(--bsc-ink); }
.bsc-sheet-search { padding: 10px 14px; border-bottom: 1px solid var(--bsc-line); }
.bsc-sheet-search input { width: 100%; border: 1px solid var(--bsc-line); padding: 8px 10px; font-size: 0.86rem; outline: none; }
.bsc-sheet-list { flex: 1; overflow-y: auto; }
.bsc-pick { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; border-bottom: 1px solid var(--bsc-line); background: #fff; padding: 10px 14px; cursor: pointer; text-align: left; color: var(--bsc-ink); }
.bsc-pick:hover { background: var(--bsc-soft); }
.bsc-pick .bsc-card { flex: 1; max-width: none; min-width: 0; border: 0; padding: 0; background: transparent; }
.bsc-empty { padding: 28px 16px; text-align: center; font-size: 0.84rem; color: var(--bsc-muted); }
.bsc-conv { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--bsc-line); background: #fff; padding: 11px 14px; cursor: pointer; text-align: left; color: var(--bsc-ink); }
.bsc-conv:hover, .bsc-conv.active { background: var(--bsc-soft); }
.bsc-conv-top { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 600; }
.bsc-conv-top .grow { flex: 1; }
.bsc-conv-preview { font-size: 0.78rem; color: var(--bsc-muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bsc-unread { min-width: 18px; height: 18px; border-radius: 9px; background: #c0392b; color: #fff; font-size: 0.66rem; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
.bsc-state { font-size: 0.66rem; font-weight: 600; color: var(--bsc-muted); }
.bsc-state.on { color: #1e7e34; }

/* 訪客 */
.bsc-guest { padding: 28px 22px; text-align: center; }
.bsc-guest h2, .bsc-guest h3 { font-family: var(--font-serif, serif); font-size: 1.2rem; margin: 0 0 8px; }
.bsc-guest p { font-size: 0.85rem; color: var(--bsc-muted); line-height: 1.7; margin: 0 0 18px; }
.bsc-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border: 1px solid var(--bsc-ink); background: var(--bsc-ink); color: #fff !important; text-decoration: none !important; font-size: 0.82rem; letter-spacing: 0.06em; cursor: pointer; }
.bsc-btn.ghost { background: #fff; color: var(--bsc-ink) !important; }
.bsc-btn.sm { padding: 6px 12px; font-size: 0.76rem; }

/* 商品頁「詢問客服」 */
.pd-ask-btn {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; padding: 6px 0; border: 0; background: none; cursor: pointer;
  color: #1a2947; font-size: 0.85rem; text-decoration: underline; text-underline-offset: 3px; font-family: inherit;
}
.pd-ask-btn:hover { color: #b8941f; }

/* 圖片預覽 */
.bsc-lightbox { position: fixed; inset: 0; background: rgba(10, 15, 30, 0.85); z-index: 10050; display: none; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out; }
.bsc-lightbox.open { display: flex; }
.bsc-lightbox img { max-width: 100%; max-height: 100%; }

@media (max-width: 768px) {
  .bsc-fab { right: 16px; bottom: 16px; width: 52px; height: 52px; }
  .bsc-fab.is-open { display: none; }
  /* 手機全螢幕：固定貼齊畫面，不撐寬頁面 */
  .bsc-panel { inset: 0; width: 100%; height: 100%; max-height: none; max-width: 100%; border: 0; overscroll-behavior: contain; }
  /* iOS 輸入框小於 16px 會自動放大頁面，放大後就會出現水平捲動 */
  .bsc input, .bsc textarea, .bsc select { font-size: 16px !important; }
  .bsc-page { grid-template-columns: minmax(0, 1fr); height: calc(100vh - 140px); }
  .bsc-page .bsc-side { display: none; }
  .bsc-only-mobile { display: inline-flex !important; }
  .bsc-page.show-side .bsc-side { display: flex; }
  .bsc-page.show-side .bsc-main { display: none; }
  .bsc-msg { max-width: 90%; }
}

/* 訪客：聯絡信箱 */
.bsc .bsc-guest .bsc-guest-mail { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid rgba(26, 41, 71, 0.1); font-size: 0.8rem; opacity: 0.8; overflow-wrap: anywhere; }
.bsc-guest-mail a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
