body { overflow: hidden; }

.page-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 28px 0; max-width: 1100px; margin: 0 auto;
    opacity: 0; animation: slideDown 0.5s var(--ease) 0.05s forwards;
}
.brand-title { font-size: 15px; font-weight: 500; color: var(--fg); }
.brand-sub { font-size: 12px; color: var(--fg-3); margin-left: 10px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.back {
    display: inline-flex; align-items: center; gap: 6px;
    color: var(--fg-3); font-size: 12px; text-decoration: none;
    transition: color 0.15s, transform 0.15s;
}
.back:hover { color: var(--fg); transform: translateX(-2px); }

.model-select {
    background: var(--panel);
    border: 1px solid var(--line-2);
    border-radius: 7px;
    color: var(--fg-2);
    padding: 6px 10px;
    font-size: 12px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    backdrop-filter: blur(10px);
    transition: border-color 0.15s;
}
.model-select:hover { border-color: var(--line-3); color: var(--fg); }

.btn-ghost {
    padding: 6px 12px; border-radius: 7px;
    color: var(--fg-3); font-size: 12px;
    background: none; transition: all 0.15s;
}
.btn-ghost:hover { color: var(--fg); background: rgba(200, 195, 230, 0.06); }

.wrap {
    max-width: 880px;
    margin: 0 auto;
    padding: 18px 24px 110px;
    height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-sidebar {
    position: fixed;
    left: 0;
    top: 60px;
    bottom: 0;
    width: 240px;
    background: rgba(8, 9, 16, 0.85);
    border-right: 1px solid rgba(200, 195, 230, 0.08);
    backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transform: translateX(0);
    transition: transform 0.25s var(--ease);
}
.chat-sidebar.collapsed { transform: translateX(-100%); }
.cs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 14px 10px;
    border-bottom: 1px solid rgba(200, 195, 230, 0.06);
}
.cs-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fg-3);
    font-weight: 500;
}
.cs-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    background: transparent;
    border: 0;
    color: var(--fg-3);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.cs-icon:hover { background: rgba(200, 195, 230, 0.08); color: var(--fg); }
.cs-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cs-list::-webkit-scrollbar { width: 4px; }
.cs-list::-webkit-scrollbar-thumb { background: rgba(200, 195, 230, 0.1); border-radius: 4px; }
.cs-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 10px;
    border-radius: 7px;
    background: transparent;
    color: var(--fg-2);
    font-size: 12.5px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.cs-item:hover { background: rgba(200, 195, 230, 0.05); color: var(--fg); }
