/* === Reset & base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #fff; color: #333; }
body { display: flex; }

/* === Sidebar === */
#sidebar {
    width: 280px; min-width: 280px;
    background: #f7f7f8; border-right: 1px solid #e0e0e0;
    display: flex; flex-direction: column;
    padding: 12px; overflow-y: auto;
    transition: margin-left 0.2s;
}
#sidebar.collapsed { margin-left: -280px; }
.sidebar-header { text-align: center; margin-bottom: 12px; }
.sidebar-header .logo { height: 40px; }
#new-conv-btn {
    width: 100%; padding: 10px; border: 1px dashed #aaa; border-radius: 8px;
    background: transparent; cursor: pointer; font-size: 14px; color: #555;
    margin-top: 8px; margin-bottom: 8px;
}
#new-conv-btn:hover { background: #ececec; }
#conv-list { flex: 1; overflow-y: auto; }
.conv-item {
    padding: 8px 10px; border-radius: 6px; cursor: pointer;
    font-size: 13px; color: #444; margin-bottom: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item:hover { background: #e8e8ea; }
.conv-item.active { background: #d6eff2; font-weight: 600; }

/* === Main area === */
#main {
    flex: 1; display: flex; flex-direction: column;
    min-width: 0;
}
header {
    padding: 8px 16px;
    background: #fff;
    display: flex; align-items: center; gap: 12px;
}
header.chat-active {
    padding: 16px 24px 8px; border-bottom: 1px solid #e0e0e0;
}
header h1 { font-size: 1.3rem; color: #222; font-weight: 700; line-height: 1.2; }
.subtitle { font-size: 0.85rem; color: #666; font-style: italic; }
.sidebar-toggle-btn {
    background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #555;
}

/* === Chat === */
#chat-container {
    flex: 1; overflow-y: auto; padding: 16px 24px;
    display: flex; flex-direction: column;
}
#chat-container.welcome-mode {
    justify-content: center;
}
#messages { max-width: 800px; margin: 0 auto; width: 100%; }

.msg { margin-bottom: 16px; line-height: 1.6; }
.msg-user {
    background: #56b8c5; color: #fff; padding: 10px 16px; border-radius: 16px 16px 4px 16px;
    max-width: 75%; margin-left: auto; word-wrap: break-word;
}
.msg-assistant {
    background: #fff; padding: 12px 16px; border-radius: 16px 16px 16px 4px;
    border: 1px solid #e0e0e0; word-wrap: break-word;
}
.msg-assistant p { margin-bottom: 0.5em; }
.msg-assistant p:last-child { margin-bottom: 0; }
.msg-assistant ul, .msg-assistant ol { margin-left: 1.2em; margin-bottom: 0.5em; }
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3 { margin: 0.6em 0 0.3em; }
.msg-assistant strong { font-weight: 600; }
.msg-assistant code { background: #f0f0f0; padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }

/* Filter banner */
.filter-banner {
    background: #e8f4fd; color: #1a5276; padding: 8px 12px; border-radius: 8px;
    font-size: 0.85rem; margin-bottom: 8px;
}

/* Sources */
.sources {
    margin-top: 8px; padding-top: 8px; border-top: 1px solid #eee;
    font-size: 0.82rem; color: #666;
}
.sources strong { color: #555; }
.sources a { color: #56b8c5; }

/* Feedback */
.feedback-row { margin-top: 6px; display: flex; gap: 6px; }
.feedback-btn {
    background: none; border: 1px solid #ddd; border-radius: 6px;
    padding: 4px 10px; cursor: pointer; font-size: 0.9rem; color: #888;
}
.feedback-btn:hover { background: #f5f5f5; }
.feedback-btn.selected { border-color: #56b8c5; color: #56b8c5; background: #eef7f8; }

/* Thinking indicator */
.thinking {
    display: inline-flex; align-items: center; gap: 6px;
    color: #888; font-style: italic; padding: 10px 16px;
}
.thinking .dots span {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: #aaa; animation: blink 1.4s infinite both;
}
.thinking .dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* === Welcome (landing page — vertically centered inside chat-container) === */
#welcome {
    padding: 40px 16px 24px;
    max-width: 800px; width: 100%; margin: 0 auto;
}
.welcome-title {
    font-size: 2.8rem; color: #222; font-weight: 700; line-height: 1.15;
}
.welcome-subtitle {
    font-size: 1.05rem; color: #666; font-style: italic; margin-top: 6px;
}
.welcome-cols {
    display: flex; gap: 48px; margin-top: 28px;
}
.welcome-col { flex: 1; }
.welcome-col strong { display: block; margin-bottom: 8px; font-size: 1rem; }
.welcome-col ul { list-style: disc; margin-left: 1.2em; font-size: 0.95rem; line-height: 1.8; }

/* === Chat form === */
#chat-form {
    padding: 16px 40px; background: #fff;
    display: flex; gap: 10px; width: 100%;
}
#chat-input {
    flex: 1; padding: 14px 18px; border: 1px solid #ccc; border-radius: 10px;
    font-size: 1rem; outline: none;
}
#chat-input:focus { border-color: #56b8c5; }
#send-btn {
    padding: 14px 24px; background: #56b8c5; color: #fff; border: none;
    border-radius: 10px; cursor: pointer; font-size: 1rem; font-weight: 500;
}
#send-btn:hover { background: #4aa3af; }
#send-btn:disabled { background: #aaa; cursor: not-allowed; }

/* === Footer === */
footer {
    text-align: center; padding: 10px; font-size: 0.8rem; color: #999;
}
footer a { color: #56b8c5; text-decoration: none; }

/* === Idle warning === */
#idle-warning {
    position: fixed; top: 0; left: 0; right: 0; z-index: 99999;
    background: #f0ad4e; color: #333; text-align: center;
    padding: 10px; font-size: 14px; cursor: pointer;
}

/* === Error === */
.msg-error {
    background: #fdecea; color: #922; padding: 10px 16px; border-radius: 8px;
    border: 1px solid #f5c6cb; font-size: 0.9rem;
}

/* === Mobile === */
@media (max-width: 768px) {
    #sidebar {
        position: fixed; left: -280px; top: 0; bottom: 0; z-index: 1000;
        transition: left 0.2s; box-shadow: 2px 0 8px rgba(0,0,0,0.1);
        margin-left: 0;
    }
    #sidebar.collapsed { margin-left: 0; }
    #sidebar.open { left: 0; }
    #welcome { padding: 24px 20px 16px; }
    .welcome-title { font-size: 1.8rem; }
    .welcome-cols { flex-direction: column; gap: 16px; }
    .msg-user { max-width: 90%; }
}
