.aibot-widget-root {
  --aibot-primary: #0f766e;
  --aibot-primary-soft: color-mix(in srgb, var(--aibot-primary) 14%, transparent);
  --aibot-primary-mid: color-mix(in srgb, var(--aibot-primary) 28%, transparent);
  --aibot-bg: #fafbfc;
  --aibot-surface: #ffffff;
  --aibot-text: #132033;
  --aibot-muted: #6b7a90;
  --aibot-border: rgba(19, 32, 51, 0.08);
  --aibot-shadow: 0 24px 64px rgba(19, 32, 51, 0.16);
  --aibot-pos-right: 18px;
  --aibot-pos-bottom: 18px;
  --aibot-panel-width: 400px;
  --aibot-panel-height: 640px;
  --aibot-radius: 20px;
  position: fixed;
  z-index: 2147483000;
  right: var(--aibot-pos-right);
  bottom: var(--aibot-pos-bottom);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--aibot-text);
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
}

.aibot-widget-root *,
.aibot-widget-root *::before,
.aibot-widget-root *::after {
  box-sizing: border-box;
}

/* ── FAB ─────────────────────────────────────────── */
.aibot-widget-fab {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: none;
  cursor: pointer;
  background: var(--aibot-primary);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--aibot-primary) 38%, transparent);
  color: #fff;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.22s ease,
    border-radius 0.22s ease;
}

.aibot-widget-fab:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 14px 34px color-mix(in srgb, var(--aibot-primary) 45%, transparent);
}

.aibot-widget-fab:active {
  transform: translateY(0) scale(0.97);
}

.aibot-widget--open .aibot-widget-fab {
  border-radius: 50%;
}

.aibot-widget-fab-icon {
  width: 26px;
  height: 26px;
  display: block;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  background-image: url("../images/aibot-icon.svg");
  transition: opacity 0.18s ease, transform 0.22s ease;
}

.aibot-widget-fab:hover .aibot-widget-fab-icon {
  background-image: url("../images/aibot-icon-hover.svg");
  transform: scale(1.06);
}

.aibot-widget-fab-close {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: rotate(-45deg) scale(0.6);
  transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.aibot-widget-fab-close svg {
  width: 22px;
  height: 22px;
  stroke: #fff;
  stroke-width: 2.4;
  fill: none;
  stroke-linecap: round;
}

.aibot-widget--open .aibot-widget-fab-icon {
  opacity: 0;
  transform: rotate(45deg) scale(0.6);
}

.aibot-widget--open .aibot-widget-fab-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* ── Panel ───────────────────────────────────────── */
.aibot-widget-panel {
  width: var(--aibot-panel-width);
  height: var(--aibot-panel-height);
  max-width: calc(100vw - 32px);
  /* 预留 FAB + posBottom + 顶部安全区，避免矮屏/横屏把头裁掉 */
  max-height: calc(
    100svh
    - var(--aibot-pos-bottom)
    - 74px
    - env(safe-area-inset-top, 0px)
    - 8px
  );
  border-radius: var(--aibot-radius);
  background: var(--aibot-surface);
  box-shadow: var(--aibot-shadow);
  border: 1px solid var(--aibot-border);
  overflow: hidden;
  position: absolute;
  right: 0;
  bottom: 74px;
  transform: translateY(12px) scale(0.96);
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease,
    transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0.22s;
  display: flex;
  flex-direction: column;
}

.aibot-widget--open .aibot-widget-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.22s ease,
    transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0s;
}

/* ── Header ──────────────────────────────────────── */
.aibot-widget-header {
  padding: 14px 14px 14px 16px;
  background: #ffffff;
  border-bottom: 1px solid var(--aibot-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}

.aibot-widget-header-left {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.aibot-widget-avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: var(--aibot-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  flex: 0 0 auto;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--aibot-primary) 30%, transparent);
}

.aibot-widget-titlewrap {
  min-width: 0;
}

