/* ── Chat Layout ──────────────────────────────────────────── */
.chat-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--toolbar-height));
    margin: -24px;
    background: var(--bg);
    position: relative;
}

.chat-sidebar {
    position: fixed;
    top: var(--toolbar-height);
    right: 0;
    width: 380px;
    max-width: 90vw;
    height: calc(100vh - var(--toolbar-height));
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 160;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
}

.chat-layout.show-sidebar .chat-sidebar {
    transform: translateX(0);
    box-shadow: -4px 0 24px rgba(0,0,0,0.12);
}

.chat-sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
}
.chat-sidebar-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}
.chat-sidebar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-rooms-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.chat-room-item {
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    margin-bottom: 2px;
    transition: var(--transition);
}
.chat-room-item:hover { background: var(--bg); }
.chat-room-item.active { background: var(--accent-light); }
.chat-room-item .room-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-room-item .room-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Chat Main Area ──────────────────────────────────────── */
.chat-main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
}

#chatContent {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Welcome / Suggested Questions (Feedback #1) ─────────── */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    flex: 1;
    padding: 40px 20px;
    text-align: center;
    overflow-y: auto;
}

.chat-welcome-icon {
    width: 72px; height: 72px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 20px;
}

.chat-welcome h2 {
    font-size: 1.3rem;
    margin-bottom: 8px;
}

.chat-welcome p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
    max-width: 480px;
}

/* Suggested questions grid — KEY UX IMPROVEMENT */
.suggested-questions {
    width: 100%;
    max-width: 640px;
    margin-top: 12px;
}

.suggested-questions h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.sq-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

.sq-btn {
    position: relative;
    padding: 16px 18px 16px 52px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    overflow: hidden;
}

.sq-btn .sq-emoji {
    position: absolute;
    left: 16px;
    top: 16px;
    font-size: 1.3rem;
    line-height: 1;
}

.sq-btn .sq-arrow {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%) translateX(4px);
    opacity: 0;
    transition: all 0.2s ease;
    color: var(--primary);
    font-size: 1rem;
}

.sq-btn:hover {
    border-color: var(--primary);
    background: linear-gradient(135deg, var(--accent-light) 0%, var(--bg-card) 100%);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transform: translateY(-2px);
}

.sq-btn:hover .sq-arrow {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.sq-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.sq-btn strong {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text);
    padding-right: 20px;
}

.sq-btn .sq-category {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--primary);
    background: var(--accent-light);
    padding: 2px 8px;
    border-radius: 99px;
    width: fit-content;
    letter-spacing: 0.01em;
}

/* Question guide hint — at the bottom of welcome */
.question-guide {
    margin-top: 16px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--accent-light);
    border-radius: var(--radius-sm);
    max-width: 600px;
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.question-guide svg { flex-shrink: 0; margin-top: 2px; color: var(--accent); }

.welcome-icon {
    width: 72px; height: 72px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--accent), #6366f1);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 20px;
}

/* ── Messages ────────────────────────────────────────────── */
.message {
    display: flex;
    gap: 10px;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message-user { align-self: flex-end; flex-direction: row-reverse; }
.message-agent { align-self: flex-start; }

.bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.6;
    position: relative;
    min-width: 60px;
}

.bubble-user {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.bubble-agent {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.bubble-content { word-break: break-word; }

.bubble-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.bubble-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 6px;
}

.msg-copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0;
    transition: var(--transition);
    display: flex;
    align-items: center;
}
.bubble-agent:hover .msg-copy-btn { opacity: 1; }
.msg-copy-btn:hover { color: var(--accent); background: var(--accent-light); }
.msg-copy-btn.copied { color: #22c55e; opacity: 1; }

.message-user .bubble-time { text-align: right; color: rgba(255,255,255,0.7); }
.message-user .bubble-footer { justify-content: flex-end; }

/* Sources */
.message-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.sources-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.source-item {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    font-size: 0.75rem;
    padding: 4px 8px;
    background: var(--bg);
    border-radius: 4px;
    margin: 2px 0;
    color: var(--text-secondary);
}

.source-path { font-weight: 500; word-break: break-word; flex: 1; }
.source-title { font-weight: 500; }
.source-score { color: var(--accent); font-size: 0.7rem; }

.source-page {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-light);
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
}

