/* Chat 페이지 레이아웃 */
.chat-layout {
    display: flex;
    height: calc(100vh - 3rem);
}

.chat-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-messages-inner {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 100%;
    padding: 1rem;
    border-radius: 8px;
    line-height: 1.5;
    overflow: hidden;
}

/* "내 피드백" 에서 점프해 들어왔을 때 대상 답변을 잠깐 강조 (2s 후 JS 가 제거). */
.message.msg-feedback-flash {
    animation: msgFeedbackFlash 2s ease-out;
}
@keyframes msgFeedbackFlash {
    0%, 30% { background: var(--color-info-bg, #eff6ff); box-shadow: 0 0 0 2px var(--color-primary-light, #94a3b8); }
    100% { background: transparent; box-shadow: 0 0 0 2px transparent; }
}

.system-message, .ai-message {
    align-self: flex-start;
    background: transparent;
    color: #212529;
    border-bottom-left-radius: 0;
}

.user-message {
    align-self: flex-end;
    background: #f1f3f5;
    color: #212529;
    border-bottom-right-radius: 0;
}

/* 입력 영역 */
.chat-input-area {
    padding: 0.625rem 1.5rem 0.625rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--color-bg);
    position: relative;
}

/* ↓ 스크롤 to bottom 버튼 — 응답 생성 중 사용자가 위로 스크롤한 상태에서
   chat-input-inner (max-width 800px 박스) 의 우측 상단에 floating. 화면 우측
   끝이 아닌 *입력창 우측 끝* 에 정렬. 클릭하면 바닥으로 스크롤 + auto-follow
   모드 복귀. */
.scroll-to-bottom-btn {
    position: absolute;
    right: 0;
    top: -2.75rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--color-bg);
    border: 1px solid var(--color-border, #e5e7eb);
    color: var(--color-text, #1e293b);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: background 0.15s, transform 0.1s;
    z-index: 10;
}
.scroll-to-bottom-btn:hover {
    background: var(--color-bg-hover, #f1f5f9);
}
.scroll-to-bottom-btn:active {
    transform: scale(0.95);
}

.chat-input-inner {
    max-width: 800px;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem 0.75rem;
    background: var(--color-bg-secondary);
    /* exec-trace 와 동일한 외곽 border — 시각 톤 통일. */
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 1rem;
    cursor: text;
    position: relative; /* mention-picker absolute 기준 */
}

#image-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

#chat-input {
    width: 100%;
    /* 한 줄 (line-height 1.5 * font-size 1rem = 1.5rem) 정확히 맞도록 — 빈 상태에서
       textarea 가 헐겁게 부풀어 row 가 들썩이지 않게. autoResize 가 입력 길이에
       따라 확장 (1.5rem → 최대 15rem). */
    min-height: 1.5rem;
    max-height: 15rem;
    padding: 0;
    border: none;
    resize: none;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    background: transparent;
    overflow-y: hidden;
}

#chat-input:focus {
    outline: none;
}

#chat-input::placeholder {
    color: var(--color-text-muted, #94a3b8);
}

.input-buttons {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding-top: 0.5rem;
    /* send 버튼이 토글 (보임/숨김) 되어도 row 높이가 변하지 않도록 명시적 높이 예약.
       image-btn / send-btn 모두 1.75rem 정사각이라 1.75rem + 살짝의 여유. */
    min-height: 1.75rem;
}

#image-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    background: none;
    color: var(--color-text-muted, #94a3b8);
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 300;
    line-height: 1;
}

#image-btn:hover { background: var(--color-bg, #f0f0f0); color: var(--color-text); }
#image-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* PDF attach button — same square footprint as image-btn so the input-buttons
   row keeps a stable height. icon-only (SVG + tiny "PDF" label inside). */
#pdf-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    background: none;
    color: var(--color-text-muted, #94a3b8);
    border: none;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}
#pdf-btn:hover { background: var(--color-bg, #f0f0f0); color: var(--color-text); }
#pdf-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#pdf-input { display: none; }

#send-btn {
    margin-left: 0;
    align-items: center;
    justify-content: center;
    /* image-btn 과 같은 1.75rem 정사각으로 고정 — 토글되어 나타나도 row 높이 안 변함.
       svg 는 1.25rem → padding 0.25rem 으로 끼움. */
    width: 1.75rem;
    height: 1.75rem;
    padding: 0.25rem;
    background: var(--slate-700, #334155);
    color: white;
    border: none;
    border-radius: 35%;
    cursor: pointer;
}
#send-btn svg { width: 1.05rem; height: 1.05rem; }

#send-btn:hover {
    background: var(--slate-800, #1e293b);
}

#send-btn:disabled {
    background: var(--slate-300);
    cursor: not-allowed;
    opacity: 0.7;
}

#send-btn.stop-mode {
    background: var(--color-error, #dc2626);
}
#send-btn.stop-mode:hover {
    background: #b91c1c;
}

#chat-input:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* 능력 요약 + 모델 선택기 + 마이크 를 좌/우로 가르는 신축 공간. */
.input-buttons-spacer { flex: 1 1 auto; }