.aibot-widget-title {
  font-weight: 700;
  color: var(--aibot-text);
  font-size: 15px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.aibot-widget-subtitle {
  font-size: 12px;
  color: var(--aibot-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.aibot-widget-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
  flex: 0 0 auto;
}

.aibot-widget-header-right {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 0 0 auto;
}

.aibot-widget-iconbtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--aibot-border);
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  color: var(--aibot-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.aibot-widget-iconbtn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.aibot-widget-iconbtn:hover {
  color: var(--aibot-text);
  background: #fff;
  border-color: color-mix(in srgb, var(--aibot-text) 16%, transparent);
}

.aibot-widget-clear:hover {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.06);
}

.aibot-widget-close {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.06);
}

.aibot-widget-close:hover {
  color: #fff;
  border-color: #dc2626;
  background: #dc2626;
}

/* ── Messages ────────────────────────────────────── */
.aibot-widget-messages {
  flex: 1;
  padding: 16px 14px 10px;
  overflow: auto;
  background: var(--aibot-bg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.aibot-widget-bubble {
  max-width: 88%;
  width: fit-content;
  padding: 10px 14px;
  border-radius: 16px;
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.55;
  animation: aibot-msg-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes aibot-msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.aibot-widget-bubble--user {
  align-self: flex-end;
  background: var(--aibot-primary);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--aibot-primary) 28%, transparent);
}

.aibot-widget-bubble--assistant {
  align-self: flex-start;
  background: var(--aibot-surface);
  color: var(--aibot-text);
  border: 1px solid var(--aibot-border);
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 8px rgba(19, 32, 51, 0.04);
}

.aibot-widget-bubble--assistant .aibot-widget-bubble-text {
  white-space: normal;
}

.aibot-widget-bubble--assistant a {
  color: var(--aibot-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.aibot-widget-bubble--assistant ul {
  margin: 6px 0;
  padding-left: 18px;
}

.aibot-widget-bubble--assistant li {
  margin: 3px 0;
}

.aibot-widget-bubble--assistant code {
  background: rgba(19, 32, 51, 0.06);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.aibot-widget-bubble--assistant strong {
  font-weight: 700;
}

.aibot-widget-bubble--assistant br {
  display: block;
  content: "";
  margin: 4px 0;
}

.aibot-widget-bubble--system {
  align-self: stretch;
  max-width: 100%;
  width: auto;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--aibot-text);
  font-size: 14px;
  line-height: 1.6;
  padding: 4px 2px 10px;
  margin: 0;
  animation: none;
}

/* ── Composer ────────────────────────────────────── */
.aibot-widget-composer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--aibot-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--aibot-surface);
  flex: 0 0 auto;
}

.aibot-widget-input {
  flex: 1;
  border-radius: 14px;
  border: 1px solid var(--aibot-border);
  padding: 10px 14px;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  min-height: 42px;
  max-height: 120px;
  resize: none;
  background: #f3f6f8;
  color: var(--aibot-text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.aibot-widget-input::placeholder {
  color: #94a3b8;
}

.aibot-widget-input:focus {
  border-color: color-mix(in srgb, var(--aibot-primary) 50%, transparent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--aibot-primary-soft);
}

.aibot-widget-send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 14px;
  padding: 0;
  background: var(--aibot-primary);
  color: #fff;
  cursor: pointer;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 14px color-mix(in srgb, var(--aibot-primary) 30%, transparent);
}

.aibot-widget-send svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.aibot-widget-send:hover:not(:disabled) {
  transform: translateY(-1px);
}

.aibot-widget-send:active:not(:disabled) {
  transform: scale(0.96);
}

.aibot-widget-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

.aibot-widget-input:disabled {
  opacity: 0.75;
}

/* ── Loading ─────────────────────────────────────── */
.aibot-widget-loading {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  height: 20px;
  padding: 2px 2px;
}

.aibot-widget-loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--aibot-muted);
  animation: aibot-bounce 0.95s ease-in-out infinite;
}

