/* 智能体：深度思考按钮、会话记录与新会话并排、隐藏规划与参数设置 */

body.agent-bifang-host #btn-agent-settings,
body.agent-bifang-host #btn-agent-mobile-settings,
body.agent-bifang-host #btn-agent-toggle-plan-panel,
body.agent-bifang-host .agent-head-actions > :not(#btn-agent-reset):not(#btn-agent-sessions):not(#btn-agent-side-open),
body.agent-bifang-host #agent-settings-modal,
body.agent-bifang-host #agent-sessions-modal,
body.agent-bifang-host .agent-pipeline-steps-head,
body.agent-bifang-host .agent-pipeline-steps--readonly,
body.agent-bifang-host #agent-plan-actions {
  display: none !important;
}

.agent-think-btn {
  flex-shrink: 0;
  align-self: flex-end;
  min-height: 40px;
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid #111;
  background: #fff;
  color: #111;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.agent-think-btn.is-on {
  background: #111;
  color: #fff;
}

.agent-think-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.agent-sessions-drawer {
  position: fixed;
  inset: 0;
  z-index: 10240;
  pointer-events: none;
}

.agent-sessions-drawer.is-open {
  pointer-events: auto;
}

.agent-sessions-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.agent-sessions-drawer.is-open .agent-sessions-drawer-backdrop {
  opacity: 1;
}

.agent-sessions-drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(86vw, 360px);
  background: #fff;
  border-right: 1px solid var(--border, #ddd);
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.08);
  transform: translateX(-102%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
}

.agent-sessions-drawer.is-open .agent-sessions-drawer-panel {
  transform: translateX(0);
}

.agent-sessions-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border, #eee);
}

.agent-sessions-drawer-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.agent-sessions-drawer-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 12px 20px;
}

body.agent-sessions-drawer-open {
  overflow: hidden;
}

@media (max-width: 960px) {
  body.agent-bifang-host #btn-agent-think-chat,
  body.agent-bifang-host #btn-agent-think-input {
    display: none !important;
  }

  /* 手机端顶部不放「开启新会话」，入口只留在左侧会话记录栏（agent-side-head 克隆按钮） */
  body.agent-bifang-host .agent-chat-head {
    display: none !important;
  }

  body.agent-bifang-host .agent-think-btn {
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }

  body.agent-bifang-host #btn-agent-sessions,
  body.agent-bifang-host #btn-agent-reset {
    min-width: 44px;
    min-height: 44px;
    padding: 0 12px;
  }

  body.agent-bifang-host .agent-head-actions {
    justify-content: flex-start;
    gap: 8px;
  }
}

/* 中间对话占满；会话记录只在按钮打开的抽屉里 */

body.agent-bifang-host #btn-agent-sessions {
  display: none !important;
}

body.agent-bifang-host .agent-layout-resizer[data-resize="input"] {
  display: none !important;
}

body.agent-bifang-host #agent-layout.agent-layout {
  grid-template-columns: minmax(0, 1fr) !important;
}

body.agent-bifang-host .agent-chat-panel {
  grid-column: 1 !important;
}

body.agent-bifang-host {
  --agent-side-drawer-w: min(86vw, 340px);
}

body.agent-bifang-host .agent-input-panel {
  display: none !important;
  flex-direction: column;
  box-sizing: border-box;
  position: fixed;
  z-index: 10220;
  top: var(--agent-bifang-nav-h, 44px);
  left: 0;
  bottom: 0;
  width: var(--agent-side-drawer-w);
  max-height: none;
  margin: 0;
  padding: 16px 14px 12px;
  background: #fff;
  border: 0;
  border-right: 1px solid #ececec;
  border-radius: 0;
  box-shadow: 8px 0 28px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

body.agent-bifang-host.agent-side-open .agent-input-panel {
  display: flex !important;
}

body.agent-bifang-host #btn-agent-side-open {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  position: fixed;
  z-index: 10260;
  top: calc(50% + var(--agent-bifang-nav-h, 44px) / 2);
  left: 0;
  transform: translateY(-50%);
  touch-action: none;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.18em;
  white-space: nowrap;
  box-sizing: border-box;
  width: 44px;
  min-width: 44px;
  min-height: 88px;
  padding: 18px 0;
  border-radius: 0 14px 14px 0;
  border: 1px solid #e4e4e4;
  border-left: 0;
  background: #fff;
  color: #111;
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.08);
}

