/* ═══════════════════════════════════════════════════════════
   多语言客服中心 · 视觉设计系统 v2
   配色: 对齐 MoldHub 主品牌蓝 #185FA5
   间距: 4px 基准网格 · 8px 复合单位
   字体: 系统字体栈 + 清晰字重层级
   ═══════════════════════════════════════════════════════════ */

:root {
  /* ── 品牌色（对齐首页 style.css）── */
  --cs-brand: #185FA5;
  --cs-brand-light: #e8f0fe;
  --cs-brand-hover: #0f4a87;
  --cs-brand-glow: rgba(24, 95, 165, 0.08);

  /* ── 语义色 ── */
  --cs-bg: #f0f3f9;
  --cs-surface: #ffffff;
  --cs-ink: #1a2332;
  --cs-ink-secondary: #4a5568;
  --cs-muted: #8896a7;
  --cs-line: #e2e8f0;
  --cs-line-strong: #cbd5e1;

  /* ── 角色色 ── */
  --cs-buyer-bg: #eff4ff;
  --cs-buyer-border: #c7d8f7;
  --cs-buyer-ink: #1d4ed8;
  --cs-seller-bg: #f0fdf4;
  --cs-seller-border: #bbf7d0;
  --cs-seller-ink: #059669;

  /* ── 状态色 ── */
  --cs-success: #16a34a;
  --cs-warn: #d97706;
  --cs-error: #dc2626;

  /* ── 阴影系统 ── */
  --cs-shadow-sm: 0 1px 2px rgba(26, 35, 50, 0.05);
  --cs-shadow-md: 0 4px 12px rgba(26, 35, 50, 0.07);
  --cs-shadow-lg: 0 8px 30px rgba(26, 35, 50, 0.10);
  --cs-shadow-hover: 0 6px 20px rgba(24, 95, 165, 0.15);

  /* ── 圆角 / 间距 ── */
  --cs-rs: 10px;
  --cs-rs-lg: 16px;
  --cs-rs-xl: 20px;
  --cs-sp-xs: 4px;
  --cs-sp-sm: 8px;
  --cs-sp-md: 16px;
  --cs-sp-lg: 24px;
  --cs-sp-xl: 32px;
}

/* ───────────── Reset & Base ───────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--cs-ink);
  background: var(--cs-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ───────────── App Shell ───────────── */
.cs-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1280px;
  margin: 0 auto;
  background: var(--cs-surface);
  box-shadow: var(--cs-shadow-lg);
  border-radius: var(--cs-rs-lg);
  overflow: hidden;
  margin-top: var(--cs-sp-md);
  margin-bottom: var(--cs-sp-md);
}

/* ═════════════ HEADER ════════════ */
.cs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--cs-brand) 0%, #124a8a 100%);
  color: #fff;
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}
.cs-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
}

.cs-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cs-logo {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,.18);
  border-radius: var(--cs-rs);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  backdrop-filter: blur(4px);
  flex-shrink: 0;
}
.cs-title {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.cs-sub {
  font-size: 12px;
  opacity: .82;
  font-weight: 400;
  margin-top: 1px;
}

.cs-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 连接状态指示器 */
.cs-conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: rgba(255,255,255,.12);
  padding: 4px 10px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
}
.cs-conn .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,.4);
  display: inline-block;
  transition: background .3s ease;
}
.cs-conn .dot.on {
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74,222,128,.5);
}
.cs-conn .dot.off {
  background: rgba(255,255,255,.4);
}

/* 显示原文开关 */
.cs-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  opacity: .85;
  transition: opacity .2s;
  user-select: none;
}
.cs-switch:hover { opacity: 1; }
.cs-switch input[type="checkbox"] {
  accent-color: #4ade80;
  width: 14px;
  height: 14px;
}

/* 语言切换按钮 */
.cs-langbtn {
  border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.12);
  color: #fff;
  border-radius: 8px;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s ease;
  backdrop-filter: blur(4px);
}
.cs-langbtn:hover {
  background: rgba(255,255,255,.22);
  border-color: rgba(255,255,255,.45);
}
/* 返回首页入口（与语言切换同风格） */
.cs-home {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.12);
  color: #fff;
  border-radius: 8px;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all .2s ease;
  backdrop-filter: blur(4px);
}
.cs-home:hover {
  background: rgba(255,255,255,.22);
  border-color: rgba(255,255,255,.45);
}

