/* ===== 厚朴知识助手 · 用户端 v2 ===== */

:root {
    --bg: #f4ecd8;
    --bg-card: #fdfbf3;
    --bg-soft: #ede4cf;
    --text: #2c1810;
    --text-secondary: #6d4c41;
    --text-light: #9a8070;
    --primary: #8b2c1c;
    --primary-light: #fde8e0;
    --primary-dark: #6b1f12;
    --accent: #c4a35a;
    --accent-light: #f0e6cc;
    --accent-dark: #9a7f3e;
    --border: #c8b6a3;
    --border-light: #e0d5c0;
    --success: #4a7c2e;
    --warning: #b8860b;
    --danger: #8b2c1c;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 4px rgba(44,24,16,0.08);
    --shadow-lg: 0 4px 20px rgba(44,24,16,0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", "Source Han Serif SC", serif;
    background: var(--bg);
    color: var(--text);
    background-image:
        radial-gradient(ellipse 800px 400px at 20% 0%, rgba(196,163,90,0.08), transparent),
        radial-gradient(ellipse 600px 300px at 80% 100%, rgba(139,44,28,0.05), transparent);
}

.user-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== 顶部栏 ===== */
.user-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: relative;
    z-index: 10;
}

.user-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--accent), transparent);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 900px;
    margin: 0 auto;
    padding: 12px 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary);
}

.brand-name {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-text {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-text:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.user-display {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
}

.btn-history-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.btn-history-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== 弹窗 ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(44,24,16,0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(2px);
}

.modal-overlay.show {
    display: flex;
}

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    width: 360px;
    box-shadow: var(--shadow-lg);
    border-top: 3px solid var(--primary);
}

.modal-box h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text);
    letter-spacing: 2px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    outline: none;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.btn-action {
    padding: 8px 18px;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-action:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.btn-action.primary {
    background: var(--primary);
    color: #fdfbf3;
    border-color: var(--primary);
}

.btn-action.primary:hover {
    background: var(--primary-dark);
    color: #fdfbf3;
}

/* ===== 历史抽屉 ===== */
.history-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.history-drawer.open {
    transform: translateX(0);
}

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(44,24,16,0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 99;
}

.drawer-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.drawer-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.drawer-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: color 0.2s;
}

.drawer-close:hover {
    color: var(--primary);
}

.btn-new-conv {
    margin: 12px 16px;
    padding: 10px 16px;
    background: var(--primary);
    color: #fdfbf3;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s;
    font-family: inherit;
}

.btn-new-conv:hover {
    background: var(--primary-dark);
}

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
}

.conv-empty-hint {
    text-align: center;
    color: var(--text-light);
    font-size: 13px;
    padding: 24px 0;
}

.conv-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
    border-left: 2px solid transparent;
}

.conv-item:hover {
    background: var(--bg-soft);
    border-left-color: var(--accent);
}

.conv-item.active {
    background: var(--primary-light);
    border-left-color: var(--primary);
}

.conv-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conv-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-item-meta {
    font-size: 11px;
    color: var(--text-light);
}

.conv-item-del {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: opacity 0.2s, color 0.2s;
    flex-shrink: 0;
}

.conv-item:hover .conv-item-del {
    opacity: 0.4;
}

.conv-item-del:hover {
    opacity: 1 !important;
    color: var(--danger);
}

/* ===== 对话主区 ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    gap: 12px;
}

.welcome-seal {
    width: 64px;
    height: 64px;
    background: var(--primary);
    color: #fdfbf3;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 900;
    margin-bottom: 8px;
    box-shadow: 0 4px 12px rgba(139,44,28,0.25);
    border: 2px solid var(--accent);
}

.welcome h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 3px;
}

.welcome-desc {
    font-size: 14px;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.welcome-guest-hint {
    font-size: 12px;
    color: var(--text-light);
    background: var(--accent-light);
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
}

.suggestions {
    display: flex;
    gap: 8px;
    margin-top: 24px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 600px;
}

.suggestion {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.25s;
    font-family: inherit;
}

.suggestion:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.message {
    margin-bottom: 16px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.message.user {
    display: flex;
    justify-content: flex-end;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.8;
    box-shadow: var(--shadow);
}

.message.user .message-bubble {
    background: var(--primary);
    color: #fdfbf3;
    border-bottom-right-radius: 2px;
    max-width: 75%;
}

.message.assistant .message-bubble {
    background: var(--bg-card);
    color: var(--text);
    border-bottom-left-radius: 2px;
    border: 1px solid var(--border-light);
    border-left: 3px solid var(--accent);
}

.message.assistant .message-bubble.refusal {
    border-left: 3px solid var(--warning);
}

.message-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.message-meta .tag {
    padding: 2px 8px;
    background: var(--accent-light);
    color: var(--accent-dark);
    border-radius: 2px;
    font-size: 11px;
}

.message-meta .token-tag {
    background: #e8f5e9;
    color: #2e7d32;
    font-weight: 600;
}

.references {
    margin-top: 12px;
    border-top: 1px dashed var(--border);
    padding-top: 8px;
}

.references-title {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 600;
}

.ref-item {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 8px;
    background: var(--bg-soft);
    border-radius: 2px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 2px solid var(--border);
}

.ref-item:hover {
    background: var(--accent-light);
    border-left-color: var(--accent);
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.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% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== 输入栏 ===== */
.chat-input-bar {
    padding: 12px 20px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    position: relative;
}

.chat-input-bar::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 20px;
    right: 20px;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--accent), transparent);
}

.group-select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    flex-shrink: 0;
    max-width: 120px;
}
.group-select:focus {
    border-color: var(--primary);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 8px 8px 16px;
    transition: border-color 0.25s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    line-height: 1.6;
    resize: none;
    max-height: 200px;
    font-family: inherit;
    color: var(--text);
}

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

.btn-send {
    width: 38px;
    height: 38px;
    background: var(--primary);
    color: #fdfbf3;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.btn-send:disabled {
    background: var(--border);
    cursor: not-allowed;
    transform: none;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    padding: 10px 24px;
    background: var(--text);
    color: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s;
    z-index: 999;
    border-left: 3px solid var(--accent);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dark); }

/* ===== 移动端 ===== */
@media (max-width: 600px) {
    .header-inner { padding: 10px 16px; }
    .brand-name { font-size: 17px; }
    .chat-messages { padding: 16px 12px; }
    .chat-input-bar { padding: 10px 12px 14px; }
    .message-bubble { font-size: 14px; }
    .history-drawer { width: 260px; }
    .welcome h1 { font-size: 22px; }
    .modal-box { width: 320px; padding: 24px; }
}
