/* ===== 修正：hidden 屬性必須優先於任何 display 設定 ===== */
.sp-panel [hidden],
.sp-body[hidden],
[hidden] { display: none !important; }

/* ===== 客服浮動按鈕 ===== */
.sp-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 12px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--brand, #0f766e);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(15, 118, 110, .38);
  transition: transform .18s, box-shadow .18s;
}
.sp-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(15, 118, 110, .45);
}
.sp-fab-icon { font-size: 19px; line-height: 1; }
.sp-dot {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid #fff;
  animation: sp-pulse 1.6s infinite;
}
@keyframes sp-pulse {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%      { transform: scale(1.25); opacity: .75; }
}

/* ===== 遮罩 ===== */
.sp-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  opacity: 0;
  visibility: hidden;
  transition: .22s;
  z-index: 210;
}
.sp-mask.on { opacity: 1; visibility: visible; }

/* ===== 面板 ===== */
.sp-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 400px;
  max-width: calc(100vw - 40px);
  max-height: min(640px, calc(100vh - 40px));
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .26);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 220;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(.97);
  transform-origin: bottom right;
  transition: .24s cubic-bezier(.4, 0, .2, 1);
}
.sp-panel.on {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.sp-head {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #0f766e, #115e59);
  color: #fff;
}
.sp-head h2 { font-size: 17px; font-weight: 800; }
.sp-head p {
  font-size: 12px;
  opacity: .85;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}
.sp-close {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  font-family: inherit;
}
.sp-close:hover { background: rgba(255, 255, 255, .34); }

.sp-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  -webkit-overflow-scrolling: touch;
}
.sp-body.chat { display: flex; flex-direction: column; padding: 0; }

.sp-hint {
  background: var(--brand-lt, #ccfbf1);
  color: #115e59;
  font-size: 12.5px;
  line-height: 1.7;
  padding: 11px 13px;
  border-radius: 10px;
  margin-bottom: 16px;
}

/* ===== 表單 ===== */
.sp-fld {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft, #64748b);
  margin-bottom: 14px;
}
.sp-fld input,
.sp-fld textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 10px 13px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 400;
  color: var(--ink, #1e293b);
  line-height: 1.7;
  outline: none;
  resize: vertical;
  background: #fff;
}
.sp-fld input:focus,
.sp-fld textarea:focus { border-color: var(--brand, #0f766e); }
.sp-req { color: #dc2626; }
.sp-count {
  display: block;
  text-align: right;
  font-size: 11px;
  font-weight: 400;
  color: #94a3b8;
  margin-top: 3px;
}

.sp-btn {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: .15s;
}
.sp-btn.primary { background: var(--brand, #0f766e); color: #fff; }
.sp-btn.primary:hover:not(:disabled) { background: #0d5f59; }
.sp-btn:disabled { opacity: .6; cursor: default; }

.sp-link {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 6px;
  border: 0;
  background: none;
  color: var(--ink-soft, #64748b);
  font-size: 12.5px;
  font-family: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.sp-link:hover { color: var(--brand, #0f766e); }

.sp-err {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 9px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 600;
}

/* ===== 對話串 ===== */
.sp-meta {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 16px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line, #e2e8f0);
  font-size: 12px;
}
.sp-code { color: #94a3b8; font-family: ui-monospace, monospace; letter-spacing: .3px; }
.sp-status {
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 11px;
}
.sp-status.wait { background: #fef3c7; color: #b45309; }
.sp-status.ok   { background: #dcfce7; color: #15803d; }
.sp-status.done { background: #e2e8f0; color: #64748b; }

.sp-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 180px;
  -webkit-overflow-scrolling: touch;
}
.sp-msg { display: flex; flex-direction: column; max-width: 84%; }
.sp-msg.user  { align-self: flex-end;   align-items: flex-end; }
.sp-msg.admin { align-self: flex-start; align-items: flex-start; }

.sp-who {
  font-size: 11px;
  color: #94a3b8;
  margin-bottom: 4px;
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.sp-who time { font-size: 10px; opacity: .8; }

.sp-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}
.sp-msg.user .sp-bubble {
  background: var(--brand, #0f766e);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sp-msg.admin .sp-bubble {
  background: #f1f5f9;
  color: var(--ink, #1e293b);
  border-bottom-left-radius: 4px;
}

.sp-reply {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line, #e2e8f0);
  background: #fff;
}
.sp-reply textarea {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  outline: none;
  resize: none;
}
.sp-reply textarea:focus { border-color: var(--brand, #0f766e); }
.sp-reply .sp-btn { width: auto; padding: 9px 18px; font-size: 14px; align-self: flex-end; }

.sp-foot-acts {
  flex-shrink: 0;
  display: flex;
  gap: 14px;
  padding: 0 16px 14px;
  justify-content: center;
}
.sp-foot-acts .sp-link { width: auto; margin-top: 0; }

/* ===== 手機 ===== */
@media (max-width: 640px) {
  .sp-fab { right: 14px; bottom: 14px; padding: 11px 17px; font-size: 14px; }
  .sp-fab-txt { display: none; }
  .sp-fab-icon { font-size: 22px; }

  .sp-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    border-radius: 18px 18px 0 0;
    transform-origin: bottom center;
  }
  body.sp-lock { overflow: hidden; }
  .sp-head p { max-width: 200px; }
}

/* ===== 播放頁：按鈕上移避開底部廣告 ===== */
.viewer-body .sp-fab { bottom: 76px; }
.viewer-body .sp-panel { bottom: 76px; }
@media (max-width: 640px) {
  .viewer-body .sp-panel { bottom: 0; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .viewer-body .sp-fab { bottom: 14px; }
}