.cs-item.active { background: rgba(184, 176, 218, 0.12); border-color: rgba(184, 176, 218, 0.18); color: var(--fg); }
.cs-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cs-item-time { font-size: 10px; color: var(--fg-3); flex-shrink: 0; }
.cs-item-del {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--fg-3);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.cs-item:hover .cs-item-del { opacity: 1; }
.cs-item-del:hover { background: rgba(208, 130, 130, 0.18); color: #d08282; }
.cs-empty {
    text-align: center;
    color: var(--fg-3);
    font-size: 11.5px;
    padding: 24px 14px;
    line-height: 1.6;
}
.cs-foot {
    padding: 10px;
    border-top: 1px solid rgba(200, 195, 230, 0.06);
}
.cs-clear-btn {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid rgba(208, 130, 130, 0.18);
    color: #d08282;
    font-size: 11.5px;
    cursor: pointer;
    transition: background 0.12s;
}
.cs-clear-btn:hover { background: rgba(208, 130, 130, 0.1); }

.cs-expand {
    position: fixed;
    left: 8px;
    top: 70px;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: rgba(8, 9, 16, 0.85);
    border: 1px solid rgba(200, 195, 230, 0.1);
    color: var(--fg-3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 59;
    backdrop-filter: blur(10px);
    transition: color 0.12s, background 0.12s;
}
.cs-expand:hover { background: rgba(200, 195, 230, 0.08); color: var(--fg); }

@media (min-width: 1100px) {
    body:has(.chat-sidebar:not(.hidden):not(.collapsed)) .wrap { margin-left: 240px; }
}

.hidden { display: none !important; }

.setup-notice { margin: 60px auto; max-width: 600px; }
.setup-card {
    background: var(--panel); border: 1px solid var(--line-2);
    border-radius: 14px; padding: 30px; text-align: center;
    backdrop-filter: blur(20px);
}
.setup-icon {
    width: 42px; height: 42px; border-radius: 50%;
    background: rgba(184, 176, 218, 0.12); color: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 600; margin: 0 auto 14px;
}
.setup-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.setup-desc { font-size: 13px; color: var(--fg-2); line-height: 1.6; }
.setup-desc code {
    background: rgba(200, 195, 230, 0.08);
    padding: 2px 7px; border-radius: 4px;
    font-size: 12px; color: var(--accent);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}

.chat-view {
    flex: 1; display: flex; flex-direction: column; min-height: 0;
    opacity: 0; animation: slideUp 0.45s var(--ease) 0.1s forwards;
}

.messages {
    flex: 1; overflow-y: auto;
    padding: 8px 0 24px;
    display: flex; flex-direction: column; gap: 18px;
}

.empty-state {
    margin: auto; text-align: center; padding: 40px 20px;
    max-width: 440px;
}
.empty-title {
    font-size: 22px; font-weight: 700; letter-spacing: -0.02em;
    margin-bottom: 6px; color: var(--fg);
}
.empty-sub { font-size: 13px; color: var(--fg-3); margin-bottom: 22px; }
.quick-row {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.quick-chip {
    padding: 7px 13px; border-radius: 999px;
    background: var(--panel); border: 1px solid var(--line-2);
    color: var(--fg-2); font-size: 11.5px; font-weight: 500;
    transition: all 0.15s; backdrop-filter: blur(10px);
}
.quick-chip:hover { background: rgba(40, 42, 58, 0.6); color: var(--fg); border-color: var(--line-3); }

.msg {
    display: flex; flex-direction: column; gap: 4px;
    animation: slideUp 0.3s var(--ease) forwards;
    max-width: 88%;
}
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; max-width: 92%; }
.msg-role {
    font-size: 10px; font-weight: 600; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--fg-3);
    padding: 0 14px;
}
.msg.user .msg-role { text-align: right; color: var(--accent); }
.msg-bubble {
    padding: 11px 16px; border-radius: 14px;
    font-size: 13.5px; line-height: 1.6; color: var(--fg);
}
.msg.user .msg-bubble {
    background: rgba(184, 176, 218, 0.12);
    border: 1px solid rgba(184, 176, 218, 0.18);
    border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
    background: rgba(20, 22, 38, 0.45);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
    backdrop-filter: blur(10px);
}
.msg.error .msg-bubble {
    background: rgba(208, 130, 130, 0.07);
    border: 1px solid rgba(208, 130, 130, 0.18);
    color: #d08282;
}

.msg-bubble p { margin: 0 0 10px; }
.msg-bubble p:last-child { margin: 0; }
.msg-bubble code {
    background: rgba(200, 195, 230, 0.08);
    padding: 1px 6px; border-radius: 3px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px;
    color: var(--accent);
}

.msg-bubble .code-block {
    margin: 12px 0;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-2);
}
.msg-bubble .code-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px 6px 14px;
    background: rgba(10, 11, 20, 0.6);
    border-bottom: 1px solid var(--line);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.msg-bubble .code-lang {
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--fg-3);
    text-transform: lowercase;
}
.msg-bubble .code-copy {
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 10.5px;
    font-weight: 500;
    color: var(--fg-3);
    background: rgba(200, 195, 230, 0.05);
    border: 1px solid transparent;
    transition: all 0.15s;
    font-family: inherit;
    cursor: pointer;
}
.msg-bubble .code-copy:hover {
    color: var(--fg);
    background: rgba(200, 195, 230, 0.1);
    border-color: var(--line-2);
}
.msg-bubble pre {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 13px;
    line-height: 1.6;
    background: transparent;
    border: 0;
}
.msg-bubble .code-block pre { border-radius: 0; }
.msg-bubble pre:not(.code-block pre) {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 10px 0;
}
.msg-bubble pre code {
    background: none; padding: 0; color: var(--fg);
    font-size: inherit;
}

