/* ===== 截图对话悬浮窗样式 ===== */
/* 移植自 getDispMedia2/static/index.html，所有 ID/类名加 chat- 前缀，z-index 适配主项目 */

/* ========== CSS 变量（Claude 暖色风格） ========== */
:root {
  --chat-bg: #faf9f5;          /* 主项目米白底 */
  --chat-panel: #ffffff;        /* 面板白底 */
  --chat-panel-alt: #f5f3ee;   /* 次级面板（输入框等） */
  --chat-border: #e8e2d5;      /* 暖灰边框 */
  --chat-border-strong: #d4cdb8;
  --chat-txt: #1a1a1a;         /* 深灰文字 */
  --chat-muted: #8b8170;       /* 暖灰次要文字 */
  --chat-accent: #d97757;      /* Claude 橙棕 */
  --chat-accent-light: #f0a988;
  --chat-cyan: #d97757;        /* 兼容旧变量名 → 橙棕 */
  --chat-magenta: #c46c4e;     /* 兼容 → 深橙 */
  --chat-amber: #b8860b;       /* 兼容 → 暗金 */
  --chat-red: #dc2626;
  --chat-green: #16a34a;
}

/* box-sizing 限定在组件内部，避免影响主项目 */
#chatPanel,
#chatPanel *,
#chatCaptureOverlay,
#chatCaptureOverlay *,
#chatCfgMask,
#chatCfgMask * {
  box-sizing: border-box;
}

/* ========== 悬浮窗（毛玻璃） ========== */
.chat-panel {
  position: fixed;
  z-index: 3000; /* 高于播放器模态的 2000 */
  right: 8px;
  top: 8px;
  display: flex;
  flex-direction: column;
  width: 420px;
  height: calc(100vh - 16px);
  background: color-mix(in srgb, var(--chat-panel) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--chat-border-strong);
  border-radius: 12px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  /* 确保组件在主项目中文字颜色和字体正确 */
  color: var(--chat-txt);
  font-family: "Manrope", -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
.chat-panel.min {
  height: auto !important;
}
.chat-panel.min .chat-panel-head {
  border-bottom: none;
}
.chat-panel.min .chat-rsz {
  display: none;
}
.chat-panel.min #chatProviderBar,
.chat-panel.min #chatQuotaBar,
.chat-panel.min .chat-toolbar,
.chat-panel.min .chat-msgs,
.chat-panel.min .chat-composer,
.chat-panel.min .chat-hint {
  display: none;
}

/* ========== 折叠态：右边缘小按钮 ========== */
.chat-panel.collapsed {
  width: 48px !important;
  height: 48px !important;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
}
.chat-panel.collapsed .chat-rsz,
.chat-panel.collapsed .chat-panel-head,
.chat-panel.collapsed #chatProviderBar,
.chat-panel.collapsed #chatQuotaBar,
.chat-panel.collapsed .chat-toolbar,
.chat-panel.collapsed .chat-msgs,
.chat-panel.collapsed .chat-composer,
.chat-panel.collapsed .chat-hint {
  display: none;
}
.chat-panel.collapsed::after {
  content: "🛰";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  pointer-events: none;
}
.chat-panel.collapsed:hover {
  box-shadow: 0 4px 16px rgba(217, 119, 87, 0.35);
}

/* ========== 四边 resize 手柄 ========== */
.chat-panel .chat-rsz {
  position: absolute;
  z-index: 30;
}
.chat-panel .chat-rsz[data-dir="n"] {
  top: 0;
  left: 10px;
  right: 10px;
  height: 6px;
  cursor: n-resize;
}
.chat-panel .chat-rsz[data-dir="s"] {
  bottom: 0;
  left: 10px;
  right: 10px;
  height: 6px;
  cursor: s-resize;
}
.chat-panel .chat-rsz[data-dir="e"] {
  top: 10px;
  bottom: 10px;
  right: 0;
  width: 6px;
  cursor: e-resize;
}
.chat-panel .chat-rsz[data-dir="w"] {
  top: 10px;
  bottom: 10px;
  left: 0;
  width: 6px;
  cursor: w-resize;
}
.chat-panel.dragging .chat-rsz {
  pointer-events: none;
}

/* ========== 标题栏 ========== */
.chat-panel-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
  user-select: none;
}
.chat-panel-head .chat-t {
  font-weight: 700;
  font-size: 14px;
}
.chat-win-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-status {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--chat-border);
  color: var(--chat-muted);
}
.chat-status.ok {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.4);
}
.chat-status.warn {
  color: var(--chat-amber);
  border-color: rgba(251, 191, 36, 0.4);
}
.chat-win-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--chat-border);
  background: transparent;
  color: var(--chat-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  padding: 0;
}
.chat-win-btn:hover {
  border-color: var(--chat-accent);
  color: var(--chat-accent);
}

