/* ═══════════════════════════════════════
   SIDEBAR.CSS - AI 聊天侧边栏
   ═══════════════════════════════════════ */

/* AI 侧边栏 - 右侧抽屉，线稿风格 */
#ai-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 400px;
  background: var(--bg);
  border-left: 1px solid var(--rule);
  z-index: 2500;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  visibility: hidden;
}

#ai-sidebar.active {
  transform: translateX(0);
  visibility: visible;
}

/* 侧边栏遮罩 */
#ai-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.15);
  z-index: 2490;
  display: none;
  opacity: 0;
  transition: opacity 0.3s;
}

#ai-sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

/* ─── 头部 ─── */
#sidebar-header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

/* 划选原句 - 斜体引用 + 左细线 */
#sidebar-quote {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--ink-mid);
  line-height: 1.65;
  margin-bottom: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--rule);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#sidebar-quote:empty {
  display: none;
  margin: 0;
}


.sidebar-btn {
  font-size: 0.72rem;
  font-weight: 300;
  color: var(--ink-faint);
  cursor: pointer;
  letter-spacing: 0.04em;
  border: none;
  background: none;
  font-family: var(--font-ui);
  transition: color 0.2s;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-btn:hover {
  color: var(--ink);
}

/* 记忆条数提示（P6 用） */
#memory-warning {
  font-size: 0.68rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  padding: 8px 20px;
  border-bottom: 1px solid var(--rule);
  display: none;
}

#memory-warning.visible {
  display: block;
}

/* ─── 聊天消息区 ─── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
}

.chat-message {
  margin-bottom: 22px;
  animation: messageIn 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

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

/* AI 消息 - 左对齐无气泡，左细线 */
.chat-message.ai {
  text-align: left;
}

.chat-message.ai .message-content {
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--ink);
  padding-left: 12px;
  border-left: 2px solid var(--rule);
  display: block;
}

/* 用户消息 - 右对齐，--ink-mid，无气泡 */
.chat-message.user {
  text-align: right;
}

.chat-message.user .message-content {
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--ink-mid);
  display: inline-block;
  text-align: right;
  max-width: 90%;
}

/* 消息操作 - 极小文字，hover 显现 */
.message-actions {
  margin-top: 6px;
  font-size: 0.68rem;
  color: var(--ink-ghost);
  display: flex;
  gap: 12px;
  opacity: 0;
  transition: opacity 0.2s;
  letter-spacing: 0.04em;
}

.chat-message.user .message-actions {
  justify-content: flex-end;
}

.chat-message:hover .message-actions {
  opacity: 1;
}

.msg-action {
  cursor: pointer;
  transition: color 0.2s;
}

.msg-action:hover {
  color: var(--ink-mid);
}

/* ─── 输入区 ─── */
#chat-input-area {
  padding: 14px 20px;
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}

/* 灵感之海同款输入框 - border-bottom 只有底线 */
#chat-input {
  width: 100%;
  border: none;
  border-bottom: 1.5px solid var(--ink);
  background: transparent;
  outline: none;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 300;
  color: var(--ink);
  letter-spacing: 0.02em;
  padding: 6px 0;
  resize: none;
  min-height: 22px;
  max-height: 100px;
  line-height: 1.6;
}

#chat-input::placeholder {
  color: var(--ink-ghost);
  font-weight: 300;
}

#chat-input-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

#chat-send {
  font-size: 0.72rem;
  font-weight: 300;
  color: var(--ink-mid);
  cursor: pointer;
  letter-spacing: 0.06em;
  border: none;
  background: none;
  font-family: var(--font-ui);
  transition: color 0.2s;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

#chat-send:hover {
  color: var(--ink);
}

/* ═══════════════════════════════════════
   侧边栏操作行 - 多按钮布局
   ═══════════════════════════════════════ */

#sidebar-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

/* ═══════════════════════════════════════
   会话列表面板
   ═══════════════════════════════════════ */

/* 覆盖在侧边栏/悬浮窗上方，从左侧滑入 */
#conv-list-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80%;
  max-width: 340px;
  background: var(--bg);
  border-left: 1px solid var(--rule);
  z-index: 2600;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  visibility: hidden;
}

#conv-list-panel.active {
  transform: translateX(0);
  visibility: visible;
}

/* 桌面端：锚定在悬浮窗左侧 */
@media (min-width: 768px) {
  #conv-list-panel {
    position: absolute;
    top: 0;
    right: auto;
    left: 0;
    bottom: 0;
    width: 220px;
    max-width: 220px;
    border-left: none;
    border-right: 1px solid var(--rule);
    border-radius: 12px 0 0 12px;
    transform: translateX(-100%);
    /* 依附于 #chat-float-window（由 JS 动态定位） */
    z-index: 2601;
  }

  #conv-list-panel.active {
    transform: translateX(0);
  }
}

