/* archeon shared webviewcore styles
   Shared by admin and admin_phone. App shells supply the design tokens.
*/

/* webviewcore 변수 alias — Phase B-3-α-1에서 디자인 토큰(--bg-0..4 / --fg-0..3 / --accent / --violet)으로 매핑.
   webviewcore 발췌 코드가 var(--text), var(--bg) 등을 그대로 쓸 수 있도록 alias 정의.
   data-theme="dark|light"는 style.css의 :root / [data-theme="light"] 분기에서 토큰 자동 전환. */
:root {
  --text:           var(--fg-0);
  --text-primary:   var(--fg-0);
  --text-secondary: var(--fg-1);
  --text-muted:     var(--fg-3);
  --text-dim:       var(--fg-2);
  --bg:             var(--bg-0);
  --bg-primary:     var(--bg-0);
  --bg-secondary:   var(--bg-1);
  --bg-tertiary:    var(--bg-2);
  --bg-elevated:    var(--bg-3);
  --surface:        var(--bg-1);
  --border:         var(--line);
  --border-soft:    var(--line);
  --red:            var(--err);
  --green:          var(--ok);
  --orange:         var(--warn);
  --error:          var(--err);
  --success:        var(--ok);
  --wv-shadow-card: var(--shadow-card, 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25));
  --shadow-md:      var(--wv-shadow-card);
  --wv-msg-edge-gap: clamp(6px, 1.4vw, 14px);
  --wv-user-link-fg: var(--wv-theme-user-link-fg, var(--fg-0));
  --wv-user-link-underline: var(--wv-theme-user-link-underline, var(--accent-2, var(--accent)));
}

/* ───── 메시지 컨테이너 ───── */
.wv-messages-container {
  display: flex; flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}
.wv-empty {
  padding: 24px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  text-align: center;
}
.wv-empty .empty-title { margin: 0 0 6px; font-weight: 600; color: var(--text-secondary); }
.wv-empty .empty-sub { margin: 4px 0; font-size: 12px; line-height: 1.6; }

