/* ==========================================================================
   AI 对话助手
   ========================================================================== */

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  gap: 12px;
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 4px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 130, 155, 0.28) transparent;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.chat-scroll::-webkit-scrollbar {
  width: 10px;
}
.chat-scroll::-webkit-scrollbar-thumb {
  background: rgba(120, 130, 155, 0.24);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 99px;
}

/* ---------- 欢迎页 ---------- */

.chat-welcome {
  margin: auto;
  text-align: center;
  max-width: 620px;
  padding: 20px;
  animation: view-in 0.5s var(--ease-out);
}
.welcome-logo {
  width: 68px;
  height: 68px;
  border-radius: 22px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 16px 40px rgba(94, 92, 230, 0.32);
  animation: float-soft 4s ease-in-out infinite;
}
@keyframes float-soft {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}
.chat-welcome h2 {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 720;
  letter-spacing: -0.03em;
}
.chat-welcome > p {
  margin: 0 0 26px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink-3);
}
.welcome-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  text-align: left;
}
.welcome-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-inner);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: transform 0.2s var(--ease), box-shadow 0.2s, background 0.2s;
}
.welcome-card:hover {
  transform: translateY(-2px);
  background: var(--glass-strong);
  box-shadow: var(--glass-shadow-lg), var(--glass-inner);
}
.welcome-card:active {
  transform: scale(0.98);
}
.welcome-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  flex: none;
}

/* ---------- 消息行 ---------- */

.chat-row {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  animation: view-in 0.3s var(--ease-out);
}
.chat-row.user {
  flex-direction: row;
  justify-content: flex-end;
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  font-size: 12px;
  font-weight: 700;
  margin-top: 2px;
}
.chat-avatar.ai {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 4px 14px rgba(94, 92, 230, 0.3);
}
.chat-avatar.me {
  background: rgba(120, 130, 155, 0.18);
  color: var(--ink-2);
}

.chat-bubble-wrap {
  min-width: 0;
  max-width: min(760px, calc(100% - 44px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-row.user .chat-bubble-wrap {
  align-items: flex-end;
}

.chat-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.68;
  word-break: break-word;
}
.chat-bubble.user {
  background: var(--accent-grad);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 20px rgba(10, 132, 255, 0.26);
  white-space: pre-wrap;
}
.chat-bubble.assistant {
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-inner);
  border-bottom-left-radius: 6px;
  color: var(--ink);
}
.chat-bubble.thinking {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-3);
  font-size: 13px;
}

/* markdown */
.chat-bubble p {
  margin: 0 0 9px;
}
.chat-bubble p:last-child {
  margin-bottom: 0;
}
.chat-bubble h3 {
  margin: 14px 0 8px;
  font-size: 15.5px;
  font-weight: 680;
  letter-spacing: -0.01em;
}
.chat-bubble h4 {
  margin: 12px 0 6px;
  font-size: 14px;
  font-weight: 660;
}
.chat-bubble h3:first-child,
.chat-bubble h4:first-child {
  margin-top: 0;
}
.chat-bubble ul,
.chat-bubble ol {
  margin: 6px 0 10px;
  padding-left: 20px;
}
.chat-bubble li {
  margin: 3px 0;
}
/* 连续 li 之间不要多余空行 */
.chat-bubble li > p {
  margin: 0;
}
.chat-bubble li + li {
  margin-top: 5px;
}
.chat-bubble strong {
  font-weight: 680;
  color: var(--ink);
}
.chat-bubble em {
  font-style: normal;
  color: var(--ink-3);
  font-size: 12.5px;
}
.md-inline {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(120, 130, 155, 0.16);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
}
.md-code {
  margin: 8px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(20, 28, 44, 0.06);
  border: 1px solid var(--glass-border-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}
:root[data-theme='dark'] .md-code {
  background: rgba(255, 255, 255, 0.06);
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}
.md-table th {
  text-align: left;
  padding: 7px 10px;
  font-weight: 650;
  font-size: 12px;
  color: var(--ink-3);
  border-bottom: 1px solid var(--glass-border-soft);
  white-space: nowrap;
}
.md-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--glass-border-soft);
  color: var(--ink-2);
}
.md-table tr:last-child td {
  border-bottom: none;
}

.md-quote {
  margin: 8px 0;
  padding: 9px 13px;
  border-left: 3px solid rgba(10, 132, 255, 0.42);
  border-radius: 0 8px 8px 0;
  background: rgba(10, 132, 255, 0.06);
  color: var(--ink-2);
  line-height: 1.65;
}

/* ---------- 工具调用 chip ---------- */

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(94, 92, 230, 0.1);
  border: 1px solid rgba(94, 92, 230, 0.18);
  color: var(--accent-2);
  font-size: 11.5px;
  font-weight: 600;
}
:root[data-theme='dark'] .tool-chip {
  color: #a5a3ff;
}

/* ---------- 草稿卡片 ---------- */

