/* ============================================================
   鲸鱼娘在线 — 纯静态前端样式（日系水彩 · DSH 镜像版）
   深色为默认主题，html[data-theme="light"] 覆盖变量。
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
  color-scheme: dark;

  /* 插画取色 */
  --navy-deep: #0a2e58;
  --navy: #1b477b;
  --blue-mid: #3b6194;
  --blue-bright: #4e77a9;
  --blue-light: #6fa8c6;
  --ice: #7fd8f0;
  --ice-pale: #c5e9ee;
  --muted: #b1afc9;
  --near-white: #f5fefe;

  --bg-top: var(--navy-deep);
  --bg-bottom: #071c38;
  --bg: var(--navy-deep);

  --panel: rgba(255, 255, 255, 0.06);
  --panel-glass: rgba(10, 46, 88, 0.55);
  --panel-overlay: rgba(8, 34, 63, 0.94);
  --card-bg: rgba(9, 36, 66, 0.72);

  --surface: rgba(255, 255, 255, 0.08);
  --surface-2: rgba(255, 255, 255, 0.12);
  --surface-3: rgba(255, 255, 255, 0.18);

  --text: var(--near-white);
  --text-dim: var(--muted);
  --text-faint: rgba(177, 175, 201, 0.62);

  --border: rgba(197, 233, 238, 0.18);
  --border-strong: rgba(197, 233, 238, 0.34);

  --accent: var(--ice);
  --accent-ink: var(--ice);
  --accent-2: var(--blue-bright);
  --accent-soft: rgba(127, 216, 240, 0.12);
  --grad-accent: linear-gradient(120deg, #7fd8f0 0%, #4e77a9 100%);
  --grad-user: linear-gradient(120deg, #7fd8f0 0%, #4e77a9 100%);
  --user-text: #06203f;
  --user-glow: rgba(127, 216, 240, 0.20);
  --ai-bubble: rgba(197, 233, 238, 0.10);
  --ai-border: rgba(197, 233, 238, 0.20);

  --ok: #9fe6cf;
  --warn: #f3d29a;
  --danger: #ee9a86;
  --ok-soft: rgba(159, 230, 207, 0.12);
  --warn-soft: rgba(243, 210, 154, 0.12);
  --danger-soft: rgba(238, 154, 134, 0.14);

  --shadow-soft: 0 22px 60px rgba(2, 15, 32, 0.4);
  --shadow-bubble: 0 10px 28px rgba(2, 15, 32, 0.22);
  --shadow-pop: 0 14px 36px rgba(2, 15, 32, 0.38);

  --wash-1: rgba(127, 216, 240, 0.16);
  --wash-2: rgba(78, 119, 169, 0.16);
  --wash-3: rgba(111, 168, 198, 0.14);
  --paper-line: rgba(245, 254, 254, 0.025);

  --radius-bubble: 20px;
  --radius-panel: 22px;
  --radius-btn: 14px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Source Han Sans SC",
    Roboto, Helvetica, Arial, sans-serif;

  --app-bg: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  --app-offset: 0px;
}

html[data-theme="light"] {
  color-scheme: light;

  --bg-top: #f5fefe;
  --bg-bottom: #e9f6fb;
  --bg: #f5fefe;

  --panel: #ffffff;
  --panel-glass: rgba(255, 255, 255, 0.82);
  --panel-overlay: rgba(255, 255, 255, 0.96);
  --card-bg: rgba(255, 255, 255, 0.92);

  --surface: #ffffff;
  --surface-2: #eef8fb;
  --surface-3: #dceef5;

  --text: var(--navy-deep);
  --text-dim: var(--blue-mid);
  --text-faint: rgba(10, 46, 88, 0.45);

  --border: rgba(10, 46, 88, 0.12);
  --border-strong: rgba(10, 46, 88, 0.24);

  --accent: #7fd8f0;
  --accent-ink: #1f7d9c;
  --accent-2: #4e77a9;
  --accent-soft: rgba(127, 216, 240, 0.18);
  --grad-accent: linear-gradient(120deg, #7fd8f0 0%, #4e77a9 100%);
  --grad-user: linear-gradient(120deg, #7fd8f0 0%, #4e77a9 100%);
  --user-text: #06203f;
  --user-glow: rgba(78, 119, 169, 0.18);
  --ai-bubble: rgba(197, 233, 238, 0.38);
  --ai-border: rgba(78, 119, 169, 0.20);

  --ok: #2a9476;
  --warn: #a5762a;
  --danger: #c25a4a;
  --ok-soft: rgba(42, 148, 118, 0.1);
  --warn-soft: rgba(165, 118, 42, 0.1);
  --danger-soft: rgba(194, 90, 74, 0.1);

  --shadow-soft: 0 20px 50px rgba(10, 46, 88, 0.10);
  --shadow-bubble: 0 8px 22px rgba(10, 46, 88, 0.08);
  --shadow-pop: 0 14px 30px rgba(10, 46, 88, 0.14);

  --wash-1: rgba(127, 216, 240, 0.22);
  --wash-2: rgba(78, 119, 169, 0.10);
  --wash-3: rgba(197, 233, 238, 0.5);
  --paper-line: rgba(10, 46, 88, 0.02);

  --app-bg: linear-gradient(180deg, #f5fefe 0%, #e9f6fb 100%);
}

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

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  background: var(--app-bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: rgba(127, 216, 240, 0.32);
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.icon {
  display: block;
  flex: 0 0 auto;
}

.noscript {
  position: fixed;
  inset: 0;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  font-size: 15px;
  color: var(--text-dim);
  background: var(--bg);
  z-index: 999;
}

/* ---------- 视图骨架 + 水彩晕染 ---------- */
.view {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-offset, 0px);
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  background: var(--app-bg);
}

.view::before {
  content: "";
  position: absolute;
  inset: -12%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(38% 30% at 16% 6%, var(--wash-1), transparent 70%),
    radial-gradient(34% 28% at 86% 2%, var(--wash-2), transparent 72%),
    radial-gradient(50% 40% at 46% 108%, var(--wash-3), transparent 74%);
  filter: blur(46px);
  opacity: 0.9;
}

.view::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    45deg,
    var(--paper-line) 0,
    var(--paper-line) 1px,
    transparent 1px,
    transparent 4px
  );
  opacity: 0.9;
}

/* ---------- 登录页 ---------- */
.login-view {
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding:
    max(28px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  margin: auto;
  padding: 34px 26px 28px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-panel);
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(26px) saturate(1.05);
  backdrop-filter: blur(26px) saturate(1.05);
  box-shadow: var(--shadow-soft);
}

.login-mark {
  align-self: center;
  width: 78px;
  height: 78px;
  padding: 3px;
  margin-bottom: 4px;
  border-radius: 50%;
  background: var(--grad-accent);
  box-shadow: 0 14px 34px rgba(2, 15, 32, 0.28);
}

.login-avatar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.login-title {
  margin: 0;
  text-align: center;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}

.login-en {
  margin: -4px 0 0;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.12em;
  line-height: 1.5;
  opacity: 0.5;
  color: var(--text-dim);
}

html[data-theme="dark"] .login-en {
  color: var(--ice-pale);
}

.login-sub {
  margin: 2px 0 8px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

.field {
  display: flex;
}

.text-input {
  width: 100%;
  height: 48px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.text-input::placeholder {
  color: var(--text-faint);
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.text-input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
}

.primary-btn {
  height: 48px;
  border: 0;
  border-radius: var(--radius-btn);
  background: var(--grad-accent);
  color: var(--user-text);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 12px 30px var(--user-glow);
  transition: transform 0.16s ease, opacity 0.16s ease, box-shadow 0.16s ease;
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 36px var(--user-glow);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
}

.primary-btn:disabled {
  opacity: 0.55;
  cursor: default;
  box-shadow: none;
}

.form-error {
  margin: 0;
  text-align: center;
  font-size: 13px;
  line-height: 1.55;
  color: var(--danger);
}

.form-error:not([hidden]) {
  animation: shake 0.28s ease;
}

.form-error.is-lock {
  color: var(--warn);
  animation: none;
}

.form-success {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--ok);
}

.site-footer {
  position: relative;
  z-index: 1;
  width: 100%;
  margin: 18px auto 0;
  text-align: center;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

/* ---------- 主框架：侧栏 + 聊天区 ---------- */
.chat-view {
  overflow: hidden;
}

.app-shell {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  width: 100%;
}

.chat-panel {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- 会话侧栏 ---------- */
.sidebar {
  position: relative;
  z-index: 25;
  flex: 0 0 280px;
  width: 280px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(127, 216, 240, 0.05), transparent 32%),
    var(--panel);
  border-right: 1px solid var(--border);
  -webkit-backdrop-filter: blur(22px) saturate(1.05);
  backdrop-filter: blur(22px) saturate(1.05);
}

.sidebar-head {
  flex: 0 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px 10px;
}

.new-session-btn {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius-btn);
  background: var(--grad-accent);
  color: var(--user-text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 10px 26px var(--user-glow);
  transition: transform 0.16s ease, opacity 0.16s ease, box-shadow 0.16s ease;
}

.new-session-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 32px var(--user-glow);
}

.new-session-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
}

.new-session-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.session-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 8px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.session-list::-webkit-scrollbar {
  width: 6px;
}

.session-list::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 6px;
}

.session-empty {
  margin: auto;
  padding: 28px 14px;
  text-align: center;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-faint);
}