/* ========== Provider 信息条 ========== */
.chat-provider-bar {
  padding: 6px 14px;
  font-size: 11px;
  color: var(--chat-muted);
  border-top: 1px solid var(--chat-border);
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-panel-alt);
}
.chat-provider-bar b {
  color: var(--chat-accent);
  font-weight: 600;
}

/* ========== 工具栏 ========== */
.chat-toolbar {
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--chat-border);
}
.chat-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
button.chat-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--chat-on-accent);
  background: linear-gradient(90deg, var(--chat-accent), var(--chat-accent-light));
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  flex: 1;
}
button.chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--chat-accent) 30%, transparent);
}
button.chat-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
button.chat-btn.ghost {
  background: transparent;
  color: var(--chat-txt);
  border: 1px solid var(--chat-border);
  flex: 0 0 auto;
}
button.chat-btn.ghost:hover {
  box-shadow: none;
  border-color: var(--chat-accent);
}

/* ========== 预览缩略图 ========== */
.chat-preview-box {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}
.chat-preview-box .chat-ph {
  flex: 1;
  font-size: 11px;
  color: var(--chat-muted);
  padding: 8px 0;
}
.chat-preview-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--chat-border);
  cursor: pointer;
  display: block;
}
.chat-preview-info {
  font-size: 11px;
  color: var(--chat-muted);
  flex: 1;
}

/* ========== 消息区 ========== */
.chat-msgs {
  flex: 1;
  min-height: 60px;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, color-mix(in srgb, var(--chat-accent) 14%, transparent), color-mix(in srgb, var(--chat-accent) 7%, transparent));
  border: 1px solid color-mix(in srgb, var(--chat-accent) 28%, transparent);
}
.chat-msg.assistant {
  align-self: flex-start;
  background: color-mix(in srgb, var(--chat-panel-alt) 55%, transparent);
  border: 1px solid var(--chat-border);
  /* A5：AI 正文走 markdown 正常文档流（用户消息仍保持 pre-wrap） */
  white-space: normal;
}
/* —— A5：AI 正文 markdown 元素样式 —— */
.chat-msg.assistant > .chat-body > :last-child {
  margin-bottom: 0;
}
.chat-msg.assistant p {
  margin: 0 0 6px;
}
.chat-msg.assistant ul,
.chat-msg.assistant ol {
  margin: 4px 0 6px;
  padding-left: 20px;
}
.chat-msg.assistant li {
  margin: 2px 0;
}
.chat-msg.assistant h1,
.chat-msg.assistant h2,
.chat-msg.assistant h3,
.chat-msg.assistant h4,
.chat-msg.assistant h5,
.chat-msg.assistant h6 {
  margin: 10px 0 4px;
  line-height: 1.4;
}
.chat-msg.assistant h1 { font-size: 17px; }
.chat-msg.assistant h2 { font-size: 15.5px; }
.chat-msg.assistant h3 { font-size: 14.5px; }
.chat-msg.assistant h4,
.chat-msg.assistant h5,
.chat-msg.assistant h6 { font-size: 13.5px; }
.chat-msg.assistant blockquote {
  margin: 6px 0;
  padding: 2px 10px;
  border-left: 3px solid color-mix(in srgb, var(--chat-accent) 55%, transparent);
  color: var(--chat-muted);
}
.chat-msg.assistant a {
  color: var(--chat-accent);
  text-decoration: underline;
}
.chat-msg.assistant img {
  max-width: 100%;
  border-radius: 6px;
}
.chat-msg.assistant table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 12.5px;
}
.chat-msg.assistant th,
.chat-msg.assistant td {
  border: 1px solid var(--chat-border);
  padding: 4px 8px;
}
.chat-msg.assistant th {
  background: var(--chat-panel-alt);
}
.chat-msg.assistant hr {
  border: none;
  border-top: 1px solid var(--chat-border);
  margin: 8px 0;
}
.chat-msg.assistant code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}
.chat-msg.assistant pre {
  background: #2d2a26;
  color: #e8e2d5;
  padding: 8px 10px;
  border-radius: 8px;
  margin: 6px 0;
  overflow-x: auto; /* 代码块横向滚动，不撑破气泡 */
  white-space: pre;
}
.chat-msg.assistant pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: 12px;
}

