:root {
  --font-title: "STKaiti", "Kaiti SC", "LXGW WenKai", "Times New Roman", serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --bg-start: #d8f3ea;
  --bg-mid: #f3f8ea;
  --bg-end: #ffe9dc;
  --surface: rgba(255, 255, 255, 0.85);
  --surface-strong: rgba(255, 255, 255, 0.96);
  --surface-soft: rgba(237, 247, 242, 0.7);
  --text-main: #16352b;
  --text-muted: #4d675d;
  --accent: #1d8f6a;
  --accent-soft: #dcfff2;
  --user-bubble: #2f7f67;
  --user-text: #f4fff8;
  --system-bubble: #eef7ff;
  --error: #b13a3a;
  --error-bg: #ffe9e9;
  --shadow-lg: 0 24px 60px rgba(26, 53, 43, 0.16);
  --shadow-sm: 0 6px 18px rgba(20, 43, 35, 0.12);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --duration-fast: 0.2s;
  --duration-med: 0.36s;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--text-main);
  background: linear-gradient(to right, #b8e6d8, #f5d4b3);
  overflow: hidden;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1200px, 94vw);
  height: min(90vh, 900px);
  margin: 4vh auto;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px;
  border-radius: var(--radius-xl);
  animation: shellEnter var(--duration-med) ease-out both;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow-sm);
}

.panel-side {
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-width: 10px;
  overflow-y: auto;       /* ← 加这行：内容超出时出现滚动条 */
  min-height: 0;          /* ← 加这行：阻止 flex 子项撑破父容器 */
}

.brand h1 {
  margin: 8px 0 0;
  font-family: var(--font-title);
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: 0.06em;
}

.brand-kicker {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand-subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.status-card {
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 0px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.status-line {
  margin: 8px 0 0;
  color: var(--text-muted);
  word-break: break-all;
}

.status-line code {
  color: var(--text-main);
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  box-shadow: 0 0 0 4px rgba(29, 143, 106, 0.14);
}

.dot-connecting {
  background: #e7a544;
}

.dot-connected {
  background: #2cb575;
}

.dot-disconnected {
  background: #ca5656;
}

.side-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tips {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0px;
  color: var(--text-muted);
  font-size: 13px;
}

.tips li {
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.58);
}

.session-list-container {
  margin-top: 12px;
  padding-top: 0;
}

.session-list-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 8px 0;
  padding: 0 4px;
  letter-spacing: 0.3px;
}

.session-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.session-item {
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  font-size: 12.5px;
  color: var(--text-main);
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.8);
}

.session-item.active {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  font-weight: 500;
}

.session-item-delete {
  float: right;
  opacity: 0;
  transition: opacity 0.15s;
  color: var(--error);
  font-size: 12px;
}

.session-item:hover .session-item-delete {
  opacity: 1;
}

.panel-chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 18px 18px 14px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
}

.chat-kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.chat-header h2 {
  margin: 6px 0 0;
  font-size: 28px;
  font-family: var(--font-title);
}

.error-bar {
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--error-bg);
  border: 1px solid rgba(177, 58, 58, 0.3);
  color: var(--error);
  font-size: 14px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 6px 16px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.msg {
  max-width: min(86%, 720px);
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 1px solid rgba(23, 58, 46, 0.08);
  animation: bubbleEnter var(--duration-med) ease both;
}

.msg-title {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.msg-body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.52;
  color: var(--text-main);
}

.msg-user {
  margin-left: auto;
  background: var(--user-bubble);
  border-color: rgba(22, 75, 58, 0.4);
}

.msg-user .msg-title,
.msg-user .msg-body {
  color: var(--user-text);
}

.msg-system {
  background: var(--system-bubble);
  border-style: dashed;
}

/* ─── Welcome state ─────────────────────────────────── */

.welcome-state {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  justify-self: center;
  margin-top: 22vh;
  color: var(--text-muted);
  user-select: none;
}

.welcome-icon {
  font-size: 38px;
  line-height: 1;
  opacity: 0.75;
}