/* ═════════════ LAYOUT ════════════ */
.cs-layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ── Sidebar ── */
.cs-side {
  width: 272px;
  border-right: 1px solid var(--cs-line);
  display: flex;
  flex-direction: column;
  background: #fafbfc;
  flex-shrink: 0;
}
.cs-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cs-muted);
  border-bottom: 1px solid var(--cs-line);
}
.cs-mini {
  border: 1px solid var(--cs-line-strong);
  background: var(--cs-surface);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--cs-brand);
  transition: all .2s ease;
}
.cs-mini:hover {
  background: var(--cs-brand-light);
  border-color: var(--cs-brand);
}

.cs-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--cs-line) transparent;
}
.cs-conv-list::-webkit-scrollbar { width: 5px; }
.cs-conv-list::-webkit-scrollbar-track { background: transparent; }
.cs-conv-list::-webkit-scrollbar-thumb { background: var(--cs-line-strong); border-radius: 4px; }

.cs-conv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  border-radius: var(--cs-rs);
  cursor: pointer;
  margin-bottom: 4px;
  transition: all .15s ease;
  border: 1px solid transparent;
}
.cs-conv:hover {
  background: var(--cs-brand-light);
  border-color: var(--cs-buyer-border);
}
.cs-conv.active {
  background: var(--cs-brand-light);
  border-color: var(--cs-brand);
  box-shadow: 0 0 0 1px var(--cs-brand-glow);
}
.cs-conv .c-subj {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 155px;
  color: var(--cs-ink);
}
.cs-conv .c-meta {
  font-size: 11px;
  color: var(--cs-muted);
  margin-top: 2px;
}

/* 演示入口按钮 */
.cs-demo-entry {
  padding: 14px;
  border-top: 1px solid var(--cs-line);
  background: linear-gradient(180deg, #fefefe, #f8fafc);
}
.cs-demo-btn {
  width: 100%;
  border: 2px dashed var(--cs-brand);
  background: linear-gradient(135deg, var(--cs-brand-light), #f0f4ff);
  color: var(--cs-brand);
  border-radius: var(--cs-rs-lg);
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all .25s ease;
  position: relative;
  overflow: hidden;
}
.cs-demo-btn::before {
  content: "▶";
  margin-right: 8px;
  font-size: 12px;
}
.cs-demo-btn:hover {
  background: linear-gradient(135deg, var(--cs-brand), #124a8a);
  color: #fff;
  border-style: solid;
  box-shadow: var(--cs-shadow-hover);
  transform: translateY(-1px);
}
.cs-demo-btn:active {
  transform: translateY(0);
}

/* ── Main Chat Area ── */
.cs-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--cs-bg);
}

/* Empty state */
.cs-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--cs-muted);
  gap: var(--cs-sp-sm);
  text-align: center;
  padding: var(--cs-sp-xl);
}
.cs-empty-ico {
  font-size: 52px;
  opacity: .45;
  filter: grayscale(.3);
  margin-bottom: var(--cs-sp-sm);
}
.cs-empty p {
  font-size: 14px;
  max-width: 320px;
  line-height: 1.65;
}

/* ═════════════ CHAT VIEW ════════════ */
.cs-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Chat header bar */
.cs-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--cs-line);
  background: var(--cs-surface);
  flex-shrink: 0;
  gap: 12px;
}
.cs-chat-subj {
  font-weight: 700;
  font-size: 15px;
  color: var(--cs-ink);
}
.cs-chat-meta {
  font-size: 12px;
  color: var(--cs-muted);
  margin-top: 2px;
  font-weight: 500;
}
.cs-chat-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Transcript / Message list */
.cs-transcript {
  flex: 1;
  overflow-y: auto;
  padding: var(--cs-sp-md) var(--cs-sp-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--cs-line) transparent;
}
.cs-transcript::-webkit-scrollbar { width: 6px; }
.cs-transcript::-webkit-scrollbar-track { background: transparent; }
.cs-transcript::-webkit-scrollbar-thumb { background: var(--cs-line-strong); border-radius: 4px; }

