/* 玄微鉴 · 中式淡雅风格 · Chat 对话式布局 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600;700&display=swap');

:root {
    --bg-cream: #F5F0E8;
    --text-dark: #2C2C2C;
    --text-muted: #6B655A;
    --accent-red: #C93838;
    --border-ink: #D4C9B8;
    --border-light: #E8E0D4;
    --card-bg: #FAF7F2;
    --hover-bg: #EFE9E0;
    --bubble-user: #FAF7F2;
    --bubble-ai: #FFFFFF;
    --input-bg: #FFFFFF;
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'Noto Serif SC', 'KaiTi', 'STKaiti', serif;
    background: var(--bg-cream);
    color: var(--text-dark);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
}

/* ========== 顶部导航 ========== */
.header {
    border-bottom: 1px solid var(--border-ink);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: var(--bg-cream);
}
.header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 4px;
}
.header h1 .accent { color: var(--accent-red); }
.header nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
    cursor: pointer;
}
.header nav a:hover { color: var(--accent-red); }

/* ========== 消息列表（填充剩余高度） ========== */
.chat-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 16px;
}
.chat-container::-webkit-scrollbar { width: 4px; }
.chat-container::-webkit-scrollbar-thumb { background: var(--border-ink); border-radius: 2px; }

/* ========== 空态（居中） ========== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 0 20px;
}
.empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-dark);
    letter-spacing: 4px;
    margin-bottom: 8px;
}
.empty-hint {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 24px;
}
.empty-tips {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
    color: #999;
}
.empty-tips span {
    background: var(--card-bg);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-light);
}

/* ========== 消息行 ========== */
.message-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.msg-user    { justify-content: flex-end; }
.msg-assistant { justify-content: flex-start; }

/* 头像 */
.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0;
}
.msg-assistant .msg-avatar {
    background: var(--accent-red);
    color: #fff;
}
.user-avatar {
    background: var(--border-ink);
    color: var(--text-muted);
    order: 1;
}

/* 气泡主体 */
.msg-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.7;
    word-break: break-word;
}
.bubble-user {
    background: var(--bubble-user);
    border: 1px solid var(--accent-red);
    border-top-right-radius: 4px;
    color: var(--text-dark);
}
.bubble-assistant {
    background: var(--bubble-ai);
    border: 1px solid var(--border-light);
    border-top-left-radius: 4px;
    color: var(--text-dark);
}
.bubble-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
}

/* 气泡内的图片 */
.msg-img {
    max-width: 240px;
    max-height: 200px;
    border-radius: 8px;
    border: 1px solid var(--border-light);
    display: block;
}
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }

/* 加载动画 */
.loading-dots {
    display: inline-flex;
    gap: 4px;
}
.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent-red);
    border-radius: 50%;
    animation: dotBounce 1.4s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}
.loading-text {
    font-size: 14px;
    color: var(--text-muted);
}

/* ========== 分析结果块 ========== */
.analysis-block {
    margin-bottom: 12px;
}
.analysis-block:last-child { margin-bottom: 0; }
.analysis-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent-red);
    margin-bottom: 6px;
    letter-spacing: 1px;
}
.analysis-block p {
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-dark);
}

/* ========== 确认卡片 ========== */
.confirm-card {
    max-width: 420px;
    padding: 16px 18px;
}
.confirm-header {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-red);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
    letter-spacing: 1px;
}
.confirm-grid {
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 8px;
    margin-bottom: 10px;
    align-items: center;
}
.confirm-grid label {
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
}
.confirm-grid input,
.confirm-grid select {
    padding: 5px 8px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    background: #fff;
    color: var(--text-dark);
}
.confirm-grid input:focus,
.confirm-grid select:focus {
    outline: none;
    border-color: var(--accent-red);
}
.confirm-grid input[type="number"] { width: 70px; }
.confirm-inline { display: flex; gap: 6px; }