.source-view-btn {
    font-size: 0.65rem;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    border: none;
    padding: 2px 8px;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s;
}
.source-view-btn:hover { opacity: 0.85; }

.source-pdf { border-left: 2px solid var(--primary); }

/* ── PDF Viewer Overlay ───────────────────────────────── */
.pdf-viewer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}
.pdf-viewer-overlay.active {
    display: flex;
}

.pdf-viewer-panel {
    width: 90vw;
    max-width: 900px;
    height: 85vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pdf-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg);
}

.pdf-viewer-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pdf-viewer-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1;
}
.pdf-viewer-close:hover { color: var(--text); }

.pdf-viewer-frame {
    flex: 1;
    border: none;
    width: 100%;
}

/* ── XLSX Viewer Overlay ──────────────────────────────── */
.source-xlsx { border-left: 2px solid #16a34a; }
.source-view-xlsx { background: #16a34a; }

/* ── PPTX Viewer Button ──────────────────────────────── */
.source-pptx { border-left: 2px solid #e65100; }
.source-view-pptx { background: #e65100; }

/* ── DOCX Viewer Button ──────────────────────────────── */
.source-docx { border-left: 2px solid #1565c0; }
.source-view-docx { background: #1565c0; }

/* ── HWP Viewer Button ───────────────────────────────── */
.source-hwp { border-left: 2px solid #00897b; }
.source-view-hwp { background: #00897b; }

/* ── Image Viewer ────────────────────────────────────── */
.source-image { border-left: 2px solid #8e24aa; }
.source-view-image { background: #8e24aa; }

.image-viewer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.6);
    align-items: center;
    justify-content: center;
}
.image-viewer-overlay.active {
    display: flex;
}

.image-viewer-panel {
    width: 90vw;
    max-width: 900px;
    max-height: 90vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.image-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg);
}

.image-viewer-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-viewer-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1;
}
.image-viewer-close:hover { color: var(--text); }

.image-viewer-body {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: #f5f5f5;
}

.image-viewer-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
}

.xlsx-viewer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}
.xlsx-viewer-overlay.active {
    display: flex;
}

.xlsx-viewer-panel {
    width: 92vw;
    max-width: 1100px;
    height: 88vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.xlsx-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg);
}

.xlsx-viewer-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xlsx-viewer-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 4px;
    line-height: 1;
}
.xlsx-viewer-close:hover { color: var(--text); }

.xlsx-viewer-notice {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: auto;
    margin-right: 8px;
    white-space: nowrap;
}

.xlsx-viewer-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-light);
    background: #f8f9fa;
    overflow-x: auto;
    flex-shrink: 0;
}

.xlsx-sheet-tab {
    padding: 6px 14px;
    font-size: 0.75rem;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.15s;
}
.xlsx-sheet-tab:hover { color: var(--text); background: #eef1f5; }
.xlsx-sheet-tab.active {
    color: #16a34a;
    border-bottom-color: #16a34a;
    background: #fff;
}

.xlsx-viewer-body {
    flex: 1;
    overflow: auto;
    padding: 0;
}

.xlsx-viewer-body table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    font-size: 0.78rem;
}