/* 面板头部 */
#conv-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

#conv-list-title {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-mid);
  letter-spacing: 0.06em;
}

.conv-list-close-btn {
  font-size: 0.82rem;
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 2px;
  font-family: var(--font-ui);
  transition: color 0.15s;
  line-height: 1;
}

.conv-list-close-btn:hover {
  color: var(--ink);
}

/* 会话列表滚动区 */
#conv-list-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

/* 分组标签（活跃 / 已归档） */
.conv-group-label {
  font-size: 0.66rem;
  color: var(--ink-ghost);
  letter-spacing: 0.08em;
  padding: 10px 16px 4px;
  text-transform: uppercase;
}

/* 单条会话项 */
.conv-item {
  display: flex;
  align-items: flex-start;
  gap: 0;
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s;
  position: relative;
}

.conv-item:hover {
  background: var(--rule);
}

.conv-item.active-conv {
  background: color-mix(in srgb, var(--accent, #b5a89a) 12%, transparent);
}

/* 会话信息主体 */
.conv-item-body {
  flex: 1;
  min-width: 0;
}

.conv-item-title {
  font-size: 0.82rem;
  color: var(--ink);
  font-weight: 300;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.5;
}

.conv-item-title.editing {
  outline: none;
  border-bottom: 1px solid var(--ink-mid);
  white-space: normal;
  overflow: visible;
  cursor: text;
}

.conv-item-meta {
  font-size: 0.66rem;
  color: var(--ink-ghost);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

/* 会话操作（hover 时显现） */
.conv-item-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
  align-self: center;
}

.conv-item:hover .conv-item-actions {
  opacity: 1;
}

.conv-act-btn {
  font-size: 0.68rem;
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: var(--font-ui);
  transition: color 0.15s, background 0.15s;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.conv-act-btn:hover {
  color: var(--ink);
  background: var(--rule);
}

.conv-act-btn.danger:hover {
  color: #c0392b;
  background: rgba(192, 57, 43, 0.08);
}

/* 已归档分区折叠按钮 */
.conv-archive-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 0.72rem;
  color: var(--ink-faint);
  cursor: pointer;
  letter-spacing: 0.04em;
  user-select: none;
  transition: color 0.15s;
}

.conv-archive-toggle:hover {
  color: var(--ink-mid);
}

.conv-archive-toggle .toggle-arrow {
  transition: transform 0.2s;
  display: inline-block;
}

.conv-archive-toggle.expanded .toggle-arrow {
  transform: rotate(90deg);
}

/* 空状态提示 */
.conv-list-empty {
  padding: 32px 16px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-ghost);
  letter-spacing: 0.04em;
}

/* 面板底部新建按钮 */
#conv-list-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--rule);
  flex-shrink: 0;
}

.conv-new-btn {
  width: 100%;
  padding: 8px 0;
  font-size: 0.78rem;
  font-weight: 300;
  color: var(--ink-mid);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-ui);
  letter-spacing: 0.04em;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.conv-new-btn:hover {
  color: var(--ink);
  border-color: var(--ink-mid);
  background: var(--rule);
}

/* ═══════════════════════════════════════
   桌面端悬浮聊天窗
   ═══════════════════════════════════════ */

#chat-float-window {
  position: fixed;
  right: 24px;
  bottom: 80px;
  width: 360px;
  max-height: 560px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  z-index: 2500;
  display: none;
  flex-direction: column;
  overflow: hidden;
  /* 默认隐藏，active 时显示 */
}

#chat-float-window.active {
  display: flex;
}

/* 折叠状态：只显示标题栏 */
#chat-float-window.minimized #chat-float-body {
  display: none;
}

/* 拖拽时禁止文本选中 */
#chat-float-window.dragging {
  user-select: none;
}

/* 标题栏 */
#chat-float-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
  cursor: grab;
  background: var(--bg);
}

#chat-float-header:active {
  cursor: grabbing;
}

#chat-float-title {
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--ink-mid);
  letter-spacing: 0.06em;
}

#chat-float-actions {
  display: flex;
  gap: 6px;
}

.float-btn {
  font-size: 0.75rem;
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 4px;
  font-family: var(--font-ui);
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

.float-btn:hover {
  color: var(--ink);
  background: var(--rule);
}

/* 悬浮窗内容区（接管 #chat-messages + #chat-input-area） */
#chat-float-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* 悬浮窗内部的 #chat-messages 需限高滚动 */
#chat-float-body #chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

/* 悬浮窗内部输入区底部内边距覆盖（桌面无 safe-area） */
#chat-float-body #chat-input-area {
  padding-bottom: 14px;
}