.draft-stack {
  margin-top: 4px;
  padding: 14px;
  border-radius: var(--r-lg);
  background: var(--glass-soft);
  border: 1px solid var(--glass-border-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.draft-stack-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 660;
  color: var(--accent-2);
}
.draft-stack-head svg {
  width: 14px;
  height: 14px;
}

.draft-card {
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--glass-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  transition: opacity 0.2s;
}
.draft-card.sent {
  opacity: 0.66;
  border-color: rgba(48, 209, 88, 0.34);
  background: rgba(48, 209, 88, 0.06);
}
.draft-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.draft-player {
  font-size: 12.5px;
  font-weight: 620;
  color: var(--ink-2);
}
.draft-quote {
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(120, 130, 155, 0.1);
  border-left: 3px solid rgba(120, 130, 155, 0.32);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-2);
  margin-bottom: 9px;
  white-space: pre-wrap;
  word-break: break-word;
}
.draft-input {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.66);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
  resize: vertical;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
:root[data-theme='dark'] .draft-input {
  background: rgba(20, 28, 44, 0.6);
}
.draft-input:focus {
  border-color: rgba(10, 132, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.12);
}
.draft-input:disabled {
  opacity: 0.7;
}
.draft-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.draft-counter {
  font-size: 11.5px;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}

/* ---------- 输入区 ---------- */

.chat-composer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-quick {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.chat-quick::-webkit-scrollbar {
  display: none;
}
.quick-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 12px;
  font-weight: 560;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s var(--ease), color 0.2s;
  flex: none;
}
.quick-chip:hover {
  background: var(--glass-strong);
  color: var(--ink);
}
.quick-chip:active {
  transform: scale(0.96);
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 8px 8px 8px 16px;
  border-radius: var(--r-lg);
  background: var(--glass-strong);
  backdrop-filter: blur(var(--blur-lg)) saturate(190%);
  -webkit-backdrop-filter: blur(var(--blur-lg)) saturate(190%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-inner);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer-box:focus-within {
  border-color: rgba(10, 132, 255, 0.42);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.1), var(--glass-shadow);
}

.chat-input {
  flex: 1;
  min-height: 26px;
  max-height: 160px;
  padding: 5px 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
  resize: none;
  outline: none;
}
.chat-input::placeholder {
  color: var(--ink-4);
}

.chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  display: grid;
  place-items: center;
  background: var(--accent-grad);
  color: #fff;
  cursor: pointer;
  flex: none;
  box-shadow: 0 4px 14px rgba(10, 132, 255, 0.32);
  transition: transform 0.16s var(--ease), filter 0.2s, opacity 0.2s;
}
.chat-send:hover {
  filter: brightness(1.1);
}
.chat-send:active {
  transform: scale(0.9);
}
.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
}


/* ---------- 学习提示 ---------- */

.learn-banner {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: rgba(48, 209, 88, 0.1);
  border: 1px solid rgba(48, 209, 88, 0.26);
  animation: view-in 0.3s var(--ease-out);
}
.learn-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: rgba(48, 209, 88, 0.18);
  color: #1a9c43;
  flex: none;
}
:root[data-theme='dark'] .learn-icon {
  color: #59e07f;
}
.learn-title {
  font-size: 13.5px;
  font-weight: 660;
  color: var(--ink);
}
.learn-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
  line-height: 1.5;
}

/* ---------- 向你提问 ---------- */

.ask-stack {
  padding: 14px;
  border-radius: var(--r-lg);
  background: rgba(255, 159, 10, 0.08);
  border: 1px solid rgba(255, 159, 10, 0.28);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: view-in 0.3s var(--ease-out);
}
.ask-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 680;
  color: #b87400;
}
:root[data-theme='dark'] .ask-head {
  color: #ffbd54;
}
.ask-head svg {
  width: 15px;
  height: 15px;
}
.ask-sub {
  margin-top: -6px;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.5;
}
.ask-card {
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--glass-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
}
.ask-q {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 6px;
}
.ask-ctx {
  font-size: 12px;
  color: var(--ink-4);
  line-height: 1.5;
  margin-bottom: 9px;
  padding-left: 9px;
  border-left: 2px solid rgba(120, 130, 155, 0.28);
}
.ask-input {
  width: 100%;
  min-height: 54px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.66);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
  resize: vertical;
  outline: none;
}
:root[data-theme='dark'] .ask-input {
  background: rgba(20, 28, 44, 0.6);
}
.ask-input:focus {
  border-color: rgba(255, 159, 10, 0.55);
  box-shadow: 0 0 0 3px rgba(255, 159, 10, 0.12);
}
.ask-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 9px;
}


/* ---------- 待学习提示条 ---------- */

