/* ============================================================
   第二大脑 - 个人 RAG 知识库前端样式
   科技蓝主题 · 响应式 · 浅色/深色模式
   ============================================================ */

/* ---------- 主题变量（浅色，默认） ---------- */
:root {
  /* 主色调 */
  --color-primary: #1a73e8;
  --color-primary-dark: #0d47a1;
  --color-primary-light: #e3f2fd;
  --color-primary-soft: #bbdefb;
  --color-accent: #64b5f6;

  /* 中性色 */
  --color-bg: #f5f8ff;
  --color-surface: #ffffff;
  --color-surface-2: #f0f4fa;
  --color-border: #e1e8f0;
  --color-text: #1a2332;
  --color-text-soft: #5a6b80;
  --color-text-muted: #8b9bb0;

  /* 功能色 */
  --color-success: #16a34a;
  --color-warning: #f59e0b;
  --color-danger: #dc2626;

  /* 气泡色 */
  --bubble-user-bg: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
  --bubble-user-text: #ffffff;
  --bubble-ai-bg: #ffffff;
  --bubble-ai-text: #1a2332;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(13, 71, 161, 0.06);
  --shadow-md: 0 4px 16px rgba(13, 71, 161, 0.10);
  --shadow-lg: 0 12px 40px rgba(13, 71, 161, 0.16);

  /* 圆角 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 999px;

  /* 间距 */
  --header-h: 64px;

  /* 过渡 */
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* 字体 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

/* ---------- 深色模式 ---------- */
[data-theme="dark"] {
  --color-primary: #4e9bf5;
  --color-primary-dark: #1a73e8;
  --color-primary-light: #0d2a4a;
  --color-primary-soft: #1e3a5f;
  --color-accent: #64b5f6;

  --color-bg: #0b1220;
  --color-surface: #131c2e;
  --color-surface-2: #1a2438;
  --color-border: #243049;
  --color-text: #e6ecf5;
  --color-text-soft: #a4b1c6;
  --color-text-muted: #6b7a93;

  --bubble-user-bg: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
  --bubble-user-text: #ffffff;
  --bubble-ai-bg: #1a2438;
  --bubble-ai-text: #e6ecf5;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ---------- 基础重置 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  height: 100vh; /* fallback */
  height: 100dvh; /* 动态视口高度，iOS Safari适配 */
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition), color var(--transition);
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

textarea {
  font-family: inherit;
}

svg {
  display: block;
  flex-shrink: 0;
}

/* ---------- 顶部应用栏 ---------- */
.app-header {
  position: relative;
  z-index: 30;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.app-header__inner {
  height: var(--header-h);
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand__logo {
  display: flex;
  filter: drop-shadow(0 2px 6px rgba(26, 115, 232, 0.3));
}

.brand__text {
  min-width: 0;
}

.brand__title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.brand__subtitle {
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 状态指示器 */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: 13px;
  color: var(--color-text-soft);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.status-pill:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--color-primary-soft);
}

.status-pill__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
  flex-shrink: 0;
  transition: background var(--transition);
}

.status-pill__dot.is-ok {
  background: var(--color-success);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
  animation: pulse-dot 2s infinite;
}

.status-pill__dot.is-error {
  background: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
}

@keyframes pulse-dot {
  0%,
  100% {
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(22, 163, 74, 0.05);
  }
}

.status-pill__text {
  white-space: nowrap;
}

/* 图标按钮 */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--color-text-soft);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  transition: all var(--transition);
}

.icon-btn:hover {
  color: var(--color-primary);
  border-color: var(--color-primary-soft);
  background: var(--color-primary-light);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn--accent {
  display: none;
}

/* 主题图标显隐 */
.icon-moon {
  display: none;
}
[data-theme="dark"] .icon-sun {
  display: none;
}
[data-theme="dark"] .icon-moon {
  display: block;
}

/* 状态详情条 */
.status-detail {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--color-primary-light);
  border-top: 1px solid var(--color-primary-soft);
  font-size: 12.5px;
  color: var(--color-text-soft);
  animation: slide-down 0.3s ease;
}

@keyframes slide-down {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.status-detail__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-detail__label {
  color: var(--color-text-muted);
}

.status-detail__divider {
  width: 1px;
  height: 14px;
  background: var(--color-primary-soft);
}

/* ---------- 主体布局 ---------- */
.layout {
  flex: 1;
  display: flex;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
  overflow: hidden;
}

/* ---------- 对话区 ---------- */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0 20px;
  height: 100%;
}