.session-group {
  margin-bottom: 4px;
}

.session-group-title {
  padding: 12px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-group-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  min-width: 0;
  padding: 8px 10px 8px 14px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}

.session-item:hover {
  background: var(--surface);
  transform: translateY(-1px);
}

.session-item.is-active {
  background: rgba(127, 216, 240, 0.10);
}

.session-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 58%;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(127, 216, 240, 0.5);
}

.session-title {
  display: block;
  max-width: 100%;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item.is-active .session-title {
  font-weight: 600;
}

.session-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-faint);
}

.session-time {
  white-space: nowrap;
}

.session-badges {
  display: none;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
  overflow: hidden;
}

.session-badge {
  max-width: 104px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-faint);
  font-size: 9.5px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html[data-theme="dark"] .session-badge {
  color: var(--blue-light);
}

.running-dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(127, 216, 240, 0.16);
  animation: running-pulse 1.8s ease-in-out infinite;
}

.session-item.is-flash {
  animation: session-flash 1.5s ease-out;
}

.sidebar-footer {
  flex: 0 0 auto;
  padding: 9px 14px calc(9px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.sidebar-backdrop {
  display: none;
}

/* ---------- 顶部栏 ---------- */
.topbar {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  padding:
    calc(9px + env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    9px
    max(10px, env(safe-area-inset-left));
  background: var(--panel-glass);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(20px) saturate(1.05);
  backdrop-filter: blur(20px) saturate(1.05);
}

.topbar::before,
.topbar::after {
  position: absolute;
  pointer-events: none;
  color: var(--accent);
  opacity: 0.32;
  animation: twinkle 5s ease-in-out infinite;
}

.topbar::before {
  content: "✧";
  left: 14px;
  top: 2px;
  font-size: 10px;
}

.topbar::after {
  content: "◦";
  right: 16px;
  bottom: 2px;
  font-size: 11px;
  animation-delay: 1.4s;
}

.topbar-inner {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-title {
  margin: 0;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}

/* 仅手机显示（用更高优先级覆盖 .icon-btn 的 display:grid） */
.topbar .menu-btn {
  display: none;
}

.conn-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.conn-dot[data-state="online"] {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 0 10px rgba(127, 216, 240, 0.45);
}

.conn-dot[data-state="connecting"],
.conn-dot[data-state="reconnecting"] {
  background: var(--warn);
  box-shadow: 0 0 0 3px var(--warn-soft);
  animation: dot-pulse 1.8s ease-in-out infinite;
}

.conn-dot[data-state="offline"],
.conn-dot[data-state="agent-offline"] {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--text);
  transform: translateY(-1px);
}

.icon-btn:active {
  background: var(--surface-2);
  transform: translateY(0);
}

html[data-theme="dark"] .icon-moon {
  display: none;
}

html[data-theme="light"] .icon-sun {
  display: none;
}

/* ---------- 电脑端离线提示条 ---------- */
.agent-banner {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--accent-ink);
  background: rgba(127, 216, 240, 0.08);
  border-bottom: 1px solid var(--border);
}

.agent-banner-icon {
  animation: twinkle 3.4s ease-in-out infinite;
}

/* ---------- 消息区 ---------- */
.chat-main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.messages:focus {
  outline: none;
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 8px;
}

.messages-inner {
  width: 100%;
  max-width: 720px;
  min-height: 100%;
  margin: 0 auto;
  padding: 20px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

/* 空状态 / 状态提示 */
.empty-hint {
  margin: auto;
  padding: 28px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  color: var(--text-faint);
}

.empty-mark {
  width: 66px;
  height: 66px;
  padding: 3px;
  border-radius: 50%;
  background: var(--grad-accent);
  box-shadow: 0 14px 32px rgba(2, 15, 32, 0.26);
}

.empty-avatar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.empty-title {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-dim);
}

.empty-desc {
  font-size: 12.5px;
  line-height: 1.7;
  max-width: 300px;
  overflow-wrap: anywhere;
}

.retry-btn {
  margin-top: 4px;
  height: 38px;
  padding: 0 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-btn);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease;
}

.retry-btn:hover {
  transform: translateY(-1px);
  background: var(--surface-2);
}

/* 历史提示 */
.history-note {
  align-self: center;
  margin: 0 auto 2px;
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.5;
}

html[data-theme="dark"] .history-note {
  color: var(--blue-light);
}

/* 消息行 */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: msg-in 0.26s ease-out both;
}