.msg-bubble ul, .msg-bubble ol { margin: 8px 0 10px; padding-left: 24px; }
.msg-bubble li { margin: 4px 0; line-height: 1.6; }
.msg-bubble li::marker { color: var(--accent-2); }
.msg-bubble ul ul, .msg-bubble ol ol, .msg-bubble ul ol, .msg-bubble ol ul {
    margin: 4px 0;
}

.msg-bubble strong { color: var(--fg); font-weight: 600; }
.msg-bubble em { color: var(--fg-2); font-style: italic; }
.msg-bubble del { color: var(--fg-3); }

.msg-bubble h1, .msg-bubble h2, .msg-bubble h3,
.msg-bubble h4, .msg-bubble h5, .msg-bubble h6 {
    margin: 18px 0 8px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--fg);
    line-height: 1.3;
}
.msg-bubble h1 { font-size: 22px; }
.msg-bubble h2 { font-size: 19px; }
.msg-bubble h3 { font-size: 16.5px; }
.msg-bubble h4 { font-size: 14.5px; }
.msg-bubble h5, .msg-bubble h6 { font-size: 13.5px; color: var(--fg-2); }

.msg-bubble h1:first-child, .msg-bubble h2:first-child,
.msg-bubble h3:first-child, .msg-bubble h4:first-child { margin-top: 0; }

.msg-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: rgba(184, 176, 218, 0.4);
    transition: text-decoration-color 0.15s;
}
.msg-bubble a:hover { text-decoration-color: var(--accent); }

.msg-bubble blockquote {
    margin: 12px 0;
    padding: 10px 14px;
    border-left: 3px solid var(--accent-2);
    background: rgba(184, 176, 218, 0.05);
    border-radius: 0 8px 8px 0;
    color: var(--fg-2);
    font-style: italic;
}
.msg-bubble blockquote p { margin: 0; }

.msg-bubble hr {
    margin: 16px 0;
    border: 0;
    border-top: 1px solid var(--line-2);
}

.msg-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 12.5px;
    overflow: hidden;
    border-radius: 8px;
    border: 1px solid var(--line);
}
.msg-bubble thead {
    background: rgba(10, 11, 20, 0.5);
}
.msg-bubble th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--fg);
    border-bottom: 1px solid var(--line);
    font-size: 11.5px;
    letter-spacing: 0.02em;
}
.msg-bubble td {
    padding: 7px 12px;
    color: var(--fg-2);
    border-top: 1px solid var(--line);
}
.msg-bubble tbody tr:hover { background: rgba(200, 195, 230, 0.03); }

