/* 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;
}

.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; }

#send-btn {
    margin-left: auto;
    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;
}

/* 입력 안내 텍스트 */
.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;
}

/* Scope selection UI */
.scope-options-container { padding: 0.75rem 0; }
.scope-prompt {
    font-size: 0.9rem; color: var(--color-text-secondary, #555);
    margin: 0 0 0.75rem 0; font-weight: 500;
}
.scope-options-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.scope-option-btn {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.5rem 1rem;
    background: var(--color-bg-secondary, #f8f9fa);
    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;
}
.scope-option-btn:hover {
    background: var(--color-primary, #007bff);
    color: #fff; border-color: var(--color-primary, #007bff);
}
.scope-option-btn:active { transform: scale(0.97); }

/* 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) ────────────────────────
   Main 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;
}

/* ── 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-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; }

/* (4) Budget / max_turns chip — invocation 노드 옆 빨간 경고 */
.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; }

/* 비-admin 사용자 trace 단순화 — 헤더(아이콘+이름) + 자식 노드 nesting 만
   노출. 디버깅성 detail 박스 (input/output/stream/thinking/reasoning/도구
   광고/finish/token/budget/hook/permission_resp/salvage badge) + [상세] 모달
   링크 모두 hide. admin 은 풀 trace 그대로. */
body:not(.user-is-admin) .trace-input,
body:not(.user-is-admin) .trace-output,
body:not(.user-is-admin) .trace-output-label,
body:not(.user-is-admin) .trace-stream,
body:not(.user-is-admin) .trace-thinking,
body:not(.user-is-admin) .trace-reasoning,
body:not(.user-is-admin) .trace-tools-adv,
body:not(.user-is-admin) .trace-hook,
body:not(.user-is-admin) .trace-finish,
body:not(.user-is-admin) .trace-tokens,
body:not(.user-is-admin) .trace-budget,
body:not(.user-is-admin) .trace-permission-resp,
body:not(.user-is-admin) .trace-salvage-badge,
body:not(.user-is-admin) .trace-detail-link {
    display: none !important;
}

.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: 760px; }

.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;
}

/* ── 빈 채팅 상태 — 인사 + 예시 카드 (홈 = 새 채팅 통합) ─────────────────── */
.chat-greeting {
    text-align: center;
    padding: 3rem 1rem 1.5rem;
}
.chat-greeting-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 0 0 0.5rem;
}
.chat-greeting-sub {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin: 0;
}

.chat-examples {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
    max-width: 800px;
    margin: 0 auto 2rem;
    padding: 0 1rem;
}
.chat-example-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    padding: 1rem 1.1rem;
    text-align: left;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--color-text);
    font-family: inherit;
}
.chat-example-card:hover {
    border-color: var(--slate-400);
    background: var(--color-bg-secondary);
    transform: translateY(-1px);
}
.chat-example-icon { font-size: 1.5rem; line-height: 1; }
.chat-example-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.chat-example-text {
    font-size: 0.875rem;
    color: var(--color-text);
    line-height: 1.4;
}

/* ── 빈 채팅 상태 (no messages yet) — greeting → examples → input 순 ─────
   chat.js 가 body.chat-empty 를 토글. 첫 메시지 전송 시 해제 → input 이
   자연 하단으로 (정상 chat layout).
   빈 상태선 .chat-messages 가 flex:0 (자연 높이 = greeting+examples 분량)
   → input-area 가 examples 바로 아래에 붙어 보임.
*/
body.chat-empty .chat-main {
    justify-content: flex-start;
}
body.chat-empty .chat-messages {
    flex: 0 0 auto;
}

/* greeting / examples 는 빈 상태에서만 노출. 첫 메시지 보내면 자동 숨김. */
body:not(.chat-empty) .chat-greeting,
body:not(.chat-empty) .chat-examples {
    display: none;
}

/* ── 트레이스 admin-only 게이팅 ────────────────────────────────────────────
   일반 사용자에겐 .trace-header (이름·상태 아이콘) 만 노출.
   admin 에게만 input/output/tools_advertised/tokens/finish/[상세] 등 세부 정보.
   body.user-is-admin 은 left.js loadUserInfo() 가 role==='admin' 일 때 부여. */
body:not(.user-is-admin) .trace-input,
body:not(.user-is-admin) .trace-output,
body:not(.user-is-admin) .trace-output-label,
body:not(.user-is-admin) .trace-stream,
body:not(.user-is-admin) .trace-detail-link,
body:not(.user-is-admin) .trace-tools-adv,
body:not(.user-is-admin) .trace-tokens,
body:not(.user-is-admin) .trace-finish,
body:not(.user-is-admin) .session-usage {
    display: none !important;
}

/* 사용자에겐 collapse 화살표 (헤더 클릭으로 펼쳤다 접었다) 도 의미 없음 — 헤더 클릭 효과 제거 위해 cursor 기본화 */
body:not(.user-is-admin) .trace-header { cursor: default; }
body:not(.user-is-admin) .trace-header:hover { background: transparent; }