.aibot-widget-loading-dot:nth-child(2) {
  animation-delay: 0.14s;
}

.aibot-widget-loading-dot:nth-child(3) {
  animation-delay: 0.28s;
}

.aibot-widget-thinking {
  margin-left: 8px;
  font-size: 12px;
  color: var(--aibot-muted);
  vertical-align: middle;
}

@keyframes aibot-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ── Suggestions ─────────────────────────────────── */
.aibot-widget-suggestions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 4px 0 8px;
  align-self: stretch;
}

.aibot-widget-suggestion {
  border: 1px solid var(--aibot-border);
  background: var(--aibot-surface);
  border-radius: 12px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--aibot-text);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  flex: 0 0 auto;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(19, 32, 51, 0.04);
}

.aibot-widget-suggestion:hover {
  background: var(--aibot-primary-soft);
  border-color: var(--aibot-primary-mid);
  transform: translateY(-1px);
}

.aibot-widget-suggestion:active {
  transform: scale(0.98);
}

/* ── Tooltip ─────────────────────────────────────── */
.aibot-widget-tooltip {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: max-content;
  max-width: min(280px, calc(100vw - 48px));
  background: var(--aibot-surface);
  border-radius: 16px;
  box-shadow: 0 12px 36px rgba(19, 32, 51, 0.14);
  border: 1px solid var(--aibot-border);
  padding: 12px 36px 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--aibot-text);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 0.24s;
}

.aibot-widget-tooltip--visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
  transition: opacity 0.24s ease, transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 0s;
}

.aibot-widget-tooltip::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: var(--aibot-surface);
  border-right: 1px solid var(--aibot-border);
  border-bottom: 1px solid var(--aibot-border);
  transform: rotate(45deg);
}

.aibot-widget-tooltip-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--aibot-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.aibot-widget-tooltip-close:hover {
  background: rgba(19, 32, 51, 0.06);
  color: var(--aibot-text);
}

.aibot-widget--open .aibot-widget-tooltip {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ── Tablet ──────────────────────────────────────── */
@media (max-width: 1024px) and (min-width: 641px) {
  .aibot-widget-panel {
    max-height: calc(100dvh - 110px);
  }
}

/* ── Mobile：真全屏，打开时隐藏 FAB 避免挡发送 ── */
@media (max-width: 640px) {
  .aibot-widget-root {
    right: max(var(--aibot-pos-right), env(safe-area-inset-right, 0px));
    bottom: max(var(--aibot-pos-bottom), env(safe-area-inset-bottom, 0px));
  }

  .aibot-widget--open {
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .aibot-widget-panel {
    position: fixed;
    top: var(--aibot-vv-offset-top, 0px);
    right: 0;
    left: 0;
    bottom: auto;
    width: 100%;
    max-width: none;
    height: var(--aibot-vv-height, 100svh);
    max-height: none;
    border-radius: 0;
    border: none;
    box-shadow: none;
    transform: translateY(8px);
    transform-origin: center center;
    /* 顶部安全区落在面板内，避免刘海/浏览器栏挡住标题 */
    padding-top: env(safe-area-inset-top, 0px);
  }

  .aibot-widget--open .aibot-widget-panel {
    transform: translateY(0);
  }

  .aibot-widget--open .aibot-widget-fab {
    display: none;
  }

  .aibot-widget-header {
    padding-top: 12px;
  }

  .aibot-widget-composer {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .aibot-widget-input {
    font-size: 16px;
    min-height: 44px;
  }

  .aibot-widget-send {
    width: 44px;
    height: 44px;
  }
}

@media (min-width: 641px) and (max-height: 720px) {
  .aibot-widget-panel {
    max-height: calc(
      100svh
      - var(--aibot-pos-bottom)
      - 74px
      - env(safe-area-inset-top, 0px)
      - 8px
    );
  }
}