.msg-user {
  justify-content: flex-end;
}

.msg-assistant {
  justify-content: flex-start;
}

.msg-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: min(78%, 560px);
}

.msg-user .msg-col {
  align-items: flex-end;
}

.msg-assistant .msg-col {
  align-items: flex-start;
}

.avatar {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(2, 15, 32, 0.24);
  user-select: none;
  -webkit-user-select: none;
}

.avatar-img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* 消息行底部有时间戳，头像与气泡底边对齐 */
.msg-assistant .avatar {
  margin-bottom: 20px;
}

.typing-row .avatar {
  margin-bottom: 0;
}

.bubble {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow-bubble);
}

.msg-assistant .bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--ai-border);
  border-bottom-left-radius: 7px;
  color: var(--text);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.msg-user .bubble {
  background: var(--grad-user);
  color: var(--user-text);
  border-bottom-right-radius: 7px;
  box-shadow: 0 10px 26px rgba(59, 97, 148, 0.28);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding: 0 3px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-faint);
}

.msg-user .msg-meta {
  flex-direction: row-reverse;
}

.msg-time {
  white-space: nowrap;
}

.msg-status {
  color: var(--text-faint);
}

.msg-row.is-sending .bubble {
  opacity: 0.72;
}

.msg-row.is-failed .bubble {
  box-shadow: 0 0 0 1px var(--danger);
}