.chat__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  padding: 24px 0 12px;
}

/* 自定义滚动条 */
.chat__scroll::-webkit-scrollbar,
.sources__body::-webkit-scrollbar {
  width: 6px;
}

.chat__scroll::-webkit-scrollbar-thumb,
.sources__body::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.chat__scroll::-webkit-scrollbar-thumb:hover,
.sources__body::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary-soft);
}

.chat__messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

/* 欢迎卡片 */
.welcome {
  text-align: center;
  padding: 48px 20px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: fade-up 0.5s ease;
}

.welcome__icon {
  filter: drop-shadow(0 8px 20px rgba(26, 115, 232, 0.35));
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

.welcome__title {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
}

.welcome__desc {
  font-size: 14.5px;
  color: var(--color-text-soft);
  max-width: 460px;
}

.welcome__suggest {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.suggest-chip {
  padding: 8px 16px;
  font-size: 13.5px;
  color: var(--color-primary-dark);
  background: var(--color-surface);
  border: 1px solid var(--color-primary-soft);
  border-radius: var(--radius-full);
  transition: all var(--transition);
}

.suggest-chip:hover {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ---------- 消息气泡 ---------- */
.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fade-up 0.35s ease;
  max-width: 100%;
}

.message--user {
  flex-direction: row-reverse;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
}

.message--user .message__avatar {
  background: var(--bubble-user-bg);
  color: #fff;
}

.message--ai .message__avatar {
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary-soft));
  color: var(--color-primary-dark);
}

.message__content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: calc(100% - 52px);
  min-width: 0;
}

.message--user .message__content {
  align-items: flex-end;
}

.message__bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.message--user .message__bubble {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}

.message--ai .message__bubble {
  background: var(--bubble-ai-bg);
  color: var(--bubble-ai-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 6px;
}

/* AI 回答内容排版 */
.message--ai .message__bubble p {
  margin: 0 0 10px;
}
.message--ai .message__bubble p:last-child {
  margin-bottom: 0;
}
.message--ai .message__bubble code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  background: var(--color-surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}
.message--ai .message__bubble pre {
  background: var(--color-surface-2);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
}
.message--ai .message__bubble pre code {
  background: none;
  padding: 0;
}
.message--ai .message__bubble ul,
.message--ai .message__bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.message__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--color-text-muted);
  padding: 0 4px;
}

.message--user .message__meta {
  flex-direction: row-reverse;
}

.message__meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* 消息内的来源标记 */
.bubble-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--color-border);
}

.bubble-source-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--color-primary-dark);
  background: var(--color-primary-light);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition);
}

.bubble-source-tag:hover {
  background: var(--color-primary);
  color: #fff;
}

/* 错误消息 */
.message--error .message__bubble {
  background: #fef2f2;
  color: var(--color-danger);
  border-color: #fecaca;
}
[data-theme="dark"] .message--error .message__bubble {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.3);
}

/* ---------- 打字指示器 ---------- */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 2px;
}

.typing__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-primary);
  opacity: 0.5;
  animation: typing-bounce 1.3s infinite ease-in-out;
}

.typing__dot:nth-child(2) {
  animation-delay: 0.16s;
}
.typing__dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ---------- 输入区 ---------- */
.composer {
  flex-shrink: 0;
  flex-grow: 0;
  padding: 12px 0 20px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
  position: relative;
  z-index: 10;
}

.composer__wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.composer__wrap:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.12), var(--shadow-md);
}

.composer__input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  padding: 8px 0;
}

.composer__input::placeholder {
  color: var(--color-text-muted);
}

.composer__send {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.composer__send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(26, 115, 232, 0.4);
}

.composer__send:active:not(:disabled) {
  transform: translateY(0);
}

.composer__send:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.composer__send.is-loading {
  background: var(--color-primary-soft);
  pointer-events: none;
}

.composer__send.is-loading svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.composer__hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--color-text-muted);
  margin-top: 8px;
}

/* ---------- 引用来源面板 ---------- */
.sources {
  width: 320px;
  flex-shrink: 0;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sources__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sources__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.sources__title svg {
  color: var(--color-primary);
}

.sources__close {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: all var(--transition);
}

.sources__close:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.sources__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sources__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
  padding: 40px 12px;
  flex: 1;
}

