/* --- AI 채팅 페이지(/chat) --- */
/* (네비게이션 .main-nav/.nav-link 스타일은 style.css 공통으로 이동) */

/* 레이아웃 */
.chat-layout {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 64px);
    overflow: hidden;
}

.chat-thread {
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* 메시지 폭 제한용 가운데 정렬 래퍼 */
.msg-row { width: 100%; display: flex; }
.msg-row .bubble-wrap { width: 100%; max-width: 820px; margin: 0 auto; padding: 0 24px; }

/* 말풍선 */
.bubble {
    display: inline-block;
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 14px;
    line-height: 1.6;
    font-size: 14.5px;
    word-break: break-word;
    white-space: pre-wrap;
}
.msg-user .bubble-wrap { display: flex; justify-content: flex-end; }
.msg-user .bubble {
    background-color: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg-assistant .bubble {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.bubble a { color: var(--accent); }
.msg-user .bubble a { color: #fff; text-decoration: underline; }

/* 마크다운 렌더 (어시스턴트 답변) */
.bubble .md-p { margin: 0 0 8px; }
.bubble .md-p:last-child { margin-bottom: 0; }
.bubble .md-h { font-weight: 700; margin: 10px 0 6px; line-height: 1.3; }
.bubble .md-h:first-child { margin-top: 0; }
.bubble .md-h1 { font-size: 18px; }
.bubble .md-h2 { font-size: 16px; }
.bubble .md-h3 { font-size: 14.5px; color: var(--text-secondary); }
.bubble .md-list { margin: 4px 0 8px; padding-left: 20px; }
.bubble .md-list li { margin: 2px 0; }
.bubble code {
    font-family: var(--font-mono);
    font-size: 12.5px;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1px 5px;
}
.bubble .md-table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    font-size: 13.5px;
}
.bubble .md-table th, .bubble .md-table td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: left;
}
.bubble .md-table th { background-color: var(--bg-panel-header); font-weight: 600; }
.bubble .md-table tbody tr:nth-child(even) { background-color: rgba(255,255,255,0.015); }

/* 화자 라벨 */
.msg-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 5px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.msg-user .msg-label { text-align: right; }

/* 도구 호출 칩 */
.tool-track { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.tool-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    background-color: rgba(41, 98, 255, 0.08);
    border: 1px solid var(--border-glow);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12.5px;
    color: var(--text-secondary);
    cursor: pointer;
}
.tool-chip .tool-name { color: var(--text-primary); font-weight: 600; font-family: var(--font-mono); }
.tool-chip.running { border-color: var(--accent); }
.tool-chip.done .tool-ico-spin { display: none; }
.tool-chip.running .tool-ico-check { display: none; }
.tool-ico-spin {
    width: 12px; height: 12px; border-radius: 50%;
    border: 2px solid rgba(41,98,255,0.25); border-top-color: var(--accent);
    animation: spin 0.7s linear infinite;
}
.tool-ico-check { color: var(--up-color); font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }

.tool-detail {
    margin-top: 4px;
    background-color: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow: auto;
}
.tool-detail[hidden] { display: none; }

/* 타이핑 인디케이터 */
.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background-color: var(--text-muted);
    animation: typingBounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce { 0%,60%,100%{ transform: translateY(0); opacity:0.4;} 30%{ transform: translateY(-5px); opacity:1;} }

/* 빈 상태 환영 */
.chat-welcome {
    margin: auto;
    max-width: 560px;
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
}
.welcome-icon {
    width: 56px; height: 56px; margin: 0 auto 16px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(41,98,255,0.1); border: 1px solid var(--border-glow);
    border-radius: 16px; color: var(--accent);
}
.welcome-icon svg { width: 28px; height: 28px; }
.chat-welcome h2 { font-size: 22px; color: var(--text-primary); margin-bottom: 8px; }
.chat-welcome p { font-size: 14px; margin-bottom: 22px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.suggestion-chip {
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.suggestion-chip:hover { color: var(--text-primary); border-color: var(--accent); background-color: var(--bg-card); }

/* 입력창 */
.composer { flex-shrink: 0; padding: 12px 0 16px; border-top: 1px solid var(--border-color); background-color: var(--bg-app); }
.composer-inner {
    max-width: 820px; margin: 0 auto; padding: 0 24px;
    display: flex; align-items: flex-end; gap: 10px;
}
#chat-input {
    flex-grow: 1;
    resize: none;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 14.5px;
    line-height: 1.5;
    padding: 12px 14px;
    max-height: 160px;
    outline: none;
    transition: border-color var(--transition-fast);
}
#chat-input:focus { border-color: var(--accent); }
#chat-input::placeholder { color: var(--text-muted); }

.send-btn, .stop-btn {
    flex-shrink: 0;
    width: 44px; height: 44px;
    border: none; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all var(--transition-fast);
}
.send-btn { background-color: var(--accent); color: #fff; }
.send-btn:disabled { background-color: var(--bg-card); color: var(--text-muted); cursor: not-allowed; }
.send-btn:not(:disabled):hover { background-color: var(--accent-hover); }
.send-btn svg, .stop-btn svg { width: 20px; height: 20px; }
.stop-btn { background-color: var(--down-color); color: #fff; }
.stop-btn[hidden] { display: none; }

.composer-hint { max-width: 820px; margin: 8px auto 0; padding: 0 24px; font-size: 11.5px; color: var(--text-muted); text-align: center; }

/* 연결 상태 점 */
.connection-status .status-dot { background-color: var(--text-muted); }
.connection-status.connected .status-dot { background-color: var(--up-color); }
.connection-status.thinking .status-dot { background-color: var(--accent); }
.connection-status.error .status-dot { background-color: var(--down-color); }

/* --- 모바일 반응형 (≤768px): 문서 스크롤 + 입력창 하단 고정 --- */
@media (max-width: 768px) {
    .chat-layout {
        height: auto;
        min-height: calc(100dvh - 52px);
        overflow: visible;
    }
    .chat-thread { overflow-y: visible; padding: 16px 0; }

    /* 메시지/입력 좌우 여백 축소 */
    .msg-row .bubble-wrap { padding: 0 14px; }
    .bubble { max-width: 92%; font-size: 14px; }

    /* 입력창을 화면 하단에 고정 (문서가 스크롤돼도 항상 보이게) */
    .composer {
        position: sticky;
        bottom: 0;
        padding: 10px 0 12px;
    }
    .composer-inner { padding: 0 14px; gap: 8px; }
    .composer-hint { padding: 0 14px; font-size: 11px; }
    .send-btn, .stop-btn { width: 42px; height: 42px; }

    /* 560px 고정폭이 뷰포트보다 넓어 칩이 잘리던 문제 → 화면폭으로 제한 */
    .chat-welcome { padding: 16px; max-width: 100%; }
    .chat-welcome h2 { font-size: 19px; }
    .suggestion-chip { max-width: 100%; }
}
