/* ============================================================
   前台聊天界面 — 白/浅灰/淡蓝（清爽现代）
   ============================================================ */

body { overflow: hidden; }

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

/* ────────── 侧边栏（白色） ────────── */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: #ffffff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}
/* 顶部淡蓝装饰线 */
#sidebar::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--gold), rgba(var(--gold-rgb), 0.3));
    z-index: 1;
}

.sidebar-header {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
}
.sidebar-header h2 {
    font-family: var(--font-serif);
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 1px;
}
.sidebar-header h2::after {
    content: '';
    display: block;
    width: 24px;
    height: 2px;
    background: var(--gold);
    margin-top: 6px;
    border-radius: 1px;
}
#new-chat-btn {
    width: 34px; height: 34px;
    border-radius: var(--radius);
    background: rgba(var(--gold-rgb), 0.12);
    color: var(--gold);
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.25s;
    border: 1px solid rgba(var(--gold-rgb), 0.2);
}
#new-chat-btn:hover {
    background: rgba(var(--gold-rgb), 0.25);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(var(--gold-rgb), 0.2);
}

#session-list { flex: 1; overflow-y: auto; padding: 10px 12px; }
.session-item {
    padding: 11px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 3px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s;
    position: relative;
    border-left: 2px solid transparent;
}
.session-item:hover { background: var(--border-light); color: var(--text); }
.session-item.active {
    background: var(--gold-light);
    color: var(--primary);
    border-left-color: var(--gold);
    font-weight: 500;
}
.session-item .delete-session {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    opacity: 0; background: transparent; color: var(--text-tertiary); font-size: 16px;
    width: 24px; height: 24px; border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.session-item:hover .delete-session { opacity: 1; }
.session-item .delete-session:hover { background: rgba(239,68,68,0.2); color: #ef4444; }

.sidebar-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-light);
}
.user-info {
    margin-bottom: 8px;
}
#user-name { display: block; font-size: 13px; color: var(--text); font-weight: 500; margin-bottom: 2px; }
#quota-info { font-size: 11px; color: var(--text-tertiary); }
.admin-link {
    font-size: 12px;
    color: var(--text-tertiary);
    display: flex; align-items: center; gap: 6px;
    transition: color 0.2s;
}
.admin-link:hover { color: var(--gold); text-decoration: none; }

/* ────────── 主区域 ────────── */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

#messages-container { flex: 1; overflow-y: auto; padding: 32px 5%; }

/* 欢迎页 */
.welcome {
    text-align: center;
    padding: 80px 5% 60px;
    margin: 0 auto;
}
.welcome h1 {
    font-family: var(--font-serif);
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
    letter-spacing: 2px;
}
.welcome h1::after {
    content: '';
    display: block;
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, var(--gold), rgba(var(--gold-rgb), 0.3));
    margin: 16px auto 0;
    border-radius: 2px;
}
.welcome p { color: var(--text-secondary); line-height: 1.8; margin: 20px 0 32px; font-size: 15px; }