/* 来源卡片 */
.source-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  transition: all var(--transition);
  animation: fade-up 0.3s ease;
  position: relative;
  overflow: hidden;
}

.source-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-primary);
  opacity: 0;
  transition: opacity var(--transition);
}

.source-card:hover {
  border-color: var(--color-primary-soft);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.source-card:hover::before {
  opacity: 1;
}

.source-card__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.source-card__index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.source-card__file {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-text);
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

.source-card__score {
  font-size: 11px;
  color: var(--color-text-muted);
  background: var(--color-surface);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  flex-shrink: 0;
}

.source-card__score.is-high {
  color: var(--color-success);
  border-color: rgba(22, 163, 74, 0.3);
}

.source-card__snippet {
  font-size: 12.5px;
  color: var(--color-text-soft);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-card__snippet mark {
  background: rgba(26, 115, 232, 0.18);
  color: var(--color-primary-dark);
  border-radius: 2px;
  padding: 0 2px;
}

.sources__meta {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  color: var(--color-text-soft);
  background: var(--color-surface-2);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

/* 遮罩层（移动端） */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 18, 32, 0.5);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  transition: opacity var(--transition);
}

.overlay.is-visible {
  opacity: 1;
}

/* ============================================================
   响应式：平板及以下（≤ 768px）
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --header-h: 56px;
  }

  .app-header__inner {
    padding: 0 14px;
  }

  .brand__title {
    font-size: 17px;
  }

  .brand__subtitle {
    display: none;
  }

  .status-pill__text {
    display: none;
  }

  .status-pill {
    padding: 6px;
  }

  .icon-btn--accent {
    display: inline-flex;
  }

  .status-detail {
    padding: 8px 14px;
    font-size: 12.5px;
    gap: 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .status-detail__divider {
    flex-shrink: 0;
  }

  /* 主体单栏布局 */
  .layout {
    flex-direction: column;
  }

  .chat {
    padding: 0 14px;
  }

  .chat__scroll {
    padding: 16px 0 8px;
  }

  .chat__messages {
    gap: 16px;
  }

  .welcome {
    padding: 16px 12px 12px;
  }

  .welcome__title {
    font-size: 21px;
  }

  .welcome__desc {
    font-size: 14px;
    line-height: 1.6;
  }

  .message__avatar {
    width: 32px;
    height: 32px;
  }

  .message__content {
    max-width: calc(100% - 44px);
  }

  .message__bubble {
    font-size: 15px;
    padding: 10px 14px;
  }

  /* 来源面板改为抽屉式 */
  .sources {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 86%;
    max-width: 340px;
    z-index: 50;
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform var(--transition);
  }

  .sources.is-open {
    transform: translateX(0);
  }

  .sources__close {
    display: flex;
  }

  .composer {
    padding: 10px 0 16px;
  }

  .composer__wrap {
    padding: 6px 6px 6px 14px;
  }

  .composer__input {
    font-size: 16px;
  }

  .composer__send {
    width: 44px;
    height: 44px;
  }
}

/* 超小屏 */
@media (max-width: 380px) {
  .welcome__suggest {
    flex-direction: column;
    align-items: stretch;
  }

  .suggest-chip {
    text-align: center;
  }
}

/* 大屏优化 */
@media (min-width: 1200px) {
  .sources {
    width: 340px;
  }
}

/* 无障碍：尊重减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 选中文本颜色 */
::selection {
  background: rgba(26, 115, 232, 0.25);
  color: var(--color-text);
}

/* ============================================================
   录入功能样式
   ============================================================ */

/* 录入按钮（绿色主题） */
.icon-btn--record {
  color: var(--color-success);
  border-color: rgba(22, 163, 74, 0.3);
}

.icon-btn--record:hover {
  color: #fff;
  background: var(--color-success);
  border-color: var(--color-success);
}

/* 录入弹窗容器 */
.record-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
}

.record-modal.is-open {
  opacity: 1;
}

.record-modal[hidden] {
  display: none;
}

.record-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 18, 32, 0.55);
  backdrop-filter: blur(3px);
}

/* 录入弹窗面板 */
.record-modal__panel {
  position: relative;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  transition: transform var(--transition);
}