.xlsx-viewer-body th,
.xlsx-viewer-body td {
    border: 1px solid #d1d5db;
    padding: 4px 8px;
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.xlsx-viewer-body th {
    background: #f0f4f8;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.xlsx-viewer-body tr:nth-child(even) td {
    background: #fafbfc;
}

.xlsx-viewer-body tr:hover td {
    background: #e8f4fd;
}

.xlsx-loading, .xlsx-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.xlsx-error { color: #dc2626; }

/* ── Charts ──────────────────────────────────────────────── */
.emp-chart {
    margin: 12px 0;
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    max-width: 100%;
    min-height: 200px;
}
.emp-chart canvas {
    max-height: 360px;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
    align-items: center;
}

.typing-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

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

/* ── Chat Input ──────────────────────────────────────────── */
.chat-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

#chatInputContainer {
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: var(--transition);
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,174,255,0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: none;
    padding: 8px 0;
    font-size: 0.9rem;
    font-family: var(--font);
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    color: var(--text);
}
.chat-input:focus { outline: none; }
.chat-input::placeholder { color: var(--text-muted); }

.btn-send {
    width: 36px; height: 36px;
    border-radius: 50%;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.btn-send:disabled { background: var(--border); cursor: not-allowed; }

/* Input hint — subtle tip below input */
.chat-input-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 6px;
    padding: 0 4px;
}

/* Issue 1b — Collapsible guide bar above input */
.input-guide-bar {
    padding: 4px 4px 0;
    display: flex;
    align-items: center;
}

.input-guide-toggle {
    background: none;
    border: none;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: var(--transition);
    font-family: var(--font);
}
.input-guide-toggle:hover { color: var(--accent); background: var(--accent-light); }

.input-guide-panel {
    margin: 6px 0 4px;
    padding: 10px 14px;
    background: var(--accent-light);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.6;
}
.input-guide-panel strong { font-size: 0.8rem; color: var(--text); }
.input-guide-panel ul { margin: 4px 0 0 16px; padding: 0; }
.input-guide-panel li { margin-bottom: 2px; }

/* Issue 1d — Follow-up suggestion chips after clarification */
.followup-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 0 4px 44px; /* indent to align with agent bubble */
    animation: fadeIn 0.3s ease;
}
.followup-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    width: 100%;
    margin-bottom: 2px;
}
.followup-chip {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.78rem;
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font);
    text-align: left;
}
.followup-chip:hover { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.followup-chip strong { font-size: 0.78rem; }
.followup-chip span { font-size: 0.7rem; color: var(--text-muted); }

/* ── Chat History sidebar ────────────────────────────────── */
.chat-history {
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-history-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.85rem;
    font-weight: 600;
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    margin-bottom: 4px;
    transition: var(--transition);
}
.history-item:hover { background: var(--bg); }
.history-item.active { background: var(--accent-light); }
.history-item-title {
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-item-date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Markdown rendering in chat ──────────────────────────── */
.bubble-agent h1, .bubble-agent h2, .bubble-agent h3 { margin: 12px 0 6px; }
.bubble-agent h1 { font-size: 1.1rem; }
.bubble-agent h2 { font-size: 1rem; }
.bubble-agent h3 { font-size: 0.95rem; }
.bubble-agent p { margin-bottom: 8px; }
.bubble-agent ul, .bubble-agent ol { padding-left: 20px; margin-bottom: 8px; }
.bubble-agent li { margin-bottom: 4px; }
.bubble-agent code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.84rem;
}
.bubble-agent pre {
    background: var(--primary);
    color: #e0e0e0;
    padding: 12px 16px;
    border-radius: var(--radius-xs);
    overflow-x: auto;
    margin: 8px 0;
    font-size: 0.82rem;
}
.bubble-agent pre code { background: none; padding: 0; color: inherit; }
.bubble-agent table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 0.82rem;
}
.bubble-agent table th, .bubble-agent table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}
.bubble-agent table th { background: var(--bg); font-weight: 600; }
.bubble-agent blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

/* ── Chat header with history toggle ─────────────────────── */
.chat-main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-card);
}

.history-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s ease;
}
.history-toggle-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--accent-light);
}
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-main-title {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 150;
    transition: opacity 0.3s ease;
}
.chat-layout.show-sidebar .chat-sidebar-overlay { display: block; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
    .chat-sidebar { width: 100%; max-width: 100%; }
}

@media (max-width: 480px) {
    .sq-grid { grid-template-columns: 1fr; }
    .sq-btn { padding: 14px 14px 14px 46px; }
    .sq-btn .sq-emoji { left: 14px; top: 14px; }
    .message { max-width: 95%; }
    .chat-welcome { padding: 20px 12px; justify-content: flex-start; }
}
