/*
 * 官网客服浮层样式（T1-11）
 * 三条约束：
 * 1) 一切自定义属性挂在 .sc-widget 自己身上，不往全局挂——浮层是插进别人页面的东西，
 *    给宿主页面埋一个将来会撞名的变量就是给自己找事。
 * 2) 字号最小 12px、小字标签字距不超过 .08em、正文与底的对比不低于 4.5:1
 *    （交付口径，浅色块用 #57606a 以上的灰，不用那种「看着吃力」的浅灰）。
 * 3) 只作用于 .sc-widget 内部：选择器全部带前缀，不写裸的属性选择器，
 *    免得把厂商或主题里正在用的隐藏元素一起改了。
 */

.sc-widget {
  --sc-bg: #ffffff;
  --sc-surface: #f6f8fa;
  --sc-fg: #1f2328;
  --sc-muted: #57606a;
  --sc-border: #d6dbe1;
  --sc-accent: #1a5fb4;
  --sc-on-accent: #ffffff;
  --sc-bubble-me: #e8f1fd;
  --sc-bubble-other: #f6f8fa;
  --sc-danger: #d1242f;
  --sc-focus: #1a5fb4;
  --sc-shadow: 0 10px 30px rgba(26, 41, 66, .16);
  --sc-radius: 10px;
  --sc-gap: 12px;
  --sc-z: 9990;
  --sc-z-panel: 9991;
  position: fixed;
  z-index: var(--sc-z);
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  font-family: inherit;
  color: var(--sc-fg);
}
.sc-widget [hidden] { display: none !important; }
/* 只继承字体族：写成 font 简写会连字号、字重、颜色一起按这条更高优先级的选择器继承过去，
   把下面每个组件自己声明的 font-size / font-weight / 强调色全部静默盖掉——
   实测过一次：发送按钮的 var(--sc-on-accent) 被盖成正文色，编辑部主题上直接黑底黑字。 */
.sc-widget button,
.sc-widget textarea { font-family: inherit; }
.sc-widget *:focus-visible {
  outline: 2px solid var(--sc-focus);
  outline-offset: 2px;
}
.sc-widget *:focus:not(:focus-visible) { outline: none; }

/* ---- 入口按钮 ---- */
.scw-launcher {
  pointer-events: auto;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--sc-z);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--sc-accent);
  color: var(--sc-on-accent);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: var(--sc-shadow);
  transition: transform .16s ease, box-shadow .16s ease;
}
.scw-launcher:hover { transform: translateY(-1px); }
.scw-launcher-ico {
  width: 16px;
  height: 13px;
  border: 2px solid currentColor;
  border-radius: 4px 4px 4px 0;
  position: relative;
}
.scw-launcher-ico::after {
  content: "";
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 3px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}
.scw-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--sc-danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* ---- 面板 ---- */
.scw-panel {
  pointer-events: auto;
  position: fixed;
  right: 20px;
  bottom: 76px;
  z-index: var(--sc-z-panel);
  display: flex;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--sc-bg);
  border: 1px solid var(--sc-border);
  border-radius: var(--sc-radius);
  box-shadow: var(--sc-shadow);
  overflow: hidden;
  animation: scw-rise .18s ease-out;
}
@keyframes scw-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.scw-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sc-border);
  background: var(--sc-surface);
}
.scw-title { font-size: 16px; font-weight: 700; letter-spacing: .02em; }
.scw-sub { font-size: 12px; color: var(--sc-muted); }
.scw-close {
  margin-left: auto;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--sc-border);
  border-radius: 6px;
  background: var(--sc-bg);
  color: var(--sc-muted);
  font-size: 16px;
  line-height: 26px;
  cursor: pointer;
}
.scw-note {
  margin: 0;
  padding: 8px 16px;
  background: #fff4e5;
  border-bottom: 1px solid #f0c98a;
  color: #6a4b0e;
  font-size: 13px;
  line-height: 20px;
}
.scw-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  background: var(--sc-bg);
  -webkit-overflow-scrolling: touch;
}
.scw-log-empty {
  margin: 0;
  color: var(--sc-muted);
  font-size: 13px;
  text-align: center;
  padding: 28px 0;
}