.pending-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: var(--r-md);
  background: rgba(255, 159, 10, 0.1);
  border: 1px solid rgba(255, 159, 10, 0.3);
  font-size: 13px;
  color: var(--ink-2);
  animation: view-in 0.3s var(--ease-out);
}
.pending-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  flex: none;
  box-shadow: 0 0 0 3px rgba(255, 159, 10, 0.2);
  animation: pulse-dot 1.8s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.86); }
}
.pending-bar b {
  color: var(--ink);
  font-weight: 700;
}
.ask-item {
  margin-bottom: 8px;
}

.draft-card.duplicated {
  border-color: rgba(255, 159, 10, 0.42);
  background: rgba(255, 159, 10, 0.05);
}
.dup-warn {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 8px;
  padding: 8px 11px;
  border-radius: 9px;
  background: rgba(255, 159, 10, 0.12);
  border: 1px solid rgba(255, 159, 10, 0.28);
  color: #b87400;
  font-size: 12px;
  line-height: 1.5;
}
:root[data-theme='dark'] .dup-warn {
  color: #ffbd54;
}
.dup-warn svg {
  width: 13px;
  height: 13px;
  flex: none;
  margin-top: 1px;
}
/* ---------- 移动端 ---------- */

@media (max-width: 860px) {
  .chat-shell {
    gap: 8px;
  }
  .chat-scroll {
    gap: 14px;
    padding: 2px 0 6px;
  }

  /* 欢迎页收紧，避免一屏塞不下 */
  .chat-welcome {
    padding: 8px 4px;
  }
  .welcome-logo {
    width: 52px;
    height: 52px;
    border-radius: 17px;
    margin-bottom: 14px;
  }
  .welcome-logo svg {
    width: 24px;
    height: 24px;
  }
  .chat-welcome h2 {
    font-size: 19px;
    margin-bottom: 8px;
  }
  .chat-welcome > p {
    font-size: 13px;
    margin-bottom: 18px;
    line-height: 1.6;
  }
  .welcome-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .welcome-card {
    padding: 11px 13px;
    font-size: 12.8px;
    border-radius: var(--r-sm);
  }
  .welcome-icon {
    width: 26px;
    height: 26px;
    border-radius: 8px;
  }

  .chat-bubble {
    font-size: 14px;
    padding: 11px 14px;
    border-radius: 16px;
  }
  .chat-bubble-wrap {
    max-width: calc(100% - 38px);
  }
  .chat-avatar {
    width: 28px;
    height: 28px;
  }

  /* 输入区：贴底 + 安全区 */
  .chat-composer {
    gap: 6px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .composer-box {
    padding: 6px 6px 6px 13px;
    border-radius: var(--r-md);
  }
  .chat-input {
    font-size: 16px;
    max-height: 110px;
  }
  .chat-send {
    width: 40px;
    height: 40px;
    flex: none;
  }
  .chat-foot {
    padding: 0 2px;
  }
  .chat-foot .tiny {
    display: none;
  }
  .chat-foot .btn {
    height: 30px;
    font-size: 12px;
    padding: 0 10px;
  }

  .chat-quick {
    gap: 6px;
  }
  .quick-chip {
    height: 32px;
    font-size: 12px;
  }

  /* 草稿卡片 */
  .draft-stack {
    padding: 10px;
    gap: 8px;
  }
  .draft-stack-head {
    font-size: 12px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .draft-stack-head .btn {
    width: 100%;
    justify-content: center;
  }
  .draft-card {
    padding: 10px 12px;
  }
  .draft-quote {
    font-size: 12.5px;
    padding: 7px 10px;
  }
  .draft-input {
    font-size: 16px;
    min-height: 92px;
    line-height: 1.6;
  }
  .draft-actions {
    gap: 6px;
    flex-wrap: wrap;
  }
  .draft-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
  .draft-counter {
    width: 100%;
    text-align: right;
    order: -1;
  }

  /* 待学习卡片 */
  .ask-stack {
    padding: 10px;
  }
  .ask-card {
    padding: 10px 12px;
  }
  .ask-input {
    font-size: 16px;
    min-height: 64px;
  }
  .ask-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* markdown 表格在窄屏可横向滚动，不撑破布局 */
  .chat-bubble table,
  .md-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 12.5px;
    white-space: nowrap;
  }
  .md-table th,
  .md-table td {
    padding: 6px 8px;
  }
  .chat-bubble pre,
  .md-code {
    font-size: 11.5px;
    overflow-x: auto;
  }
  .chat-bubble h3 {
    font-size: 14.5px;
  }
  .chat-bubble h4 {
    font-size: 13.5px;
  }
  .chat-bubble ul,
  .chat-bubble ol {
    padding-left: 18px;
  }
}

/* 超窄屏 */
@media (max-width: 400px) {
  .chat-welcome h2 {
    font-size: 18px;
  }
  .chat-welcome > p {
    font-size: 12.5px;
  }
  .welcome-card {
    font-size: 12.2px;
    padding: 10px 12px;
  }
  .chat-bubble {
    font-size: 13.5px;
  }
  .draft-meta {
    gap: 5px;
  }
}