.msg-row.is-failed .msg-status {
  color: var(--danger);
}

/* 工具调用：一行小标签 */
.tool-row {
  display: flex;
  justify-content: flex-start;
  padding-left: 42px;
}

.tool-tag {
  display: inline-block;
  max-width: 100%;
  padding: 3px 11px;
  border: 1px solid var(--ai-border);
  border-radius: 999px;
  background: var(--ai-bubble);
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html[data-theme="dark"] .tool-tag {
  color: var(--blue-light);
}

/* 正在输入 */
.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msg-in 0.24s ease-out both;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--ai-border);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 7px;
  background: var(--ai-bubble);
  color: var(--text-dim);
  font-size: 12.5px;
  box-shadow: var(--shadow-bubble);
}

.typing-label {
  line-height: 1;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 12px;
}

.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: dot-bounce 1.3s ease-in-out infinite;
}

.typing-dots i:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots i:nth-child(3) {
  animation-delay: 0.32s;
}

/* 回到底部 */
.jump-btn {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: 14px;
  z-index: 4;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel-glass);
  color: var(--text-dim);
  box-shadow: var(--shadow-pop);
  cursor: pointer;
  animation: pop-in 0.2s ease-out both;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  transition: transform 0.18s ease, color 0.18s ease;
}

.jump-btn:hover {
  color: var(--text);
  transform: translateY(-1px);
}

/* ---------- 输入区 ---------- */
.composer {
  flex: 0 0 auto;
  z-index: 3;
  padding:
    8px
    max(10px, env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  background: var(--panel-glass);
  border-top: 1px solid var(--border);
  -webkit-backdrop-filter: blur(20px) saturate(1.05);
  backdrop-filter: blur(20px) saturate(1.05);
}

.composer-inner {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 5px 5px 5px 15px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-bubble);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-bubble), 0 0 0 3px var(--accent-soft);
}

