/* SGT AI 精灵 — 首页 AI 对话浮窗 */
.sgt-tutor-fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  z-index: 1000;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(135deg, #006688, #00d4ff);
  color: #fff;
  box-shadow: 0 4px 24px rgba(0, 212, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.sgt-tutor-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 28px rgba(0, 212, 255, 0.45);
}
.sgt-tutor-fab svg { width: 28px; height: 28px; }
.sgt-tutor-fab.open { background: linear-gradient(135deg, #004455, #0088aa); }

.sgt-tutor-panel {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 1000;
  width: min(400px, calc(100vw - 32px));
  max-height: 80vh;
  display: none;
  flex-direction: column;
  background: #14141f;
  border: 1px solid #1e2a4a;
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.sgt-tutor-panel.open { display: flex; }

.sgt-tutor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(0, 71, 146, 0.25);
  border-bottom: 1px solid #1e2a4a;
  flex-shrink: 0;
}
.sgt-tutor-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #00d4ff;
  letter-spacing: 0.02em;
}
.sgt-tutor-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sgt-tutor-icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(0, 212, 255, 0.38);
  background: rgba(0, 71, 146, 0.42);
  color: #c8d8ec;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.sgt-tutor-icon-btn:hover {
  color: #00d4ff;
  border-color: #00d4ff;
  background: rgba(0, 212, 255, 0.14);
}
.sgt-tutor-icon-btn:focus-visible {
  outline: 2px solid #00d4ff;
  outline-offset: 2px;
}
.sgt-tutor-icon-btn svg { width: 16px; height: 16px; }

.sgt-tutor-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 200px;
  max-height: calc(80vh - 140px);
  scroll-behavior: smooth;
}
.sgt-tutor-messages::-webkit-scrollbar { width: 6px; }
.sgt-tutor-messages::-webkit-scrollbar-thumb {
  background: #2a3a5a;
  border-radius: 3px;
}

.sgt-tutor-welcome {
  font-size: 0.88rem;
  line-height: 1.65;
  color: #b0b0c0;
  padding: 12px 14px;
  background: rgba(30, 42, 74, 0.5);
  border-radius: 10px;
  border-left: 3px solid #00d4ff;
}

.sgt-tutor-msg {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  max-width: 92%;
}
.sgt-tutor-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}
.sgt-tutor-msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}
.sgt-tutor-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.86rem;
  line-height: 1.65;
  word-break: break-word;
  overflow-wrap: anywhere;
}
/* 助手回复：仅未渲染时保留 pre-wrap；渲染后由 .sgt-md-rendered 接管 */
.sgt-tutor-msg.user .sgt-tutor-bubble {
  white-space: pre-wrap;
}
.sgt-tutor-msg.assistant .sgt-tutor-bubble.sgt-md-rendered {
  white-space: normal !important;
}
.sgt-tutor-msg.assistant .sgt-tutor-bubble:not(.sgt-md-rendered):not(.streaming) {
  white-space: pre-wrap;
}
.sgt-tutor-msg.assistant .sgt-tutor-bubble {
  max-width: 100%;
  width: 100%;
}
.sgt-tutor-msg.assistant {
  max-width: 100%;
  width: 100%;
}

