:root {
    --bg-0: #0a0b10;
    --bg-1: #0f1117;
    --panel: rgba(255, 255, 255, 0.03);
    --border: rgba(255, 255, 255, 0.07);
    --text: #e6e8ee;
    --text-dim: #8b90a0;
    --accent: #6366f1;
    --accent-2: #a855f7;
    --accent-grad: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
}

* { box-sizing: border-box; }

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
    background:
            radial-gradient(1200px 800px at 20% 0%, #1a1533 0%, transparent 60%),
            radial-gradient(1000px 600px at 100% 100%, #101a2e 0%, transparent 60%),
            var(--bg-0);
    color: var(--text);
    overflow: hidden;
}

.app { display: flex; height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
    width: 288px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: rgba(10, 11, 16, 0.55);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 14px;
    overflow: hidden;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px 8px;
}

.logo {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #fff;
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}

.brand-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.brand-sub {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

.config-section { display: flex; flex-direction: column; gap: 10px; }

.section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    padding-left: 4px;
}

.select {
    appearance: none;
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.select:focus {
    border-color: rgba(99, 102, 241, 0.6);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.switch-list { display: flex; flex-direction: column; gap: 8px; }

.switch-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.switch-item:hover { background: rgba(255, 255, 255, 0.05); }

.switch {
    appearance: none;
    width: 34px;
    height: 20px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    position: relative;
    cursor: pointer;
    transition: background 0.25s;
    outline: none;
    border: none;
}

.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.25s;
}

.switch:checked { background: var(--accent-grad); }
.switch:checked::after { transform: translateX(14px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
    padding: 7px 12px;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover {
    color: var(--text);
    border-color: rgba(99, 102, 241, 0.4);
}

.chip.active {
    background: var(--accent-grad);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.session-label {
    min-height: 18px;
    padding: 0 6px;
    font-size: 12px;
    color: var(--text-dim);
}

.conv-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conv-list::-webkit-scrollbar { width: 6px; }
.conv-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

.conv-item {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-item:hover { background: rgba(255, 255, 255, 0.05); }

.conv-item.active {
    background: rgba(99, 102, 241, 0.16);
    border-color: rgba(99, 102, 241, 0.35);
}

.conv-empty {
    padding: 12px 8px;
    font-size: 12px;
    color: var(--text-dim);
}

.sidebar-footer { margin-top: auto; padding-top: 8px; display: flex; flex-direction: column; gap: 8px; }

.ghost-btn {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.ghost-btn:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.18); }

/* ---------- 主区 ---------- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 60px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    backdrop-filter: blur(10px);
}

.topbar-title { font-size: 14px; font-weight: 600; }

.topbar-meta {
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pill {
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--panel);
    border: 1px solid var(--border);
}

.chat {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
}

/* 空状态 */
.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    animation: fadeIn 0.5s ease;
}

.empty-logo {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: var(--accent-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    color: #fff;
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.4);
    margin-bottom: 22px;
}

.empty-state h1 {
    font-size: 26px;
    font-weight: 600;
    margin: 0 0 8px;
    background: linear-gradient(135deg, #fff 0%, #c7c9ff 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-dim);
    margin: 0 0 32px;
}

.suggestions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 240px));
    gap: 12px;
}

.suggestion {
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
}

.suggestion:hover {
    transform: translateY(-2px);
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(99, 102, 241, 0.08);
}

/* 消息 */
.msg {
    display: flex;
    gap: 14px;
    margin-bottom: 26px;
    animation: fadeIn 0.3s ease;
}

.msg-user { flex-direction: row-reverse; }

.avatar {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--accent-grad);
}

.msg-user .avatar { background: rgba(255, 255, 255, 0.1); color: var(--text); }

.msg-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 720px;
    min-width: 0;
}

.tool-trace {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-dim);
    overflow-wrap: anywhere;
}

.tool-trace:empty { display: none; }

.msg-content {
    max-width: 720px;
    font-size: 14px;
    line-height: 1.7;
    padding: 12px 16px;
    border-radius: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.msg-user .msg-content {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.22),
    rgba(168, 85, 247, 0.18));
    border-color: rgba(99, 102, 241, 0.35);
    white-space: pre-wrap;
}