/* 능력(스킬·MCP) 선택 개수 요약 — 참고용, 클릭 불가. 가볍게 muted. */
.cap-summary {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    color: var(--color-text-muted, #94a3b8);
    line-height: 1;
    white-space: nowrap;
}
.cap-summary .dot {
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--agent-skill-accent, #10b981);
}

/* 모델 선택 pill (우측 하단). */
.model-selector-slot { display: inline-flex; align-items: center; }
.model-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border: none;
    background: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.8125rem;
    color: var(--color-text, #334155);
    cursor: pointer;
    line-height: 1;
    max-width: 14rem;
}
.model-chip:hover { background: var(--color-bg-subtle, #f1f5f9); }
.model-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-chip .caret { color: var(--color-text-muted, #94a3b8); font-size: 9px; }

/* 모델 선택 popover 의 선택 표시. */
.model-menu .model-check { margin-left: 8px; color: var(--agent-skill-accent, #10b981); font-weight: 700; }

/* 마이크 (음성 입력). send-btn 과 같은 1.75rem 정사각. */
.mic-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    background: none;
    color: var(--color-text-muted, #94a3b8);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
}
.mic-btn:hover { background: var(--color-bg-subtle, #f1f5f9); color: var(--color-text, #334155); }
.mic-btn.recording {
    color: #fff;
    background: var(--color-error, #dc2626);
    animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
    50% { box-shadow: 0 0 0 5px rgba(220, 38, 38, 0); }
}

/* 입력 안내 텍스트 */
.chat-input-info {
    max-width: 800px;
    width: 100%;
    text-align: center;
    font-size: 0.7rem;
    color: var(--color-text-muted, #94a3b8);
    padding-top: 0.375rem;
}

/* 타이핑 인디케이터 */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0.25rem 0;
}

.typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* 이미지 프리뷰 */
.image-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.image-preview:empty { display: none; margin-bottom: 0; }

/* @ Mention chip stack — textarea 위에 노출되는 참조 칩 영역 */
.mention-chip-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.mention-chip-stack:empty { display: none; margin-bottom: 0; }
.mention-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.5rem 0.25rem 0.6rem;
    background: var(--color-bg-tertiary, #e0e7ff);
    border: 1px solid var(--color-border, #c7d2fe);
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--color-text);
    max-width: 280px;
}
.mention-chip .mention-icon {
    color: var(--color-text-muted, #64748b);
    flex-shrink: 0;
}
.mention-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mention-chip-remove {
    border: none;
    background: transparent;
    color: var(--color-text-muted, #64748b);
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0 0.15rem;
    line-height: 1;
}
.mention-chip-remove:hover { color: var(--color-text); }

/* @ Mention picker — textarea 위 floating panel */
.mention-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 0.5rem;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    flex-direction: column;
    max-height: 320px;
    z-index: 100;
}
.mention-picker-search {
    margin: 0.5rem 0.75rem 0;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 0.375rem;
    font-size: 0.85rem;
    outline: none;
}
.mention-picker-search:focus {
    border-color: var(--color-primary, #2563eb);
}
.mention-picker-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0.5rem 0.5rem;
}
.mention-picker-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: 0.375rem;
    cursor: pointer;
}
.mention-picker-row:hover,
.mention-picker-row.mention-active { background: var(--color-bg-secondary); }
.mention-picker-row.mention-active { outline: 1px solid var(--color-border, #c7d2fe); }
.mention-picker-row .mention-icon {
    color: var(--color-text-muted, #64748b);
    flex-shrink: 0;
}
/* 파일 row 는 부모 지식 아래로 살짝 들여쓰기 — 시각적 그룹핑 */
.mention-picker-row-file { padding-left: 1.25rem; }
.mention-picker-meta {
    font-size: 0.7rem;
    color: var(--color-text-muted, #94a3b8);
    flex-shrink: 0;
    max-width: 40%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mention-picker-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.85rem;
}
.mention-picker-empty {
    padding: 1rem 0.75rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.preview-item {
    position: relative;
    display: inline-block;
}

.preview-item img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--color-border-strong);
}

.preview-item .remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--color-error);
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
}

/* 메시지 내 이미지 */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.message-images img {
    max-width: 300px;
    max-height: 200px;
    border-radius: 6px;
    object-fit: contain;
}

/* AI 메시지 마크다운 스타일 */
.ai-message p {
    margin: 0 0 0.5rem 0;
}

.ai-message p:last-child {
    margin-bottom: 0;
}

.ai-message pre {
    /* code block — slate-800 배경 (사이트 다크 헤더와 톤 일치) + slate-100 텍스트 */
    background: var(--slate-800, #1e293b);
    color: var(--slate-100, #f1f5f9);
    padding: 0.8rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
    font-size: 0.85rem;
    line-height: 1.4;
}

.ai-message pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.ai-message code {
    /* inline code — slate 100 배경 + slate 800 텍스트 (높은 대비 + 사이트 톤). */
    background: var(--slate-100, #f1f5f9);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85em;
    color: var(--slate-800, #1e293b);
}

.ai-message ul, .ai-message ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.ai-message li {
    margin-bottom: 0.25rem;
}

.ai-message blockquote {
    border-left: 3px solid var(--color-border-strong);
    margin: 0.5rem 0;
    padding: 0.25rem 0.75rem;
    color: var(--color-text-secondary);
}

.ai-message table {
    border-collapse: collapse;
    margin: 0.5rem 0;
    width: 100%;
}

.ai-message th, .ai-message td {
    border: 1px solid var(--color-border);
    padding: 0.4rem 0.6rem;
    text-align: left;
}

.ai-message th {
    background: var(--color-bg-tertiary);
    font-weight: 600;
}

.ai-message h1, .ai-message h2, .ai-message h3,
.ai-message h4, .ai-message h5, .ai-message h6 {
    margin: 0.75rem 0 0.25rem 0;
    line-height: 1.3;
}

.ai-message h1 { font-size: 1.3em; }
.ai-message h2 { font-size: 1.15em; }
.ai-message h3 { font-size: 1.05em; }

.ai-message hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 0.75rem 0;
}

.ai-message a {
    color: #007bff;
    text-decoration: underline;
}

/* AI 메시지 래퍼 (참조 버튼 포함) */
.ai-msg-wrap {
    align-self: stretch;
    width: 100%;
}
.ai-msg-wrap .message { max-width: 100%; }
/* AI message footer (inside bubble) */
.ai-msg-footer { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--color-border, #e9ecef); }
.btn-ref { display: inline-block; border: none; background: none; color: #007bff; font-size: 12px; cursor: pointer; padding: 2px 0; margin-bottom: 4px; }
.btn-ref:hover { text-decoration: underline; }

/* Message action buttons */
.msg-action-bar { display: flex; gap: 2px; }
.msg-action-btn { border: none; background: none; cursor: pointer; padding: 3px 5px; border-radius: 4px; color: var(--color-text-secondary, #6b7280); opacity: 0.4; transition: opacity 0.15s, background 0.15s, color 0.15s; line-height: 0; }
.msg-action-btn:hover { opacity: 1; background: #f0f0f0; }
.msg-action-btn.active { opacity: 1; }
.msg-action-btn svg { display: block; }
.msg-like-btn.active { color: #2563eb; }
.msg-dislike-btn.active { color: #dc2626; }

/* User message wrapper + action buttons (hover only, below bubble) */
.user-msg-wrap { align-self: flex-end; max-width: 80%; }
.msg-user-actions { display: flex; gap: 2px; justify-content: flex-end; margin-top: 4px; opacity: 0; transition: opacity 0.15s; }
.user-msg-wrap:hover .msg-user-actions { opacity: 1; }

/* Inline edit — uses same chat-input-inner style */
.user-msg-wrap.editing { min-width: 30%; }
.user-msg-wrap.editing .user-message { display: none; }
.user-msg-wrap.editing .msg-user-actions { display: none; }
.inline-edit-area { width: 100%; }
.inline-edit-inner { background: var(--color-bg-secondary); border: 1px solid var(--color-border); border-radius: 1rem; padding: 0.75rem 1rem; }
.inline-edit-textarea { width: 100%; min-height: 3rem; max-height: 15rem; padding: 0; border: none; resize: none; font-family: inherit; font-size: 1rem; line-height: 1.5; color: var(--color-text); background: transparent; overflow-y: hidden; }
.inline-edit-textarea:focus { outline: none; }
.inline-edit-buttons { display: flex; align-items: center; gap: 8px; padding-top: 0.375rem; }
.inline-edit-img-btn { display: flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; background: none; color: var(--color-text-muted, #94a3b8); border: none; cursor: pointer; font-size: 1.1rem; font-weight: 300; line-height: 1; }
.inline-edit-img-btn:hover { background: var(--color-bg, #f0f0f0); color: var(--color-text); }
.inline-edit-cancel { border: none; background: none; color: var(--color-text-secondary, #6b7280); font-size: 13px; cursor: pointer; padding: 4px 10px; border-radius: 4px; }
.inline-edit-cancel:hover { background: #f0f0f0; color: #333; }
.inline-edit-save { display: flex; align-items: center; justify-content: center; padding: 0.4rem; background: var(--slate-700, #334155); color: white; border: none; border-radius: 35%; cursor: pointer; }
.inline-edit-save:hover { background: var(--slate-800, #1e293b); }

/* 참조 패널 */
.ref-panel { width: 380px; flex-shrink: 0; border-left: 1px solid var(--color-border); background: #fff; display: flex; flex-direction: column; }
.ref-panel-header { padding: 10px 14px; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 14px; }
.ref-close { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--color-text-secondary); }
.ref-close:hover { color: #333; }
.ref-content { flex: 1; overflow-y: auto; padding: 12px; }
.ref-item { margin-bottom: 12px; padding: 10px; background: var(--color-bg-tertiary, #f8f9fa); border: 1px solid var(--color-border, #e9ecef); border-radius: 6px; font-size: 13px; line-height: 1.5; }
.ref-item:last-child { margin-bottom: 0; }
.ref-meta { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.ref-score { background: var(--color-primary, #007bff); color: #fff; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.ref-page { background: var(--color-bg-tertiary, #e9ecef); color: #333; padding: 1px 8px; border-radius: 10px; font-size: 11px; }
.ref-text { white-space: pre-wrap; color: #444; }
.ref-page-links { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.ref-page-link { display: inline-block; font-size: 11px; color: #007bff; text-decoration: none; padding: 2px 6px; background: var(--color-bg-tertiary, #f0f0f0); border-radius: 4px; border: 1px solid var(--color-border, #e9ecef); }
.ref-page-link:hover { background: #007bff; color: #fff; }
.ref-details { margin-top: 8px; }
.ref-details summary { cursor: pointer; color: #007bff; font-size: 12px; font-weight: 500; user-select: none; outline: none; }
.ref-details summary:hover { text-decoration: underline; }
.ref-child-text { margin-top: 6px; padding: 8px; background: #fff; border: 1px solid var(--color-border, #e9ecef); border-radius: 4px; font-size: 12px; white-space: pre-wrap; color: #555; }
.ref-images { margin-top: 6px; display: flex; flex-direction: column; gap: 8px; }
.ref-page-img { text-align: center; }
.ref-page-label { font-size: 11px; color: var(--color-text-secondary, #6c757d); margin-bottom: 4px; }
.ref-page-img img { max-width: 100%; max-height: 300px; object-fit: contain; border: 1px solid #dee2e6; border-radius: 4px; }

/* Page viewer modal */
.page-viewer-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.page-viewer-content { background: #fff; border-radius: 12px; width: 92vw; height: 90vh; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.page-viewer-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid #e0e0e0; font-weight: 600; }
.page-viewer-header button { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #666; }
.page-viewer-body { display: flex; flex: 1; overflow: hidden; }
.page-viewer-image { flex: 1; display: flex; align-items: center; justify-content: center; background: #f5f5f5; overflow: hidden; }
.page-viewer-image img { max-width: 100%; max-height: 100%; object-fit: contain; }
.page-viewer-markdown { flex: 1; padding: 20px; overflow-y: auto; border-left: 1px solid #e0e0e0; font-size: 14px; line-height: 1.6; }
.page-viewer-nav-btn { position: absolute; bottom: 12px; padding: 8px 16px; background: rgba(0,0,0,0.5); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem; opacity: 0.6; z-index: 10; transition: opacity 0.2s; }
.page-viewer-nav-btn:hover { opacity: 1; }
.page-viewer-nav-btn.prev { left: 12px; }
.page-viewer-nav-btn.next { right: 12px; }

/* Pipeline step results */
details.step-result {
    margin: 6px 0;
    border: 1px solid var(--color-border, #e0e0e0);
    border-radius: 8px;
    background: var(--color-bg, #fff);
}
details.step-result summary {
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    color: var(--color-text-secondary, #555);
    background: var(--color-bg-secondary, #f8f9fa);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
details.step-result summary::before {
    content: "▶ ";
    font-size: 11px;
}
details.step-result[open] summary::before {
    content: "▼ ";
}
details.step-result .step-content {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--color-text, #333);
    overflow: auto;
    max-height: 9.5em; /* ~7 lines */
    line-height: 1.35;
}
details.step-result .step-content ul {
    margin: 0;
    padding-left: 20px;
}
details.step-result .step-content li {
    margin: 2px 0;
}
details.step-result .step-content p {
    margin: 4px 0;
    white-space: pre-wrap;
    word-break: break-word;
}
.step-label { flex: 1; }
.step-expand-btn {
    background: none; border: none; cursor: pointer; font-size: 16px;
    color: var(--color-text-secondary, #888); padding: 0 4px; line-height: 1;
}
.step-expand-btn:hover { color: var(--color-primary, #007bff); }

/* Step dialog popup */
.step-dialog-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.step-dialog {
    background: #fff; border-radius: 12px; width: 80vw; max-width: 800px;
    max-height: 80vh; display: flex; flex-direction: column; overflow: hidden;
}
.step-dialog-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 20px; border-bottom: 1px solid #e0e0e0; font-weight: 600; font-size: 14px;
}
.step-dialog-close {
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #666;
}
.step-dialog-body {
    padding: 16px 20px; overflow-y: auto; font-size: 13px; line-height: 1.5;
    white-space: pre-wrap; word-break: break-word;
}

/* ask_user — inline elicitation widget (clarifying question + options/text) */
.ask-user-container {
    margin: 0.5rem 0; padding: 0.75rem 0.9rem;
    background: var(--color-bg-secondary, #f8f9fa);
    border: 1px solid var(--color-border, #e0e0e0);
    border-left: 3px solid var(--color-primary, #007bff);
    border-radius: 8px;
}
.ask-user-question {
    font-size: 0.92rem; color: var(--color-text, #333);
    margin: 0 0 0.6rem 0; font-weight: 600;
}
.ask-user-options { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
.ask-user-option-btn {
    padding: 0.45rem 1rem;
    background: #fff; border: 1px solid var(--color-border, #e0e0e0);
    border-radius: 20px; font-size: 0.85rem; color: var(--color-text, #333);
    cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.ask-user-option-btn:hover {
    background: var(--color-primary, #007bff);
    color: #fff; border-color: var(--color-primary, #007bff);
}
.ask-user-option-btn:active { transform: scale(0.97); }
.ask-user-text-row { display: flex; gap: 0.5rem; align-items: center; }
.ask-user-text-input {
    flex: 1; padding: 0.45rem 0.7rem;
    border: 1px solid var(--color-border, #e0e0e0); border-radius: 8px;
    font-size: 0.85rem; background: #fff; color: var(--color-text, #333);
}
.ask-user-submit-btn {
    padding: 0.45rem 1rem; border: none; border-radius: 8px;
    background: var(--color-primary, #007bff); color: #fff;
    font-size: 0.85rem; cursor: pointer; white-space: nowrap;
}
.ask-user-submit-btn:hover { filter: brightness(0.95); }
.ask-user-container button:disabled, .ask-user-container input:disabled {
    opacity: 0.55; cursor: default;
}
.ask-user-chosen {
    margin-top: 0.5rem; font-size: 0.85rem; font-weight: 600;
    color: var(--color-primary, #007bff);
}
.ask-user-skip-btn {
    margin-top: 0.5rem; padding: 0.3rem 0.6rem;
    background: none; border: none; color: var(--color-text-secondary, #888);
    font-size: 0.8rem; cursor: pointer; text-decoration: underline;
}
.ask-user-skip-btn:hover { color: var(--color-text, #333); }
/* Locked replay (reloaded chat): dim the whole widget and mark the chosen
   option so a revisited elicitation reads as "answered", not interactive. */
.ask-user-locked { opacity: 0.9; }
.ask-user-option-chosen {
    background: var(--color-primary, #007bff) !important;
    color: #fff !important; border-color: var(--color-primary, #007bff) !important;
    opacity: 1 !important; font-weight: 600;
}

/* Tool call results */
.tool-params { font-family: monospace; font-size: 12px; white-space: pre-wrap; color: var(--color-text-secondary, #666); }
.tool-result-content {
    margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--color-border, #e0e0e0);
    font-size: 12px; color: var(--color-text-secondary, #555); white-space: pre-wrap; word-break: break-word;
    max-height: 8em; overflow-y: auto;
}
.agent-iteration { font-size: 12px; color: var(--color-text-muted, #94a3b8); margin-left: 8px; }
/* Knowledge toggle */
.knowledge-toggle {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 0.75rem; color: var(--color-text-muted, #94a3b8);
    cursor: pointer; user-select: none; padding: 2px 8px;
    border-radius: 12px; transition: all 0.15s;
}
.knowledge-toggle:hover { color: var(--color-text); }
.knowledge-toggle input[type="checkbox"] { display: none; }
.knowledge-toggle.active {
    background: var(--color-primary, #007bff); color: #fff;
}
.knowledge-toggle.active svg { stroke: #fff; fill: #fff; }

.agent-info-badge {
    display: inline-block; font-size: 11px; color: var(--color-text-muted, #94a3b8);
    padding: 2px 8px; background: var(--color-bg-tertiary, #f0f0f0); border-radius: 10px;
    margin-bottom: 4px;
}

.web-sources { margin-bottom: 8px; }
.web-sources-label { font-size: 11px; color: var(--color-text-muted, #94a3b8); margin-bottom: 4px; }
.web-source-item {
    display: block; padding: 4px 8px; margin-bottom: 2px;
    border-radius: 4px; background: var(--color-bg-tertiary, #f8fafc);
    text-decoration: none; color: inherit; font-size: 12px;
    border: 1px solid var(--color-border, #e2e8f0);
}
.web-source-item:hover { background: var(--color-bg-secondary, #f1f5f9); }
.web-source-title { display: block; font-weight: 500; color: var(--color-text, #334155); }
.web-source-url { display: block; font-size: 11px; color: var(--color-text-muted, #94a3b8); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sub-agent-status { font-size: 11px; color: var(--color-text-muted, #94a3b8); margin-left: 8px; }

/* ── Orchestrator UI ─────────────────────────────────────── */
.orch-container {
    margin-bottom: 12px;
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 10px;
    padding: 12px;
    background: var(--color-bg, #ffffff);
}

/* Phase progress bar */
.orch-phases {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.orch-phase {
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    background: var(--color-bg-secondary, #f1f5f9);
    color: var(--color-text-muted, #94a3b8);
    transition: all 0.2s;
}
.orch-phase.active {
    background: #3b82f6;
    color: #fff;
    animation: orch-pulse 1.5s ease-in-out infinite;
}
.orch-phase.completed {
    background: #10b981;
    color: #fff;
}
@keyframes orch-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Sub-question columns */
.orch-columns {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.orch-column {
    min-width: 220px;
    max-width: 320px;
    flex: 1;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    background: var(--color-bg-secondary, #f8fafc);
}
.orch-column-header {
    font-size: 12px;
    font-weight: 600;
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    color: var(--color-text, #334155);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Task cards */
.orch-tasks {
    padding: 4px 0;
}
.orch-task {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 5px 10px;
    font-size: 12px;
    border-bottom: 1px solid var(--color-bg-secondary, #f1f5f9);
    flex-wrap: wrap;
}
.orch-task:last-child { border-bottom: none; }
.orch-task-status {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
    font-size: 12px;
}
.orch-task.running .orch-task-status {
    animation: orch-spin 1s linear infinite;
    color: #3b82f6;
}
.orch-task.completed .orch-task-status { color: #10b981; }
.orch-task.failed .orch-task-status { color: #ef4444; }
@keyframes orch-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.orch-task-label {
    flex: 1;
    color: var(--color-text, #475569);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.orch-task-tools {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding-left: 22px;
}
.orch-tool-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--color-bg-secondary, #e2e8f0);
    color: var(--color-text-muted, #64748b);
    cursor: default;
}
.orch-tool-badge.tool-error {
    background: #fef2f2;
    color: #ef4444;
}

/* Usage badge */
.orch-usage-badge {
    display: flex;
    gap: 12px;
    padding: 6px 12px;
    margin-top: 8px;
    font-size: 11px;
    color: var(--color-text-muted, #64748b);
    border-top: 1px solid var(--color-border, #e5e7eb);
}
.orch-usage-badge span { white-space: nowrap; }

/* Warning */
.orch-warning {
    padding: 8px 12px;
    margin-top: 8px;
    font-size: 12px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 6px;
}

/* ── Agent / Plain-mode selector (chat input area) ────────────────────────
   AI Agent / 일반 채팅 칩 + 단일 popover. Plain 모드는 *선택 라벨 변경만*
   ("일반 채팅") — 입력창 chrome (border / banner) 은 변경 없음. 모델은 backend 가
   user_model.is_default 로 자동 해석하므로 프론트에 모델 정보 노출 X. */
:root {
    --agent-skill-accent: #10b981;   /* teal */
}
.agent-selector-slot {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-left: 0.5rem;
}
.agent-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, #cbd5e1);
    font-size: 0.8125rem;
    color: var(--color-text, #1e293b);
    cursor: pointer;
    font-family: inherit;
    line-height: 1;
}
.agent-chip:hover { background: var(--color-bg-subtle, #f1f5f9); }
.agent-chip .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--agent-skill-accent);
}
.agent-chip .name { font-weight: 500; }
.agent-chip .badge {
    background: rgba(16, 185, 129, 0.12);
    color: #065f46;
    padding: 1px 7px; border-radius: 6px;
    font-size: 11px; font-weight: 600;
}
.agent-chip .caret { color: var(--color-text-muted, #64748b); font-size: 9px; }

/* Popover — body-mounted, JS positions absolute via getBoundingClientRect */
.agent-popover {
    position: absolute;
    background: var(--color-bg, #fff);
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 12px;
    padding: 6px;
    min-width: 280px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12);
    z-index: 1000;
}
.pop-section-title {
    font-size: 10.5px;
    color: var(--color-text-muted, #64748b);
    padding: 8px 10px 4px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.pop-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--color-text, #1e293b);
    text-decoration: none;
}
.pop-item:hover { background: var(--color-bg-subtle, #f1f5f9); }
.pop-item.active { background: rgba(16, 185, 129, 0.10); }
.pop-item .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--agent-skill-accent);
    flex-shrink: 0;
}
.pop-item .pop-name { flex: 1; min-width: 0; }
.pop-item .meta {
    color: var(--color-text-muted, #64748b);
    font-size: 11.5px;
    margin-left: auto;
}
.pop-divider {
    height: 1px;
    background: var(--color-border, #e2e8f0);
    margin: 4px 8px;
}
.pop-item.manage {
    color: var(--color-text-muted, #64748b);
    font-size: 12px;
}
.pop-item.manage .dot { background: var(--color-text-muted, #94a3b8); }
.pop-empty {
    padding: 16px 12px;
    color: var(--color-text-muted, #64748b);
    font-size: 12px;
}

/* ── "+" Capability menu + flyouts ─────────────────────────────────────────
   Reuses .agent-popover (body-mounted card) + .pop-item rows. Adds icon column,
   right-arrow flyout affordance, and an on/off switch for skill/mcp toggles. */
.cap-menu, .cap-flyout {
    min-width: 240px;
    max-height: 60vh;
    overflow-y: auto;
}
.cap-flyout { z-index: 1001; }
.cap-row .cap-ico,
.cap-know .cap-ico,
.cap-file .cap-ico,
.cap-back .cap-ico {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    font-size: 13px;
}
/* 모노크롬 SVG 아이콘 — 컬러 이모지 대체. muted 톤으로 메뉴 라벨 옆에 차분히. */
.cap-ico svg {
    width: 16px;
    height: 16px;
    display: block;
    margin: 0 auto;
    color: var(--color-text-secondary, #475569);
}
.cap-arrow {
    margin-left: auto;
    color: var(--color-text-muted, #94a3b8);
    font-size: 15px;
    padding-left: 8px;
}
.cap-back { color: var(--color-text-muted, #64748b); font-weight: 500; }

/* on/off switch pill for skill / mcp toggle rows */
.cap-switch {
    margin-left: auto;
    flex-shrink: 0;
    width: 30px;
    height: 17px;
    border-radius: 999px;
    background: var(--color-border, #cbd5e1);
    position: relative;
    transition: background 0.15s ease;
}
.cap-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}
.cap-switch.on { background: var(--agent-skill-accent, #10b981); }
.cap-switch.on::after { transform: translateX(13px); }
.cap-toggle .meta {
    margin-left: auto;
    margin-right: 8px;
    color: var(--color-text-muted, #64748b);
    font-size: 11.5px;
}

/* ── Live execution trace ──────────────────────────────────────────────────
   Hierarchical view of skill → child invocations (agent / task / mcp_tool /
   internal_tool). Inserted before the AI message bubble so the chat answer
   streams below the trace.
   - Parallel siblings are stacked top-to-bottom in arrival order; we never
     auto-collapse a sibling on new arrivals (that was the bug in the old
     `tool_call` rendering path).
   - Status colour drives the left border accent on each node.
*/
.exec-trace {
    margin: 6px 0 10px;
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 8px;
    background: var(--color-bg-subtle, #f8fafc);
    padding: 8px;
    font-size: 12px;
    line-height: 1.5;
    max-width: 100%;
    overflow-x: auto;
}
.trace-node {
    border-left: 3px solid var(--trace-accent, #94a3b8);
    margin: 4px 0;
    padding: 4px 0 4px 8px;
    background: #fff;
    border-radius: 0 6px 6px 0;
}
.trace-node + .trace-node { margin-top: 6px; }
/* Kind 별 좌측 stripe 색 — 진행/완료 모두 영구 표시되어 트레이스 종류를 한 눈에 식별.
   Agent 의 사용자 지정 색(.trace-name[style])은 텍스트 레이어, 여기 stripe 는 kind 레이어. */
.trace-node[data-kind="skill"]          { --trace-accent: #3b82f6; } /* blue */
.trace-node[data-kind="agent"],
.trace-node[data-kind="task"]           { --trace-accent: #8b5cf6; } /* violet */
.trace-node[data-kind="mcp_tool"]       { --trace-accent: #ec4899; } /* pink */
.trace-node[data-kind="internal_tool"]  { --trace-accent: #f97316; } /* orange */
.trace-node[data-kind="expand_skill"]   { --trace-accent: #64748b; } /* slate */
/* 실패만 kind 색을 override — 위험 신호로 빨강 단일화. */
.trace-node.trace-status-failed         { --trace-accent: #ef4444; }
.trace-node.trace-root                  { background: rgba(0,0,0,0.02); }

.trace-header {
    display: flex; align-items: center; gap: 6px;
    cursor: pointer; user-select: none;
}
.trace-header:hover { background: rgba(0,0,0,0.03); border-radius: 4px; }
.trace-icon { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; color: var(--color-text-muted, #64748b); flex-shrink: 0; }
.trace-icon svg { width: 14px; height: 14px; }
.trace-name {
    font-weight: 500; color: var(--color-text, #1e293b);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1; min-width: 0;
}
.trace-status::before {
    content: "";
    display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    background: var(--trace-accent);
    margin-right: 4px;
}
/* 완료 상태는 dot 자체를 숨겨 깔끔하게. failed/running 만 dot 보임. */
.trace-status-completed .trace-status::before { display: none; }
/* 진행중: kind 색 그대로 유지하면서 opacity·scale 만 펄스 — 어떤 종류가 도는지 색으로 식별. */
.trace-status-running .trace-status::before {
    animation: trace-pulse 1.4s ease-in-out infinite;
}
@keyframes trace-pulse {
    0%, 100% { opacity: 0.45; transform: scale(1); }
    50%      { opacity: 1;    transform: scale(1.25); }
}

.trace-collapsed > .trace-input,
.trace-collapsed > .trace-stream,
.trace-collapsed > .trace-output,
.trace-collapsed > .trace-output-label,
.trace-collapsed > .trace-children { display: none; }

/* trace-titles-only: the "collapsed" trace-view level — hide THIS node's own
   detail blocks but KEEP > .trace-children so the full agent/skill/task title
   outline still renders. Mirrors the .trace-collapsed detail selectors EXCEPT
   .trace-children. (.trace-collapsed additionally hides children = manual
   full-collapse; the two classes coexist and .trace-collapsed's child rule wins.)
   ⚠️ When adding a new .trace-* DETAIL block type, add it to BOTH this list and
   the matching .trace-collapsed rule. */
.trace-titles-only > .trace-input,
.trace-titles-only > .trace-stream,
.trace-titles-only > .trace-output,
.trace-titles-only > .trace-output-label,
.trace-titles-only > .trace-thinking,
.trace-titles-only > .trace-tools-adv,
.trace-titles-only > .trace-permission-resp,
.trace-titles-only > .trace-hook,
.trace-titles-only > .trace-budget,
.trace-titles-only > .trace-finish,
.trace-titles-only > .trace-reasoning,
.trace-titles-only > .trace-tokens { display: none; }
/* (intentionally NO `.trace-titles-only > .trace-children` rule — keep titles.) */

/* 'hidden' trace-view applied to the LIVE trace box: DOM + node-map preserved
   (stream events stay null-safe), visually suppressed. */
.exec-trace[data-trace-level="hidden"] { display: none; }

.trace-input, .trace-output, .trace-stream {
    margin-top: 6px;
    padding: 4px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    background: rgba(15,23,42,0.04);
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-word;
    /* 긴 도구 결과 / Skill body 도 스크롤로 전체 가독. 너무 길면 [상세] 모달 사용. */
    max-height: 400px;
    overflow-y: auto;
}
.trace-input  { color: var(--color-text-muted, #64748b); }
.trace-output { color: var(--color-text, #1e293b); }
/* 실패한 tool 의 출력은 빨강 — 헤더 status dot 색과 동일하게(#ef4444). */
.trace-node.trace-status-failed > .trace-output { color: var(--trace-accent); }
.trace-stream { color: var(--color-text-muted, #475569); }
.trace-stream:empty { display: none; }

/* trace-output 직전 라벨 — expand_skill body / Skill 본문 같은 특수 출력 명시 */
.trace-output-label {
    margin-top: 6px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--color-text-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* (C) Ghost placeholder — Skill body 가 expected stages 로 선언한 subagent 들 */
.trace-node.trace-ghost {
    opacity: 0.45;
    border-style: dashed;
}
.trace-node.trace-ghost > .trace-header > .trace-name {
    font-style: italic;
}
.trace-node.trace-ghost > .trace-header > .trace-icon {
    filter: grayscale(100%);
}

/* (E) Extended-thinking 박스 — 일반 streamed text 와 시각 구분 */
.trace-thinking {
    margin-top: 6px;
    padding: 6px 8px;
    background: rgba(168, 85, 247, 0.06);
    border-left: 2px solid rgba(168, 85, 247, 0.45);
    border-radius: 0 4px 4px 0;
    font-size: 11.5px;
}
.trace-thinking-head {
    font-weight: 600;
    color: #7e22ce;
    margin-bottom: 3px;
    font-size: 10.5px;
    letter-spacing: 0.02em;
}
.trace-thinking-body {
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--color-text-muted, #4b5563);
    max-height: 240px;
    overflow-y: auto;
    font-style: italic;
}
.trace-collapsed > .trace-thinking { display: none; }

/* (2) Per-turn tool advertisement 박스 — 어떤 도구가 광고됐는지 */
.trace-tools-adv {
    margin-top: 4px;
    padding: 4px 8px;
    font-size: 10.5px;
    background: rgba(14, 165, 233, 0.06);
    border-left: 2px solid rgba(14, 165, 233, 0.4);
    border-radius: 0 3px 3px 0;
}
.trace-tools-adv-head {
    font-weight: 600;
    color: #0369a1;
    margin-bottom: 2px;
    font-size: 10px;
    letter-spacing: 0.02em;
}
.trace-tools-adv-body {
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--color-text-muted, #475569);
    max-height: 160px;
    overflow-y: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.trace-collapsed > .trace-tools-adv { display: none; }

/* (5) askUser 응답 chip — 사용자가 모달에서 allow/deny 한 결정 */
.trace-permission-resp {
    margin-top: 4px;
    padding: 3px 8px;
    font-size: 10.5px;
    color: var(--color-text, #1e293b);
    background: rgba(99, 102, 241, 0.10);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 3px;
    width: fit-content;
}
.trace-collapsed > .trace-permission-resp { display: none; }

/* (1) Hook fired chip — pre_tool_use deny/ask/modify 결정 라벨 */
.trace-hook {
    margin-top: 4px;
    padding: 3px 8px;
    font-size: 10.5px;
    color: #92400e;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.35);
    border-radius: 3px;
    width: fit-content;
}
.trace-collapsed > .trace-hook { display: none; }

/* 중단 / max_turns chip — invocation 노드 옆 빨간 경고 (사용자 중단 또는 turn 한도) */
.trace-budget {
    margin-top: 4px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #b91c1c;
    background: rgba(239, 68, 68, 0.10);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 3px;
    width: fit-content;
}
.trace-collapsed > .trace-budget { display: none; }

/* (G) JSON salvage badge — Subagent 헤더 옆에 attach */
.trace-salvage-badge {
    margin-left: 6px;
    padding: 1px 5px;
    font-size: 9.5px;
    font-weight: 600;
    color: #9a3412;
    background: rgba(251, 146, 60, 0.18);
    border: 1px solid rgba(251, 146, 60, 0.4);
    border-radius: 3px;
    cursor: help;
}

/* (F) finish_reason chip — turn 종료 이유 (tool_use / stop / max_tokens) */
.trace-finish {
    margin-top: 4px;
    padding: 2px 6px;
    font-size: 10.5px;
    color: var(--color-text-muted, #6b7280);
    background: rgba(15, 23, 42, 0.04);
    border-radius: 3px;
    width: fit-content;
}
.trace-collapsed > .trace-finish { display: none; }

/* (D) Per-turn reasoning box — 각 turn 의 LLM 텍스트 (라우팅 결정 또는 최종 답변) */
.trace-reasoning {
    margin-top: 6px;
    padding: 6px 8px;
    background: rgba(99, 102, 241, 0.06);
    border-left: 2px solid rgba(99, 102, 241, 0.4);
    border-radius: 0 4px 4px 0;
    font-size: 11.5px;
}
.trace-reasoning-head {
    font-weight: 600;
    color: #4338ca;
    margin-bottom: 3px;
    font-size: 10.5px;
    letter-spacing: 0.02em;
}
.trace-reasoning-body {
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--color-text, #1e293b);
    max-height: 280px;
    overflow-y: auto;
}
.trace-collapsed > .trace-reasoning { display: none; }

/* (Removed: the former body:not(.user-is-admin) gate that hid trace detail
   boxes + [상세] link from non-admins. Regular users now see the full trace
   for their OWN chats — aligned to the admin view — governed instead by the
   per-user trace_view setting (hidden/collapsed/expanded). Backend session
   access stays owner-scoped, so users still only ever load their own traces.) */

.trace-children {
    padding-left: 14px;
    margin-left: 6px;
    border-left: 1px dashed rgba(15,23,42,0.08);
}
.trace-children:empty { padding: 0; margin-left: 0; border-left: none; }

/* Per-LLM-call token usage chip — shown under each trace node */
.trace-tokens {
    margin-top: 4px;
    padding: 2px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    color: var(--color-text-muted, #64748b);
    background: rgba(59,130,246,0.06);
    border-radius: 4px;
    display: inline-block;
}
.trace-collapsed > .trace-tokens { display: none; }

/* Session-level token grand total — footer line under AI message */
.session-usage {
    margin: 6px 0 0 0;
    padding: 6px 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: var(--color-text-muted, #64748b);
    background: rgba(15,23,42,0.04);
    border-left: 3px solid #3b82f6;
    border-radius: 4px;
}

/* ── LLM 호출 상세 모달 ───────────────────────────────────────────────────
   trace 노드의 [상세] 클릭 시 그 invocation 의 messages 전체를 카드로 표시.
   role 별 옅은 배경색으로 system/user/assistant 구분. */
.modal-box.modal-xwide { max-width: 960px; width: calc(100vw - 2rem); }

.trace-header .trace-detail-link {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--color-primary, #2563eb);
    text-decoration: none;
    flex-shrink: 0;
}
.trace-header .trace-detail-link:hover { text-decoration: underline; }

#llm-detail-body {
    max-height: 70vh;
    overflow-y: auto;
}
#llm-detail-body .llm-msg-card {
    padding: 0.55rem 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--color-border, #e2e8f0);
    margin-bottom: 0.5rem;
    font-size: 0.82rem;
}
#llm-detail-body .llm-msg-card.role-system    { background: #f8fafc; }
#llm-detail-body .llm-msg-card.role-user      { background: #eff6ff; }
#llm-detail-body .llm-msg-card.role-assistant { background: #f0fdf4; }
#llm-detail-body .llm-msg-card.role-tool      { background: #fefce8; }
#llm-detail-body .llm-msg-head {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.72rem;
    color: var(--color-text-muted, #6b7280);
}
#llm-detail-body .llm-msg-role {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
#llm-detail-body pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    background: rgba(15, 23, 42, 0.04);
    padding: 0.4rem 0.55rem;
    border-radius: 4px;
}
#llm-detail-body .llm-msg-text {
    white-space: pre-wrap;
    word-break: break-word;
}
#llm-detail-body .llm-empty {
    color: var(--color-text-muted, #94a3b8);
    font-size: 0.78rem;
    padding: 0.5rem;
    text-align: center;
}
#llm-detail-body .llm-turn-group {
    margin-bottom: 1.1rem;
}
#llm-detail-body .llm-turn-group:last-child { margin-bottom: 0; }
#llm-detail-body .llm-turn-head {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted, #6b7280);
    padding: 0.25rem 0.1rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--color-border, #e2e8f0);
}


/* ── 신규 사용자 빈-상태 — API 키 / 모델 / 기본 모델 미설정 안내 ──────────
   chat handler 의 setupReason 분기로 렌더. 차가운 설정 페이지로 리다이렉트
   하지 않고 익숙한 chat 화면 안에서 다음 단계를 친절히 안내.                 */
.chat-setup-required {
    text-align: center;
    max-width: 520px;
    margin: 3.5rem auto 2rem;
    padding: 2rem 1.5rem 2.5rem;
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}
.chat-setup-icon {
    color: var(--color-primary, #2563eb);
    margin: 0 auto 0.75rem;
    line-height: 1;
}
.chat-setup-title {
    font-size: 1.45rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 0.6rem;
}
.chat-setup-body {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    margin: 0 0 1.5rem;
    line-height: 1.55;
}
.chat-setup-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

/* 입력 영역 비활성 — setupReason 이 있을 때 textarea 는 disabled 속성으로
   막혀 있고, 시각적 신호를 위해 부모 영역에 흐리게 효과 + 클릭 차단. */
.chat-input-area-disabled {
    opacity: 0.55;
    pointer-events: none;
}
.chat-input-area-disabled textarea {
    cursor: not-allowed;
}

/* ── 빈 채팅 상태 — 입력창 아래 제안 칩 (홈 = 새 채팅 통합) ──────────────
   카드 그리드(올드)에서 미니멀 제안 칩으로 전면 개선. 입력창 폭(800px)에
   정렬되고, 클릭 시 입력창에 문구를 채운다(자동전송 X). */
.chat-examples-wrap {
    max-width: 800px;
    margin: 0.75rem auto 0;
    padding: 0 0.25rem;
}

/* 둥근 제안 칩 — 가볍게 wrap 되는 한 행(또는 두 행). 아이콘 + 라벨만. */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.chat-suggestion {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    line-height: 1;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.chat-suggestion:hover {
    background: var(--color-bg-secondary);
    border-color: var(--slate-300);
    color: var(--color-text);
    transform: translateY(-1px);
}
.chat-suggestion:active { transform: translateY(0); }
.chat-suggestion-ico {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--agent-skill-accent, #10b981);
}

@media (max-width: 640px) {
    /* 800px max-width 해제 — 모바일 본문 폭 모두 사용. 칩은 그대로 wrap. */
    .chat-examples-wrap { max-width: none; }
    /* 모바일 좌우 거터 축소 — 메시지·입력 영역 좌우 패딩만 줄임(상하 유지). */
    .chat-messages { padding-left: 0.75rem; padding-right: 0.75rem; }
    .chat-input-area { padding-left: 0.75rem; padding-right: 0.75rem; }
}

/* ── 빈 채팅 상태 (no messages yet) — input → 예시 카드 순 ─────────────
   chat.js 가 body.chat-empty 를 토글. 첫 메시지 전송 시 해제 → input 이
   자연 하단으로, examples 사라짐 (정상 chat layout 복귀).

   빈 상태에선 flex order 로 .chat-input-area 를 .chat-messages 위로 끌어
   올린다 — DOM 순서를 바꾸지 않고도 시각 순서만 뒤집힌다. 동시에
   .chat-messages 는 flex:0 (자연 높이 = examples 분량) 로 두어 페이지
   상단 영역에 input 이 자연스럽게 붙음.
*/
body.chat-empty .chat-main {
    justify-content: flex-start;
}
body.chat-empty .chat-messages {
    flex: 0 0 auto;
    order: 2;
    padding-top: 0;
}
body.chat-empty .chat-input-area {
    order: 1;
    padding-top: 2rem;
}
/* Home hero sits ABOVE the composer in the empty state (order 0 < input's 1). */
body.chat-empty .chat-hero {
    order: 0;
}

/* 예시 wrap 은 빈 상태에서만 노출. 첫 메시지 보내면 자동 숨김.
   .chat-hero / .home-news-preview 도 같은 라이프사이클 — 첫 메시지 후엔
   채팅 흐름과 섞이지 않게 사라짐. chat.js 가 직접 안 만지고 CSS 토글로 처리. */
body:not(.chat-empty) .chat-examples-wrap,
body:not(.chat-empty) .chat-hero,
body:not(.chat-empty) .home-recent-stocks,
body:not(.chat-empty) .home-knowledge-preview,
body:not(.chat-empty) .home-news-preview {
    display: none;
}

/* ── Home: recently viewed stocks (signed-in only) ─────────────────────────
   Up to 6 rich cards (ticker + name + price + change%) linking into /stock.
   Aligns with the composer's 800px column. */
.home-recent-stocks {
    max-width: 800px;
    width: 100%;
    margin: 1.5rem auto 0;
}
.home-recent-stocks-head {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    padding: 0 0.25rem;
}
.home-recent-stocks-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
}
.home-recent-stocks-link {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--color-primary, #2563eb);
    text-decoration: none;
}
.home-recent-stocks-link:hover { text-decoration: underline; }
.home-recent-stocks-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
}
.home-stock-card {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.6rem 0.75rem;
    background: var(--color-bg-elev, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.12s, background 0.12s;
}
.home-stock-card:hover {
    border-color: var(--color-primary, #2563eb);
    background: var(--color-bg-subtle, #f8fafc);
}
.home-stock-card-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem;
}
.home-stock-ticker {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.01em;
}
.home-stock-price {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}
.home-stock-bottom {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem;
}
.home-stock-name {
    font-size: 0.75rem;
    color: var(--color-text-muted, #64748b);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.home-stock-change {
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
/* 한국 관례: 상승=빨강, 하락=파랑 */
.home-stock-change.up { color: #dc2626; }
.home-stock-change.down { color: #2563eb; }
@media (max-width: 640px) {
    .home-recent-stocks-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Home hero (landing decoration above the composer) ─────────────────────
   Aligns with the composer's 800px column. Anonymous visitors get the full
   product value-prop (brand + headline + feature list, absorbed from the
   removed /login page); signed-in users get only .chat-hero-greeting. */
.chat-hero {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 0.5rem;
    text-align: center;
}
.chat-hero-greeting {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
    margin: 0;
}
.chat-hero-brand {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text-muted, #64748b);
    margin-bottom: 0.75rem;
}
.chat-hero-headline {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--color-text);
    margin: 0 0 0.6rem;
}
.chat-hero-sub {
    font-size: 1rem;
    color: var(--color-text-muted, #64748b);
    line-height: 1.55;
    margin: 0 auto 1.75rem;
    max-width: 560px;
}
/* Feature highlights — 2-col grid of icon + title/desc, left-aligned cells. */
.chat-hero-features {
    list-style: none;
    margin: 0 auto;
    padding: 0;
    max-width: 620px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.5rem;
    text-align: left;
}
.chat-hero-features li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}
.chat-hero-feat-icon {
    flex-shrink: 0;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 0.5rem;
    background: var(--color-bg-secondary, #f1f5f9);
    color: var(--color-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-hero-feat-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.1rem;
}
.chat-hero-feat-desc {
    font-size: 0.82rem;
    color: var(--color-text-muted, #64748b);
    line-height: 1.45;
}
@media (max-width: 640px) {
    .chat-hero { padding: 1.5rem 1rem 0.25rem; }
    .chat-hero-headline { font-size: 1.45rem; }
    .chat-hero-features { grid-template-columns: 1fr; gap: 0.85rem; max-width: 360px; }
}

/* (Removed: the second body:not(.user-is-admin) trace gate + the header-click
   disable. The trace header is now clickable for all users so they can drill
   into a node's details under the 'collapsed (titles only)' view, matching the
   admin experience. Trace visibility is now the per-user trace_view setting.) */

/* ── PDF attachment cards ──────────────────────────────────────────────────
   Two card variants live inside #image-preview, alongside regular image
   thumbnails:
     .pdf-progress-card — in-flight upload + processing. Has a progress bar.
     .pdf-group-card    — completed attachment. Shows filename + page count
                          + a thumbnail of page 1.
   Both follow the existing .preview-item position pattern (relative + right-
   top × button), but expand horizontally because they carry text. */

.pdf-progress-card,
.pdf-group-card {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.55rem 0.4rem 0.5rem;
    border: 1px solid var(--color-border-strong);
    border-radius: 8px;
    background: var(--color-bg, #fff);
    min-height: 60px;
    max-width: 280px;
    box-sizing: border-box;
}

/* Progress card — stacked: head row (icon + name + status), then bar */
.pdf-progress-card {
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    padding-right: 1.5rem; /* room for the × button */
}
.pdf-progress-head {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--color-text);
    min-width: 0;
}
.pdf-progress-icon { font-size: 1rem; flex-shrink: 0; }
.pdf-progress-name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
.pdf-progress-status {
    flex-shrink: 0;
    font-size: 0.72rem;
    color: var(--color-text-muted);
}
.pdf-progress-bar {
    height: 4px;
    background: var(--color-bg-subtle, #f1f5f9);
    border-radius: 2px;
    overflow: hidden;
}
.pdf-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--agent-skill-accent, #10b981);
    transition: width 0.15s ease-out;
}
.pdf-progress-card.pdf-status-processing .pdf-progress-bar-fill {
    /* 처리 중 — indeterminate. 50% 폭에서 좌우로 살짝 진동. */
    width: 50%;
    animation: pdfProcessingPulse 1.4s ease-in-out infinite;
}
@keyframes pdfProcessingPulse {
    0%   { width: 35%; opacity: 0.7; }
    50%  { width: 80%; opacity: 1;   }
    100% { width: 35%; opacity: 0.7; }
}
.pdf-progress-card.pdf-status-error {
    border-color: var(--color-error, #ef4444);
}
.pdf-progress-card.pdf-status-error .pdf-progress-status {
    color: var(--color-error, #ef4444);
    font-weight: 600;
}

/* Group card — completed PDF attachment. Icon + (name+meta) + thumb. */
.pdf-group-card .pdf-group-icon { font-size: 1.4rem; flex-shrink: 0; }
.pdf-group-card .pdf-group-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
    flex: 1 1 auto;
}
.pdf-group-card .pdf-group-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pdf-group-card .pdf-group-meta {
    font-size: 0.7rem;
    color: var(--color-text-muted);
}
.pdf-group-card .pdf-group-truncated {
    font-size: 0.68rem;
    color: var(--color-warning, #d97706);
    font-weight: 500;
    margin-top: 0.1rem;
}
.pdf-group-card .remove-btn,
.pdf-progress-card .remove-btn {
    position: absolute;
}
.pdf-progress-card { position: relative; }
.pdf-group-card { position: relative; }

/* ── User message bubble — PDF group attachment chip ───────────────────────
   입력 프리뷰의 .pdf-group-card 와 *동일한* 흰바탕 + 테두리 룩. 사용자가
   첨부할 때 본 모양 그대로 메시지에서도 보임 → 시각 일관성. 아이콘 없이
   파일명 + 페이지수만. */
.message-images .pdf-msg-group {
    display: inline-flex;
    align-items: center;
    padding: 0.4rem 0.65rem;
    margin: 0.15rem 0.3rem 0.15rem 0;
    background: var(--color-bg, #fff);
    color: var(--color-text, #1e293b);
    border: 1px solid var(--color-border-strong);
    border-radius: 8px;
    max-width: 320px;
}
.message-images .pdf-msg-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}
.message-images .pdf-msg-name {
    font-size: 0.85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-images .pdf-msg-meta {
    font-size: 0.72rem;
    color: var(--color-text-muted);
}
.message-images .pdf-msg-truncated {
    font-size: 0.7rem;
    color: var(--color-warning, #d97706);
    font-weight: 500;
    margin-top: 0.1rem;
}
