html, body {
    height: 100%;
    overflow: hidden;
    margin: 0;
}

.chat_page {
    height: 100vh;
    height: 100dvh;
    background: #0f1419;
    color: #e8eaed;
    padding: 16px 0 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
}

.chat_page a:not(.chat_btn) { color: #EEC41E; }
.chat_page a:not(.chat_btn):hover { color: #ffd84a; }

.chat_wrap {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

.chat_header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.chat_header h1 {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    margin: 0;
}

.chat_header h1 span { color: #EEC41E; }

.chat_meta {
    font-size: 13px;
    color: rgba(255,255,255,0.55);
    margin-top: 2px;
}

.chat_btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none !important;
    background: #EEC41E;
    color: #1a1a1a !important;
}

.chat_btn:hover {
    background: #ffd84a;
    color: #1a1a1a !important;
}

.chat_btn.chat_btn_ghost {
    background: transparent;
    color: #e8eaed !important;
    border: 1px solid rgba(255,255,255,0.3);
}

.chat_btn.chat_btn_ghost:hover {
    border-color: #EEC41E;
    color: #EEC41E !important;
    background: transparent;
}

.chat_btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.chat_actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.chat_gate,
.chat_loading,
.chat_error {
    max-width: 480px;
    margin: 80px auto;
    text-align: center;
    padding: 40px 28px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
}

.chat_gate h2,
.chat_error h2 {
    color: #fff;
    font-size: 24px;
    margin-bottom: 12px;
}

.chat_gate p,
.chat_error p,
.chat_loading p {
    color: rgba(255,255,255,0.75);
    margin-bottom: 24px;
}

.chat_gate .chat_actions,
.chat_error .chat_actions { justify-content: center; }

.chat_content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat_layout {
    display: flex;
    flex: 1;
    min-height: 0;
    height: 100%;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    overflow: hidden;
}

.chat_sidebar {
    width: var(--sidebar-width, 280px);
    flex: 0 0 var(--sidebar-width, 280px);
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(0,0,0,0.22);
}

.chat_sidebar_head {
    padding: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.chat_sidebar_head .chat_btn {
    width: 100%;
    text-align: center;
    padding: 9px 12px;
}

.chat_session_list {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.chat_session_empty {
    padding: 16px 10px;
    font-size: 13px;
    color: rgba(255,255,255,0.4);
    text-align: center;
    line-height: 1.5;
}

.chat_session_item {
    display: flex;
    align-items: stretch;
    gap: 4px;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    flex-shrink: 0;
}

.chat_session_item.active {
    background: rgba(238, 196, 30, 0.12);
    border-color: rgba(238, 196, 30, 0.35);
}

.chat_session_item:hover {
    background: rgba(255,255,255,0.06);
}

.chat_session_item.active:hover {
    background: rgba(238, 196, 30, 0.16);
}

.chat_session_btn {
    flex: 1;
    text-align: left;
    border: none;
    background: transparent;
    color: #e8eaed;
    cursor: pointer;
    padding: 10px 10px;
    min-width: 0;
}

.chat_session_title {
    display: block;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat_session_time {
    display: block;
    margin-top: 3px;
    font-size: 11px;
    color: rgba(255,255,255,0.4);
}

.chat_session_del {
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.35);
    cursor: pointer;
    padding: 0 10px;
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}

.chat_session_del:hover {
    color: #ffb3bb;
}

.chat_resizer {
    flex: 0 0 6px;
    width: 6px;
    cursor: col-resize;
    position: relative;
    background: rgba(255,255,255,0.06);
    border-left: 1px solid rgba(255,255,255,0.08);
    border-right: 1px solid rgba(255,255,255,0.08);
    touch-action: none;
    user-select: none;
}

.chat_resizer::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 28px;
    margin: -14px 0 0 -1px;
    border-radius: 1px;
    background: rgba(255,255,255,0.28);
}

.chat_resizer:hover,
.chat_layout.is-resizing .chat_resizer {
    background: rgba(238, 196, 30, 0.18);
}

.chat_resizer:hover::after,
.chat_layout.is-resizing .chat_resizer::after {
    background: #EEC41E;
}

.chat_layout.is-resizing {
    cursor: col-resize;
    user-select: none;
}

.chat_shell {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat_run_panel {
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.28);
    overflow: hidden;
    font-size: 12px;
    color: rgba(255,255,255,0.7);
}

.chat_run_panel[hidden] { display: none !important; }

.chat_run_head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    min-height: 36px;
}

.chat_run_dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.35);
    flex-shrink: 0;
}

.chat_run_panel.is-live .chat_run_dot {
    background: #EEC41E;
    box-shadow: 0 0 0 3px rgba(238, 196, 30, 0.2);
    animation: chat_pulse 1.2s ease-in-out infinite;
}

.chat_run_panel.is-error .chat_run_dot {
    background: #ff6b7a;
    box-shadow: none;
    animation: none;
}

.chat_run_panel.is-done .chat_run_dot {
    background: #5dcea0;
    animation: none;
}

@keyframes chat_pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.chat_run_label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgba(255,255,255,0.85);
}

