/* SGT AI 精灵 — 专题页 ai.html（与全站白底学术风格一致） */
.page-ai {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.page-ai .sgt-ai-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  color: #222222;
  padding-top: 52px;
  position: relative;
  z-index: 1;
}

.sgt-ai-page-hero {
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 44px 24px 20px;
  border-bottom: 1px solid #eeeeee;
  background: linear-gradient(180deg, rgba(0, 71, 146, 0.04) 0%, rgba(255, 255, 255, 0) 100%);
}
.sgt-ai-page-hero h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #004792;
  margin: 0 0 8px;
  line-height: 1.45;
  font-family: "Noto Serif SC", "Songti SC", "SimSun", serif;
}
html.lang-en .sgt-ai-page-hero h1 {
  font-family: "Source Serif 4", "Times New Roman", Georgia, serif;
}
.sgt-ai-page-hero p {
  margin: 0;
  font-size: 0.9rem;
  color: #666666;
  max-width: 720px;
  line-height: 1.75;
}

.sgt-ai-layout {
  flex: 1;
  display: flex;
  min-height: 0;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 48px;
  gap: 24px;
}

.sgt-ai-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sgt-ai-sidebar-section {
  background: #fafbfd;
  border: 1px solid rgba(0, 71, 146, 0.12);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 71, 146, 0.04);
}
.sgt-ai-sidebar-head {
  padding: 10px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #666666;
  border-bottom: 1px solid #eeeeee;
  background: rgba(255, 255, 255, 0.8);
}
.sgt-ai-nav-current {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: #222222;
  font-size: 0.86rem;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  font-family: inherit;
}
.sgt-ai-nav-current:hover {
  background: rgba(0, 71, 146, 0.05);
  color: #004792;
}
.sgt-ai-nav-current.is-active {
  background: rgba(0, 71, 146, 0.08);
  border-left-color: #004792;
  color: #004792;
  font-weight: 600;
}

.sgt-ai-archive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 380px;
  overflow-y: auto;
  background: #ffffff;
}
.sgt-ai-archive-empty {
  padding: 16px 14px;
  font-size: 0.82rem;
  color: #888888;
}
.sgt-ai-archive-item {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #eeeeee;
}
.sgt-ai-archive-item:last-child { border-bottom: none; }
.sgt-ai-archive-btn {
  flex: 1;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-left: 3px solid transparent;
  min-width: 0;
  font-family: inherit;
}
.sgt-ai-archive-item.is-active .sgt-ai-archive-btn,
.sgt-ai-archive-btn:hover {
  background: rgba(0, 71, 146, 0.05);
}
.sgt-ai-archive-item.is-active .sgt-ai-archive-btn {
  border-left-color: #004792;
}
.sgt-ai-archive-title {
  display: block;
  font-size: 0.82rem;
  color: #222222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.sgt-ai-archive-item.is-active .sgt-ai-archive-title {
  color: #004792;
  font-weight: 600;
}
.sgt-ai-archive-meta {
  display: block;
  font-size: 0.68rem;
  color: #888888;
}
.sgt-ai-archive-del {
  width: 36px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #aaaaaa;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.sgt-ai-archive-del:hover { color: #c0392b; }

.sgt-ai-privacy {
  padding: 12px 14px;
  font-size: 0.72rem;
  line-height: 1.6;
  color: #666666;
  background: #fafafa;
  border: 1px solid #eeeeee;
  border-radius: 2px;
}
.sgt-ai-privacy strong { color: #444444; }

.sgt-ai-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sgt-ai-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #fafbfd;
  border: 1px solid rgba(0, 71, 146, 0.12);
  border-radius: 2px 2px 0 0;
  border-bottom: none;
}
.sgt-ai-toolbar-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: #004792;
}
.sgt-ai-toolbar-actions { display: flex; gap: 8px; }
.sgt-ai-btn {
  padding: 8px 14px;
  font-size: 0.8rem;
  border-radius: 2px;
  border: 1px solid rgba(0, 71, 146, 0.25);
  background: #ffffff;
  color: #004792;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.sgt-ai-btn:hover {
  background: rgba(0, 71, 146, 0.06);
  border-color: #004792;
}
.sgt-ai-btn-primary {
  background: #004792;
  border-color: #004792;
  color: #ffffff;
}
.sgt-ai-btn-primary:hover {
  background: #003a75;
  color: #ffffff;
}

.sgt-ai-btn-short { display: none; }

#sgt-ai-history-toggle { display: none; }

.sgt-ai-drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(0, 0, 0, 0.35);
  border: none;
  padding: 0;
  cursor: pointer;
}

.sgt-ai-readonly-banner {
  padding: 10px 16px;
  background: #fffbf0;
  border: 1px solid #e8dcc0;
  border-top: none;
  font-size: 0.82rem;
  color: #8a6d1a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.sgt-ai-chat-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 480px;
  max-height: calc(100vh - 300px);
  background: #ffffff;
  border: 1px solid rgba(0, 71, 146, 0.12);
  border-radius: 0 0 2px 2px;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0, 71, 146, 0.05);
}

