/* 心晴驿站 —— 温暖系响应式聊天界面 */
:root {
  --bg: #faf3ec;
  --bg-soft: #f5ebe1;
  --panel: #fffaf5;
  --ink: #3e2f28;
  --ink-soft: #8a7468;
  --accent: #d97757;
  --accent-deep: #c05f3f;
  --accent-soft: #fbe9e0;
  --bubble-user: #efe0d3;
  --crisis-bg: #fdf0ec;
  --crisis-border: #e0a191;
  --radius: 18px;
  --shadow: 0 4px 24px rgba(120, 80, 60, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ===== 布局 ===== */
.layout { display: flex; height: 100dvh; }

/* ===== 侧边栏（历史会话） ===== */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid #eadcd0;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  transition: transform 0.25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid #eadcd0;
  margin-bottom: 14px;
}
.sidebar-brand .logo { font-size: 26px; }
.sidebar-brand .name { font-size: 17px; font-weight: 600; }
.sidebar-brand .sub { font-size: 11px; color: var(--ink-soft); }

.new-session-btn {
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(217, 119, 87, 0.35);
  transition: background 0.15s;
  margin-bottom: 14px;
}
.new-session-btn:hover { background: var(--accent-deep); }

.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.session-list .empty { color: var(--ink-soft); font-size: 13px; text-align: center; padding: 24px 8px; line-height: 1.7; }
.session-item {
  text-align: left;
  background: var(--panel);
  border: 1px solid #efe2d6;
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color 0.15s;
}
.session-item:hover { border-color: var(--accent); }
.session-item .date { font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.session-item .snippet {
  font-size: 13px; line-height: 1.5; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.session-item .badges { margin-top: 6px; display: flex; gap: 6px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--bg-soft); color: var(--ink-soft); }
.badge.crisis { background: var(--crisis-bg); color: var(--accent-deep); }

/* ===== 主聊天区 ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid #f0e3d8;
}
.menu-btn { display: none; font-size: 20px; color: var(--ink-soft); padding: 4px 8px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, #f6c89f, #e8956d);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(217, 119, 87, 0.3);
}
.chat-header .who .name { font-size: 16px; font-weight: 600; }
.chat-header .who .status { font-size: 12px; color: #7fae7f; display: flex; align-items: center; gap: 5px; }
.chat-header .who .status::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #8ec78e;
}
.chat-header .spacer { flex: 1; }
.end-btn {
  font-size: 13px; color: var(--ink-soft);
  border: 1px solid #e8d9cc; border-radius: 99px;
  padding: 7px 14px; transition: all 0.15s;
}
.end-btn:hover { color: var(--accent-deep); border-color: var(--accent); }

/* 消息流 */
.messages { flex: 1; overflow-y: auto; padding: 24px 20px 12px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 10px; max-width: 82%; animation: fadeUp 0.25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.assistant { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .mini-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #f6c89f, #e8956d);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  margin-top: 2px;
}
.msg .bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px; line-height: 1.75;
  white-space: pre-wrap; word-break: break-word;
  box-shadow: var(--shadow);
}
.msg.assistant .bubble { background: var(--panel); border-top-left-radius: 6px; }
.msg.user .bubble { background: var(--bubble-user); border-top-right-radius: 6px; }
.msg .time { font-size: 11px; color: var(--ink-soft); margin-top: 5px; padding: 0 4px; }
.msg.user .time { text-align: right; }

/* 危机资源卡 */
.crisis-card {
  align-self: stretch;
  background: var(--crisis-bg);
  border: 1px solid var(--crisis-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 14px; line-height: 1.8;
  white-space: pre-wrap;
  animation: fadeUp 0.3s ease;
}
.crisis-card .title { font-weight: 600; color: var(--accent-deep); margin-bottom: 6px; }

/* 打字指示器 */
.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: #d3b8a5;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: none; opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* 输入区 */
.input-area {
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid #f0e3d8;
}
.input-row { display: flex; gap: 10px; align-items: flex-end; }
.input-row textarea {
  flex: 1; resize: none;
  border: 1px solid #e8d9cc; border-radius: 16px;
  padding: 12px 16px;
  font-size: 15px; font-family: inherit; line-height: 1.5;
  background: var(--bg);
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s;
}
.input-row textarea:focus { border-color: var(--accent); }
.send-btn {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(217, 119, 87, 0.35);
  transition: all 0.15s;
}
.send-btn:hover { background: var(--accent-deep); transform: translateY(-1px); }
.send-btn:disabled { background: #dcc9bb; box-shadow: none; cursor: not-allowed; transform: none; }
.disclaimer { text-align: center; font-size: 11px; color: #b6a397; margin-top: 10px; }

/* ===== 知情同意弹窗 ===== */
.modal-mask[hidden] { display: none !important; }  /* 修复 hidden 属性被 display:flex 覆盖的问题 */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(62, 47, 40, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--panel);
  border-radius: 22px;
  max-width: 520px; width: 100%;
  max-height: 85dvh; overflow-y: auto;
  padding: 32px 30px;
  box-shadow: 0 12px 48px rgba(62, 47, 40, 0.25);
}
.modal .hello { font-size: 40px; text-align: center; margin-bottom: 10px; }
.modal h1 { font-size: 21px; text-align: center; margin-bottom: 6px; }
.modal .lead { font-size: 14px; color: var(--ink-soft); text-align: center; margin-bottom: 20px; }
.modal .points { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.modal .point { display: flex; gap: 10px; font-size: 14px; line-height: 1.7; }
.modal .point .icon { flex-shrink: 0; }
.modal .point b { color: var(--accent-deep); }
.agree-btn {
  width: 100%; padding: 14px;
  border-radius: 14px;
  background: var(--accent); color: #fff;
  font-size: 16px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(217, 119, 87, 0.4);
  transition: background 0.15s;
}
.agree-btn:hover { background: var(--accent-deep); }
.modal .fine { font-size: 11px; color: #b6a397; text-align: center; margin-top: 12px; line-height: 1.6; }

/* 会话结束遮罩提示 */
.ended-banner {
  text-align: center;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 14px;
  padding: 12px;
  border-radius: 12px;
  margin: 0 20px 10px;
}

/* ===== 移动端 ===== */
.sidebar-mask { display: none; }
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%);
    box-shadow: 8px 0 30px rgba(62, 47, 40, 0.15);
  }
  .sidebar.open { transform: none; }
  .sidebar-mask {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgba(62, 47, 40, 0.35);
    opacity: 0; pointer-events: none; transition: opacity 0.25s;
  }
  .sidebar-mask.show { opacity: 1; pointer-events: auto; }
  .menu-btn { display: block; }
  .msg { max-width: 92%; }
  .messages { padding: 16px 14px 8px; }
  .input-area { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .modal { padding: 26px 22px; }
}

/* ===== 会前筛查页 ===== */
.modal.screening { max-width: 560px; }
.screening-q { margin-bottom: 18px; }
.screening-q .q-text { font-size: 14.5px; line-height: 1.7; margin-bottom: 10px; }
.screening-q .q-num { color: var(--accent); font-weight: 600; margin-right: 4px; }
.screening-q .q-safety { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.q-options { display: flex; gap: 8px; flex-wrap: wrap; }
.q-option {
  flex: 1; min-width: 100px;
  padding: 9px 6px;
  font-size: 13px; text-align: center;
  border: 1px solid #e8d9cc; border-radius: 12px;
  background: var(--bg); color: var(--ink);
  transition: all 0.15s;
}
.q-option:hover { border-color: var(--accent); }
.q-option.selected {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(217, 119, 87, 0.3);
}
.agree-btn:disabled { background: #dcc9bb; box-shadow: none; cursor: not-allowed; }
@media (max-width: 768px) {
  .q-option { min-width: 44%; flex: 1 1 44%; }
}