/* ========== A3：定位播放按钮 ========== */
.chat-msg .chat-play-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  background: linear-gradient(90deg, var(--chat-accent), var(--chat-accent-light));
  border: none;
  border-radius: 999px;
  padding: 3px 12px;
  margin: 2px 2px;
  cursor: pointer;
  vertical-align: middle;
  line-height: 1.6;
  transition: transform 0.12s, box-shadow 0.12s;
}
.chat-msg .chat-play-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--chat-accent) 40%, transparent);
}

/* ========== A4：兜底定位卡片 ========== */
.chat-locate-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.chat-locate-card {
  border: 1px dashed color-mix(in srgb, var(--chat-accent) 55%, var(--chat-border));
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
  background: color-mix(in srgb, var(--chat-accent) 5%, transparent);
  transition: background 0.12s, border-color 0.12s;
}
.chat-locate-card:hover {
  background: color-mix(in srgb, var(--chat-accent) 12%, transparent);
  border-color: var(--chat-accent);
}
.chat-locate-meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--chat-accent);
  margin-bottom: 2px;
}
.chat-locate-text {
  font-size: 12px;
  color: var(--chat-txt);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-msg .chat-role {
  font-size: 10px;
  color: var(--chat-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
/* 对话内图片缩略图 */
.chat-msg .chat-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  margin-top: 6px;
  border: 1px solid var(--chat-border);
  cursor: pointer;
  vertical-align: middle;
}

/* ========== 全局图片放大浮层（fixed，逃出 overflow:hidden） ========== */
#chatImgViewer {
  position: fixed;
  z-index: 5000;
  display: none;
  pointer-events: none;
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 8px;
  border: 2px solid var(--chat-accent);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8);
}

/* ========== thinking 折叠区 / 空提示 / 光标 / 错误 ========== */
.chat-think {
  margin-top: 8px;
  border: 1px dashed var(--chat-border);
  border-radius: 8px;
  overflow: hidden;
}
.chat-think summary {
  cursor: pointer;
  font-size: 11px;
  color: var(--chat-magenta);
  padding: 6px 10px;
  list-style: none;
  background: rgba(240, 171, 252, 0.06);
}
.chat-think[open] summary {
  border-bottom: 1px dashed var(--chat-border);
}
.chat-think .chat-body {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--chat-muted);
  white-space: pre-wrap;
}
.chat-empty {
  color: var(--chat-muted);
  font-size: 13px;
  text-align: center;
  margin: auto;
  line-height: 1.7;
}
.chat-cursor::after {
  content: "▋";
  color: var(--chat-accent);
  animation: chat-blink 1s steps(2) infinite;
}
@keyframes chat-blink {
  50% {
    opacity: 0;
  }
}
.chat-err {
  color: #f87171;
  font-size: 12px;
  padding: 8px 10px;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 8px;
  white-space: pre-wrap;   /* 错误消息保留换行 */
}

/* ========== 输入区 ========== */
.chat-composer {
  border-top: 1px solid var(--chat-border);
  padding: 10px 14px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-composer textarea {
  flex: 1;
  resize: none;
  background: var(--chat-panel-alt);
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  color: var(--chat-txt);
  font-family: inherit;
  font-size: 13.5px;
  padding: 10px;
  height: 56px;
  max-height: 120px;
  outline: none;
}
.chat-composer textarea:focus {
  border-color: var(--chat-accent);
}
.chat-composer .chat-send-btn {
  flex: 0 0 auto;
  width: 45px;
  height: 45px;
  border-radius: var(--radius-md, 8px);
  border: none;
  background: var(--chat-accent);
  color: var(--chat-on-accent);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.12s;
  padding: 0;
}
.chat-composer .chat-send-btn:hover {
  opacity: 0.85;
}
.chat-composer .chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.chat-hint {
  font-size: 10px;
  color: var(--chat-muted);
  text-align: center;
  margin-top: 4px;
}

/* ========== 截图 overlay — absolute 定位，不用 flex ========== */
#chatCaptureOverlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: none;
  background: rgba(0, 0, 0, 0.92);
}
#chatCaptureOverlay.show {
  display: block;
}
#chatCaptureCanvas {
  position: absolute;
  display: block;
  cursor: crosshair;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}