.composer-input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 24px;
  max-height: calc(8.75em + 14px);
  margin: 0;
  padding: 7px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.75;
  resize: none;
  outline: none;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-appearance: none;
  appearance: none;
}

.composer-input::-webkit-scrollbar {
  display: none;
}

.composer-input::placeholder {
  color: var(--text-faint);
}

.send-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--grad-accent);
  color: var(--user-text);
  box-shadow: 0 8px 20px var(--user-glow);
  cursor: pointer;
  transition: transform 0.16s ease, opacity 0.16s ease, box-shadow 0.16s ease;
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px var(--user-glow);
}

.send-btn:active:not(:disabled) {
  transform: translateY(0) scale(0.95);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

/* ---------- 信息面板（右侧抽屉，可操作） ---------- */
.drawer-layer {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-offset, 0px);
  height: var(--app-height, 100dvh);
  z-index: 70;
  overflow: hidden;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 20, 40, 0.5);
  opacity: 0;
  transition: opacity 0.24s ease;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.drawer-layer.is-open .drawer-backdrop {
  opacity: 1;
}

.info-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 390px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(127, 216, 240, 0.06), transparent 26%),
    var(--panel-overlay);
  border-left: 1px solid var(--border);
  box-shadow: -24px 0 60px rgba(2, 15, 32, 0.34);
  transform: translateX(102%);
  transition: transform 0.3s cubic-bezier(0.22, 0.8, 0.25, 1);
  will-change: transform;
}

.drawer-layer.is-open .info-panel {
  transform: translateX(0);
}

.info-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid var(--border);
}

.info-heading {
  min-width: 0;
}