.sgt-ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
  background: #ffffff;
}
.sgt-ai-scroll-anchor {
  display: none;
}
.sgt-ai-messages .sgt-tutor-msg { max-width: 88%; }
.sgt-ai-messages .sgt-tutor-msg.assistant { max-width: 100%; width: 100%; }

/* 专题页内聊天气泡 — 浅色 */
.page-ai .sgt-ai-messages .sgt-tutor-msg.user .sgt-tutor-bubble {
  background: #004792;
  color: #ffffff;
  border-bottom-right-radius: 4px;
}
.page-ai .sgt-ai-messages .sgt-tutor-msg.assistant .sgt-tutor-bubble {
  background: #fafafa;
  color: #222222;
  border: 1px solid #eeeeee;
  border-bottom-left-radius: 4px;
}
.page-ai .sgt-ai-messages .sgt-tutor-sources {
  color: #666666;
}
.page-ai .sgt-ai-messages .sgt-tutor-sources a { color: #004792; }
.page-ai .sgt-ai-messages .sgt-tutor-typing {
  background: #fafafa;
  border: 1px solid #eeeeee;
}
.page-ai .sgt-ai-messages .sgt-tutor-typing span {
  background: #004792;
}

/* 专题页 Markdown 浅色 */
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered h1,
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered h2,
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered h3,
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered h4 {
  color: #004792;
}
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered strong { color: #222222; }
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered em { color: #444444; }
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered a { color: #004792; }
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered hr {
  border-top-color: #eeeeee;
}
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered th,
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered td {
  border-color: #dddddd;
}
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered th {
  background: rgba(0, 71, 146, 0.06);
  color: #004792;
}
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered tbody tr:nth-child(even) td {
  background: #fafafa;
}
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered pre,
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered .sgt-md-pre {
  background: #f5f5f5;
  border-color: #dddddd;
  color: #222222;
}
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered code {
  background: rgba(0, 71, 146, 0.08);
  color: #222222;
}
.page-ai .sgt-ai-messages .sgt-tutor-bubble.sgt-md-rendered .katex { color: #222222; }
.page-ai .sgt-ai-messages .sgt-tutor-bubble.streaming::after { color: #004792; }

.page-ai .sgt-ai-messages .sgt-tutor-copy-raw {
  border-color: #cccccc;
  background: #ffffff;
  color: #666666;
}
.page-ai .sgt-ai-messages .sgt-tutor-copy-raw:hover {
  color: #004792;
  border-color: #99b8d8;
  background: #f5f9fc;
}
.page-ai .sgt-ai-messages .sgt-tutor-copy-raw.is-copied {
  color: #1a7a4a;
  border-color: #8fd4a8;
}
.page-ai .sgt-ai-messages .sgt-tutor-copy-raw:focus-visible {
  outline-color: #004792;
}

.sgt-ai-page-welcome {
  padding: 20px 18px;
  border-radius: 2px;
  background: rgba(0, 71, 146, 0.04);
  border-left: 3px solid #004792;
  margin-bottom: 8px;
}
.sgt-ai-page-welcome h2 {
  font-size: 1rem;
  color: #004792;
  margin: 0 0 10px;
  font-weight: 700;
}
.sgt-ai-page-welcome p {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.7;
  color: #444444;
}
.sgt-ai-page-welcome strong { color: #004792; font-weight: 600; }

.sgt-ai-input-wrap {
  flex-shrink: 0;
  padding: 14px 16px;
  border-top: 1px solid #eeeeee;
  background: #fafbfd;
}
.sgt-ai-input-wrap.is-hidden { display: none; }

.sgt-ai-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.sgt-ai-input {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 12px 14px;
  resize: none;
  border: 1px solid #dddddd;
  border-radius: 2px;
  background: #ffffff;
  color: #222222;
  font-size: 0.88rem;
  font-family: inherit;
  line-height: 1.5;
}
.sgt-ai-input:focus {
  outline: none;
  border-color: #004792;
  box-shadow: 0 0 0 2px rgba(0, 71, 146, 0.1);
}
.sgt-ai-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 2px;
  background: #004792;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.sgt-ai-send:hover:not(:disabled) { background: #003a75; }
.sgt-ai-send svg { width: 20px; height: 20px; }
.sgt-ai-send:disabled { opacity: 0.45; cursor: not-allowed; }

.sgt-ai-hint {
  margin: 8px 0 0;
  font-size: 0.72rem;
  color: #888888;
  text-align: center;
}
.sgt-ai-char-count {
  margin: 4px 0 0;
  font-size: 0.68rem;
  color: #aaaaaa;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.sgt-ai-char-count.is-near-limit { color: #b8860b; }
.sgt-ai-char-count.is-at-limit { color: #a03020; font-weight: 600; }

.sgt-ai-err {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: #a03020;
  padding: 8px 12px;
  background: #fef5f3;
  border: 1px solid #f0d0c8;
  border-radius: 2px;
  display: none;
}
.sgt-ai-err.visible { display: block; }

@media (max-width: 900px) {
  /* 手机：全屏聊天壳，仅消息区滚动；输入区 fixed + 安全区，避免真机底部被遮挡 */
  body.page-ai {
    overflow: hidden;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100svh;
  }
  body.page-ai .site-footer,
  body.page-ai .sgt-ai-page-hero,
  body.page-ai .sgt-ai-privacy,
  body.page-ai .sgt-ai-readonly-banner { display: none !important; }

  body.page-ai .sgt-ai-page {
    position: fixed;
    top: var(--sgt-ai-header-h, 52px);
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    padding-top: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  body.page-ai .sgt-ai-layout {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
    max-width: none;
    gap: 0;
    position: relative;
  }

  body.page-ai .sgt-ai-main {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
  }

  /* 侧栏 → 右侧抽屉 */
  body.page-ai .sgt-ai-sidebar {
    position: fixed;
    top: var(--sgt-ai-header-h, 52px);
    right: 0;
    bottom: 0;
    bottom: env(safe-area-inset-bottom, 0px);
    width: min(280px, 86vw);
    z-index: 125;
    margin: 0;
    padding: 8px;
    gap: 8px;
    background: #ffffff;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.page-ai.sgt-ai-drawer-open .sgt-ai-sidebar {
    transform: translateX(0);
  }
  body.page-ai.sgt-ai-drawer-open .sgt-ai-drawer-backdrop {
    display: block;
  }

  body.page-ai .sgt-ai-sidebar-head {
    padding: 8px 10px;
    font-size: 0.68rem;
  }
  body.page-ai .sgt-ai-nav-current {
    padding: 10px 12px;
    font-size: 0.8rem;
  }
  body.page-ai .sgt-ai-archive-list {
    max-height: none;
    flex: 1;
  }
  body.page-ai .sgt-ai-archive-btn {
    padding: 8px 10px;
  }
  body.page-ai .sgt-ai-archive-title { font-size: 0.78rem; }

  body.page-ai .sgt-ai-btn-long { display: none !important; }
  body.page-ai .sgt-ai-btn-short { display: inline !important; }
  body.page-ai #sgt-ai-history-toggle { display: inline-block; }

  body.page-ai .sgt-ai-toolbar {
    flex-shrink: 0;
    padding: 6px 10px;
    gap: 8px;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }
  body.page-ai .sgt-ai-toolbar-title {
    font-size: 0.78rem;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  body.page-ai .sgt-ai-toolbar-actions {
    flex-shrink: 0;
    gap: 6px;
  }
  body.page-ai .sgt-ai-btn {
    padding: 5px 9px;
    font-size: 0.72rem;
    white-space: nowrap;
  }
  body.page-ai .sgt-ai-btn-primary {
    padding: 5px 10px;
  }

  body.page-ai .sgt-ai-err {
    flex-shrink: 0;
    margin: 0;
    border-radius: 0;
  }

  body.page-ai .sgt-ai-chat-box {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: none;
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }

  body.page-ai .sgt-ai-messages {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-padding-bottom: 12px;
    padding: 12px 12px 0;
  }

  /* 底部占位：高度随 fixed 输入栏动态变化，避免末条消息/复制按钮被遮挡 */
  body.page-ai .sgt-ai-scroll-anchor {
    display: block;
    width: 100%;
    flex-shrink: 0;
    height: calc(var(--sgt-ai-input-h, 112px) + 20px);
    pointer-events: none;
  }

  /* 真机底部：fixed + safe-area，避免被 Home 条 / 浏览器栏遮挡 */
  body.page-ai .sgt-ai-input-wrap:not(.is-hidden) {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 110;
    flex-shrink: 0;
    padding: 8px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(0, 71, 146, 0.14);
    background: rgba(250, 251, 253, 0.98);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  body.page-ai .sgt-ai-input {
    min-height: 40px;
    padding: 10px 12px;
    font-size: 16px;
  }
  body.page-ai .sgt-ai-send {
    width: 40px;
    height: 40px;
  }
  body.page-ai .sgt-ai-char-count {
    margin: 2px 0 0;
    font-size: 0.62rem;
  }

  body.page-ai .sgt-ai-chat-box:has(.sgt-ai-input-wrap.is-hidden) .sgt-ai-messages {
    padding-bottom: 12px;
  }
}

@media (max-width: 520px) {
  body.page-ai .sgt-ai-toolbar { padding: 5px 8px; }
  body.page-ai .sgt-ai-messages { padding: 10px 10px 0; }
}