/* 用神按钮 */
.yong-shen-section {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 10px;
    align-items: center;
}
.ys-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 4px;
}
.ys-btn {
    padding: 3px 10px;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.ys-btn:hover { border-color: var(--accent-red); color: var(--accent-red); }
.ys-btn.active {
    background: var(--accent-red);
    color: #fff;
    border-color: var(--accent-red);
}

/* 提问输入 */
.confirm-question textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    background: #fff;
    color: var(--text-dark);
    resize: vertical;
    min-height: 44px;
    transition: border-color 0.2s;
}
.confirm-question textarea:focus {
    outline: none;
    border-color: var(--accent-red);
}
.confirm-question textarea::placeholder {
    color: #bbb;
    font-style: italic;
}

.confirm-btn {
    width: 100%;
    margin-top: 10px;
    padding: 8px 0;
    font-size: 14px;
}

/* ========== 底部输入栏（flex 流式，非 fixed） ========== */
.input-bar {
    flex-shrink: 0;
    background: var(--bg-cream);
    border-top: 1px solid var(--border-ink);
    padding: 8px 16px 12px;
}

.attach-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    padding: 4px 8px;
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-light);
    width: fit-content;
}
.attach-preview img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-light);
}
.attach-remove {
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.attach-remove:hover { color: var(--accent-red); }

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-ink);
    border-radius: 12px;
    padding: 6px 6px 6px 12px;
    transition: border-color 0.2s;
}
.input-row:focus-within {
    border-color: var(--accent-red);
}

.attach-btn {
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding-bottom: 4px;
    transition: color 0.2s;
}
.attach-btn:hover { color: var(--accent-red); }
.attach-btn input[type="file"] { display: none; }

.input-row textarea {
    flex: 1;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-dark);
    background: transparent;
    resize: none;
    max-height: 120px;
    padding: 4px 0;
    line-height: 1.5;
}
.input-row textarea::placeholder {
    color: #bbb;
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent-red);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
.send-btn:hover { background: #a52a2a; }
.send-btn:disabled {
    background: var(--border-ink);
    cursor: not-allowed;
    opacity: 0.5;
}

/* ========== 保存对话框 ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-box {
    background: var(--card-bg);
    border: 1px solid var(--border-ink);
    border-radius: 12px;
    padding: 24px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal-box h3 {
    font-size: 16px;
    color: var(--accent-red);
    margin-bottom: 16px;
    letter-spacing: 2px;
}
.modal-box input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    background: #fff;
    color: var(--text-dark);
    margin-bottom: 16px;
}
.modal-box input:focus {
    outline: none;
    border-color: var(--accent-red);
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ========== 历史侧栏 ========== */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.2);
    z-index: 90;
}
.history-sidebar {
    position: fixed;
    top: 0;
    right: -340px;
    width: 320px;
    height: 100vh;
    background: var(--card-bg);
    border-left: 1px solid var(--border-ink);
    z-index: 91;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.08);
}
.history-sidebar.open {
    right: 0;
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.sidebar-header h3 {
    font-size: 16px;
    color: var(--accent-red);
    letter-spacing: 2px;
}
.sidebar-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
}
.sidebar-close:hover { color: var(--accent-red); }
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}
.sidebar-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    font-size: 14px;
}
.sidebar-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 8px;
    border: 1px solid var(--border-light);
}
.sidebar-item:hover {
    background: var(--hover-bg);
    border-color: var(--border-ink);
}
.sidebar-item-title {
    font-size: 14px;
    color: var(--text-dark);
    font-weight: 600;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-item-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    align-items: center;
}
.sidebar-del {
    margin-left: auto;
    cursor: pointer;
    color: #bbb;
    padding: 2px 4px;
}
.sidebar-del:hover { color: var(--accent-red); }

/* ========== 响应式 ========== */
@media (max-width: 900px) {
    .header { padding: 12px 16px; }
    .header h1 { font-size: 18px; }
    .chat-container { padding: 16px 10px; }
    .msg-bubble { max-width: 85%; }
    .confirm-card { max-width: 100%; }
    .input-bar { padding: 6px 10px 10px; }
    .empty-title { font-size: 18px; }
}