.info-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.info-sub {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 18px calc(20px + env(safe-area-inset-bottom));
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.info-section {
  margin-bottom: 22px;
}

.info-section:last-child {
  margin-bottom: 4px;
}

.info-section-title {
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.info-current {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(127, 216, 240, 0.07);
}

.info-current-label {
  flex: 0 0 auto;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--accent-ink);
}

.info-current-value {
  min-width: 0;
  font-size: 13.5px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.info-group {
  margin-top: 10px;
}

.info-group-name {
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.info-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: 14px;
}

.info-item + .info-item {
  margin-top: 2px;
}

.info-item.is-current {
  background: rgba(127, 216, 240, 0.10);
  border-color: rgba(127, 216, 240, 0.32);
}

.info-item-main {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.info-item-name {
  font-size: 13px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.info-item-sub {
  font-size: 11px;
  line-height: 1.55;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}

.info-item.is-busy .info-item-sub {
  color: var(--accent-ink);
}

.info-badge {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent-soft);
}

.info-badge.is-muted {
  color: var(--text-faint);
  background: var(--surface-2);
}

.info-badge.is-pink {
  color: var(--user-text);
  background: var(--grad-accent);
}

/* 可点击的模型 / 模式行 */
.info-action {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

.info-action:hover:not(:disabled) {
  background: var(--surface);
  transform: translateY(-1px);
}

.info-action:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.info-action.is-current {
  border-color: rgba(127, 216, 240, 0.32);
}

.info-note {
  margin: 6px 2px 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--warn);
}

.info-feedback {
  margin: 2px 2px 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}

.info-feedback.is-ok {
  color: var(--ok);
}

.info-feedback.is-warn {
  color: var(--warn);
}

.info-feedback.is-error {
  color: var(--danger);
}

.info-empty {
  padding: 6px 2px;
  font-size: 12.5px;
  color: var(--text-faint);
}

.bundle-item.is-disabled .info-item-name {
  color: var(--text-faint);
}

.bundle-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.bundle-state {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 自绘开关 */
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--navy);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.18s ease;
}

html[data-theme="light"] .switch {
  background: var(--surface-3);
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f5fefe;
  box-shadow: 0 2px 6px rgba(2, 15, 32, 0.28);
  transition: transform 0.22s ease;
}

.switch.is-on {
  background: var(--grad-accent);
  border-color: transparent;
}

.switch.is-on::after {
  transform: translateX(18px);
}

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

.switch:disabled {
  opacity: 0.5;
  cursor: default;
}

.switch.is-confirm {
  box-shadow: 0 0 0 3px rgba(127, 216, 240, 0.35);
}

.switch.is-busy::before {
  content: "";
  position: absolute;
  inset: -3px;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

/* ---------- 通用弹窗 ---------- */
.modal-layer {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-offset, 0px);
  height: var(--app-height, 100dvh);
  z-index: 85;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 20, 40, 0.52);
  opacity: 0;
  transition: opacity 0.22s ease;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 390px;
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 22px 20px;
  border-radius: var(--radius-panel);
  background: var(--panel-overlay);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.modal-layer.is-open .modal-backdrop {
  opacity: 1;
}

.modal-layer.is-open .modal-card {
  opacity: 1;
  transform: none;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.modal-close {
  margin-right: -6px;
  font-size: 20px;
  line-height: 1;
}

.modal-sub {
  margin: 4px 0 16px;
  font-size: 12.5px;
  color: var(--text-dim);
}

/* 新建会话（项目选择） */
.create-card {
  max-width: 420px;
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  margin: 4px 0 2px;
  padding-right: 2px;
}

.project-option {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.project-option:hover:not(:disabled) {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.project-option:disabled {
  opacity: 0.55;
  cursor: default;
}

.project-option-name {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.project-option-path {
  font-size: 11.5px;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}

.project-option.is-none {
  background: transparent;
  border-style: dashed;
}

.project-empty {
  margin: 4px 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-faint);
  overflow-wrap: anywhere;
}

.create-card .form-error {
  margin-top: 10px;
}

/* 修改密码 */
.pwd-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-label {
  font-size: 12.5px;
  color: var(--text-dim);
}

.modal-field .text-input {
  height: 46px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.ghost-btn {
  height: 42px;
  padding: 0 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}

.ghost-btn:hover {
  background: var(--surface);
  transform: translateY(-1px);
}

.modal-submit {
  height: 42px;
  min-width: 88px;
  padding: 0 18px;
  font-size: 14px;
}

/* ---------- Toast ---------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 95;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(92vw, 430px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--panel-overlay);
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
  box-shadow: var(--shadow-pop);
  animation: toast-in 0.2s ease-out both;
  overflow-wrap: anywhere;
}

/* ---------- 动画 ---------- */
@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes dot-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.42;
  }
}

@keyframes dot-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes running-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.42;
    transform: scale(0.72);
  }
}

@keyframes session-flash {
  0%,
  25% {
    background: rgba(127, 216, 240, 0.16);
    box-shadow: 0 0 0 1px rgba(127, 216, 240, 0.4);
  }
  100% {
    background: transparent;
    box-shadow: 0 0 0 1px transparent;
  }
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.16;
    transform: scale(0.92) rotate(0deg);
  }
  50% {
    opacity: 0.42;
    transform: scale(1.06) rotate(8deg);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

/* ---------- 桌面端 ---------- */
@media (min-width: 768px) {
  .session-badges {
    display: flex;
  }
}

@media (min-width: 820px) {
  .messages-inner {
    padding: 26px 24px 18px;
    gap: 15px;
  }

  .msg-col {
    max-width: 68%;
  }

  .msg-assistant .msg-col {
    max-width: 64%;
  }

  .bubble {
    font-size: 15.5px;
  }
}

@media (hover: hover) and (pointer: fine) {
  .msg-row:hover .bubble {
    border-color: rgba(127, 216, 240, 0.34);
  }
}

/* ---------- 手机：侧栏变抽屉 ---------- */
@media (max-width: 767px) {
  .topbar .menu-btn {
    display: grid;
  }

  .topbar-inner {
    gap: 6px;
  }

  .topbar-title {
    font-size: 15px;
  }

  .topbar-actions .icon-btn {
    width: 34px;
    height: 34px;
  }

  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 300px;
    max-width: 88vw;
    flex: none;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.22, 0.8, 0.25, 1);
    box-shadow: 0 0 46px rgba(2, 15, 32, 0.42);
    will-change: transform;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 20;
    background: rgba(4, 20, 40, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.26s ease, visibility 0.26s ease;
  }

  .sidebar-backdrop.is-open {
    opacity: 1;
    visibility: visible;
  }

  .info-panel {
    width: 100%;
    max-width: 100%;
  }

  .composer {
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }
}

/* ---------- 减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