/* Markdown 排版 */
.markdown h1, .markdown h2, .markdown h3 { margin: 14px 0 8px; font-weight: 600; }
.markdown h1 { font-size: 18px; }
.markdown h2 { font-size: 16px; }
.markdown h3 { font-size: 14px; }
.markdown p { margin: 8px 0; }
.markdown ul, .markdown ol { padding-left: 22px; margin: 8px 0; }
.markdown li { margin: 4px 0; }
.markdown code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12.5px;
    font-family: "JetBrains Mono", Consolas, monospace;
    color: #c7c9ff;
}
.markdown pre {
    background: #0a0b10;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    overflow-x: auto;
    margin: 10px 0;
}
.markdown pre code { background: none; padding: 0; color: #e6e8ee; }
.markdown table {
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
}
.markdown th, .markdown td {
    border: 1px solid var(--border);
    padding: 6px 12px;
    text-align: left;
}
.markdown th { background: rgba(255, 255, 255, 0.04); }
.markdown blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    color: var(--text-dim);
    margin: 10px 0;
}
.markdown strong { color: #fff; }
.markdown a { color: #a5b4fc; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.markdown img { max-width: 100%; border-radius: 8px; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }

/* 输入框 */
.composer-wrap { padding: 12px 24px 20px; }

.composer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 10px 10px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.composer-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.composer:focus-within {
    border-color: rgba(99, 102, 241, 0.55);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.composer textarea {
    flex: 1;
    resize: none;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    max-height: 200px;
    padding: 8px 0;
    font-family: inherit;
}

.composer textarea::placeholder { color: var(--text-dim); }

.model-picker {
    position: relative;
    flex-shrink: 0;
    align-self: flex-end;
}

.model-picker-btn {
    width: 148px;
    height: 38px;
    padding: 0 28px 0 12px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.model-picker-btn::after {
    content: "";
    position: absolute;
    top: 16px;
    right: 12px;
    border: 4px solid transparent;
    border-top-color: #8b90a0;
}

.model-picker-btn:focus {
    border-color: rgba(99, 102, 241, 0.6);
    outline: none;
}

.model-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 30;
    min-width: 180px;
    max-width: 260px;
    padding: 4px;
    border-radius: 10px;
    background: #161822;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.model-option {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.model-option:hover,
.model-option.active {
    background: rgba(99, 102, 241, 0.22);
}

.model-empty {
    padding: 8px 10px;
    color: var(--text-dim);
    font-size: 12px;
}

.send-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 10px;
    border: none;
    background: var(--accent-grad);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover:not(:disabled) { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.composer-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 8px;
}

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

.hidden { display: none !important; }

/* ---------- 认证遮罩 ---------- */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(6, 7, 12, 0.72);
    backdrop-filter: blur(14px);
    animation: fadeIn 0.25s ease;
}

.auth-card {
    width: 380px;
    max-width: 100%;
    background: rgba(18, 20, 28, 0.96);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 28px 24px 22px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
    text-align: center;
}

.auth-card.wide { width: 560px; text-align: left; }

.auth-logo {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    border-radius: 14px;
    background: var(--accent-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.4);
}

.auth-title { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
.auth-sub { margin: 0 0 18px; font-size: 12.5px; color: var(--text-dim); }

.auth-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 16px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 8px 0;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-tab.active {
    background: var(--accent-grad);
    color: #fff;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.auth-form { display: flex; flex-direction: column; gap: 10px; }

.auth-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-input:focus {
    border-color: rgba(99, 102, 241, 0.6);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.auth-submit {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--accent-grad);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.2s;
}

.auth-submit:hover:not(:disabled) { transform: translateY(-1px); }
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-error {
    min-height: 18px;
    margin-top: 10px;
    font-size: 12.5px;
    color: #ff8a8a;
}

.auth-hint {
    margin-top: 14px;
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
}

/* ---------- 管理面板 ---------- */
.admin-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.admin-head h3 { margin: 0; font-size: 17px; font-weight: 600; }

.ghost-btn.small {
    width: auto;
    padding: 6px 14px;
    font-size: 12px;
}

.admin-tip {
    margin: 0 0 14px;
    font-size: 12.5px;
    color: var(--text-dim);
}

.code-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 260px;
    overflow-y: auto;
    padding: 4px 0 14px;
}

.code-item {
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.28);
    font-family: Consolas, monospace;
    font-size: 13px;
    letter-spacing: 1px;
    color: #c7c9ff;
    user-select: all;
}

.code-empty {
    width: 100%;
    padding: 20px 0;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
}

.admin-actions { padding-top: 4px; }