.chat_run_meta {
    color: rgba(255,255,255,0.4);
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.chat_run_toggle {
    border: 1px solid rgba(255,255,255,0.2);
    background: transparent;
    color: rgba(255,255,255,0.7);
    border-radius: 3px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
    flex-shrink: 0;
}

.chat_run_toggle:hover {
    border-color: #EEC41E;
    color: #EEC41E;
}

.chat_run_trace {
    margin: 0;
    padding: 0 12px 10px 28px;
    max-height: 140px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    list-style: none;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.chat_run_trace[hidden] { display: none !important; }

.chat_run_trace li {
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    line-height: 1.4;
    color: rgba(255,255,255,0.55);
    word-break: break-all;
    overflow-wrap: break-word;
}

.chat_run_trace li:last-child { border-bottom: none; }

.chat_run_trace .ev-type {
    color: #EEC41E;
    font-weight: 600;
    margin-right: 6px;
}

.chat_run_trace .ev-ok { color: #5dcea0; }
.chat_run_trace .ev-bad { color: #ff6b7a; }
.chat_run_trace .ev-ms {
    color: rgba(255,255,255,0.35);
    margin-left: 6px;
}

.chat_messages {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.chat_empty {
    margin: auto;
    text-align: center;
    color: rgba(255,255,255,0.45);
    font-size: 14px;
    max-width: 320px;
    line-height: 1.6;
}

.chat_bubble {
    max-width: min(720px, 88%);
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 15px;
    line-height: 1.55;
    word-break: break-word;
    flex-shrink: 0;
}

.chat_bubble.user {
    align-self: flex-end;
    background: rgba(238, 196, 30, 0.18);
    border: 1px solid rgba(238, 196, 30, 0.35);
    color: #fff;
    white-space: pre-wrap;
}

.chat_bubble.assistant {
    align-self: flex-start;
    background: rgba(0,0,0,0.28);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
}

.chat_bubble.pending { opacity: 0.85; }

.chat_bubble.error {
    align-self: flex-start;
    background: rgba(220, 53, 69, 0.15);
    border: 1px solid rgba(220, 53, 69, 0.4);
    color: #ffb3bb;
    white-space: pre-wrap;
}

.chat_bubble.assistant.md-body { white-space: normal; }
.chat_bubble.assistant.md-body > *:first-child { margin-top: 0; }
.chat_bubble.assistant.md-body > *:last-child { margin-bottom: 0; }

.chat_bubble.assistant .chat_thinking {
    color: rgba(255, 255, 255, 0.42);
    font-size: 0.9em;
    line-height: 1.5;
    margin: 0 0 0.85em;
    padding: 0 0 0.75em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.chat_bubble.assistant .chat_thinking p { color: rgba(255, 255, 255, 0.42); }
.chat_bubble.assistant .chat_answer { color: #fff; }
.chat_bubble.assistant .chat_answer p,
.chat_bubble.assistant .chat_answer li { color: #fff; }

.chat_bubble.assistant.md-body p { margin: 0 0 0.7em; }
.chat_bubble.assistant.md-body h1,
.chat_bubble.assistant.md-body h2,
.chat_bubble.assistant.md-body h3,
.chat_bubble.assistant.md-body h4 {
    color: #fff;
    font-weight: 700;
    line-height: 1.3;
    margin: 0.9em 0 0.45em;
}
.chat_bubble.assistant.md-body h1 { font-size: 1.35em; }
.chat_bubble.assistant.md-body h2 { font-size: 1.2em; }
.chat_bubble.assistant.md-body h3 { font-size: 1.08em; }
.chat_bubble.assistant.md-body ul,
.chat_bubble.assistant.md-body ol {
    margin: 0 0 0.7em;
    padding-left: 1.4em;
}
.chat_bubble.assistant.md-body li { margin: 0.2em 0; }
.chat_bubble.assistant.md-body a { color: #EEC41E; }
.chat_bubble.assistant.md-body blockquote {
    margin: 0 0 0.7em;
    padding: 0.35em 0.8em;
    border-left: 3px solid rgba(238, 196, 30, 0.55);
    color: #fff;
}
.chat_bubble.assistant .chat_thinking blockquote {
    color: rgba(255, 255, 255, 0.42);
    border-left-color: rgba(255, 255, 255, 0.25);
}
.chat_bubble.assistant.md-body hr {
    border: 0;
    border-top: 1px solid rgba(255,255,255,0.15);
    margin: 0.9em 0;
}
.chat_bubble.assistant.md-body code {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.9em;
    background: rgba(255,255,255,0.08);
    padding: 0.1em 0.35em;
    border-radius: 3px;
}
.chat_bubble.assistant.md-body pre {
    margin: 0 0 0.7em;
    padding: 10px 12px;
    overflow-x: auto;
    background: rgba(0,0,0,0.45);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
}
.chat_bubble.assistant.md-body pre code {
    background: none;
    padding: 0;
    font-size: 0.86em;
    line-height: 1.45;
}
.chat_bubble.assistant.md-body table {
    border-collapse: collapse;
    margin: 0 0 0.7em;
    width: 100%;
    font-size: 0.92em;
}
.chat_bubble.assistant.md-body th,
.chat_bubble.assistant.md-body td {
    border: 1px solid rgba(255,255,255,0.15);
    padding: 6px 8px;
    text-align: left;
}
.chat_bubble.assistant.md-body th {
    background: rgba(255,255,255,0.06);
    color: #EEC41E;
}

/* KaTeX on dark bubbles */
.chat_bubble.assistant .katex { color: inherit; font-size: 1.05em; }
.chat_bubble.assistant .katex-display {
    margin: 0.75em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.chat_composer {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 14px 14px 16px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.chat_compact_panel {
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.22);
    font-size: 12px;
    color: rgba(255,255,255,0.7);
}

.chat_compact_panel[hidden] { display: none !important; }

.chat_compact_head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    min-height: 36px;
}

.chat_compact_title {
    color: #EEC41E;
    font-weight: 600;
    flex-shrink: 0;
}

.chat_compact_meta {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: rgba(255,255,255,0.45);
    font-variant-numeric: tabular-nums;
}

.chat_compact_actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.chat_compact_body {
    margin: 0;
    padding: 0 12px 12px;
    max-height: 220px;
    overflow-x: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 1px solid rgba(255,255,255,0.06);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    line-height: 1.5;
    color: rgba(255,255,255,0.82);
    background: transparent;
}

.chat_compact_body[hidden] { display: none !important; }

.chat_compact_empty {
    color: rgba(255,255,255,0.4);
    font-style: italic;
}

.chat_rag_panel {
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.18);
    font-size: 12px;
    color: rgba(255,255,255,0.7);
}

.chat_rag_head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    min-height: 36px;
}

.chat_rag_title {
    color: #EEC41E;
    font-weight: 600;
    flex-shrink: 0;
}

.chat_rag_meta {
    flex: 1;
    min-width: 0;
    color: rgba(255,255,255,0.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat_rag_list {
    margin: 0;
    padding: 0 12px 10px;
    list-style: none;
    max-height: 110px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.chat_rag_list[hidden] { display: none !important; }

.chat_rag_list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.chat_rag_list li:last-child { border-bottom: none; }

.chat_rag_name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: rgba(255,255,255,0.85);
}

.chat_rag_status {
    flex-shrink: 0;
    color: rgba(255,255,255,0.4);
    font-variant-numeric: tabular-nums;
}

.chat_rag_status.is-ready { color: #5dcea0; }
.chat_rag_status.is-failed { color: #ff6b7a; }

.chat_rag_del {
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.35);
    cursor: pointer;
    padding: 0 4px;
    font-size: 14px;
    line-height: 1;
}

.chat_rag_del:hover { color: #ffb3bb; }

.chat_rag_file {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.chat_composer textarea {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 140px;
    padding: 11px 12px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-size: 15px;
    line-height: 1.4;
    outline: none;
}

.chat_composer textarea:focus { border-color: #EEC41E; }
.chat_composer textarea::placeholder { color: rgba(255,255,255,0.4); }

.chat_content[hidden],
.chat_gate[hidden],
.chat_loading[hidden],
.chat_error[hidden] { display: none !important; }

/* thin scrollbars */
.chat_session_list,
.chat_messages {
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.25) transparent;
}
.chat_session_list::-webkit-scrollbar,
.chat_messages::-webkit-scrollbar {
    width: 8px;
}
.chat_session_list::-webkit-scrollbar-thumb,
.chat_messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.22);
    border-radius: 4px;
}
.chat_session_list::-webkit-scrollbar-thumb:hover,
.chat_messages::-webkit-scrollbar-thumb:hover {
    background: rgba(238, 196, 30, 0.55);
}

@media (max-width: 768px) {
    .chat_layout {
        flex-direction: column;
    }
    .chat_sidebar {
        width: 100% !important;
        flex: 0 0 auto !important;
        max-height: 36%;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    .chat_resizer {
        display: none;
    }
    .chat_shell {
        flex: 1 1 auto;
        min-height: 0;
    }
}