/* ═════════════ MESSAGE BUBBLES ════════════ */
.msg {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: var(--cs-rs-lg);
  box-shadow: var(--cs-shadow-sm);
  transition: transform .15s ease;
  position: relative;
}
.msg:hover {
  box-shadow: var(--cs-shadow-md);
}

.msg-buyer {
  align-self: flex-start;
  background: var(--cs-buyer-bg);
  border: 1px solid var(--cs-buyer-border);
  border-bottom-left-radius: 4px;
}
.msg-seller {
  align-self: flex-end;
  background: var(--cs-seller-bg);
  border: 1px solid var(--cs-seller-border);
  border-bottom-right-radius: 4px;
}

/* Message meta row */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--cs-muted);
  margin-bottom: 7px;
  flex-wrap: wrap;
  line-height: 1.4;
}
.msg-role {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.msg-buyer .msg-role { color: var(--cs-buyer-ink); }
.msg-seller .msg-role { color: var(--cs-seller-ink); }

/* Badges in meta */
.lang-badge {
  display: inline-flex;
  align-items: center;
  background: var(--cs-surface);
  border: 1px solid var(--cs-line-strong);
  border-radius: 20px;
  padding: 1px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.src-badge {
  display: inline-flex;
  align-items: center;
  background: #f1f5f9;
  border-radius: 20px;
  padding: 1px 9px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.src-api { color: var(--cs-success); background: #ecfdf5; border: 1px solid #a7f3d0; }
.src-cache { color: var(--cs-brand); background: var(--cs-brand-light); border: 1px solid #bfdbfe; }
.src-offline { color: var(--cs-warn); background: #fffbeb; border: 1px solid #fde68a; }
.src-same { color: var(--cs-muted); }

.msg-time {
  font-size: 10px;
  opacity: .6;
  font-variant-numeric: tabular-nums;
}

/* Translation text (main content) */
.msg-trans {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--cs-ink);
  font-weight: 500;
}

/* Original text (collapsible) */
.msg-orig {
  margin-top: 8px;
  font-size: 13px;
  color: var(--cs-ink-secondary);
  border-top: 1px dashed var(--cs-line-strong);
  padding-top: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}
.msg-orig .lab {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cs-muted);
  opacity: .75;
}

/* ═════════════ COMPOSER ════════════ */
.cs-composer {
  padding: 14px 20px;
  border-top: 1px solid var(--cs-line);
  background: var(--cs-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.cs-comp-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 12px;
  border-radius: var(--cs-rs);
  transition: box-shadow .2s ease;
}
.cs-comp-row:focus-within {
  box-shadow: 0 0 0 2px var(--cs-brand-glow), var(--cs-shadow-sm);
}
.cs-comp-row.buyer {
  background: linear-gradient(135deg, var(--cs-buyer-bg), #fff);
  border: 1px solid var(--cs-buyer-border);
}
.cs-comp-row.seller {
  background: linear-gradient(135deg, var(--cs-seller-bg), #fff);
  border: 1px solid var(--cs-seller-border);
}

.cs-comp-tag {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  width: 80px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 11px;
}
.cs-comp-row.buyer .cs-comp-tag { color: var(--cs-buyer-ink); }
.cs-comp-row.seller .cs-comp-tag { color: var(--cs-seller-ink); }

.cs-comp-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--cs-line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  outline: none;
  background: var(--cs-surface);
  color: var(--cs-ink);
  transition: border-color .2s ease, box-shadow .2s ease;
  min-height: 42px;
  line-height: 1.5;
}
.cs-comp-input:focus {
  border-color: var(--cs-brand);
  box-shadow: 0 0 0 3px var(--cs-brand-glow);
}
.cs-comp-input::placeholder {
  color: var(--cs-muted);
  opacity: .7;
}

.cs-send {
  border: none;
  background: linear-gradient(135deg, var(--cs-brand), var(--cs-brand-hover));
  color: #fff;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s ease;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}
.cs-send:hover {
  box-shadow: var(--cs-shadow-hover);
  transform: translateY(-1px);
}
.cs-send:active {
  transform: translateY(0);
}
.cs-send:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.cs-detect {
  font-size: 11px;
  color: var(--cs-muted);
  margin-top: 4px;
  padding-left: 2px;
}
.cs-detect .auto {
  color: var(--cs-success);
  font-weight: 700;
}

/* ═════════════ TOAST ════════════ */
.cs-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--cs-ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: var(--cs-rs);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--cs-shadow-lg);
  z-index: 9999;
  animation: toastIn .3s ease both;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ═════════════ EMBED MODE ════════════ */
.cs-app.embed {
  box-shadow: none;
  max-width: none;
  height: 100vh;
  border-radius: 0;
  margin: 0;
}
.cs-app.embed .cs-side { display: none; }

/* ═════════════ RESPONSIVE ════════════ */

/* Tablet */
@media (max-width: 900px) {
  .cs-app {
    border-radius: 0;
    margin: 0;
    height: 100vh;
  }
  .cs-side { width: 220px; }
  .cs-conv .c-subj { max-width: 120px; }
  .msg { max-width: 82%; }
  .cs-transcript { padding: 12px 14px; }
}

/* Mobile phone */
@media (max-width: 640px) {
  .cs-header {
    padding: 10px 14px;
    gap: 8px;
  }
  .cs-title { font-size: 15px; }
  .cs-sub { display: none; }
  .cs-head-actions { gap: 8px; }
  .cs-conn span { display: none; }  /* hide label, keep dot */
  .cs-switch span { display: none; }  /* keep checkbox only */
  .cs-langbtn { padding: 4px 10px; font-size: 12px; }  /* 缩小但始终可见 */

  .cs-side {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--cs-line);
    max-height: 45vh;
  }
  .cs-layout {
    flex-direction: column;
  }
  .cs-main { min-height: 55vh; }

  .msg { max-width: 90%; }
  .cs-composer { padding: 10px 12px; }
  .cs-comp-row { flex-wrap: wrap; }
  .cs-comp-tag { width: auto; }
  .cs-chat-head { padding: 10px 14px; }
  .cs-transcript { padding: 10px 12px; gap: 12px; }

  .cs-demo-btn { padding: 11px 14px; font-size: 13px; }
}

/* Very small screens */
@media (max-width: 400px) {
  .cs-logo { width: 34px; height: 34px; font-size: 18px; }
  .cs-title { font-size: 14px; }
  .cs-langbtn { padding: 4px 10px; font-size: 12px; }
  .msg-trans { font-size: 14px; }
  .cs-send { padding: 8px 14px; font-size: 12px; }
}

/* Dark mode support (follows parent data-theme) */
[data-theme="dark"] {
  --cs-bg: #0f1419;
  --cs-surface: #161b22;
  --cs-ink: #e6edf3;
  --cs-ink-secondary: #8b949e;
  --cs-muted: #6e7681;
  --cs-line: #21262d;
  --cs-line-strong: #30363d;

  --cs-buyer-bg: #0d2137;
  --cs-buyer-border: #1b3a5c;
  --cs-seller-bg: #0d2818;
  --cs-seller-border: #1a4a2e;

  --cs-brand-light: #0d2137;
  --cs-brand-glow: rgba(24, 95, 165, 0.2);

  .cs-app { box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .cs-demo-entry { background: linear-gradient(180deg, #161b22, #0d1117); }
  .src-api { background: #0d2818; border-color: #1a4a2e; }
  .src-cache { background: #0d2137; border-color: #1b3a5c; }
  .src-offline { background: #2d2006; border-color: #5c430d; }
  .lang-badge { background: #21262d; border-color: #30363d; }
  .src-badge { background: #21262d; }
  .cs-comp-input { background: #0d1117; }
  .cs-conv:hover,
  .cs-conv.active { background: #0d2137; border-color: #1b3a5c; }
}