body.agent-bifang-host.agent-side-open #btn-agent-side-open {
  /* 打开时贴会话栏边缘垂直居中；固定位置，不允许上下拖动。 */
  top: calc(50% + var(--agent-bifang-nav-h, 44px) / 2) !important;
  transform: translateY(-50%) !important;
  left: min(var(--agent-side-drawer-w), calc(100vw - 44px));
  background: #111;
  color: #fff;
  border-color: #111;
}
body.agent-bifang-host #btn-agent-side-open.is-dragging {
  cursor: grabbing;
  box-shadow: 6px 0 22px rgba(0, 0, 0, 0.16);
}


@media (min-width: 961px) {
  body.agent-bifang-host #agent-layout.agent-layout {
    height: calc(100vh - var(--agent-bifang-nav-h, 44px));
    min-height: 0 !important;
  }

  body.agent-bifang-host .agent-chat-panel {
    min-width: 0;
    min-height: 0 !important;
    max-height: none !important;
    height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  body.agent-bifang-host .agent-chat-head {
    display: none;
  }

  body.agent-bifang-host.agent-side-open .agent-chat-panel {
    padding-left: calc(var(--agent-side-drawer-w) + 44px);
    box-sizing: border-box;
  }
}

body.agent-bifang-host .agent-side-backdrop {
  display: none;
  position: fixed;
  top: var(--agent-bifang-nav-h, 44px);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10210;
  border: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.28);
  cursor: pointer;
}

body.agent-bifang-host .agent-side-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  color: #111;
}

/* 仅窄屏抽屉盖住对话时显示遮罩。桌面侧栏与对话并排，打开会话不得把整页变暗。 */
@media (max-width: 960px), (hover: none) and (pointer: coarse) {
  body.agent-bifang-host.agent-side-dragging {
    -webkit-user-select: none;
    user-select: none;
  }

  body.agent-bifang-host .agent-chat-panel,
  body.agent-bifang-host .agent-input-panel,
  body.agent-bifang-host .agent-side-backdrop {
    touch-action: pan-y;
  }

  body.agent-bifang-host.agent-side-open .agent-chat-panel {
    padding-left: 0;
  }

  body.agent-bifang-host .agent-input-panel {
    display: flex !important;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-100%);
    transition: transform 200ms ease-out, visibility 0s 200ms;
  }

  body.agent-bifang-host .agent-side-backdrop {
    display: block;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease-out, visibility 0s 200ms;
  }

  body.agent-bifang-host.agent-side-open .agent-input-panel {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
    transition-delay: 0s;
  }

  body.agent-bifang-host.agent-side-open .agent-side-backdrop {
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    transition-delay: 0s;
  }

  body.agent-bifang-host.agent-side-dragging .agent-input-panel {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(calc((var(--agent-side-progress, 0) - 1) * 100%));
    transition: none;
    will-change: transform;
  }

  body.agent-bifang-host.agent-side-dragging .agent-side-backdrop {
    visibility: visible;
    pointer-events: auto;
    opacity: var(--agent-side-progress, 0);
    transition: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.agent-bifang-host .agent-input-panel,
  body.agent-bifang-host .agent-side-backdrop {
    transition-duration: 0s;
  }
}

/* 侧栏已开时收掉旧抽屉，避免两层 28% 黑遮罩叠在对话上 */
body.agent-bifang-host.agent-side-open .agent-sessions-drawer {
  display: none !important;
}

body.agent-bifang-host .agent-side-head {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  flex: 0 0 auto;
  margin-bottom: 12px;
}

body.agent-bifang-host .agent-side-new {
  width: 100%;
  min-height: 44px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  border: 0;
  font-weight: 650;
}

body.agent-bifang-host .agent-side-switch {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: #ececee;
}

body.agent-bifang-host .agent-side-tab {
  flex: 1 1 0;
  min-height: 44px;
  margin: 0;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #5c5c5c;
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
  cursor: pointer;
}

body.agent-bifang-host .agent-side-tab.is-on {
  background: #fff;
  color: #111;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

body.agent-bifang-host .agent-side-open-btn {
  min-height: 44px;
  min-width: 44px;
}

body.agent-bifang-host .agent-side-sessions {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

body.agent-bifang-host .agent-side-sessions .agent-sessions-list {
  max-height: none;
  margin: 0;
}

body.agent-bifang-host .agent-side-sessions .agent-session-item {
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 10px;
}

body.agent-bifang-host .agent-side-sessions .agent-session-item:hover {
  background: #fff;
}

body.agent-bifang-host .agent-chat-body {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  border: 0;
  background: transparent;
}

#agent-inspire-empty {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 24px 16px 8px;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
  text-align: center;
}

/* 显隐只认 hidden 类 / 会话已开始（agent-composer-chrome.js 的 mountInspireEmpty），不写内联 display */
#agent-inspire-empty.hidden,
.agent-chat-panel:not(.is-inspire-empty) #agent-inspire-empty {
  display: none !important;
}