.wv-bottom-jump {
  position: fixed;
  z-index: 5000;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  left: 50%;
  right: auto;
  border: 1px solid color-mix(in oklab, var(--accent) 28%, transparent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: color-mix(in oklab, var(--accent) 62%, transparent);
  box-shadow: none;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 0.16s ease, transform 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}
.wv-bottom-jump.is-visible {
  opacity: 0.34;
  pointer-events: auto;
  transform: translate(-50%, 0);
}
.wv-bottom-jump:hover {
  opacity: 0.72;
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.wv-bottom-jump svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

/* ───── wv-msg base + role 변형 (admin dark 톤) ───── */
.wv-msg {
  padding: 8px 10px 4px;
  border-radius: 8px;
  margin-left: var(--wv-msg-edge-gap);
  margin-right: var(--wv-msg-edge-gap);
  margin-bottom: 4px;
  /* B-2-c (owner 정정): messageFont 슬라이더 즉시 반영. var fallback 13px. */
  font-size: var(--msg-font-size, 13px);
  line-height: 1.5;
  word-wrap: break-word;
}
.wv-msg[data-last="1"] {
  margin-bottom: 1px;
}
/* 정보 밀도(tight)에서 메시지 카드 padding/margin 축소 */
html[data-density="tight"] .wv-msg {
  padding: 4px 8px 3px;
  margin-bottom: 2px;
  line-height: 1.35;
}
html[data-density="tight"] .wv-msg[data-last="1"] {
  margin-bottom: 1px;
}
/* ctx threshold colors. Input meta overrides token color; footer meta owns ctx color. */
.wv-tokens.wv-ctx-warn {
  color: var(--warn);
  font-weight: 600;
}
.wv-tokens.wv-ctx-mid {
  color: var(--warn);
  font-weight: 600;
}
.wv-tokens.wv-ctx-high {
  color: var(--warn);
  font-weight: 600;
}
.wv-tokens.wv-ctx-critical {
  color: var(--err);
  font-weight: 700;
  text-shadow: 0 0 6px color-mix(in oklab, var(--err) 75%, transparent);
  animation: wv-ctx-pulse 1.2s ease-in-out infinite;
}
@keyframes wv-ctx-pulse {
  0%, 100% { opacity: 1;    text-shadow: 0 0 6px color-mix(in oklab, var(--err) 75%, transparent); }
  50%      { opacity: 0.55; text-shadow: 0 0 14px var(--err); }
}
html[data-theme="light"] .wv-tokens.wv-ctx-critical {
  text-shadow: 0 0 4px color-mix(in oklab, var(--err) 60%, transparent);
}

/* B-3-α-4-B-2 (2026-05-04 owner 정정): 색 분리 다시 적용 (owner: "서로 다른게 낫지 않아? 알아서 해").
   user = accent(테마 프리셋과 동기) 미세 톤, assistant = violet 미세 톤. margin은 5%만. */
.wv-msg.user {
  background: color-mix(in oklab, var(--accent) 10%, var(--bg-secondary));
  border: 1px solid var(--accent-line);
  margin-left: max(5%, var(--wv-msg-edge-gap));
}
.wv-msg.assistant {
  /* B-2 정정 (owner): 보라 톤 폐지 — 입력창 바탕색 계열(--bg-2) + 약간 어둡게. */
  background: var(--bg-2);
  border: 1px solid var(--line);
  margin-right: max(5%, var(--wv-msg-edge-gap));
}
.wv-msg.system {
  background: color-mix(in oklab, var(--warn) 5%, transparent);
  border: 1px solid color-mix(in oklab, var(--warn) 12%, transparent);
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 4px 8px;
}
.wv-msg a { color: var(--accent); text-decoration: underline; }
.wv-msg .wv-channel-label {
  display: inline-block;
  color: var(--accent);
  font-size: calc(1em - 2px);
  font-weight: 600;
}

/* URL 자동 링크 호버 액션 */
.wv-msg .url-wrap { display: inline; position: relative; }
.wv-msg .url-text { color: var(--accent); word-break: break-all; }
.wv-msg .url-actions {
  display: inline-flex; align-items: center; gap: 2px;
  margin-left: 2px; opacity: 0; transition: opacity 0.2s;
  vertical-align: middle;
}
.wv-msg .url-wrap:hover .url-actions { opacity: 1; }
.wv-msg .url-btn {
  font-size: 11px; padding: 1px 3px; border: none; background: none;
  cursor: pointer; border-radius: 3px; line-height: 1;
}
.wv-msg .url-btn:hover { background: var(--accent-soft); }
.wv-msg .url-open { text-decoration: none; color: var(--accent); }
.wv-msg.user a,
.wv-msg.user .url-text,
.wv-msg.user .url-open,
.wv-msg.user .msg-file-name,
.wv-msg.user .msg-file-link,
.wv-msg.user .wv-attach-chip,
.wv-msg.user .wv-image-preview-link {
  color: var(--wv-user-link-fg) !important;
  text-decoration-color: var(--wv-user-link-underline) !important;
}

.msg-file-list.is-collapsible {
  margin: 3px 0 2px;
}
.msg-file-list.is-collapsible > summary {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 6px;
  border: 1px solid color-mix(in oklab, var(--accent) 22%, transparent);
  border-radius: 4px;
  color: var(--accent);
  background: color-mix(in oklab, var(--accent) 7%, transparent);
  font-size: calc(1em - 3px);
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
}
.msg-file-list.is-collapsible > summary:hover {
  border-color: var(--accent-line);
  background: color-mix(in oklab, var(--accent) 11%, transparent);
}
.msg-file-list.is-collapsible .msg-file-list-body {
  margin-top: 3px;
}

.wv-msg strong { color: var(--accent-2); font-weight: 600; }
.wv-msg code {
  font-family: "Menlo","Consolas",monospace; font-size: 12px;
  background: var(--wv-theme-code-bg, color-mix(in oklab, var(--accent) 8%, var(--bg-tertiary))); padding: 1px 4px; border-radius: 3px;
}
.wv-msg pre {
  white-space: pre-wrap;
  font-family: "Menlo","Consolas",monospace; font-size: 12px;
  background: var(--bg-tertiary); padding: 8px; border-radius: 6px;
  border: 1px solid var(--border); margin: 0; overflow-x: auto;
}
.wv-msg pre code { background: none; padding: 0; }

/* ───── 코드블록 (lang label + copy button) ───── */
.code-block { position: relative; margin: 4px 0; }
/* B-2-c: 코드 블록 폰트 크기 변수 (Tweaks 슬라이더 10~16px) */
.code-block pre, .code-block code, .wv-body code {
  font-size: var(--code-font-size, 12px);
}
/* B-2-c: 줄바꿈 시각화 (data-show-breaks="1") — assistant body pre-wrap + ↵ 마커 */
html[data-show-breaks="1"] .wv-msg.assistant .wv-body { white-space: pre-wrap; }
html[data-show-breaks="1"] .wv-msg .wv-body br::after {
  content: ' ↵';
  color: var(--fg-3);
  font-size: 0.85em;
  opacity: 0.6;
}
.code-block .code-lang {
  position: absolute; top: 4px; left: 8px;
  font-size: 9px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.code-copy-btn {
  position: absolute; top: 4px; right: 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 4px; padding: 2px 6px;
  cursor: pointer; font-size: 12px; line-height: 1;
  opacity: 0.5; transition: opacity 0.15s;
}
.code-block:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:active { background: var(--bg-elevated); }

/* ───── thinking / tools fold ───── */
.wv-msg .thinking-wrap { margin: 1px 0 2px; }
.wv-msg .thinking-wrap summary {
  font-size: 9.5px; color: var(--text-muted); cursor: pointer;
  line-height: 1.1;
}
.wv-msg .thinking-content {
  font-size: 9.5px; color: var(--text-secondary);
  padding: 2px 5px; margin-top: 1px;
  background: var(--bg-tertiary);
  border-left: 1px solid var(--border);
  border-radius: 3px;
  max-height: 3.4em; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  line-height: 1.15;
}
.wv-msg .tools-fold { margin: 1px 0; }
.wv-msg .tools-fold summary {
  font-size: 9.5px; color: var(--accent); cursor: pointer;
  user-select: none; padding: 1px 4px;
  background: var(--accent-soft); border-radius: 3px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wv-msg .tools-fold summary:active { background: color-mix(in oklab, var(--accent) 18%, transparent); }
.wv-msg .tools-list {
  padding: 1px 0 1px 4px;
  border-left: 1px solid var(--accent);
  margin: 1px 0 1px 2px;
}
.wv-msg .tool-item {
  display: flex;
  gap: 4px;
  min-width: 0;
  padding: 0 3px;
  margin: 0;
  font-size: 9.5px;
  line-height: 1.15;
}
.wv-msg .wv-live-progress,
.wv-live-progress-bar .wv-live-progress {
  display: block;
  max-width: 100%;
  min-height: 0;
  border: 1px solid color-mix(in oklab, var(--accent) 22%, transparent);
  border-radius: 4px;
  padding: 1px 5px;
  margin: 1px 0 1px;
  color: var(--text-secondary);
  background: color-mix(in oklab, var(--accent) 7%, transparent);
  font-size: 10.5px;
  line-height: 1.15;
  overflow: hidden;
}
.wv-msg .wv-live-progress.is-empty,
.wv-live-progress-bar.is-empty {
  opacity: 0.55;
}
.wv-msg .wv-live-label,
.wv-live-progress-bar .wv-live-label {
  display: block;
  max-height: 1.2em;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wv-live-progress-bar {
  display: block;
  flex: 0 0 18px;
  min-height: 0;
  max-height: 18px;
  margin: -6px 4px 1px;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}
.wv-live-progress-bar .wv-live-progress {
  width: calc(100% - 4ch);
  margin: 1px auto;
}
.wv-live-progress-bar .wv-live-thinking .wv-live-label {
  text-align: center;
  color: var(--accent);
}
.wv-live-progress-bar .wv-live-tool-kind {
  color: var(--accent);
  font-weight: 600;
}
.wv-tmux-activity-bar {
  display: flex;
  align-items: center;
  position: sticky;
  bottom: 2px;
  z-index: 3;
  flex: 0 0 14px;
  height: 14px;
  box-sizing: border-box;
  min-height: 0;
  max-height: 14px;
  margin: -6px 4px 1px;
  padding: 0 5px 0 calc(5px + 5ch);
  border: 0;
  border-radius: 4px;
  color: var(--text-secondary);
  background: color-mix(in oklab, var(--accent) 7%, transparent);
  font-size: 9.5px;
  line-height: 12px;
  overflow: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
  user-select: none;
}
.wv-tmux-activity-bar.is-empty {
  opacity: 0.55;
}
.wv-tmux-activity-glyph {
  flex: 0 0 auto;
  margin-right: 2px;
  font-weight: 700;
}
.wv-tmux-activity-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wv-input-bottom-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 10px;
}
.wv-input-bottom-row .wv-input-status.wv-tmux-activity-bar {
  position: static;
  z-index: auto;
  flex: 1 1 auto;
  height: 10px;
  min-height: 10px;
  max-height: 10px;
  margin: 0;
  padding: 0 0 0 calc(4px + 4ch);
  border: 0;
  border-radius: 0;
  color: var(--text-secondary);
  background: transparent;
  font-size: 10px;
  line-height: 10px;
}
.wv-input-bottom-row .wv-input-meta {
  flex: 0 1 auto;
  margin-left: auto;
  max-width: 58%;
}
.wv-tmux-activity-glyph-amber {
  color: #f6c453;
}
.wv-tmux-activity-glyph-cyan {
  color: #38d5d5;
}
.wv-tmux-activity-glyph-green {
  color: #7bd66f;
}
.wv-tmux-activity-glyph-violet {
  color: #c084fc;
}
.wv-tmux-activity-glyph-default {
  color: var(--accent);
}
.wv-msg .wv-live-thinking .wv-live-label {
  display: inline-flex;
  flex-wrap: wrap;
  white-space: normal;
}
.wv-msg .wv-live-char {
  display: inline-block;
  animation: wv-live-char 1.25s ease-in-out infinite;
  animation-delay: calc(var(--i) * 65ms);
  transform-origin: 50% 70%;
}
.wv-msg .wv-smooth-typing {
  white-space: pre-wrap;
}
.wv-msg .wv-smooth-typing.is-typing::after {
  content: '';
  display: inline-block;
  width: 1.5px;
  height: 1.1em;
  margin-left: 2px;
  vertical-align: -0.18em;
  background: var(--accent);
  border-radius: 1px;
  animation: wv-type-caret 0.86s steps(1, end) infinite;
}
@keyframes wv-live-char {
  0%, 70%, 100% { transform: scale(1); opacity: 0.72; }
  35% { transform: scale(1.18); opacity: 1; }
}
@keyframes wv-type-caret {
  0%, 48% { opacity: 1; }
  49%, 100% { opacity: 0; }
}
.wv-msg .tool-name {
  color: var(--accent); font-weight: 600;
  font-family: "Menlo","Consolas",monospace; font-size: 9.5px;
  flex: 0 0 auto;
}
.wv-msg .tool-preview {
  color: var(--text-muted); font-size: 9.5px; margin-top: 0;
  word-break: normal; max-height: 1.2em; overflow: hidden;
  font-family: "Menlo","Consolas",monospace;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

/* ───── 메시지 footer 액션 버튼 (M / C) — macmini 정본 wv-act-btn 패턴 ───── */
.wv-footer .wv-act-btn { opacity: 0; transition: opacity 0.15s; }
.wv-msg:hover .wv-footer .wv-act-btn { opacity: 1; }
.wv-act-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 18px; min-width: 18px; padding: 0 4px;
  margin-left: 2px;
  font-family: 'Geist Mono', "Menlo", "Consolas", monospace;
  font-size: 10px; font-weight: 600;
  color: var(--fg-2);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: 0.05em;
}
.wv-act-btn:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.wv-act-btn:active { background: color-mix(in oklab, var(--accent) 18%, transparent); color: var(--fg-0); }

/* ───── toast (CP/MD 결과 표시) ───── */
.wvc-toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 8px 16px;
  background: var(--bg-3);
  color: var(--fg-0);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: 12px;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
  z-index: 9999;
}
.wvc-toast.show { opacity: 0.95; }

/* ───── 본문 + 푸터 ───── */
.wv-inner { position: relative; }
.wv-body { white-space: normal; word-break: break-word; }
.wv-body.wv-live-plain { white-space: pre-wrap; }
/* B-2 정정 (2026-05-04 owner): user 입력은 plain text + Shift+Enter 줄바꿈을 시각적으로 보존.
   백엔드는 이미 \n 보존. CSS white-space: normal이면 HTML 표시상 \n이 공백으로 무시 → 한 줄로 보임.
   user 카드만 pre-wrap. assistant는 마크다운 단락(\n\n) 그대로. */
.wv-msg.user .wv-body { white-space: pre-wrap; }
.wv-user-collapsible {
  --wv-user-collapsed-lines: 8;
  --wv-user-fade-bg: var(--wv-user-bubble-bg, color-mix(in oklab, var(--accent) 10%, var(--bg-secondary)));
}
.wv-user-collapsible .wv-user-full {
  display: none;
}
.wv-user-collapsible.is-expanded .wv-user-preview {
  display: none;
}
.wv-user-collapsible.is-expanded .wv-user-full {
  display: block;
}
.wv-user-preview {
  position: relative;
  padding-bottom: 2px;
}
.wv-user-preview-body {
  max-height: calc(1.5em * var(--wv-user-collapsed-lines));
  overflow: hidden;
}
.wv-user-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  height: 5.2em;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    color-mix(in oklab, var(--wv-user-fade-bg) 0%, transparent) 0%,
    color-mix(in oklab, var(--wv-user-fade-bg) 72%, transparent) 62%,
    var(--wv-user-fade-bg) 100%
  );
}
.wv-msg.user .wv-user-preview,
.wv-msg.user .wv-user-full,
.wv-msg.user .wv-user-preview-body {
  white-space: pre-wrap;
}
.wv-user-toggle {
  display: inline-flex;
  align-items: center;
  position: relative;
  z-index: 1;
  min-height: 17px;
  margin: 1px 0 0;
  padding: 0 4px;
  border: 0;
  border-radius: 3px;
  color: var(--accent);
  background: transparent;
  font: inherit;
  font-size: calc(1em - 3px);
  line-height: 1.3;
  cursor: pointer;
  opacity: 0.9;
}
.wv-user-toggle:hover {
  opacity: 1;
  background: color-mix(in oklab, var(--accent) 8%, transparent);
}
.wv-superpowers-label {
  display: block;
  margin: 0 0 4px;
  color: var(--accent);
  font-size: calc(1em - 3px);
  line-height: 1.25;
  font-weight: 600;
  opacity: 0.9;
}
.wv-body br { line-height: 1.3; }
.wv-body .p-gap { margin: 8px 0; }
.wv-body p { margin: 10px 0 0 0; }
.wv-body p:first-child { margin-top: 0; }
.wv-mne-block {
  margin: 8px 0;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-left-width: 3px;
  border-radius: 6px;
  background: color-mix(in oklab, var(--bg-secondary) 88%, var(--accent) 12%);
}
.wv-mne-block-label {
  margin-bottom: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
}
.wv-mne-block-body {
  color: var(--text-primary);
}
.wv-mne-important {
  border-left-color: var(--warn);
}
.wv-mne-question {
  border-left-color: var(--accent);
}

.wv-footer {
  display: flex; align-items: center;
  margin-top: 1px; padding-top: 2px;
  border-top: 1px solid var(--border-soft);
  line-height: 1;
  min-width: 0;
  /* 푸터 누수 차단 (2026-05-06): 사용자가 메시지 본문을 마우스 드래그로
     선택해 Ctrl+C 복사할 때, 시각/ctx/날짜/CP/MD 텍스트가 함께 클립보드에
     실리던 회귀를 막는다. user-select는 자식(.wv-time/.wv-tokens/.wv-date/
     .wv-act-btn)에 상속되므로 한 줄로 푸터 전체가 비선택. CP 버튼은
     클릭으로 동작하므로 선택 차단의 영향을 받지 않는다 (data-raw 기반
     WebviewCore.copyMsg는 본문만 복사). */
  user-select: none;
  -webkit-user-select: none;
}
.wv-footer-top {
  display: flex; align-items: center; gap: 4px; width: 100%;
  flex-wrap: nowrap; min-width: 0;
  line-height: 1;
}
.wv-footer-spacer {
  flex: 1 1 auto;
  min-width: 0;
}
.wv-time, .wv-tokens, .wv-tool-count, .wv-date {
  font-size: 10px; color: var(--text-secondary);
  font-family: inherit; font-weight: 500;
  flex: 0 0 auto;
  line-height: 1;
}
.wv-tool-count {
  color: var(--accent);
  opacity: 0.88;
}
.wv-date {
  opacity: 0; transition: opacity 0.15s;
}
.wv-msg:hover .wv-date { opacity: 0.7; }

/* ───── agent meta footer (ctx · 5h · 주 · N턴) ─────
   배치: 시계 바로 뒤, 좌측 정렬. 날짜/M/C는 우측 hover cluster로 분리. */
.wv-agent-meta {
  font-size: 10px; color: var(--text-secondary);
  font-family: inherit; font-weight: 500;
  line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 0 1 auto; min-width: 0;
  text-align: left;
  margin-left: 0;
  padding-right: 4px;
  opacity: 0.92;
}
.wv-agent-meta .wv-tokens {
  color: inherit;
  animation: none;
  text-shadow: inherit;
}
.wv-agent-meta.wv-ctx-warn {
  color: var(--warn);
}
.wv-agent-meta.wv-ctx-mid {
  color: var(--warn);
}
.wv-agent-meta.wv-ctx-high {
  color: var(--warn);
}
.wv-agent-meta.wv-ctx-critical {
  color: var(--err);
  text-shadow: 0 0 8px color-mix(in oklab, var(--err) 45%, transparent);
  animation: wv-ctx-pulse 1.2s ease-in-out infinite;
}

/* ───── 마크다운 표 ───── */
.table-wrap { overflow-x: auto; margin: 6px 0; }
.wv-table {
  font-size: 11px; border-collapse: collapse;
  background: var(--bg-tertiary); border-radius: 6px; width: 100%;
}
.wv-table th, .wv-table td {
  padding: 4px 8px; border: 1px solid var(--border);
}
.wv-table th {
  background: var(--bg-elevated); font-weight: 600;
  color: var(--accent-2); text-align: left;
}
.wv-table td { color: var(--text-primary); }
.wv-table tbody tr:hover { background: var(--bg-elevated); }

/* ───── compact divider ───── */
.wv-msg.compact {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  margin: 16px 4px !important;
}
.wv-compact-divider {
  display: flex; align-items: center; gap: 12px; opacity: 0.55;
}
.wv-compact-divider::before,
.wv-compact-divider::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.wv-compact-divider span {
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap; letter-spacing: 0.3px;
}

/* ───── 첨부 chip ───── */
.wv-attach-wrap {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed color-mix(in oklab, var(--warn) 25%, transparent);
}
.wv-attach-label {
  font-size: 11px; color: var(--warn);
  margin-bottom: 6px; letter-spacing: 0.3px;
}
.wv-attach-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.wv-attach-chip {
  display: inline-flex; align-items: center;
  max-width: 100%; padding: 5px 10px; font-size: 12px;
  color: var(--warn);
  background: color-mix(in oklab, var(--warn) 8%, transparent);
  border: 1px solid color-mix(in oklab, var(--warn) 25%, transparent);
  border-radius: 14px; cursor: pointer; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wv-attach-chip:hover { background: color-mix(in oklab, var(--warn) 16%, transparent); border-color: color-mix(in oklab, var(--warn) 50%, transparent); }
.wv-attachment-queue {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0 2px;
}
.wv-attachment-queue[hidden] { display: none; }
.wv-aq-card {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 7px;
  min-width: 150px;
  max-width: 260px;
  min-height: 50px;
  padding: 5px;
  border: 1px solid color-mix(in oklab, var(--border) 76%, var(--accent));
  border-radius: 8px;
  background: color-mix(in oklab, var(--bg-tertiary) 90%, var(--accent));
  color: var(--text-primary);
}
.wv-aq-thumb {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.wv-aq-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.wv-aq-body { min-width: 0; }
.wv-aq-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.25;
}
.wv-aq-meta {
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 10px;
}
.wv-aq-remove {
  width: 18px;
  height: 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}
.wv-aq-remove:hover {
  color: var(--err);
  border-color: color-mix(in oklab, var(--err) 42%, transparent);
}
.is-attachment-dragover {
  outline: 1px dashed var(--accent);
  outline-offset: 3px;
}
.wv-image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.wv-image-preview-link {
  display: block;
  overflow: hidden;
  border: 1px solid color-mix(in oklab, var(--warn) 25%, transparent);
  border-radius: 8px;
  background: var(--bg-tertiary);
}
.wv-image-preview {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

/* 파일 첨부/검증 링크 행 표시 */
.msg-file-list {
  display: grid;
  gap: 3px;
  margin-top: 4px;
}
.msg-file-attach {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 2px 4px;
  border: 1px solid color-mix(in oklab, var(--accent) 14%, transparent);
  border-radius: 5px;
  background: color-mix(in oklab, var(--accent) 5%, transparent);
  opacity: 0.9;
  line-height: 1.25;
}
.msg-file-label {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 10px;
}
.msg-file-name {
  min-width: 0;
  color: var(--accent);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-file-path {
  grid-column: 2 / 3;
  display: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  opacity: 0.86;
}
.msg-file-ambiguous {
  color: var(--warn);
  font-size: 10px;
  white-space: nowrap;
  justify-self: end;
}
.msg-file-link {
  min-width: 0;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}
.msg-file-actions {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  flex: 0 0 auto;
  justify-self: end;
}
.msg-file-btn {
  appearance: none;
  border: 1px solid color-mix(in oklab, var(--accent) 24%, transparent);
  border-radius: 4px;
  background: color-mix(in oklab, var(--accent) 7%, transparent);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  padding: 3px 5px;
}
.msg-file-btn:hover {
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 48%, transparent);
  background: color-mix(in oklab, var(--accent) 12%, transparent);
}
.msg-file-btn:disabled {
  cursor: default;
  color: var(--text-muted);
  border-color: color-mix(in oklab, var(--text-muted) 16%, transparent);
  background: transparent;
  opacity: 0.45;
}
@media (max-width: 720px) {
  .msg-file-attach {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }
  .msg-file-name {
    font-size: 10px;
  }
}

/* ───── view mode toggle (raw / rendered) ───── */
.wv-mode-toggle {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 0;
  font-size: 11px;
}
.wv-mode-toggle .mode-label {
  color: var(--text-muted); margin-right: 4px;
}
.wv-mode-toggle button {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 8px;
  cursor: pointer; font-size: 11px;
}
.wv-mode-toggle button.is-active {
  background: var(--accent); color: var(--accent-contrast); border-color: var(--accent);
}
.wv-mode-toggle .mode-stat { margin-left: auto; color: var(--text-muted); }

/* copied toast (작은 piece, 좌측 webview body 위로 표시) */
#wvc-copied-toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 12px;
  box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s;
  z-index: 9999;
}
#wvc-copied-toast.show { opacity: 1; }

.image-workbench-panel[hidden] {
  display: none !important;
}
.image-workbench-panel {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 28px);
}
.iw-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim-strong);
  backdrop-filter: blur(3px);
}
.iw-shell {
  position: relative;
  width: min(760px, 100%);
  height: min(760px, calc(100vh - 28px));
  max-height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
}
.iw-head {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.iw-status {
  min-width: 0;
  color: var(--text-muted);
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}
.iw-status[data-kind="err"] { color: var(--err); }
.iw-status[data-kind="warn"] { color: var(--warn); }
.iw-status[data-kind="ok"] { color: var(--accent); }
.iw-refresh,
.iw-close,
.iw-create {
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
}
.iw-refresh,
.iw-close {
  width: 30px;
  height: 30px;
  border-radius: 6px;
}
.iw-refresh:hover,
.iw-close:hover,
.iw-create:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.iw-create {
  align-self: flex-start;
  margin: 10px 12px 0;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.iw-list {
  overflow: auto;
  padding: 10px 12px 14px;
  min-height: 120px;
  flex: 1 1 auto;
}
.iw-empty {
  padding: 20px 4px;
  color: var(--text-muted);
  font-size: 13px;
}
.iw-session {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.iw-session-title {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.iw-session-title:hover {
  color: var(--accent);
}
.iw-session-meta {
  color: var(--text-muted);
  font-size: 11px;
}
.iw-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 42px;
}
.iw-thumb {
  width: 56px;
  height: 42px;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
}
.iw-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.iw-no-thumb {
  align-self: center;
  color: var(--text-muted);
  font-size: 11px;
}
.iw-composer {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border-soft);
  background: color-mix(in oklab, var(--bg-elevated) 94%, var(--accent));
}
.iw-compose-head {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}
.iw-compose-head button {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
}
.iw-compose-head button:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.iw-composer textarea {
  width: 100%;
  min-height: 62px;
  max-height: 180px;
  resize: vertical;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 10px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font: inherit;
  line-height: 1.45;
}
.iw-composer textarea:focus {
  outline: none;
  border-color: var(--accent);
}

@media (max-width: 680px) {
  .image-workbench-panel {
    align-items: center;
    padding: 8px;
  }
  .iw-shell {
    width: 100%;
    height: calc(var(--phone-viewport-h, 100dvh) - 16px);
    max-height: calc(var(--phone-viewport-h, 100dvh) - 16px);
  }
  .iw-list {
    min-height: 0;
    max-height: none;
  }
  .iw-head {
    grid-template-columns: 1fr auto auto;
  }
  .iw-status {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
  }
}