.example-questions { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.example-q {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 28px;
    width: 100%; max-width: 520px;
    font-size: 14px;
    text-align: center;
    color: var(--primary);
    transition: all 0.25s;
    box-shadow: var(--shadow-sm);
}
.example-q:hover {
    border-color: var(--gold);
    color: var(--gold);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ────────── 消息 ────────── */
.message { display: flex; margin: 0 0 20px; animation: fadeUp 0.35s ease-out; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.message.user { justify-content: flex-end; }
.message.user .bubble {
    background: var(--primary);
    color: white;
    padding: 14px 22px;
    border-radius: 18px 18px 4px 18px;
    font-size: 14px; line-height: 1.6;
    max-width: 72%;
    box-shadow: 0 2px 10px rgba(var(--primary-rgb), 0.2);
}

.message.assistant { justify-content: flex-start; }
.message.assistant .bubble {
    max-width: 78%;
    background: var(--surface);
    border: 1px solid var(--border-light);
    padding: 20px 24px;
    border-radius: 4px 18px 18px 18px;
    font-size: 14px; line-height: 1.8;
    box-shadow: var(--shadow);
}

/* 助手消息 Markdown 渲染 */
.msg-content h2 { font-family: var(--font-serif); font-size: 17px; font-weight: 700; margin: 20px 0 10px; color: var(--text-blue); padding-bottom: 6px; border-bottom: 1px solid var(--border-light); }
.msg-content h3 { font-family: var(--font-serif); font-size: 15px; font-weight: 700; margin: 16px 0 8px; color: var(--text-blue); }
.msg-content h4 { font-size: 14px; margin: 14px 0 6px; color: var(--text); }
.msg-content p { margin: 8px 0; }
.msg-content strong { font-weight: 600; color: var(--text-blue); }
.msg-content blockquote {
    border-left: 3px solid var(--gold);
    padding: 10px 16px; margin: 10px 0;
    background: var(--gold-light);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: var(--font-serif);
    line-height: 1.8;
}
.msg-content hr { border: none; border-top: 1px dashed var(--border); margin: 18px 0; }
.msg-content ul, .msg-content ol { margin: 8px 0; padding-left: 22px; }
.msg-content li { margin: 4px 0; }
.msg-content table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.msg-content th { background: var(--primary); color: white; padding: 8px 12px; text-align: left; font-weight: 500; }
.msg-content td { padding: 8px 12px; border-bottom: 1px solid var(--border-light); }
.msg-content tr:nth-child(even) td { background: var(--surface-warm); }

/* 来源链接 */
.source-link {
    color: var(--gold-dark);
    cursor: pointer;
    border-bottom: 1px dashed var(--gold);
    transition: all 0.2s;
    font-size: 13px;
}
.source-link:hover { background: var(--gold-light); }

/* AI 补充说明 */
.ai-supplement-badge {
    display: inline-block;
    background: var(--gold-light);
    color: var(--gold-dark);
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 4px;
    margin-top: 12px;
    border: 1px solid rgba(var(--gold-rgb), 0.25);
    font-weight: 500;
}

/* 引用来源块 */
.sources-block {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border-light);
}
.sources-block summary {
    font-size: 12px;
    color: var(--text-tertiary);
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}
.sources-block summary:hover { color: var(--gold); }
.source-item {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 6px 0;
    padding: 6px 12px;
    background: var(--surface-warm);
    border-radius: var(--radius-sm);
    border-left: 2px solid var(--gold-light);
    transition: all 0.2s;
}
.source-item:hover { border-left-color: var(--gold); background: var(--gold-light); }
.source-item .doc-name { color: var(--text-blue); font-weight: 500; }
.source-num { color: var(--gold); font-weight: 700; margin-right: 4px; font-size: 13px; }
.source-ref {
    color: var(--gold); font-weight: 700; font-size: 12px;
    cursor: pointer; text-decoration: none;
    vertical-align: super; line-height: 0;
    padding: 0 2px; transition: color 0.2s;
}
.source-ref:hover { color: var(--primary); background: var(--gold-light); border-radius: 3px; }
a.source-ref { color: var(--gold); }

/* ────────── 消息工具栏 ────────── */
.msg-toolbar {
    display: flex; gap: 4px; justify-content: flex-end;
    margin-top: 8px; padding-top: 8px;
    border-top: 1px solid var(--border-light);
    opacity: 0.3; transition: opacity 0.2s;
}
.message.assistant:hover .msg-toolbar { opacity: 1; }
.toolbar-btn {
    background: none; border: none; cursor: pointer;
    font-size: 14px; color: var(--text-secondary); padding: 2px 6px;
    border-radius: 4px; transition: all 0.2s; line-height: 1;
}
.toolbar-btn:hover { background: var(--surface-hover); color: var(--text); }
.toolbar-btn.active { color: var(--gold); }
.up-btn.active { color: #22c55e; }
.down-btn.active { color: #ef4444; }
.source-preview {
    font-size: 12px; color: var(--text-tertiary); padding: 4px 12px 8px 16px;
    line-height: 1.5; border-bottom: 1px solid var(--border-light);
}

/* ────────── 输入区 ────────── */
#input-area {
    padding: 20px 40px 28px;
    border-top: 1px solid var(--border-light);
    background: var(--surface-warm);
}
.input-wrapper { display: flex; gap: 10px; align-items: flex-end; margin: 0 5%; }
#question-input {
    flex: 1; resize: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    font-size: 14px; line-height: 1.6;
    max-height: 120px;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
#question-input::placeholder { color: var(--text-tertiary); }
#send-btn {
    padding: 14px 28px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-lg);
    font-size: 14px; font-weight: 500;
    transition: all 0.25s;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.25);
}
#send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.35);
}
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 模型指示器 */
.model-indicator {
    display: flex; align-items: center; gap: 12px;
    margin: 10px 5% 0;
}
#quota-display { font-size: 12px; color: var(--text-tertiary); }
#model-badge {
    display: inline-block; padding: 3px 12px;
    border-radius: 4px; font-size: 11px; font-weight: 500;
}
#model-badge.flash { background: rgba(var(--primary-rgb), 0.08); color: var(--primary); }
#model-badge.pro { background: var(--gold-light); color: var(--gold-dark); }
#status-indicator { font-size: 12px; color: var(--text-tertiary); }