#chatCapTip {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4010;
  background: rgba(250, 249, 245, 0.95);
  border: 1px solid var(--chat-accent);
  color: var(--chat-accent);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
#chatCapSelBox {
  position: absolute;
  border: 2px dashed var(--chat-accent);
  background: rgba(34, 211, 238, 0.06);
  display: none;
  pointer-events: none;
  z-index: 4005;
}
#chatCapSelBox.show {
  display: block;
}
#chatCapSelBox .chat-corner {
  position: absolute;
  width: 10px;
  height: 10px;
  border: 2px solid var(--chat-accent);
}
#chatCapSelBox .chat-corner.tl {
  top: -1px;
  left: -1px;
  border-right: none;
  border-bottom: none;
}
#chatCapSelBox .chat-corner.tr {
  top: -1px;
  right: -1px;
  border-left: none;
  border-bottom: none;
}
#chatCapSelBox .chat-corner.bl {
  bottom: -1px;
  left: -1px;
  border-right: none;
  border-top: none;
}
#chatCapSelBox .chat-corner.br {
  bottom: -1px;
  right: -1px;
  border-left: none;
  border-top: none;
}
#chatCapSelLabel {
  position: absolute;
  top: -22px;
  left: 0;
  background: var(--chat-accent);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  font-family: monospace;
}
#chatCapToolbar {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4010;
  display: none;
  gap: 6px;
  background: var(--chat-panel);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  align-items: center;
}
#chatCapToolbar.show {
  display: flex;
}
#chatCapToolbar .chat-label {
  font-size: 11px;
  color: var(--chat-muted);
  margin-right: 2px;
}
#chatCapToolbar button {
  font-size: 12px;
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--chat-border);
  background: var(--chat-bg);
  color: var(--chat-txt);
}
#chatCapToolbar button.chat-tool {
  font-size: 15px;
  padding: 7px 9px;
  line-height: 1;
}
#chatCapToolbar button.chat-tool.active {
  border-color: var(--chat-red);
  color: var(--chat-red);
  background: rgba(239, 68, 68, 0.15);
}
#chatCapToolbar button:hover {
  opacity: 0.85;
}
#chatCapToolbar .chat-sep {
  width: 1px;
  height: 24px;
  background: var(--chat-border);
  margin: 0 2px;
}
#chatCapToolbar .chat-primary {
  background: var(--chat-accent);
  color: var(--chat-bg);
  font-weight: 700;
  border: none;
}

/* ========== 隐藏 video（不能用 display:none） ========== */
#chatHiddenVideo {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  pointer-events: none;
}

/* ========== 配置弹窗 ========== */
.chat-modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 4500;
  display: none;
  align-items: center;
  justify-content: center;
}
.chat-modal-mask.show {
  display: flex;
}
.chat-modal {
  width: 380px;
  background: var(--chat-panel);
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  padding: 20px;
}
.chat-modal label {
  font-size: 11px;
  color: var(--chat-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.chat-modal input {
  width: 100%;
  margin: 5px 0 12px;
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  color: var(--chat-txt);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.chat-modal input:focus {
  border-color: var(--chat-accent);
}
.chat-modal h3 {
  margin: 0 0 6px;
  font-size: 16px;
}
.chat-modal p {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--chat-muted);
}

/* ========== 对话额度显示 ========== */
.chat-quota-bar {
  padding: 4px 12px;
  font-size: 12px;
  color: var(--chat-muted);
  background: var(--chat-panel-alt);
  border-top: 1px solid var(--chat-border);
}
.chat-quota-bar.exhausted {
  color: var(--chat-red);
  font-weight: bold;
  background: color-mix(in srgb, var(--chat-red) 8%, transparent);
}