/* artifact_panel.css — 通用右侧 artifact 面板（14 §6.3）
 *
 * 定位：作为 .preview-panel 内的兄弟容器，与 #pvPreview（deck 预览器）
 * 及各 overlay（search/image/parse/sub-agent）共存。共存规则（§6.3 末段）：
 * 当前会话有 deck 产物（#pvPreview .page-card 存在）时本面板隐藏，
 * deck 预览器优先；deck 无产物且后端推 render_intent 事件时本面板显示。
 *
 * 窄屏（<900px）折叠为隐藏 + toggle 按钮（§6.3 "窄屏折叠为消息流内卡片"
 * 简化版：仅 toggle 显隐，不做卡片流）。
 */

/* ══════ Artifact 面板容器 ══════ */
.artifact-panel {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  background: var(--bg2);
  z-index: 5; /* 低于 search/image/parse/sub-agent overlay（z-index 10+）*/
  /* 默认隐藏；.visible 时显示 */
  display: none;
}
.artifact-panel.visible {
  display: flex;
}

/* 标签页栏 */
.ap-tabs {
  display: flex; align-items: center; gap: 2px;
  padding: 0 12px; height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  overflow-x: auto;
  flex-shrink: 0;
}
.ap-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid transparent;
  border-radius: 6px; background: transparent;
  color: var(--text2); cursor: pointer;
  font-size: 12px; white-space: nowrap;
  max-width: 180px; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.15s, color 0.15s;
}
.ap-tab:hover { background: var(--bg3); color: var(--text); }
.ap-tab.active {
  background: var(--accent-glow); color: var(--accent);
  border-color: var(--accent);
}
.ap-tab-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 14px; line-height: 1; color: var(--text3);
  border: none; background: transparent; cursor: pointer; padding: 0;
}
.ap-tab-close:hover { background: var(--bg3); color: var(--text); }

/* 标签页工具栏（右侧 toggle） */
.ap-collapse-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 6px; border: none;
  background: transparent; color: var(--text3); cursor: pointer;
}
.ap-collapse-btn:hover { background: var(--bg3); color: var(--text); }
.ap-toolbar {
  margin-left: auto; display: flex; align-items: center; gap: 6px;
  padding-right: 4px;
}
.ap-toggle-btn {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg2);
  color: var(--text2); cursor: pointer; padding: 0;
}
.ap-toggle-btn:hover { background: var(--bg3); color: var(--text); }

/* 内容区 */
.ap-body {
  flex: 1; overflow: auto; position: relative;
  background: var(--bg2);
}
.ap-pane { display: none; padding: 12px; height: 100%; box-sizing: border-box; }
.ap-pane.active { display: block; }

/* 空态 */
.ap-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text3); gap: 10px;
}
.ap-empty svg { opacity: 0.15; }

/* ── html_preview：iframe 沙箱 ── */
.ap-html-preview {
  width: 100%; height: 100%; min-height: 400px;
  border: 1px solid var(--border); border-radius: 8px;
  background: white;
}

/* ── markdown ── */
.ap-markdown {
  font-size: 14px; line-height: 1.7; color: var(--text);
  max-width: 100%; overflow-wrap: break-word;
}
.ap-markdown h1, .ap-markdown h2, .ap-markdown h3 { margin: 16px 0 8px; }
.ap-markdown p { margin: 8px 0; }
.ap-markdown pre {
  background: var(--bg3); padding: 10px; border-radius: 6px;
  overflow-x: auto; font-size: 12px;
}
.ap-markdown code { font-family: monospace; }
.ap-markdown table { border-collapse: collapse; margin: 8px 0; }
.ap-markdown th, .ap-markdown td { border: 1px solid var(--border); padding: 4px 8px; }

/* ── image_gallery ── */
.ap-gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px; padding: 4px 0;
}
.ap-gallery-item {
  position: relative; cursor: pointer; border-radius: 8px;
  overflow: hidden; background: var(--bg3); aspect-ratio: 4/3;
}
.ap-gallery-item img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.ap-gallery-item .ap-gallery-cap {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.6); color: white; font-size: 11px;
  padding: 4px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── file_list ── */
.ap-file-list { display: flex; flex-direction: column; gap: 6px; }
.ap-file-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg2);
  text-decoration: none; color: var(--text);
}
.ap-file-item:hover { background: var(--bg3); border-color: var(--accent); }
.ap-file-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg3); border-radius: 6px; color: var(--accent);
}
.ap-file-info { flex: 1; min-width: 0; }
.ap-file-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ap-file-meta { font-size: 11px; color: var(--text3); }

/* ── JSON 兜底 ── */
.ap-json-fallback {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px; font-family: monospace;
  font-size: 12px; white-space: pre-wrap; word-break: break-all;
  max-height: 60vh; overflow: auto;
}
.ap-json-fallback summary {
  cursor: pointer; color: var(--text2); font-weight: 500;
  margin-bottom: 8px; display: block;
}
.ap-json-fallback .ap-json-title { color: var(--text2); font-size: 12px; margin-bottom: 6px; }

/* ── 图片放大 lightbox ── */
.ap-lightbox {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85); z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.ap-lightbox img { max-width: 90vw; max-height: 90vh; object-fit: contain; }
.ap-lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.15); color: white;
  border: none; cursor: pointer; font-size: 20px;
}

/* ── 窄屏折叠 toggle（<900px） ── */
@media (max-width: 899px) {
  .artifact-panel { display: none !important; }
  .artifact-panel.expanded { display: flex !important; position: fixed; z-index: 9998; }
  .ap-mobile-toggle {
    display: inline-flex !important;
  }
}
.ap-mobile-toggle {
  display: none;
  align-items: center; justify-content: center;
  position: fixed; right: 16px; bottom: 80px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: white;
  border: none; cursor: pointer; z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