.record-modal.is-open .record-modal__panel {
  transform: translateY(0) scale(1);
}

/* 弹窗头部 */
.record-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.record-modal__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--color-text);
}

.record-modal__close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: all var(--transition);
}

.record-modal__close:hover {
  background: var(--color-surface-2);
  color: var(--color-danger);
}

/* 标签页切换 */
.record-modal__tabs {
  display: flex;
  gap: 4px;
  padding: 12px 22px 0;
  flex-shrink: 0;
}

.record-tab {
  padding: 8px 16px;
  font-size: 13.5px;
  color: var(--color-text-soft);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}

.record-tab:hover {
  color: var(--color-text);
}

.record-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  font-weight: 600;
}

/* 弹窗主体 */
.record-modal__body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 录入面板（仅激活的显示） */
.record-pane {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.record-pane.active {
  display: flex;
}

/* 文本输入框 */
.record-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.record-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.12);
}

.record-input::placeholder {
  color: var(--color-text-muted);
}

/* 多行文本域 */
.record-textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  resize: vertical;
  min-height: 120px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.record-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.12);
}

.record-textarea::placeholder {
  color: var(--color-text-muted);
}

/* 拖拽上传区 */
.record-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 20px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}

.record-dropzone svg {
  color: var(--color-primary);
  opacity: 0.7;
}

.record-dropzone p {
  font-size: 13.5px;
  color: var(--color-text-soft);
}

.record-dropzone__hint {
  font-size: 11.5px;
  color: var(--color-text-muted);
}

.record-dropzone:hover,
.record-dropzone.is-dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.record-dropzone.is-dragover {
  border-style: solid;
}

/* 文件信息展示 */
.record-file-info {
  padding: 12px 14px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.record-file-info__name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-text);
  word-break: break-all;
}