/* Markdown 渲染（助手气泡内，高优先级 scoped） */
.sgt-tutor-bubble.sgt-md-rendered {
  display: block;
  white-space: normal !important;
}
.sgt-tutor-bubble.sgt-md-rendered p {
  display: block;
  margin: 0 0 0.65em;
  line-height: 1.65;
}
.sgt-tutor-bubble.sgt-md-rendered h1,
.sgt-tutor-bubble.sgt-md-rendered h2,
.sgt-tutor-bubble.sgt-md-rendered h3,
.sgt-tutor-bubble.sgt-md-rendered h4,
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-h1,
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-h2,
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-h3,
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-h4 {
  display: block;
  font-weight: 700;
  line-height: 1.35;
  margin: 0.85em 0 0.45em;
  color: #00d4ff;
}
.sgt-tutor-bubble.sgt-md-rendered h1:first-child,
.sgt-tutor-bubble.sgt-md-rendered h2:first-child,
.sgt-tutor-bubble.sgt-md-rendered h3:first-child { margin-top: 0; }
.sgt-tutor-bubble.sgt-md-rendered ul,
.sgt-tutor-bubble.sgt-md-rendered ol {
  display: block;
  margin: 0.35em 0 0.65em 1.15em;
  padding: 0;
}
.sgt-tutor-bubble.sgt-md-rendered li { display: list-item; margin-bottom: 0.35em; }
.sgt-tutor-bubble.sgt-md-rendered strong { color: #f0f0f8; font-weight: 600; }
.sgt-tutor-bubble.sgt-md-rendered a { color: #6ab8d4; }
.sgt-tutor-bubble.sgt-md-rendered hr {
  border: none;
  border-top: 1px solid #2a3a5a;
  margin: 0.85em 0;
}
.sgt-tutor-bubble.sgt-md-rendered table {
  display: table !important;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
  table-layout: auto;
  margin: 0.65em 0;
}
.sgt-tutor-bubble.sgt-md-rendered thead { display: table-header-group !important; }
.sgt-tutor-bubble.sgt-md-rendered tbody { display: table-row-group !important; }
.sgt-tutor-bubble.sgt-md-rendered tr { display: table-row !important; }
.sgt-tutor-bubble.sgt-md-rendered th,
.sgt-tutor-bubble.sgt-md-rendered td {
  display: table-cell !important;
  border: 1px solid #2a3a5a;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
}
.sgt-tutor-bubble.sgt-md-rendered th {
  background: rgba(0, 212, 255, 0.1);
  color: #00d4ff;
  font-weight: 600;
}
.sgt-tutor-bubble.sgt-md-rendered tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-table-wrap {
  display: block;
  width: 100%;
  overflow-x: auto;
  margin: 0.65em 0;
  -webkit-overflow-scrolling: touch;
}
.sgt-tutor-bubble.sgt-md-rendered pre,
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-pre {
  display: block;
  background: #0a0a12;
  border: 1px solid #2a3a5a;
  border-radius: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  font-size: 0.78rem;
  margin: 0.5em 0;
  white-space: pre-wrap;
}
.sgt-tutor-bubble.sgt-md-rendered code {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.82em;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.sgt-tutor-bubble.sgt-md-rendered strong { color: #f0f0f8; font-weight: 600; }
.sgt-tutor-bubble.sgt-md-rendered em { color: #c8c8d8; }
.sgt-tutor-bubble.sgt-md-rendered a { color: #6ab8d4; text-decoration: underline; }
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-math-block {
  display: block;
  overflow-x: auto;
  margin: 0.5em 0;
  padding: 4px 0;
}
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-math-inline { white-space: normal; }
.sgt-tutor-bubble.sgt-md-rendered .katex { font-size: 1.02em; color: #e8e8f0; }
.sgt-tutor-bubble.sgt-md-rendered .sgt-md-math-fail {
  color: #c9a227;
  font-size: 0.8em;
}
.sgt-tutor-bubble.streaming::after {
  content: '▋';
  display: inline-block;
  color: #00d4ff;
  animation: sgt-tutor-cursor 0.9s step-end infinite;
  margin-left: 2px;
  font-size: 0.85em;
}
.sgt-tutor-bubble.sgt-md-rendered.streaming::after {
  display: inline;
  vertical-align: text-bottom;
}
@keyframes sgt-tutor-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.sgt-tutor-msg.user .sgt-tutor-bubble {
  background: linear-gradient(135deg, #004466, #006688);
  color: #e8f4ff;
  border-bottom-right-radius: 4px;
}
.sgt-tutor-msg.assistant .sgt-tutor-bubble {
  background: #1e2438;
  color: #e8e8f0;
  border: 1px solid #2a3a5a;
  border-bottom-left-radius: 4px;
}
.sgt-tutor-sources {
  margin-top: 6px;
  font-size: 0.72rem;
  color: #666680;
  line-height: 1.5;
  padding-left: 2px;
}
.sgt-tutor-sources a { color: #6a8aaa; }

.sgt-tutor-msg-actions {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  margin-top: 4px;
  padding-left: 2px;
}
.sgt-tutor-copy-raw {
  appearance: none;
  border: 1px solid #3a4a6a;
  background: rgba(30, 36, 56, 0.85);
  color: #9aa8c0;
  font-size: 0.68rem;
  line-height: 1.2;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.sgt-tutor-copy-raw:hover {
  color: #d0d8e8;
  border-color: #5a7a9a;
  background: rgba(40, 50, 78, 0.95);
}
.sgt-tutor-copy-raw.is-copied {
  color: #7fd4a8;
  border-color: #3a8a68;
}
.sgt-tutor-copy-raw:focus-visible {
  outline: 2px solid #00d4ff;
  outline-offset: 2px;
}

.sgt-tutor-typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 16px;
  background: #1e2438;
  border: 1px solid #2a3a5a;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}
.sgt-tutor-typing span {
  width: 7px;
  height: 7px;
  background: #00d4ff;
  border-radius: 50%;
  animation: sgt-tutor-bounce 1.2s ease-in-out infinite;
}
.sgt-tutor-typing span:nth-child(2) { animation-delay: 0.15s; }
.sgt-tutor-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sgt-tutor-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.sgt-tutor-input-wrap {
  flex-shrink: 0;
  padding: 12px 14px;
  border-top: 1px solid #1e2a4a;
  background: rgba(20, 20, 31, 0.95);
}
.sgt-tutor-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.sgt-tutor-input {
  flex: 1;
  min-height: 40px;
  max-height: 100px;
  padding: 10px 12px;
  resize: none;
  border: 1px solid #2a3a5a;
  border-radius: 8px;
  background: #0a0a12;
  color: #e8e8f0;
  font-size: 0.86rem;
  font-family: inherit;
  line-height: 1.45;
}
.sgt-tutor-input:focus {
  outline: none;
  border-color: #00d4ff;
}
.sgt-tutor-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.sgt-tutor-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #0088aa, #00d4ff);
  color: #0a0a0f;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sgt-tutor-send:hover:not(:disabled) { opacity: 0.9; }
.sgt-tutor-send:disabled { opacity: 0.45; cursor: not-allowed; }
.sgt-tutor-send svg { width: 18px; height: 18px; }
.sgt-tutor-hint {
  font-size: 0.68rem;
  color: #555568;
  margin-top: 6px;
  text-align: center;
}
.sgt-tutor-hint a { color: #6ab8d4; text-decoration: underline; }
.sgt-tutor-hint a:hover { color: #00d4ff; }
.sgt-tutor-char-count {
  font-size: 0.65rem;
  color: #666680;
  text-align: right;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.sgt-tutor-char-count.is-near-limit { color: #c9a227; }
.sgt-tutor-char-count.is-at-limit { color: #e07050; font-weight: 600; }
.sgt-tutor-expand {
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sgt-tutor-expand svg { width: 16px; height: 16px; }

.sgt-tutor-err {
  font-size: 0.78rem;
  color: #e07050;
  padding: 8px 12px;
  margin: 0 16px 8px;
  background: rgba(224, 112, 80, 0.1);
  border-radius: 6px;
  display: none;
}
.sgt-tutor-err.visible { display: block; }

@media (max-width: 480px) {
  .sgt-tutor-fab { right: 14px; bottom: 16px; width: 52px; height: 52px; }
  .sgt-tutor-panel {
    right: 8px;
    left: 8px;
    width: auto;
    bottom: 80px;
  }
}