/* ---- 消息 ---- */
.scw-msg { margin-bottom: var(--sc-gap); text-align: left; }
.scw-msg.me { text-align: right; }
.scw-who {
  display: inline-block;
  margin-right: 6px;
  font-size: 12px;
  color: var(--sc-muted);
  letter-spacing: .04em;
}
.scw-time { font-size: 12px; color: var(--sc-muted); }
.scw-bubble {
  display: inline-block;
  clear: both;
  margin-top: 4px;
  max-width: 80%;
  padding: 9px 12px;
  border: 1px solid var(--sc-border);
  border-radius: 8px;
  background: var(--sc-bubble-other);
  font-size: 14px;
  line-height: 22px;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.scw-msg.me .scw-bubble { background: var(--sc-bubble-me); }
.scw-msg.scw-pending { opacity: .55; }
.scw-msg.scw-k-system { text-align: center; }
.scw-msg.scw-k-system .scw-bubble {
  border: none;
  background: transparent;
  max-width: 100%;
  color: var(--sc-muted);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

/* ---- 输入区 ---- */
.scw-form { border-top: 1px solid var(--sc-border); background: var(--sc-surface); padding: 12px 16px 10px; }
.scw-input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 60px;
  max-height: 140px;
  padding: 9px 10px;
  border: 1px solid var(--sc-border);
  border-radius: 8px;
  background: var(--sc-bg);
  color: var(--sc-fg);
  font-size: 14px;
  line-height: 21px;
  resize: vertical;
}
.scw-input::placeholder { color: var(--sc-muted); }
.scw-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.scw-handoff,
.scw-again,
.scw-send {
  min-height: 36px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--sc-border);
  background: var(--sc-bg);
  color: var(--sc-fg);
  font-size: 14px;
  cursor: pointer;
}
.scw-send {
  margin-left: auto;
  border-color: transparent;
  background: var(--sc-accent);
  color: var(--sc-on-accent);
  font-weight: 600;
}
.scw-again { border-color: var(--sc-accent); color: var(--sc-accent); font-weight: 600; }
.scw-send[disabled],
.scw-handoff[disabled] { opacity: .5; cursor: default; }
.scw-hint { margin: 8px 0 0; font-size: 12px; line-height: 18px; color: var(--sc-muted); }

/* ---- 窄屏：整屏抽屉 ---- */
@media (max-width: 640px) {
  .scw-panel {
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .scw-launcher { right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); padding: 10px 14px; }
  .scw-bubble { max-width: 88%; }
  .scw-input { min-height: 56px; font-size: 16px; } /* 移动端 <16px 会让输入框聚焦时页面被放大 */
  /* 触屏没有 hover，按手指尺寸给：抽屉里这三个是主操作，关闭按钮也不能只靠 28px 方框点 */
  .scw-send,
  .scw-handoff,
  .scw-again { min-height: 44px; }
  .scw-close { width: 40px; height: 40px; line-height: 38px; }
  /* iPhone 底部横条压在输入区下面会点不到发送 */
  .scw-form { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
}

/* ---- 减少动态效果：动效一律关掉 ---- */
@media (prefers-reduced-motion: reduce) {
  .sc-widget *,
  .sc-widget *::before,
  .sc-widget *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .scw-launcher:hover { transform: none; }
}

/* ---- 科技主题：深色面板，对比全部重算 ---- */
.sc-widget[data-sc-theme="tech"] {
  --sc-bg: #101826;
  --sc-surface: #16202f;
  --sc-fg: #e9eef6;
  --sc-muted: #a3b1c6;
  --sc-border: #26374d;
  --sc-accent: #2f80ed;
  --sc-on-accent: #08101d;
  --sc-bubble-me: #1b3552;
  --sc-bubble-other: #16202f;
  --sc-focus: #6cb2ff;
  --sc-shadow: 0 12px 34px rgba(3, 10, 20, .55);
}
.sc-widget[data-sc-theme="tech"] .scw-note {
  background: #2a2313;
  border-bottom-color: #6b5320;
  color: #f0d9a8;
}
.sc-widget[data-sc-theme="tech"] .scw-close { background: #1b2636; }

/* ---- 极简编辑部主题：纸面 + 墨色，靠字重不靠色相 ---- */
.sc-widget[data-sc-theme="editorial"] {
  --sc-bg: #ffffff;
  --sc-surface: #f7f6f3;
  --sc-fg: #14161a;
  --sc-muted: #55595f;
  --sc-border: #ded9d0;
  --sc-accent: #14161a;
  --sc-on-accent: #ffffff;
  --sc-bubble-me: #f1ece2;
  --sc-bubble-other: #f7f6f3;
  --sc-focus: #14161a;
  --sc-shadow: 0 8px 24px rgba(20, 22, 26, .12);
  --sc-radius: 2px;
}
.sc-widget[data-sc-theme="editorial"] .scw-title { font-weight: 800; letter-spacing: .06em; }
.sc-widget[data-sc-theme="editorial"] .scw-note {
  background: #f3ece0;
  border-bottom-color: #d8c9ad;
  color: #5a4520;
}