#agent-inspire-empty .agent-inspire-heading {
  position: relative;
  z-index: 1;
  padding: 12px 0 24px;
  color: #242424;
}

#agent-inspire-empty .agent-inspire-title {
  margin: 0;
  color: inherit;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: clamp(24px, 2.6vw, 36px);
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
  overflow-wrap: anywhere;
  letter-spacing: -0.02em;
}

.agent-inspire-capability {
  margin: 8px 0 12px;
  color: #5b5954;
  font-size: 14px;
  line-height: 1.6;
}

.agent-inspire-modes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(100%, 680px);
  max-height: min(22dvh, 160px);
  overflow: auto;
  pointer-events: auto;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 3px 8px 6px;
  list-style: none;
}

.agent-inspire-modes:empty,
.agent-inspire-modes-status:empty { display: none; }

.agent-inspire-modes li {
  box-sizing: border-box;
  max-width: 100%;
  padding: 7px 13px;
  border: 1px solid #e2e2e2;
  border-radius: 10px;
  background: #fff;
  color: #403f3a;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.agent-inspire-modes-status { color: #655f56; font-size: 13px; margin: 5px 0 0; }

@media (min-width: 961px) and (hover: hover) and (pointer: fine) {
  body.agent-bifang-host .agent-chat-panel.is-inspire-empty {
    --agent-chat-col: min(800px, 80vw);
  }

  body.agent-bifang-host .agent-chat-panel.is-inspire-empty > .agent-chat-body {
    flex: 0 0 auto !important;
    margin-top: auto !important;
    overflow: visible !important;
  }

  body.agent-bifang-host .agent-chat-panel.is-inspire-empty #agent-chat-composer {
    width: min(800px, 80vw) !important;
    max-width: 100% !important;
    margin-top: 0 !important;
    margin-bottom: auto !important;
    padding-top: 0 !important;
  }

  body.agent-bifang-host .agent-chat-panel.is-inspire-empty #agent-inspire-empty {
    padding: 0 16px;
  }
}

body.agent-bifang-host .agent-chat-panel.is-inspire-empty #agent-thread {
  display: none !important;
}

.agent-chat-body > .agent-thread,
.agent-chat-body > #agent-clarify,
.agent-chat-body > #agent-inspire-empty {
  position: relative;
  z-index: 1;
}

/* ---------------- 输入卡聚焦：卡片外圈蓝色呼吸光圈，不改底色 ---------------- */

#agent-chat-composer:focus-within .agent-inspire-card {
  animation: bifangComposerRingBreath 2.4s ease-in-out infinite;
}

@keyframes bifangComposerRingBreath {
  0%,
  100% {
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.4), 0 0 10px rgba(59, 130, 246, 0.18);
  }

  50% {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.85), 0 0 22px rgba(59, 130, 246, 0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  #agent-chat-composer:focus-within .agent-inspire-card {
    animation: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.6);
  }
}

/* ---------------- 嵌入态（用户端 iframe）：按比例的居中列、白底、输入卡贴底 ---------------- */

body.agent-embed {
  --agent-chat-col: min(1120px, 80vw);
  overflow-x: hidden !important;
  max-width: 100vw !important;
}

body.agent-embed #panel-experience.panel,
body.agent-embed #experience-agent-section.experience-section,
body.agent-embed #agent-layout.agent-layout {
  min-height: 0 !important;
}

body.agent-embed .agent-chat-panel {
  min-height: 0 !important;
  height: 100% !important;
}

/* 输入卡的蓝色光圈不能被裁掉：外层放开裁剪 */
body.agent-embed .agent-chat-panel,
body.agent-embed #experience-agent-section,
body.agent-embed #panel-experience {
  overflow: visible !important;
}

body.agent-embed,
body.agent-embed .agent-standalone-main,
body.agent-embed #panel-experience,
body.agent-embed #experience-agent-section,
body.agent-embed #agent-layout,
body.agent-embed .agent-chat-panel,
body.agent-embed .agent-chat-body,
body.agent-embed #agent-thread,
body.agent-embed #agent-chat-composer {
  background-color: #fff !important;
}

/* 对话区本身是居中列，标题、对话、反问、输入卡共用这一条中轴 */
body.agent-embed .agent-chat-body {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  width: var(--agent-chat-col) !important;
  max-width: var(--agent-chat-col) !important;
  min-height: 0 !important;
  margin-left: auto !important;
  margin-right: auto !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  border: 0 !important;
  box-shadow: none !important;
}