/* ────────── Toast 提示 ────────── */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--primary-dark); color: #ffffff;
    padding: 10px 20px; border-radius: 8px;
    font-size: 14px; z-index: 9999;
    box-shadow: 0 4px 16px rgba(15,23,42,0.18);
    pointer-events: none;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(-4px); }
}
/* 加载动画 */
.typing-indicator { display: inline-flex; align-items: center; gap: 5px; padding: 10px 14px; }
.typing-indicator span {
    width: 6px; height: 6px; background: var(--gold); border-radius: 50%;
    animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,60%,100% { opacity: 0.2; transform: scale(1); } 30% { opacity: 1; transform: scale(1.3); } }

/* ────────── 弹窗 ────────── */
.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border-top: 3px solid var(--gold);
    padding: 28px; max-width: 680px; width: 90%;
    max-height: 80vh; overflow-y: auto;
    box-shadow: var(--shadow-lg); position: relative;
}
.modal-close {
    position: absolute; top: 14px; right: 18px;
    font-size: 26px; cursor: pointer; color: var(--text-tertiary);
    transition: color 0.2s; line-height: 1;
}
.modal-close:hover { color: var(--primary); }
.modal h3 { font-family: var(--font-serif); font-size: 16px; margin-bottom: 14px; padding-right: 28px; color: var(--primary); }
.modal pre {
    white-space: pre-wrap; font-size: 13px; line-height: 1.7;
    color: var(--text-secondary); background: var(--surface-warm);
    padding: 16px; border-radius: var(--radius-sm);
    max-height: 50vh; overflow-y: auto; font-family: var(--font);
}

/* ────────── 汉堡菜单按钮（小屏） ────────── */
#hamburger-btn {
    display: none;
    position: fixed;
    top: 10px; left: 10px;
    z-index: 60;
    width: 36px; height: 36px;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    font-size: 18px;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    border: none;
    cursor: pointer;
}

/* ────────── 响应式 ────────── */

/* 窄屏 < 768px */
@media (max-width: 767px) {
    #hamburger-btn { display: flex; }

    #sidebar {
        position: fixed;
        top: 0; left: -100%;
        width: 260px; height: 100vh;
        z-index: 55;
        padding-top:30px;
        transition: left 0.3s ease;
    }
    #sidebar.open { left: 0; }

    /* 点击遮罩 */
    #sidebar-overlay {
        display: none;
        position: fixed; top: 0; left: 0;
        width: 100vw; height: 100vh;
        background: rgba(0,0,0,0.4);
        z-index: 54;
    }
    #sidebar-overlay.active { display: block; }

    #messages-container { padding: 16px 12px 16px 48px; }
    #input-area { padding: 12px 5% 20px; }
    .welcome { padding: 32px 12px 24px; }
    .welcome h1 { font-size: 22px; }
    .message.user .bubble { max-width: 90%; }
    .message.assistant .bubble { max-width: 92%; padding: 16px 18px; }
    .input-wrapper { max-width: none; margin: 0 5%; }
    .model-indicator { max-width: none; margin: 10px 5% 0; }
    #send-btn { padding: 12px 16px; }
}

/* 中等屏 768–1199px */
@media (min-width: 768px) and (max-width: 1199px) {
    #sidebar { width: 200px; min-width: 200px; }
    :root { --sidebar-width: 200px; }
    .sidebar-header { padding: 16px 14px 12px; }
    .sidebar-header h2 { font-size: 15px; }
    #session-list { padding: 8px 10px; }

    #messages-container { padding: 24px 5%; }
    #input-area { padding: 16px 5% 24px; }
}

/* 宽屏 ≥ 1200px — 流体，无变化 */