.msg-bubble details.think {
    margin: 8px 0 12px;
    padding: 0;
    background: rgba(10, 11, 20, 0.4);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.msg-bubble details.think summary {
    padding: 7px 12px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    color: var(--fg-3);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    user-select: none;
    list-style: none;
    transition: background 0.15s;
}
.msg-bubble details.think summary::-webkit-details-marker { display: none; }
.msg-bubble details.think summary::before {
    content: "▸ ";
    display: inline-block;
    transition: transform 0.15s;
}
.msg-bubble details.think[open] summary::before { content: "▾ "; }
.msg-bubble details.think summary:hover { background: rgba(20, 22, 38, 0.5); }
.msg-bubble details.think .think-body {
    padding: 10px 14px 12px;
    font-size: 11.5px;
    color: var(--fg-3);
    border-top: 1px solid var(--line);
    line-height: 1.6;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    max-height: 300px;
    overflow-y: auto;
}

.cursor {
    display: inline-block;
    width: 6px; height: 14px;
    background: var(--accent);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 1.05s step-end infinite;
}
@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

.composer {
    padding: 8px 0 0;
    background: linear-gradient(180deg, transparent 0%, var(--bg) 30%);
}
.composer-inner {
    display: flex;
    align-items: end;
    gap: 10px;
    position: relative;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0 8px 0 4px;
    backdrop-filter: none;
    --border-height: 1px;
    --border-before-color: rgba(200, 195, 230, 0.18);
    --border-after-color: linear-gradient(90deg, #8a80b6 0%, #c9c1ff 50%, #b8b0da 100%);
}
.composer-inner .input {
    color: var(--fg);
    font-size: 1.05rem;
    background-color: transparent;
    flex: 1;
    box-sizing: border-box;
    padding-inline: 0.9em;
    padding-block: 0.8em;
    border: none;
    border-bottom: var(--border-height) solid rgba(200, 195, 230, 0.18);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    max-height: 220px;
    overflow-y: auto;
}
.composer-inner .input::placeholder { color: var(--fg-3); }
.composer-inner .input:focus { outline: none; }
.composer-inner .input-border {
    position: absolute;
    background: rgba(200, 195, 230, 0.5);
    width: 0;
    height: 2px;
    bottom: 0;
    left: 0;
    transition: width 0.3s cubic-bezier(0.6, -0.28, 0.735, 0.045);
    pointer-events: none;
}
.composer-inner .input-border-alt {
    height: 3px;
    background: linear-gradient(90deg, #8a80b6 0%, #c9c1ff 50%, #b8b0da 100%);
    background-size: 200% 100%;
    background-position: 0% 50%;
    transition: width 0.4s cubic-bezier(0.42, 0, 0.58, 1);
}
.composer-inner .input:focus + .input-border,
.composer-inner .input:focus + .input-border-alt {
    width: calc(100% - 50px);
}


.msg.assistant.streaming .msg-bubble {
    border: 2px solid transparent;
    background:
        linear-gradient(rgba(20, 22, 38, 0.92), rgba(20, 22, 38, 0.92)) padding-box,
        linear-gradient(90deg,
            #6e6798 0%,
            #8a80b6 12%,
            #a89dd0 24%,
            #c9c1ff 36%,
            #d6d0ff 48%,
            #c9c1ff 60%,
            #a89dd0 72%,
            #8a80b6 84%,
            #6e6798 100%
        ) border-box;
    background-size: 100% 100%, 400% 100%;
    background-position: 0 0, 0% 50%;
    box-shadow: 0 0 28px rgba(201, 193, 255, 0.22);
    will-change: background-position, box-shadow;
    animation:
        noctMsgGradientShift 4.5s linear infinite,
        noctMsgGlowPulse 3.6s ease-in-out infinite;
    transition: box-shadow 0.35s ease;
}
@keyframes noctMsgGradientShift {
    0%   { background-position: 0 0, 0% 50%; }
    100% { background-position: 0 0, 400% 50%; }
}
@keyframes noctMsgGlowPulse {
    0%, 100% { box-shadow: 0 0 22px rgba(201, 193, 255, 0.16); }
    50%      { box-shadow: 0 0 34px rgba(201, 193, 255, 0.3); }
}
.send-btn {
    flex-shrink: 0;
    width: 34px; height: 34px;
    border-radius: 9px;
    background: var(--fg);
    color: var(--bg);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.15s;
    border: 1px solid var(--fg);
}
.send-btn:not(:disabled):hover { background: var(--accent); border-color: var(--accent); transform: translateY(-1px); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.composer-foot {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px 4px;
    font-size: 11px;
    color: var(--fg-3);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
}
.dot-sep { opacity: 0.5; }
.status-tag.streaming { color: var(--accent); }
.status-tag.error { color: #d08282; }

.messages::-webkit-scrollbar { width: 6px; }

@media (max-width: 720px) {
    .wrap { padding: 14px 16px 110px; }
    .msg, .msg.assistant { max-width: 96%; }
    .quick-row { flex-direction: column; align-items: stretch; }
}

