:root {
  --bg: #f7f8f5;
  --ink: #152d35;
  --muted: #65737a;
  --line: #dce2df;
  --panel: #ffffff;
  --good: #0e7c66;
  --bad: #b84a3a;
  --accent: #d98a1a;
}

.ai-trigger {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #e0f7f7 0%, #b2ebeb 100%);
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(74, 158, 158, 0.3), 0 2px 8px rgba(21, 45, 53, 0.12);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}

.ai-trigger::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid rgba(74, 158, 158, 0.2);
  animation: aiPulse 2.4s ease-in-out infinite;
  pointer-events: none;
}

.ai-trigger:hover {
  transform: translateY(-4px) scale(1.08);
  box-shadow: 0 14px 36px rgba(74, 158, 158, 0.4), 0 4px 14px rgba(21, 45, 53, 0.18);
}

.ai-trigger:active {
  transform: translateY(-1px) scale(0.96);
}

.ai-elephant {
  width: 52px;
  height: 52px;
  transition: transform 0.3s ease;
}

.ai-trigger:hover .ai-elephant {
  transform: rotate(-6deg) scale(1.05);
}

.ai-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 440px;
  max-width: 100vw;
  height: 100vh;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(21, 45, 53, 0.14);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-drawer.open {
  transform: translateX(0);
}

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff 80%, rgba(14,124,102,0.02));
  gap: 8px;
  flex-wrap: wrap;
}

.ai-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: radial-gradient(circle at 50% 50%, rgba(244, 238, 207, 0.28), rgba(14, 124, 102, 0.06));
  overflow: hidden;
}

.ai-avatar-ring {
  position: absolute;
  inset: 4px;
  border-radius: 999px;
  border: 1px solid rgba(14, 124, 102, 0.16);
}

.ai-avatar-ring-1 {
  animation: aiSpin 10s linear infinite;
}

.ai-avatar-ring-2 {
  inset: 9px;
  border-color: rgba(21, 45, 53, 0.18);
  animation: aiSpinReverse 12s linear infinite;
}

.ai-avatar-core {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #f4eecf, #e7d99f);
  box-shadow: 0 0 0 6px rgba(14, 124, 102, 0.08);
}

.ai-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.ai-identity-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.ai-mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
}

.ai-mode-switch button {
  padding: 6px 10px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.ai-mode-switch button.active {
  background: var(--good);
  color: #fff;
}

.ai-llm-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.ai-llm-toggle input {
  margin: 0;
}

.ai-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.ai-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.ai-hint {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(14,124,102,0.12);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(14, 124, 102, 0.06), rgba(255, 255, 255, 0.95));
  color: var(--ink);
  font-size: 12px;
  line-height: 1.7;
}

.ai-hint strong {
  display: block;
  margin-bottom: 3px;
  color: var(--good);
}

.ai-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.ai-quick button {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}

.ai-quick button:hover {
  border-color: var(--good);
}

.ai-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-msg {
  max-width: 92%;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.7;
  animation: aiMsgIn 0.2s ease;
}

.ai-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #152d35 0%, #1e3f4a 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(21,45,53,0.04);
}

.ai-msg.bot .ai-section {
  margin: 6px 0;
}

.ai-msg.bot .ai-section strong {
  display: block;
  color: var(--good);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.ai-msg.bot .ai-section--secondary {
  color: rgba(226,232,240,0.85);
}
.ai-msg.bot .ai-section--secondary strong {
  color: rgba(226,232,240,0.9);
}

.ai-msg.bot .ai-section--muted {
  color: rgba(148,163,184,0.85);
}
.ai-msg.bot .ai-section--muted strong {
  color: rgba(148,163,184,0.85);
}

.ai-msg.bot .ai-section--meta {
  color: rgba(148,163,184,0.7);
  font-size: 11px;
}
.ai-msg.bot .ai-section--meta strong {
  color: rgba(148,163,184,0.75);
}

.ai-support-note {
  margin-top: 8px;
  padding: 7px 9px;
  border: 1px solid rgba(217,138,26,0.22);
  border-radius: 6px;
  background: rgba(217,138,26,0.06);
  color: #8a5a12;
  font-size: 12px;
  line-height: 1.45;
}

.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ai-actions a {
  display: inline-flex;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--good);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.ai-actions a:hover {
  background: rgba(14, 124, 102, 0.08);
}

.ai-task-card {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(14, 124, 102, 0.16);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(14, 124, 102, 0.04), rgba(255, 255, 255, 0.96));
}