body.agent-embed #agent-inspire-empty,
body.agent-embed #agent-thread,
body.agent-embed #agent-clarify.agent-clarify {
  width: 100% !important;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  box-sizing: border-box;
}

body.agent-embed #agent-thread {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  overflow-x: hidden !important;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.agent-embed #agent-inspire-empty {
  border: 0 !important;
  box-shadow: none !important;
  outline: none !important;
}

body.agent-embed #agent-clarify.agent-clarify {
  margin-top: 0 !important;
  margin-bottom: 10px !important;
  padding: 12px 14px !important;
  background: #fff !important;
  border: 1px solid #ebebee !important;
  border-radius: 16px !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06) !important;
}

body.agent-embed #agent-clarify .btn,
body.agent-embed #agent-clarify button {
  border-radius: 999px !important;
}

body.agent-embed #agent-clarify .agent-clarify-title,
body.agent-embed #agent-clarify h3,
body.agent-embed #agent-clarify strong {
  font-weight: 650;
  color: #1d1d1f;
}

/* 输入卡贴底；上边距留给聚焦光圈 */
body.agent-embed #agent-chat-composer {
  flex: 0 0 auto !important;
  width: var(--agent-chat-col) !important;
  max-width: none !important;
  margin-top: auto !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding: 14px 0 0 !important;
  overflow: visible !important;
  box-sizing: border-box;
}

body.agent-embed #agent-chat-composer .agent-inspire-card {
  width: 100% !important;
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  box-sizing: border-box;
  background-color: #fff !important;
  border: 1px solid #ebebee;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

body.agent-embed #agent-status-bar {
  width: var(--agent-chat-col) !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* 手机：列宽几乎占满，只给光圈留一点边；长文本不撑出横向滚动 */
@media (max-width: 640px) {
  body.agent-embed {
    --agent-chat-col: calc(100vw - 28px);
  }

  body.agent-embed #agent-thread .agent-note,
  body.agent-embed #agent-thread .agent-msg,
  body.agent-embed #agent-thread p {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
}

/* 开启新会话：文字放大，点击/聚焦/禁用态都保持实色，不变浅。 */
body.agent-bifang-host #btn-agent-reset,
body.agent-bifang-host #btn-agent-reset-side {
  min-height: 44px !important;
  padding: 0 16px !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  opacity: 1 !important;
}

body.agent-bifang-host #btn-agent-reset {
  border: 1px solid #111 !important;
  background: #fff !important;
  color: #111 !important;
}

body.agent-bifang-host #btn-agent-reset-side {
  background: #111 !important;
  color: #fff !important;
  border: 0 !important;
}

body.agent-bifang-host #btn-agent-reset:active,
body.agent-bifang-host #btn-agent-reset:focus,
body.agent-bifang-host #btn-agent-reset:focus-visible,
body.agent-bifang-host #btn-agent-reset-side:active,
body.agent-bifang-host #btn-agent-reset-side:focus,
body.agent-bifang-host #btn-agent-reset-side:focus-visible {
  background: #111 !important;
  color: #fff !important;
  opacity: 1 !important;
}

body.agent-bifang-host #btn-agent-reset:disabled,
body.agent-bifang-host #btn-agent-reset-side:disabled {
  opacity: 1 !important;
  color: #111 !important;
  background: #fff !important;
}

/* 会话详情：智能体页内弹窗（桌面居中，手机全屏），不再占用左侧会话栏。 */
#agent-session-detail-modal.page-modal {
  z-index: 10240;
  padding: 24px;
}
#agent-session-detail-modal .page-modal-card {
  width: min(860px, calc(100vw - 48px));
  max-width: min(860px, calc(100vw - 48px));
  max-height: min(88vh, 900px);
  padding: 22px 24px 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#agent-session-detail-modal .page-modal-title,
#agent-session-detail-modal .page-modal-card > .field-hint {
  flex: 0 0 auto;
}
#agent-session-detail-modal .page-modal-title {
  margin-bottom: 6px;
}
#agent-session-detail-modal .agent-session-detail-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 10px 0;
}
#agent-session-detail-modal .page-modal-actions {
  flex: 0 0 auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
@media (max-width: 640px) {
  #agent-session-detail-modal.page-modal {
    padding: 0;
    align-items: stretch;
  }
  #agent-session-detail-modal .page-modal-card {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    padding: max(14px, env(safe-area-inset-top, 0px)) 14px max(12px, env(safe-area-inset-bottom, 0px));
  }
}