.record-file-info__meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* 图片预览 */
.record-image-preview {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.record-image-preview img {
  display: block;
  width: 100%;
  max-height: 200px;
  object-fit: cover;
}

/* 弹窗底部 */
.record-modal__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* 状态提示文本 */
.record-status {
  font-size: 12.5px;
  color: var(--color-text-muted);
  flex: 1;
  min-width: 0;
}

.record-status.is-error {
  color: var(--color-danger);
}

/* 录入提交按钮 */
.btn-record-submit {
  padding: 9px 28px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--color-success);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-record-submit:hover:not(:disabled) {
  background: #15803d;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.35);
}

.btn-record-submit:active:not(:disabled) {
  transform: translateY(0);
}

.btn-record-submit:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

/* 深色模式适配 */
[data-theme="dark"] .icon-btn--record {
  border-color: rgba(22, 163, 74, 0.4);
}

[data-theme="dark"] .record-dropzone:hover,
[data-theme="dark"] .record-dropzone.is-dragover {
  background: var(--color-primary-soft);
}

[data-theme="dark"] .btn-record-submit:hover:not(:disabled) {
  background: #22c55e;
}

/* 响应式：移动端 */
@media (max-width: 768px) {
  .record-modal__panel {
    width: 94%;
    max-height: 88vh;
  }

  .record-modal__head {
    padding: 14px 16px;
  }

  .record-modal__tabs {
    padding: 10px 16px 0;
  }

  .record-modal__body {
    padding: 14px 16px;
  }

  .record-modal__foot {
    padding: 12px 16px;
  }

  .record-tab {
    padding: 7px 12px;
    font-size: 13px;
  }
}


/* ============================================================
   移动端布局优化 v3 (2026-08-06)
   基于截图反馈：导航栏减负、间距统一8px网格、触摸区域规范
   ============================================================ */

/* ---------- 安全区域适配 ---------- */
@supports (padding: env(safe-area-inset-top)) {
  .app-header {
    padding-top: env(safe-area-inset-top);
  }
  .composer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .record-modal__foot {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .sources__meta {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* ---------- 移动端导航栏优化 ---------- */
@media (max-width: 768px) {
  :root {
    --header-h: 52px;
  }

  /* 隐藏状态指示器（详情栏已展示状态，避免顶部拥挤） */
  .status-pill {
    display: none;
  }

  /* 导航栏内边距 */
  .app-header__inner {
    padding: 0 12px;
    gap: 8px;
  }

  /* 品牌区域紧凑 */
  .brand {
    gap: 8px;
  }
  .brand__logo svg {
    width: 28px;
    height: 28px;
  }
  .brand__title {
    font-size: 17px;
  }

  /* 操作按钮区域 */
  .app-header__actions {
    gap: 6px;
  }

  /* 所有图标按钮统一44px触摸区域 */
  .app-header__actions .icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    border-radius: 10px;
  }

  /* 图标内SVG缩小以适配 */
  .app-header__actions .icon-btn svg {
    width: 18px;
    height: 18px;
  }

  /* 显示来源面板按钮 */
  .icon-btn--accent {
    display: inline-flex;
  }
}

/* ---------- 状态详情栏优化 ---------- */
@media (max-width: 768px) {
  .status-detail {
    padding: 7px 14px;
    font-size: 12px;
    gap: 10px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .status-detail__item {
    font-size: 12px;
    white-space: nowrap;
  }
  .status-detail__label {
    font-size: 11px;
  }
  .status-detail__divider {
    flex-shrink: 0;
  }
}

/* ---------- 欢迎卡片优化 ---------- */
@media (max-width: 768px) {
  .welcome {
    padding: 16px 12px 12px;
    gap: 10px;
  }
  .welcome__icon {
    margin-bottom: 4px;
  }
  .welcome__icon svg {
    width: 44px;
    height: 44px;
  }
  .welcome__title {
    font-size: 21px;
    line-height: 1.3;
  }
  .welcome__desc {
    font-size: 14px;
    line-height: 1.6;
    max-width: 100%;
    padding: 0 8px;
  }
  .welcome__suggest {
    gap: 8px;
    margin-top: 4px;
  }
  /* 快捷标签：增大触摸区域 */
  .suggest-chip {
    min-height: 38px;
    padding: 8px 16px;
    font-size: 13.5px;
    border-radius: 20px;
  }
}

/* ---------- 对话区优化 ---------- */
@media (max-width: 768px) {
  .chat {
    padding: 0 12px;
  }
  .chat__scroll {
    padding: 12px 0 8px;
  }
  .chat__messages {
    gap: 14px;
  }
  .message {
    gap: 8px;
  }
  .message__avatar {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }
  .message__content {
    max-width: calc(100% - 42px);
    gap: 4px;
  }
  .message__bubble {
    font-size: 15px;
    line-height: 1.65;
    padding: 10px 14px;
    max-width: 85%;
  }
  .message__meta {
    font-size: 11px;
    gap: 6px;
  }
}

/* ---------- 底部输入区优化 ---------- */
@media (max-width: 768px) {
  .composer {
    padding: 8px 0 10px;
  }
  .composer__wrap {
    padding: 6px 6px 6px 14px;
    gap: 6px;
    border-radius: 16px;
  }
  .composer__input {
    font-size: 16px;
    min-height: 44px;
    padding: 10px 0;
    line-height: 1.5;
  }
  .composer__voice {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .composer__voice svg {
    width: 18px;
    height: 18px;
  }
  .composer__send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .composer__send svg {
    width: 20px;
    height: 20px;
  }
  .composer__hint {
    font-size: 11px;
    margin-top: 6px;
    padding: 0 4px;
  }
}

/* ---------- 录入弹窗优化 ---------- */
@media (max-width: 768px) {
  /* 底部弹出 */
  .record-modal {
    align-items: flex-end;
  }
  .record-modal__panel {
    width: 100%;
    max-width: 100%;
    border-radius: 16px 16px 0 0;
    margin: 0;
    max-height: 85vh;
    transform: translateY(100%);
  }
  .record-modal.is-open .record-modal__panel {
    transform: translateY(0);
  }
  .record-modal__head {
    padding: 12px 16px 8px;
  }
  .record-modal__title {
    font-size: 16px;
  }
  .record-modal__close {
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .record-modal__tabs {
    padding: 0 12px;
    gap: 2px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .record-tab {
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .record-modal__body {
    padding: 12px 16px;
  }
  .record-modal__foot {
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }
  /* 输入框16px防iOS缩放 */
  .record-input {
    font-size: 16px;
    min-height: 44px;
    padding: 10px 14px;
  }
  .record-textarea {
    font-size: 16px;
    line-height: 1.5;
  }
  .record-select {
    font-size: 16px;
    min-height: 44px;
  }
  .btn-record-submit {
    min-height: 44px;
    font-size: 15px;
    padding: 10px 28px;
  }
  .voice-record-btn {
    width: 68px;
    height: 68px;
  }
}

/* ---------- 来源面板优化 ---------- */
@media (max-width: 768px) {
  .sources {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 88%;
    max-width: 340px;
    z-index: 50;
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform var(--transition);
  }
  .sources.is-open {
    transform: translateX(0);
  }
  .sources__close {
    display: flex;
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
  }
  .sources__head {
    padding: 12px 16px 8px;
  }
  .sources__body {
    padding: 12px 14px;
  }
  .source-card {
    padding: 12px 14px;
  }
  .source-card__file {
    font-size: 13.5px;
  }
  .source-card__snippet {
    font-size: 13px;
    line-height: 1.55;
  }
}

/* ---------- 交互体验优化 ---------- */
/* 去除点击高亮 */
@supports (-webkit-tap-highlight-color: transparent) {
  * {
    -webkit-tap-highlight-color: transparent;
  }
}

/* 按钮禁止长按选中 */
.icon-btn,
.voice-record-btn,
.suggest-chip,
.record-tab,
.btn-record-submit,
.composer__send,
.composer__voice {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* 移动端hover效果改为active反馈 */
@media (max-width: 768px) {
  .icon-btn:hover,
  .suggest-chip:hover,
  .source-card:hover {
    transform: none;
  }
  .icon-btn:active {
    transform: scale(0.95);
    opacity: 0.85;
  }
  .suggest-chip:active {
    transform: scale(0.96);
  }
  .composer__send:active:not(:disabled) {
    transform: scale(0.95);
  }
}

/* iOS滚动惯性 */
@media (max-width: 768px) {
  .chat__scroll,
  .sources__body,
  .record-modal__body,
  .record-modal__tabs {
    -webkit-overflow-scrolling: touch;
  }
}

/* 全局移动端输入框16px（防iOS缩放） */
@media (max-width: 768px) {
  input[type="text"],
  input[type="search"],
  textarea,
  select {
    font-size: 16px;
  }
}

/* 超小屏适配 */
@media (max-width: 380px) {
  .app-header__actions .icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }
  .app-header__actions {
    gap: 4px;
  }
  .brand__title {
    font-size: 16px;
  }
  .welcome__suggest {
    flex-direction: column;
    align-items: stretch;
  }
  .suggest-chip {
    text-align: center;
  }
}


/* ============================================================
   修复移动端聊天框不可见 (2026-08-06)
   ============================================================ */

/* iOS Safari: 使用dvh确保地址栏不遮挡内容 */
@media (max-width: 768px) {
  html {
    height: 100%;
  }

  body {
    height: 100vh;
    height: 100dvh;
    /* 确保body不滚动，只有chat__scroll区域滚动 */
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  /* 确保header不被压缩 */
  .app-header {
    flex-shrink: 0;
  }

  /* 确保layout填满剩余空间 */
  .layout {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* chat区域填满layout */
  .chat {
    flex: 1;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  /* chat__scroll是唯一滚动区域 */
  .chat__scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* composer固定在底部，不被压缩 */
  .composer {
    flex-shrink: 0;
    flex-grow: 0;
    flex-basis: auto;
    position: relative;
    z-index: 10;
    background: var(--color-bg);
  }

  /* 状态详情栏不占太多空间 */
  .status-detail {
    flex-shrink: 0;
    max-height: 40px;
    overflow: hidden;
  }

  /* 欢迎卡片减少padding避免撑高 */
  .welcome {
    padding: 12px 12px 8px;
  }
  .welcome__icon {
    margin-bottom: 0;
  }
  .welcome__icon svg {
    width: 40px;
    height: 40px;
  }
  .welcome__title {
    font-size: 19px;
    margin-bottom: 0;
  }
  .welcome__desc {
    font-size: 13px;
    margin-bottom: 4px;
  }
  .welcome__suggest {
    margin-top: 2px;
  }
}

/* PWA模式（standalone）下不需要dvh，直接用100vh */
@media all and (display-mode: standalone) {
  body {
    height: 100vh;
  }
}

/* iOS PWA全屏模式 */
@media all and (display-mode: fullscreen) {
  body {
    height: 100vh;
  }
}
