/* =====================================================================
   chat-mvp · 访客端聊天窗
   色板与官网一致：深海军 #0B1F33 / 品牌蓝 #005CA8 / 点缀橙 #F59E0B
                  浅底 #F4F7FA / 正文灰 #4A5568
   z-index 取高位，避免被官网其他悬浮元素盖住。
   ===================================================================== */

.sc-launcher,
.sc-panel,
.sc-panel * {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
}

/* 宿主网站常有全局 p/button 样式，会穿透进聊天窗（比如把标题染成正文灰）。
   这里用 :where() 写零特异性重置：能压住宿主样式，又不会盖掉下面各 class 的设定。 */
.sc-panel :where(p) {
  margin: 0;
  color: inherit;
  font-size: inherit;
  line-height: inherit;
}
.sc-panel :where(button) { font: inherit; color: inherit; }
.sc-panel :where(a) { color: inherit; }

/* ---------- 右下角气泡 ---------- */

.sc-launcher {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 2147482999;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: #005CA8;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(11, 31, 51, 0.22), 0 2px 6px rgba(11, 31, 51, 0.12);
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.sc-launcher:hover {
  background: #004a87;
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(11, 31, 51, 0.26), 0 3px 8px rgba(11, 31, 51, 0.14);
}

.sc-launcher:active { transform: translateY(0); }

.sc-launcher:focus-visible,
.sc-panel button:focus-visible,
.sc-panel input:focus-visible,
.sc-panel textarea:focus-visible {
  outline: 2px solid #F59E0B;
  outline-offset: 2px;
}

.sc-launcher.is-open { display: none; }

.sc-badge {
  position: absolute;
  top: -5px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #F59E0B;
  color: #2A1B00;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

/* ---------- 面板 ---------- */

.sc-panel {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  width: 360px;
  height: 480px;
  max-height: calc(100vh - 120px);
  max-height: calc(100dvh - 120px);
  background: #fff;
  color: #1B2A3A;
  line-height: 1.45;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(11, 31, 51, 0.28), 0 6px 16px rgba(11, 31, 51, 0.12);
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transform-origin: right bottom;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.sc-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- 头部 ---------- */

.sc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
  background: #0B1F33;
  color: #fff;
  flex: none;
}

.sc-head-main { flex: 1; min-width: 0; }

.sc-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: #fff;
}

.sc-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(232, 238, 245, 0.68);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sc-subtitle::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #38C172;
  box-shadow: 0 0 0 3px rgba(56, 193, 114, 0.18);
  flex: none;
}

.sc-close {
  width: 36px;
  height: 36px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
}

.sc-close:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

/* ---------- 提示条 ---------- */

.sc-notice {
  margin: 0;
  padding: 9px 16px;
  background: #FFF7E8;
  border-bottom: 1px solid #F5E3C2;
  color: #7A5312;
  font-size: 12.5px;
  line-height: 1.45;
  flex: none;
}

/* ---------- 主体 ---------- */

.sc-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #F4F7FA;
}

/* 首次表单 */
.sc-intro {
  padding: 18px 16px;
  overflow-y: auto;
}

.sc-intro-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 650;
  color: #1B2A3A;
}

.sc-intro-text {
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #4A5568;
}

.sc-input,
.sc-textarea {
  display: block;
  width: 100%;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  background: #fff;
  color: #1B2A3A;
  font-size: 16px; /* ≥16px 防止 iOS 聚焦时自动放大 */
  line-height: 1.45;
  padding: 10px 12px;
  margin-bottom: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sc-textarea {
  resize: none;
  min-height: 76px;
  max-height: 120px;
}

.sc-input::placeholder,
.sc-textarea::placeholder { color: #9AA7B6; }

.sc-input:focus,
.sc-textarea:focus {
  outline: none;
  border-color: #005CA8;
  box-shadow: 0 0 0 3px rgba(0, 92, 168, 0.12);
}

.sc-form-error {
  margin: 0 0 8px;
  color: #C0392B;
  font-size: 12.5px;
}

.sc-start {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: #005CA8;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 92, 168, 0.25);
}

.sc-start:hover { background: #004a87; }

/* 消息区 */
.sc-thread {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sc-load-more {
  align-self: center;
  margin: 10px 0 2px;
  padding: 6px 12px;
  border: 1px solid #E2E8F0;
  border-radius: 999px;
  background: #fff;
  color: #4A5568;
  font-size: 12px;
  cursor: pointer;
  min-height: 32px;
  flex: none;
}

.sc-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
  scrollbar-color: #C9D4E0 transparent;
}

.sc-msgs::-webkit-scrollbar { width: 8px; }
.sc-msgs::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 8px; }

.sc-empty {
  margin: 26px auto;
  font-size: 12.5px;
  color: #8A97A8;
}

.sc-day {
  align-self: center;
  margin: 10px 0 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(11, 31, 51, 0.06);
  color: #7C8A9B;
  font-size: 11px;
}

.sc-row {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  margin: 2px 0;
}

.sc-row.is-visitor { align-items: flex-end; }
.sc-row.is-agent { align-items: flex-start; }

.sc-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.sc-row.is-visitor .sc-bubble {
  background: #005CA8;
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 8px rgba(0, 92, 168, 0.2);
}

.sc-row.is-agent .sc-bubble {
  background: #fff;
  color: #1B2A3A;
  border: 1px solid #E6EBF1;
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 2px rgba(11, 31, 51, 0.06);
}

.sc-row.is-pending .sc-bubble { opacity: 0.65; }
.sc-row.is-failed .sc-bubble { box-shadow: 0 0 0 1px rgba(192, 57, 43, 0.5); }

.sc-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 2px 0;
  font-size: 10.5px;
  color: #8A97A8;
}

.sc-state { color: #8A97A8; }
.sc-row.is-failed .sc-state { color: #C0392B; }

.sc-retry {
  border: 0;
  background: transparent;
  padding: 0;
  color: #C0392B;
  font-size: 10.5px;
  text-decoration: underline;
  cursor: pointer;
}

/* 输入区 */
.sc-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #E2E8F0;
  flex: none;
}

.sc-input-msg {
  flex: 1;
  min-height: 42px;
  max-height: 96px;
  margin: 0;
  border-radius: 12px;
  background: #FBFCFE;
  resize: none;
  padding: 10px 12px;
}

.sc-send {
  width: 42px;
  height: 42px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  background: #005CA8;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 92, 168, 0.24);
}

.sc-send:hover { background: #004a87; }

.sc-foot {
  padding: 0 12px 8px;
  background: #fff;
  text-align: right;
  min-height: 0;
}

.sc-counter {
  font-size: 11px;
  color: #8A97A8;
}

/* ---------- 手机端：全屏 ---------- */

@media (max-width: 520px), (max-height: 560px) {
  .sc-panel {
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    width: auto;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    transform: translateY(8px);
  }

  .sc-head {
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  .sc-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    height: 48px;
    padding: 0 16px;
    font-size: 14px;
  }

  .sc-msgs { padding: 12px 12px 6px; }
  .sc-bubble { max-width: 86%; }
}

@media (prefers-reduced-motion: reduce) {
  .sc-panel,
  .sc-launcher {
    transition: none;
  }
}