.ai-task-title {
  margin-bottom: 8px;
  color: var(--good);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ai-task-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0;
  font-size: 12px;
}

.ai-task-row span {
  color: var(--muted);
}

.ai-task-row b {
  color: var(--ink);
  text-align: right;
}

.ai-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ai-followups button {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.ai-followups button:hover {
  border-color: var(--good);
  color: var(--good);
}

.ai-feedback-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(220, 226, 223, 0.86);
  color: var(--muted);
  font-size: 12px;
}

.ai-feedback-bar button {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.ai-feedback-bar button:hover {
  border-color: var(--good);
  color: var(--good);
}

.ai-feedback-bar em {
  color: var(--good);
  font-style: normal;
  font-weight: 700;
}

.ai-input-area {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(14,124,102,0.02), #fff);
}

.ai-input-area input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid rgba(14,124,102,0.2);
  border-radius: 10px;
  font-size: 14px;
  transition: border-color 0.15s;
}

.ai-input-area input:focus {
  outline: none;
  border-color: var(--good);
  box-shadow: 0 0 0 3px rgba(14,124,102,0.06);
}

.ai-input-area button {
  width: auto;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
}

.ai-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(21, 45, 53, 0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.ai-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

@keyframes aiPulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.18); opacity: 0.15; }
}

@keyframes aiSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes aiSpinReverse {
  from { transform: rotate(360deg); }
  to { transform: rotate(0deg); }
}

.ask-ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid rgba(14, 124, 102, 0.25);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(14, 124, 102, 0.06), rgba(14, 124, 102, 0.02));
  color: var(--good);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.ask-ai-chip:hover {
  border-color: var(--good);
  background: linear-gradient(180deg, rgba(14, 124, 102, 0.12), rgba(14, 124, 102, 0.04));
  box-shadow: 0 2px 8px rgba(14, 124, 102, 0.12);
  transform: translateY(-1px);
}

.ask-ai-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f4eecf, #e7d99f);
  box-shadow: 0 0 0 2px rgba(244, 238, 207, 0.25);
}

@media (max-width: 860px) {
  .ai-drawer {
    width: 100vw;
  }
  .ai-quick {
    grid-template-columns: 1fr;
  }
}

@keyframes aiMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── 会话上下文指示器 ── */
.ai-session-ctx {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(14,124,102,0.06);
  border: 1px solid rgba(14,124,102,0.12);
  color: var(--good);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 10px;
}

.ai-session-ctx .ctx-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--good);
}

/* ── 思考中指示器 ── */
.ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(14,124,102,0.06), rgba(14,124,102,0.02));
  border: 1px solid rgba(14,124,102,0.08);
}

.ai-typing-label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.3px;
  animation: aiShimmer 2s ease-in-out infinite;
}

@keyframes aiShimmer {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.ai-typing-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--good);
  opacity: 0.3;
  animation: aiDotBounce 1.4s ease-in-out infinite;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.35s; }
.ai-typing-dot:nth-child(4) { animation-delay: 0.55s; }

@keyframes aiDotBounce {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.7); }
  40% { opacity: 1; transform: scale(1.3); }
}

/* ── 数据来源标注 ── */
.ai-source-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  margin-top: 6px;
}
.ai-source-badge.local {
  background: rgba(14,124,102,0.08);
  color: var(--good);
}
.ai-source-badge.llm {
  background: rgba(217,138,26,0.08);
  color: #8a5a12;
}
.ai-source-badge.rule {
  background: #f1f5f9;
  color: var(--muted);
}
