/* =========================================================
   多聚AI — Artifacts（FE-B）：消息里的卡片、右侧面板、Artifacts 页面、首页「最近的 Artifacts」
   只用 claude.css 定义的设计变量（SPEC-frontend §2），深色模式跟着变量走。类名统一以 art- 开头。
   ========================================================= */

/* ---------- 消息里的卡片 ---------- */
.art-card {
  display: flex; align-items: center; gap: 12px; width: 100%; max-width: 420px; min-height: 64px; padding: 11px 14px 11px 12px;
  border-radius: var(--r-lg); background: var(--bg-page); box-shadow: inset 0 0 0 1px var(--border-2);
  color: var(--text); font-family: var(--font-ui); text-align: left; cursor: pointer; user-select: none;
  transition: background-color .12s, box-shadow .12s;
}
.art-card:hover { background: var(--bg-hover); }
.art-card:active { background: var(--bg-active); }
.art-card.is-active { box-shadow: inset 0 0 0 1px var(--text-3); background: var(--bg-subtle); }
.art-card:focus-visible { box-shadow: inset 0 0 0 1px var(--border-2), 0 0 0 2px var(--accent); }
.art-tile {
  width: 40px; height: 40px; flex: none; display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-md); background: var(--bg-subtle); box-shadow: inset 0 0 0 1px var(--border); color: var(--text-2);
}
.art-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.art-card-title { font-size: 14px; line-height: 20px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-card-sub { font-size: 12px; line-height: 16px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-card-sub.is-error { color: var(--danger); }
.art-card-sub.is-muted { color: var(--text-3); }
.art-card-sub.is-live, .art-status {
  background: linear-gradient(90deg, var(--text-3) 0%, var(--text-3) 35%, var(--text) 50%, var(--text-3) 65%, var(--text-3) 100%);
  background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: art-shimmer 1.8s linear infinite;
}
@keyframes art-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ---------- 右侧面板（#artifactPanel 由 chat.html 提供；没有 has-panel 时 claude.css 把它隐藏） ---------- */
body.has-panel #artifactPanel {
  position: relative; flex: none; display: flex; min-width: 360px; max-width: 70%; width: 50%; height: 100%;
  background: var(--bg-page); border-left: 1px solid var(--border);
}
.art-panel { position: relative; flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; container: artpanel / inline-size; }
.art-resize { position: absolute; left: -4px; top: 0; bottom: 0; width: 7px; z-index: 6; cursor: col-resize; touch-action: none; }
.art-resize::after { content: ""; position: absolute; left: 2px; top: 0; bottom: 0; width: 2px; background: transparent; transition: background-color .15s; }
.art-resize:hover::after, .art-resize:focus-visible::after, body.art-resizing .art-resize::after { background: var(--accent); }
.art-resize:focus-visible { box-shadow: none; }
body.art-resizing { cursor: col-resize; user-select: none; }
body.art-resizing iframe { pointer-events: none; }

.art-head { flex: none; height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 14px; border-bottom: 1px solid var(--border); }
.art-head-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.art-back { margin-left: -6px; }
.art-head-icon { display: flex; flex: none; color: var(--text-2); }
.art-head-title { min-width: 0; font: 500 14px/20px var(--font-ui); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-ver {
  flex: none; display: inline-flex; align-items: center; gap: 2px; height: 24px; padding: 0 4px 0 8px; margin-left: -2px;
  border-radius: var(--r-sm); font-size: 12.5px; color: var(--text-2); white-space: nowrap; transition: background-color .12s, color .12s;
}
.art-ver:hover, .art-ver.is-menu-open { background: var(--bg-hover); color: var(--text); }
.art-status { flex: none; font-size: 12.5px; white-space: nowrap; }
.art-head-tools { flex: none; display: flex; align-items: center; gap: 4px; }
.art-seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 9px; background: var(--bg-active); margin-right: 4px; }
.art-seg-btn {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 7px;
  font-size: 12.5px; color: var(--text-2); white-space: nowrap; transition: background-color .12s, color .12s;
}
.art-seg-btn:hover:not(:disabled) { color: var(--text); }
.art-seg-btn[aria-selected="true"] { background: var(--bg-elevated); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.art-seg-btn:disabled { opacity: .45; cursor: default; }
.art-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; flex: none;
  border-radius: var(--r-md); background: var(--bg-elevated); box-shadow: inset 0 0 0 1px var(--border-2);
  font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; transition: background-color .12s, opacity .12s, color .12s;
}
.art-btn:hover:not(:disabled) { background: var(--bg-hover); }
.art-btn:disabled { opacity: .5; cursor: default; }
.art-btn .cl-i { flex: none; }
.art-btn.is-done { color: var(--success); }
.art-btn-ghost { background: transparent; box-shadow: none; color: var(--text-2); }
.art-btn-ghost:hover:not(:disabled) { color: var(--text); }
.art-btn-fix { background: var(--bg-inverse); color: var(--text-inverse); box-shadow: none; }
.art-btn-fix:hover:not(:disabled) { background: var(--bg-inverse); opacity: .88; }
.art-head-sep { width: 1px; height: 18px; margin: 0 2px; background: var(--border-2); flex: none; }
.art-act-more { display: none; }
@container artpanel (max-width: 600px) {
  .art-seg-label, .art-copy .art-btn-label { display: none; }
  .art-seg-btn { padding: 0 7px; }
  .art-copy { width: 28px; padding: 0; background: transparent; box-shadow: none; color: var(--text-2); }
  .art-copy:hover:not(:disabled) { color: var(--text); }
}
@container artpanel (max-width: 470px) {
  .art-act-download, .art-act-full { display: none; }
  .art-act-more { display: inline-flex; }
  .art-head { padding-left: 12px; gap: 6px; }
}

.art-body { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
.art-stage { flex: 1; min-height: 0; position: relative; overflow: hidden; background: var(--bg-page); }
.art-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; opacity: 0; transition: opacity .16s ease; color-scheme: light; }
.art-frame.is-light { background: #fff; }
.art-frame.is-dark { background: #1a1a1a; color-scheme: dark; }
.art-frame.is-ready { opacity: 1; }
.art-compiler { position: fixed; left: -10000px; top: 0; width: 8px; height: 8px; border: 0; opacity: 0; pointer-events: none; }

/* 加载 / 渲染中 / 出错 */
.art-state {
  position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 24px; text-align: center; color: var(--text-2); font-size: 13px; background: var(--bg-page);
}
.art-state.is-loading { animation: art-fade-in .2s .18s both; }
.art-state-ic { color: var(--danger); }
.art-state-title { font-size: 14px; font-weight: 500; color: var(--text); }
.art-state-msg {
  max-width: min(640px, 100%); max-height: 55%; overflow: auto; margin: 0; padding: 10px 12px; text-align: left;
  border-radius: var(--r-md); background: var(--danger-bg); color: var(--text); font: 12.5px/1.55 var(--font-mono);
  white-space: pre-wrap; word-break: break-word;
}
.art-spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-2); border-top-color: var(--text-2); animation: art-spin .8s linear infinite; }
@keyframes art-spin { to { transform: rotate(360deg); } }
@keyframes art-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* 代码视图：行号 + 高亮，不换行，横向滚动 */
.art-code { flex: 1; min-height: 0; overflow: auto; background: var(--code-bg); overscroll-behavior: contain; }
.art-code:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.art-code-inner { display: flex; align-items: stretch; min-width: max-content; min-height: 100%; font: 13px/1.6 var(--font-mono); }
.art-gutter {
  position: sticky; left: 0; z-index: 1; margin: 0; padding: 14px 12px 32px 16px; min-width: 3.2em; text-align: right;
  color: var(--text-3); background: var(--code-bg); border-right: 1px solid var(--border); font: inherit; user-select: none;
}
.art-src { margin: 0; padding: 14px 32px 32px 14px; font: inherit; color: var(--text); white-space: pre; tab-size: 4; background: none; }
.art-src code { font: inherit; background: none; padding: 0; border: 0; color: inherit; white-space: inherit; }
.art-src .tok-c { color: var(--text-3); font-style: italic; }
.art-src .tok-k { color: #a6409b; }
.art-src .tok-s { color: #2f7d1f; }
.art-src .tok-n { color: #b35c00; }
:root[data-theme="dark"] .art-src .tok-k { color: #e08fd8; }
:root[data-theme="dark"] .art-src .tok-s { color: #9fd38d; }
:root[data-theme="dark"] .art-src .tok-n { color: #f0b36b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .art-src .tok-k { color: #e08fd8; }
  :root:not([data-theme="light"]) .art-src .tok-s { color: #9fd38d; }
  :root:not([data-theme="light"]) .art-src .tok-n { color: #f0b36b; }
}
.art-caret { display: inline-block; width: 7px; height: 1.15em; margin-left: 1px; vertical-align: text-bottom; background: var(--text-2); animation: art-blink 1s steps(1) infinite; }
@keyframes art-blink { 50% { opacity: 0; } }

/* Markdown 文档预览（在面板里直接渲染） */
.art-md-scroll { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; }
.art-md { max-width: 740px; margin: 0 auto; padding: 32px 40px 72px; font-family: var(--font-chat); font-size: 15.5px; line-height: 1.7; color: var(--text); }
@container artpanel (max-width: 520px) { .art-md { padding: 22px 20px 56px; } }

/* 提示条（已停止 / 修改失败）与运行错误条 */
.art-note { flex: none; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 8px 6px 14px; border-top: 1px solid var(--border); background: var(--bg-subtle); color: var(--text-2); font-size: 13px; }
.art-note.is-error { color: var(--danger); background: var(--danger-bg); }
.art-note-text { flex: 1; min-width: 0; }
.art-errbar { flex: none; border-top: 1px solid var(--border); background: var(--danger-bg); }
.art-err-main { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 10px 8px 14px; }
.art-err-ic { color: var(--danger); flex: none; }
.art-err-text { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.art-err-msg { min-width: 0; color: var(--danger); font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-err-count { flex: none; font-size: 12px; color: var(--text-3); }
.art-err-acts { flex: none; display: flex; align-items: center; gap: 4px; }
.art-link-btn { height: 28px; padding: 0 8px; border-radius: var(--r-sm); font-size: 12.5px; color: var(--text-2); }
.art-link-btn:hover { color: var(--text); background: var(--bg-hover); }
.art-err-detail {
  margin: 0; padding: 0 14px 12px 40px; max-height: 200px; overflow: auto; color: var(--text);
  font: 12px/1.55 var(--font-mono); white-space: pre-wrap; word-break: break-word;
}
@container artpanel (max-width: 520px) {
  .art-err-main { flex-wrap: wrap; row-gap: 4px; }
  .art-err-text { flex-basis: calc(100% - 30px); }
  .art-err-msg { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .art-err-acts { margin-left: auto; }
}

/* 此对话中的 Artifacts（列表） */
.art-list { flex: 1; min-height: 0; overflow: auto; padding: 10px; }
.art-list-items { display: flex; flex-direction: column; gap: 2px; }
.art-list-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px; border-radius: var(--r-lg); text-align: left; color: var(--text); }
.art-list-row:hover { background: var(--bg-hover); }
.art-list-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.art-list-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-list-sub { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-list-go { color: var(--text-3); }
.art-list .art-state { position: static; padding: 64px 24px; }

/* 外部链接确认框 */
.art-link-url {
  margin-top: 10px; padding: 8px 10px; border-radius: var(--r-md); background: var(--bg-subtle); box-shadow: inset 0 0 0 1px var(--border);
  font: 12.5px/1.5 var(--font-mono); color: var(--text); word-break: break-all; max-height: 120px; overflow: auto;
}

/* 全屏：盖住整个窗口 */
body.has-panel #artifactPanel.is-fullscreen { position: fixed; inset: 0; z-index: 80; width: auto !important; min-width: 0; max-width: none; border-left: 0; animation: none; }
#artifactPanel.is-fullscreen .art-resize { display: none; }

/* 手机：全屏的面板 */
@media (max-width: 767px) {
  body.has-panel #artifactPanel {
    position: fixed; inset: 0; z-index: 70; width: auto !important; min-width: 0; max-width: none; border-left: 0;
    padding-bottom: env(safe-area-inset-bottom); animation: art-sheet-in .22s var(--ease, ease) both;
  }
  .art-resize { display: none; }
  .art-card { max-width: 100%; }
}
@keyframes art-sheet-in { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Artifacts 页面（#/artifacts） ---------- */
.art-gallery { container: artgallery / inline-size; }
.art-g-tools { display: flex; align-items: center; gap: 4px; }
.art-g-search { width: 240px; }
.art-g-search .cl-i { flex: none; }
.art-g-search-input::-webkit-search-cancel-button { cursor: pointer; }
.art-g-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@container artgallery (max-width: 760px) { .art-g-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; } .art-g-search { width: 180px; } }
@container artgallery (max-width: 470px) { .art-g-grid { grid-template-columns: minmax(0, 1fr); } .art-g-search { width: 150px; } .art-g-row-type { display: none; } }
.art-g-card {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden; border-radius: var(--r-lg);
  background: var(--bg-page); box-shadow: inset 0 0 0 1px var(--border); color: var(--text); transition: box-shadow .15s, background-color .15s;
}
.art-g-card:hover { box-shadow: inset 0 0 0 1px var(--border-2), 0 2px 10px rgba(0, 0, 0, .06); }
.art-g-card:focus-visible { box-shadow: inset 0 0 0 1px var(--border-2), 0 0 0 2px var(--accent); }
.art-g-thumb { position: relative; aspect-ratio: 2 / 1; overflow: hidden; background: var(--bg-subtle); border-bottom: 1px solid var(--border); }
.art-g-thumb.is-blue { background: rgba(44, 132, 219, .13); }
.art-g-thumb.is-violet { background: rgba(124, 92, 214, .13); }
.art-g-thumb.is-green { background: rgba(47, 125, 31, .12); }
.art-g-thumb.is-amber { background: rgba(214, 140, 30, .15); }
.art-g-thumb.is-sand { background: rgba(190, 146, 86, .16); }
.art-g-thumb.is-gray { background: var(--bg-active); }
.art-g-page {
  position: absolute; left: 9%; right: 9%; top: 13%; bottom: -10px; overflow: hidden; border-radius: 7px 7px 0 0;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 1px rgba(0, 0, 0, .06); transition: transform .2s var(--ease, ease);
}
.art-g-card:hover .art-g-page { transform: translateY(-2px); }
.art-g-card[data-type="code"] .art-g-page { background: var(--code-bg); }
.art-g-card[data-type="markdown"] .art-g-page { background: var(--bg-elevated); }
:root[data-theme="dark"] .art-g-card[data-type="mermaid"] .art-g-page { background: #1a1a1a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .art-g-card[data-type="mermaid"] .art-g-page { background: #1a1a1a; } }
.art-g-ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: rgba(0, 0, 0, .28); }
.art-g-card[data-type="code"] .art-g-ph, .art-g-card[data-type="markdown"] .art-g-ph { color: var(--text-3); }
.art-g-page.has-frame .art-g-ph { display: none; }
.art-frame-thumb { position: absolute; left: 0; top: 0; inset: auto; transform-origin: 0 0; pointer-events: none; }
.art-g-text { position: absolute; inset: 0; margin: 0; padding: 10px 12px; overflow: hidden; color: var(--text-2); font: 9.5px/1.5 var(--font-mono); white-space: pre; }
.art-g-text.is-doc { font: 11px/1.55 var(--font-serif); white-space: pre-wrap; word-break: break-word; }
.art-g-meta { padding: 10px 12px 12px; min-width: 0; }
.art-g-name { font-size: 14px; line-height: 20px; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-g-sub { margin-top: 1px; font-size: 12px; line-height: 16px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-g-card.is-skel { pointer-events: none; }
.art-g-card.is-skel .art-g-thumb, .art-skel-line {
  background: linear-gradient(90deg, var(--bg-subtle), var(--bg-active), var(--bg-subtle)); background-size: 200% 100%; animation: art-skel 1.4s ease-in-out infinite;
}
.art-skel-line { height: 10px; width: 68%; margin: 5px 0; border-radius: 4px; }
.art-skel-line.is-short { width: 38%; }
@keyframes art-skel { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.art-g-list { display: flex; flex-direction: column; }
.art-g-row { display: flex; align-items: center; gap: 12px; min-height: 56px; margin: 0 -12px; padding: 0 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.art-g-row:hover { background: var(--bg-hover); border-radius: var(--r-md); }
.art-g-row .art-tile { width: 32px; height: 32px; }
.art-g-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.art-g-row-chat { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-g-row-type { flex: none; width: 160px; font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-g-row-time { flex: none; width: 88px; font-size: 13px; color: var(--text-3); text-align: right; white-space: nowrap; }
.art-g-empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 72px 24px; text-align: center; color: var(--text-2); }
.art-g-empty h3 { font: 400 20px/28px var(--font-serif); color: var(--text); }
.art-g-empty p { max-width: 380px; font-size: 14px; line-height: 21px; }
.art-g-empty .cl-btn { margin-top: 6px; }
.art-g-empty-ic { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; border-radius: 14px; background: var(--bg-active); color: var(--text-2); }
.art-g-more { display: flex; justify-content: center; padding: 28px 0 8px; }

/* ---------- 首页「最近的 Artifacts」 ---------- */
.art-recent { width: 100%; }
.art-recent-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; padding: 0 2px; font-size: 13px; color: var(--text-2); }
.art-recent-title { font-weight: 500; }
.art-recent-all { color: var(--text-2); border-radius: 6px; padding: 2px 4px; margin-right: -4px; }
.art-recent-all:hover { color: var(--text); background: var(--bg-hover); }
.art-recent-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.art-recent-card { max-width: none; min-height: 56px; padding: 8px 10px; gap: 10px; }
.art-recent-card .art-tile { width: 34px; height: 34px; }
@media (max-width: 640px) { .art-recent-row { grid-template-columns: minmax(0, 1fr); } }

@media (prefers-reduced-motion: reduce) {
  .art-card-sub.is-live, .art-status { animation: none; color: var(--text-2); background: none; }
  .art-caret { animation: none; }
  .art-frame, .art-g-page { transition: none; }
  body.has-panel #artifactPanel { animation: none; }
}