.welcome-text {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* ─── Typing indicator ──────────────────────────────── */

.typing {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  animation: bounce 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.12s;
}

.typing span:nth-child(3) {
  animation-delay: 0.24s;
}

.typing em {
  font-style: normal;
}

.composer {
  display: grid;
  grid-template-rows: auto auto;
  gap: 10px;
  background: var(--surface-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  border: 1px solid rgba(23, 58, 46, 0.12);
}

.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 62px;
  max-height: 200px;
  border: 1px solid rgba(32, 78, 62, 0.24);
  border-radius: 10px;
  font: inherit;
  color: var(--text-main);
  padding: 10px 12px;
  background: white;
}

.composer textarea:focus {
  outline: 2px solid rgba(29, 143, 106, 0.26);
  border-color: rgba(29, 143, 106, 0.5);
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 9px 16px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: transform var(--duration-fast) ease, opacity var(--duration-fast) ease,
    background var(--duration-fast) ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-send {
  color: white;
  background: linear-gradient(115deg, #167d5e, #2da67f);
}

.btn-voice {
  color: var(--text-main);
  background: #d9f6eb;
  position: relative;
  border: 1px solid #2f7f67;
}

.btn-voice.is-recording {
  color: white;
  background: linear-gradient(115deg, #de4a4a, #d06666);
  animation: pulse 1.45s infinite ease-out;
}

.btn-ghost {
  background: rgba(244, 252, 249, 0.92);
  border: 1px solid rgba(34, 84, 67, 0.24);
  color: var(--text-main);
}

.btn-danger {
  border-color: rgba(177, 58, 58, 0.28);
  color: #8f2f2f;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes shellEnter {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes bubbleEnter {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(222, 74, 74, 0.34);
  }
  70% {
    box-shadow: 0 0 0 15px rgba(222, 74, 74, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(222, 74, 74, 0);
  }
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.6;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

/* ─── Vision / Stress dashboard ─────────────────────────────────── */

.vision-panel {
  margin-top: -20px;
  padding: 30px 14px 14px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

.vision-panel.level-warn {
  border-color: rgba(255, 182, 92, 0.7);
  box-shadow: 0 0 0 1px rgba(255, 182, 92, 0.2) inset;
}

.vision-panel.level-alarm {
  border-color: rgba(255, 107, 107, 0.8);
  box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.3) inset, 0 0 16px rgba(255, 107, 107, 0.18);
  animation: pulseAlarm 2.4s ease-in-out infinite;
}

@keyframes pulseAlarm {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.3) inset, 0 0 12px rgba(255, 107, 107, 0.15); }
  50%      { box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.45) inset, 0 0 22px rgba(255, 107, 107, 0.28); }
}

.vision-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.vision-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.btn-camera {
  font-size: 12px;
  padding: 4px 10px;
}

.btn-camera.is-on {
  background: rgba(143, 216, 177, 0.2);
  color: #8fd8b1;
}

.camera-preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror like a selfie */
}

.camera-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff6b6b;
  box-shadow: 0 0 6px rgba(255, 107, 107, 0.8);
  animation: recordBlink 1.2s ease-in-out infinite;
}

@keyframes recordBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.stress-readout {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stress-score-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.stress-label {
  font-size: 12px;
  opacity: 0.7;
}

.stress-score {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stress-trend {
  font-size: 16px;
  opacity: 0.85;
}

#stressChart {
  width: 100%;
  max-width: 100%;
  height: 60px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 8px;
}

.stress-signals {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
}

.stress-line {
  margin: 0;
  opacity: 0.85;
}

.stress-summary {
  margin: 2px 0 0 0;
  font-size: 12px;
  opacity: 0.7;
  font-style: italic;
}

.burst-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  cursor: help;
}

.burst-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #ff8c42;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
}

.burst-compound {
  font-size: 11.5px;
  color: #c8421a;
  font-weight: 600;
}

.burst-pulse {
  animation: burst-pulse-anim 600ms ease-out;
}

.btn-voice.is-continuous {
  background: linear-gradient(135deg, #b6d7c1, #d8f3ea);
  color: #2e7d32;
  cursor: not-allowed;
  opacity: 0.85;
}

.stress-expression-line {
  font-weight: 600;
  font-size: 13px;
}
.expr-pos { color: #2e7d32; }
.expr-neg { color: #c8421a; }
.expr-neu { color: #5e6f6a; }

@keyframes burst-pulse-anim {
  0%   { transform: scale(1);   opacity: 0.6; }
  40%  { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .shell {
    margin: 0;
    width: 100vw;
    min-height: 100vh;
    height: auto;
    border-radius: 0;
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .panel-side {
    gap: 14px;
  }

  .panel-chat {
    min-height: 68vh;
  }

  .composer {
    position: sticky;
    bottom: 0;
  }

  .msg {
    max-width: 92%;
  }
}

.panel-side::-webkit-scrollbar {
  width: 6px;
}

.panel-side::-webkit-scrollbar-thumb {
  background: rgba(221, 221, 221, 0.9);
  border-radius: 3px;
}

#wechat-login-overlay #wechat-qr-container iframe {
  border: none;
}

#wechat-login-overlay #wechat-qr-container iframe body {
  font-size: 24px !important;
  font-weight: 700 !important;
}
