/* ============================================
   朝花醉拾 - Web Design System
   色彩体系：暖色调，以琥珀/暖灰为主
   设计语言：圆润、透气、克制
   ============================================ */

/* ===== CSS Variables ===== */
:root {
    /* 主色 - 琥珀暖色系 */
    --primary: #B8621B;
    --primary-light: #D4893C;
    --primary-lighter: #F5E6D3;
    --primary-lightest: #FBF4EC;
    --primary-dark: #8A4A14;

    /* 中性色 */
    --gray-50: #FAFAF9;
    --gray-100: #F5F5F4;
    --gray-200: #E7E5E4;
    --gray-300: #D6D3D1;
    --gray-400: #A8A29E;
    --gray-500: #78716C;
    --gray-600: #57534E;
    --gray-700: #44403C;
    --gray-800: #292524;
    --gray-900: #1C1917;

    /* 语义色 */
    --success: #059669;
    --warning: #D97706;
    --error: #DC2626;
    --info: #2563EB;

    /* 背景 */
    --bg-primary: #FFFFFF;
    --bg-secondary: #FAFAF9;
    --bg-tertiary: #F5F5F4;
    --bg-chat: #FAF9F7;

    /* 文本 */
    --text-primary: #1C1917;
    --text-secondary: #57534E;
    --text-muted: #A8A29E;
    --text-inverse: #FFFFFF;

    /* 阴影 */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
    --shadow-xl: 0 16px 48px rgba(0,0,0,0.1);

    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* 间距 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* 布局 */
    --sidebar-width: 280px;
    --topbar-height: 56px;
    --chat-max-width: 768px;

    /* 过渡 */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;

    /* 字体 */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --font-serif: "Noto Serif SC", "Source Han Serif SC", "STSong", Georgia, serif;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--bg-secondary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

textarea {
    font-family: inherit;
    border: none;
    outline: none;
    resize: none;
}

a {
    color: var(--primary);
    text-decoration: none;
}

/* ===== Layout ===== */
#app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.brand-icon {
    font-size: 24px;
    line-height: 1;
}

.brand-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.btn-new {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    width: 100%;
    padding: 10px var(--space-md);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-fast);
}

/* Sidebar Stats */
.sidebar-stats {
    padding: 0 var(--space-xs);
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 0;
    font-size: 12px;
}

.stats-label {
    color: var(--text-muted);
    flex-shrink: 0;
}

.stats-value {
    color: var(--text-primary);
    font-weight: 500;
    text-align: right;
}

.stats-value.topic {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--primary);
    font-size: 11px;
}

.stats-value.depth {
    letter-spacing: 1px;
    color: var(--primary-dark);
}

/* Sidebar Section Title */
.sidebar-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px var(--space-md);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chapter-count {
    background: var(--primary-lightest);
    color: var(--primary);
    font-size: 11px;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    font-weight: 600;
}

/* Chapter List */
.sidebar-chapters {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--space-sm);
}

.sidebar-chapters::-webkit-scrollbar {
    width: 4px;
}

.sidebar-chapters::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-chapters::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 2px;
}

/* Chapter Item */
.chapter-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: 4px;
    border: 1px solid transparent;
}

.chapter-item:hover {
    background: var(--gray-100);
    border-color: var(--gray-200);
}

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

.chapter-item-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    margin-bottom: 6px;
}

.chapter-item-icon {
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 1px;
}

.chapter-item-info {
    flex: 1;
    min-width: 0;
}

.chapter-item-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.chapter-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Maturity Bar */
.chapter-maturity {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.maturity-bar {
    flex: 1;
    height: 4px;
    background: var(--gray-200);
    border-radius: 2px;
    overflow: hidden;
}

.maturity-bar.large {
    height: 6px;
    border-radius: 3px;
}

.maturity-fill {
    height: 100%;
    border-radius: 2px;
    transition: width var(--transition-normal);
}

.maturity-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 500;
    min-width: 28px;
    text-align: right;
}

/* Chapter Tags */
.chapter-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 6px;
}

.chapter-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    background: var(--gray-100);
    color: var(--text-secondary);
}

.chapter-tag.more {
    background: var(--primary-lightest);
    color: var(--primary);
}

/* Sidebar Footer Actions */
.sidebar-footer-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: var(--space-sm);
}

.btn-sidebar-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    width: 100%;
    text-align: left;
}

.btn-sidebar-action:hover {
    background: var(--gray-100);
    color: var(--text-primary);
}

.sidebar-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--gray-100);
}

.sidebar-footer-info {
    text-align: center;
    font-size: 12px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
    backdrop-filter: blur(2px);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--bg-chat);
}

/* ===== Topbar ===== */
.topbar {
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    gap: var(--space-sm);
    z-index: 10;
}

.topbar-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.btn-hamburger {
    display: none;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
}

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

.btn-primary:active {
    transform: scale(0.98);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--gray-100);
}

.btn-lg {
    padding: 12px 28px;
    font-size: 16px;
    border-radius: var(--radius-md);
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background: var(--gray-100);
    color: var(--text-primary);
}

/* ===== Views ===== */
.view {
    display: none;
    flex: 1;
    overflow: hidden;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ===== Welcome View ===== */
.view-welcome {
    align-items: center;
    justify-content: center;
    background: linear-gradient(180deg, var(--primary-lightest) 0%, var(--bg-chat) 60%);
}

.welcome-content {
    text-align: center;
    padding: var(--space-xl);
    max-width: 480px;
    animation: fadeInUp 600ms ease-out;
}

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

.welcome-icon {
    font-size: 64px;
    margin-bottom: var(--space-lg);
    animation: gentleFloat 3s ease-in-out infinite;
}

@keyframes gentleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.welcome-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    letter-spacing: 2px;
}

.welcome-subtitle {
    font-size: 16px;
    color: var(--primary);
    font-weight: 500;
    margin-bottom: var(--space-lg);
}

.welcome-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.8;
    margin-bottom: var(--space-md);
}

.welcome-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: var(--space-xl);
    font-style: italic;
}

/* ===== Chat View ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg) var(--space-md);
    scroll-behavior: smooth;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

.chat-messages-inner {
    max-width: var(--chat-max-width);
    margin: 0 auto;
}

.message {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    animation: messageIn 300ms ease-out;
    max-width: var(--chat-max-width);
    margin-left: auto;
    margin-right: auto;
}

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.ai .message-avatar {
    background: var(--primary-lighter);
}

.message.human .message-avatar {
    background: var(--gray-200);
}

.message-body {
    flex: 1;
    min-width: 0;
}

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 15px;
    line-height: 1.7;
    word-break: break-word;
}

.message.ai .message-content {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--gray-200);
    border-top-left-radius: var(--space-xs);
}

.message.human .message-content {
    background: var(--primary);
    color: var(--text-inverse);
    border-top-right-radius: var(--space-xs);
    margin-left: auto;
}

.message.human {
    flex-direction: row-reverse;
}

.message.human .message-body {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: var(--space-xs);
    padding: 0 4px;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 16px 20px;
    align-items: center;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Streaming message - typewriter cursor effect */
.message.ai.streaming .message-content::after {
    content: '▌';
    color: var(--primary);
    animation: cursorBlink 0.8s ease-in-out infinite;
    font-weight: 300;
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

.message.ai.streaming .message-content {
    transition: none; /* 避免内容增长时的过渡动画 */
}

/* System message */
.message.system {
    justify-content: center;
}

.message.system .message-content {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 8px 16px;
}

/* ===== Chat Input ===== */
.chat-input-area {
    padding: var(--space-sm) var(--space-md) var(--space-md);
    background: var(--bg-chat);
}

.chat-input-wrapper {
    max-width: var(--chat-max-width);
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
    background: var(--bg-primary);
    border: 1.5px solid var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 8px 8px 8px 16px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(184, 98, 27, 0.1);
}

.chat-input {
    flex: 1;
    min-height: 24px;
    max-height: 120px;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    background: transparent;
    padding: 4px 0;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--primary);
    color: var(--text-inverse);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.btn-send:disabled {
    background: var(--gray-200);
    color: var(--gray-400);
    cursor: default;
}

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

.btn-send:not(:disabled):active {
    transform: scale(0.95);
}

.chat-input-hint {
    max-width: var(--chat-max-width);
    margin: 6px auto 0;
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== Suggestions Bar (消息流底部 - sticky 卡片式布局) ===== */
.suggestions-bar {
    max-width: var(--chat-max-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 8px 4px 4px;
    position: sticky;
    bottom: 0;
    background: linear-gradient(to bottom, transparent 0%, var(--bg-chat) 12%);
    /* 平滑展开动画 */
    animation: suggestionsExpand 300ms ease-out;
    z-index: 5;
}

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

.suggestions-header {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0 2px 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    letter-spacing: 0.3px;
}

.suggestions-header svg {
    opacity: 0.6;
}

.suggestion-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.45;
    font-weight: 400;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    background: transparent;
    text-align: left;
    width: 100%;
    color: var(--text-secondary);
}

.suggestion-chip .chip-bar {
    width: 3px;
    min-height: 18px;
    align-self: stretch;
    border-radius: 2px;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

.suggestion-chip .chip-label {
    flex: 1;
    word-break: break-word;
    white-space: normal;
}

/* deepen - 蓝色系 */
.suggestion-chip.deepen .chip-bar {
    background: #93C5FD;
}

.suggestion-chip.deepen:hover {
    background: #EFF6FF;
    border-color: #BFDBFE;
    color: #1D4ED8;
}

.suggestion-chip.deepen:hover .chip-bar {
    background: #3B82F6;
}

/* expand - 绿色系 */
.suggestion-chip.expand .chip-bar {
    background: #86EFAC;
}

.suggestion-chip.expand:hover {
    background: #F0FDF4;
    border-color: #BBF7D0;
    color: #15803D;
}

.suggestion-chip.expand:hover .chip-bar {
    background: #22C55E;
}

/* connect - 琥珀色系 */
.suggestion-chip.connect .chip-bar {
    background: #FCD34D;
}

.suggestion-chip.connect:hover {
    background: #FFFBEB;
    border-color: #FDE68A;
    color: #B45309;
}

.suggestion-chip.connect:hover .chip-bar {
    background: #F59E0B;
}

.suggestion-chip:active {
    transform: scale(0.985);
}

.suggestion-chip.loading {
    opacity: 0.5;
    pointer-events: none;
}

.suggestion-chip.loading .chip-label::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 1.5px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 6px;
    vertical-align: middle;
}

/* 交错淡入动画 */
@keyframes suggestionSlideIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.suggestion-chip {
    animation: suggestionSlideIn 300ms ease-out both;
}

.suggestion-chip:nth-child(2) { animation-delay: 60ms; }
.suggestion-chip:nth-child(3) { animation-delay: 120ms; }
.suggestion-chip:nth-child(4) { animation-delay: 180ms; }

/* 建议选择标记（聊天记录中） */
.message.suggestion-choice {
    justify-content: center;
    padding: 8px 0;
}

.suggestion-choice-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.suggestion-choice.deepen .suggestion-choice-label {
    background: #EFF6FF;
    color: #1D4ED8;
    border: 1px solid #BFDBFE;
}

.suggestion-choice.expand .suggestion-choice-label {
    background: #F0FDF4;
    color: #15803D;
    border: 1px solid #BBF7D0;
}

.suggestion-choice.connect .suggestion-choice-label {
    background: #FFFBEB;
    color: #B45309;
    border: 1px solid #FDE68A;
}

/* ===== Insights View ===== */
.insights-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    padding: 0 var(--space-md);
}

.insights-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) 0;
}

.insights-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.insights-tabs {
    display: flex;
    gap: var(--space-xs);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--gray-200);
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.tab-btn:hover {
    background: var(--gray-100);
}

.tab-btn.active {
    background: var(--primary-lightest);
    color: var(--primary-dark);
}

.insights-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md) 0;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Entity Cards */
.entity-card {
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    transition: box-shadow var(--transition-fast);
}

.entity-card:hover {
    box-shadow: var(--shadow-md);
}

.entity-card-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.entity-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.entity-card-icon.person {
    background: #FEE2E2;
}

.entity-card-icon.event {
    background: #DBEAFE;
}

.entity-card-icon.location {
    background: #D1FAE5;
}

.entity-card-title {
    font-size: 16px;
    font-weight: 600;
}

.entity-card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

.entity-card-body {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.entity-tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    margin-right: 4px;
    margin-bottom: 4px;
    background: var(--gray-100);
    color: var(--text-secondary);
}

.entity-field {
    margin-top: 8px;
}

.entity-field-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.empty-state {
    text-align: center;
    padding: var(--space-2xl) var(--space-md);
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.empty-state-text {
    font-size: 14px;
}

/* ===== Memoir View ===== */
.memoir-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    padding: 0 var(--space-md);
}

.memoir-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) 0;
}

.memoir-header h2 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.memoir-header-actions {
    display: flex;
    gap: var(--space-xs);
}

.memoir-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md) 0 var(--space-2xl);
}

/* 已保存回忆录列表 */
.memoir-saved-list {
    margin-bottom: var(--space-md);
    border-bottom: 1px solid var(--gray-200);
    padding-bottom: var(--space-md);
}

.memoir-list-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.memoir-list-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: 4px;
    gap: var(--space-sm);
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
}

.memoir-list-item:hover {
    background: var(--primary-lightest);
    border-color: var(--primary-light);
}

.memoir-list-item .memoir-list-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.memoir-list-item .memoir-list-info {
    flex: 1;
    min-width: 0;
}

.memoir-list-item .memoir-list-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.memoir-list-item .memoir-list-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* 回忆录文章排版 */
.memoir-article {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-2xl) var(--space-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    position: relative;
}

/* 装饰线 */
.memoir-article::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    border-radius: 2px;
}

.memoir-article h1 {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: var(--space-sm);
    letter-spacing: 2px;
    margin-top: var(--space-md);
}

.memoir-article .memoir-stats {
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--gray-200);
}

.memoir-article .memoir-body {
    font-family: var(--font-serif);
    font-size: 16px;
    line-height: 2;
    color: var(--gray-700);
}

.memoir-article .memoir-body p {
    margin-bottom: var(--space-lg);
    text-indent: 2em;
}

/* 首字下沉 - 第一个段落 */
.memoir-article .memoir-body .first-para::first-letter {
    float: left;
    font-size: 3.2em;
    line-height: 0.8;
    font-weight: 700;
    color: var(--primary);
    margin-right: 8px;
    margin-top: 6px;
    font-family: var(--font-serif);
}

.memoir-article .memoir-body .first-para {
    text-indent: 0;
}

/* 章节标题 */
.memoir-article .memoir-body h2 {
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 40px 0 20px;
    text-indent: 0;
    position: relative;
    padding-left: 20px;
}

.memoir-article .memoir-body h2::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 24px;
    background: var(--primary);
    border-radius: 2px;
}

.memoir-article .memoir-body h3 {
    font-family: var(--font-serif);
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 28px 0 14px;
    text-indent: 0;
}

/* 引言/感悟块 */
.memoir-article .memoir-body blockquote,
.memoir-article .memoir-body .memoir-quote {
    margin: var(--space-lg) 0;
    padding: var(--space-md) var(--space-lg);
    border-left: 3px solid var(--primary-light);
    background: var(--primary-lightest);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic;
    color: var(--text-secondary);
    text-indent: 0;
}

/* 分隔线 */
.memoir-article .memoir-body hr,
.memoir-article .memoir-body .memoir-divider {
    border: none;
    text-align: center;
    margin: var(--space-xl) 0;
    height: auto;
}

.memoir-article .memoir-body hr::after,
.memoir-article .memoir-body .memoir-divider::after {
    content: '· · ·';
    color: var(--primary-light);
    font-size: 18px;
    letter-spacing: 12px;
}

/* 尾声装饰 */
.memoir-article .memoir-ending {
    text-align: center;
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--gray-200);
    color: var(--text-muted);
    font-size: 13px;
    font-family: var(--font-sans);
}

/* ===== 关系图谱 ===== */
.graph-container {
    width: 100%;
    min-height: 600px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.graph-container svg.graph-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* 节点交互 */
.graph-node {
    transition: opacity 0.2s ease;
}

.graph-node-person {
    cursor: pointer;
}

.graph-node-event {
    cursor: pointer;
}

.graph-node-location {
    cursor: pointer;
}

/* 边交互 */
.graph-edge {
    transition: opacity 0.2s ease, stroke-width 0.2s ease;
    cursor: pointer;
}

.graph-edge-label-text {
    pointer-events: none;
    user-select: none;
}

/* 图例 */
.graph-legend {
    position: absolute;
    top: var(--space-md);
    left: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: 10px 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    font-size: 12px;
    color: var(--text-secondary);
    z-index: 10;
    opacity: 0.9;
}

.graph-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.graph-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.graph-legend-dot.person { background: #F59E0B; }
.graph-legend-dot.event { background: #3B82F6; }
.graph-legend-dot.location { background: #10B981; }

/* 缩放控制按钮 */
.graph-controls {
    position: absolute;
    bottom: var(--space-md);
    right: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 10;
}

.graph-ctrl-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.graph-ctrl-btn:hover {
    background: var(--gray-100);
    color: var(--text-primary);
}

.graph-ctrl-btn:active {
    transform: scale(0.92);
}

/* Tooltip */
.graph-tooltip {
    position: absolute;
    top: 0;
    left: 0;
    max-width: 260px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    pointer-events: none;
    z-index: 100;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.graph-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.graph-tooltip-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.graph-tooltip-relation {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.graph-tooltip-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.graph-tooltip-tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    background: var(--primary-lightest);
    color: var(--primary-dark);
}

.graph-tooltip-extra {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.graph-tooltip-list {
    margin: 4px 0 0 16px;
    padding: 0;
    font-size: 12px;
    color: var(--text-secondary);
    list-style: disc;
}

.graph-tooltip-list li {
    margin-bottom: 2px;
}

/* ===== Modal ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 460px;
    width: calc(100% - 32px);
    box-shadow: var(--shadow-xl);
    animation: modalIn 300ms ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.modal-content .text-muted {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.form-group {
    margin-bottom: var(--space-lg);
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: var(--space-sm);
    color: var(--text-primary);
}

.style-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
}

.style-option {
    cursor: pointer;
}

.style-option input {
    display: none;
}

.style-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    text-align: center;
}

.style-option input:checked + .style-card {
    border-color: var(--primary);
    background: var(--primary-lightest);
}

.style-card:hover {
    border-color: var(--primary-light);
}

.style-icon {
    font-size: 24px;
}

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

.style-desc {
    font-size: 11px;
    color: var(--text-muted);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

/* ===== Auth Modal (登录/注册) ===== */
.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: var(--space-md);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.auth-tab {
    flex: 1;
    padding: 8px 0;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    transition: all var(--transition-fast);
    border: none;
    cursor: pointer;
}

.auth-tab.active {
    background: var(--primary);
    color: var(--text-inverse);
}

.auth-tab:not(.active):hover {
    background: var(--gray-100);
}

.auth-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.auth-input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(184, 98, 27, 0.1);
}

.auth-input::placeholder {
    color: var(--text-muted);
}

.auth-error {
    color: #ef4444;
    font-size: 13px;
    text-align: center;
    margin-bottom: 12px;
    padding: 8px;
    background: #FEF2F2;
    border-radius: var(--radius-sm);
}

/* 用户菜单组 */
.user-menu-group {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--gray-100);
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    padding: 2px 3px;
    transition: all var(--transition-fast);
}

.user-menu-group:hover {
    border-color: var(--gray-300);
}

.user-avatar-circle {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    line-height: 1;
    flex-shrink: 0;
}

/* 用户信息按钮 */
.user-menu-btn {
    display: flex;
    align-items: center;
    padding: 2px 8px 2px 4px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 26px;
}

.user-menu-btn:hover {
    color: var(--text-primary);
}

/* 管理员图标 */
.user-admin-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    margin-right: 1px;
}

.user-admin-icon:hover {
    color: var(--primary);
    background: var(--primary-lightest);
}

/* 暗色模式适配 */
@media (prefers-color-scheme: dark) {
    .auth-error {
        background: #3B1C1C;
        color: #FCA5A5;
    }
}

/* ===== Loading ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--space-md);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ===== Utility ===== */
.text-muted {
    color: var(--text-muted);
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
        --topbar-height: 52px;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-xl);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .btn-hamburger {
        display: flex;
    }

    .welcome-title {
        font-size: 26px;
    }

    .welcome-icon {
        font-size: 48px;
    }

    .message {
        gap: 6px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .message-content {
        padding: 10px 14px;
        font-size: 14px;
    }

    .chat-input {
        font-size: 16px; /* 避免iOS自动缩放 */
    }

    .chat-input-hint {
        display: none;
    }

    .modal-content {
        margin: var(--space-md);
    }

    .style-options {
        grid-template-columns: 1fr;
    }

    .memoir-article {
        padding: var(--space-md);
    }

    .memoir-article h1 {
        font-size: 22px;
    }

    .memoir-article .memoir-body {
        font-size: 15px;
        line-height: 1.8;
    }

    .insights-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .insights-tabs::-webkit-scrollbar {
        display: none;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }
}

/* Safe area insets for iPhone notch */
@supports (padding: max(0px)) {
    .chat-input-area {
        padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
    }

    .sidebar {
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* ===== Dark mode support (system preference) ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1C1917;
        --bg-secondary: #0C0A09;
        --bg-tertiary: #292524;
        --bg-chat: #0C0A09;

        --text-primary: #FAFAF9;
        --text-secondary: #A8A29E;
        --text-muted: #78716C;

        --gray-100: #292524;
        --gray-200: #44403C;
        --gray-300: #57534E;
        --gray-400: #78716C;
        --gray-500: #A8A29E;

        --primary-lightest: #2A1F14;
        --primary-lighter: #3D2B1A;

        --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
        --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
        --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
        --shadow-xl: 0 16px 48px rgba(0,0,0,0.5);
    }

    .message.ai .message-content {
        background: var(--gray-100);
        border-color: var(--gray-200);
    }

    .entity-card-icon.person {
        background: #3B1C1C;
    }

    .entity-card-icon.event {
        background: #1C2A3B;
    }

    .entity-card-icon.location {
        background: #1C3B2A;
    }

    /* 图谱暗色模式适配 */
    .graph-container {
        background: var(--bg-tertiary);
    }

    .graph-tooltip {
        background: var(--gray-100);
        border-color: var(--gray-200);
        color: var(--text-primary);
    }

    .graph-tooltip-tag {
        background: var(--primary-lighter);
        color: var(--primary-light);
    }

    .loading-overlay {
        background: rgba(12, 10, 9, 0.85);
    }

    .modal-backdrop {
        background: rgba(0, 0, 0, 0.6);
    }

    /* Suggestion chips 暗色适配 */
    .suggestion-chip {
        color: var(--text-secondary);
    }
    .suggestion-chip.deepen .chip-bar {
        background: #1E40AF;
    }
    .suggestion-chip.deepen:hover {
        background: #1E293B;
        border-color: #1E40AF;
        color: #93C5FD;
    }
    .suggestion-chip.deepen:hover .chip-bar {
        background: #3B82F6;
    }
    .suggestion-chip.expand .chip-bar {
        background: #166534;
    }
    .suggestion-chip.expand:hover {
        background: #14271A;
        border-color: #166534;
        color: #86EFAC;
    }
    .suggestion-chip.expand:hover .chip-bar {
        background: #22C55E;
    }
    .suggestion-chip.connect .chip-bar {
        background: #92400E;
    }
    .suggestion-chip.connect:hover {
        background: #271E0A;
        border-color: #92400E;
        color: #FCD34D;
    }
    .suggestion-chip.connect:hover .chip-bar {
        background: #D97706;
    }

    .suggestion-choice.deepen .suggestion-choice-label {
        background: #1E293B;
        color: #93C5FD;
        border-color: #1E40AF;
    }
    .suggestion-choice.expand .suggestion-choice-label {
        background: #14271A;
        color: #86EFAC;
        border-color: #166534;
    }
    .suggestion-choice.connect .suggestion-choice-label {
        background: #271E0A;
        color: #FCD34D;
        border-color: #92400E;
    }
}

/* ===== Chapter Detail View ===== */
.chapter-detail-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
    padding: 0 var(--space-md);
}

.chapter-detail-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) 0;
}

.chapter-detail-header h2 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.chapter-detail-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: var(--space-2xl);
}

/* Detail Overview */
.detail-overview {
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
}

.detail-overview-row {
    display: flex;
    justify-content: space-around;
    margin-bottom: var(--space-sm);
}

.detail-stat {
    text-align: center;
}

.detail-stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.detail-stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Detail Tags */
.detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: var(--space-md);
}

.detail-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    background: var(--gray-100);
    color: var(--text-secondary);
}

.detail-tag.time { background: #EFF6FF; color: #1D4ED8; }
.detail-tag.location { background: #ECFDF5; color: #059669; }
.detail-tag.person { background: #FEF3C7; color: #92400E; }
.detail-tag.theme { background: #F3E8FF; color: #7C3AED; }

/* Detail Section */
.detail-section {
    margin-bottom: var(--space-lg);
}

.detail-section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    display: flex;
    align-items: center;
    gap: 6px;
}

.detail-section-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
}

/* Narrative Thread */
.narrative-thread {
    background: var(--primary-lightest);
    border-left: 3px solid var(--primary-light);
    padding: var(--space-md);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
    font-style: italic;
}

/* Event Brief Card */
.event-brief-card {
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
    transition: box-shadow var(--transition-fast);
}

.event-brief-card:hover {
    box-shadow: var(--shadow-md);
}

.event-brief-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.event-brief-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.event-brief-depth {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: var(--gray-100);
    color: var(--text-muted);
    font-weight: 500;
}

.event-brief-summary {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 6px;
}

.event-brief-quote {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    padding: 6px 10px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    line-height: 1.5;
}

.event-brief-sensory {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.sensory-tag {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: #FEF3C7;
    color: #92400E;
}

.event-brief-gaps {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 6px;
}

.gap-tag {
    font-size: 11px;
    color: var(--info);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Exploration Suggestions */
.exploration-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.exploration-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
    background: var(--bg-primary);
    font-size: 13px;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1.4;
}

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

.exploration-btn:active {
    transform: scale(0.98);
}

.exploration-btn svg {
    flex-shrink: 0;
    color: var(--primary);
}

/* ===== Timeline ===== */
.timeline-span {
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--primary);
    margin-bottom: var(--space-md);
    padding: 8px;
    background: var(--primary-lightest);
    border-radius: var(--radius-sm);
}

.timeline-track {
    position: relative;
    padding-left: 24px;
}

.timeline-track::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
}

.timeline-entry {
    position: relative;
    padding-bottom: var(--space-md);
    padding-left: var(--space-md);
}

.timeline-dot {
    position: absolute;
    left: -20px;
    top: 4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--bg-chat);
    z-index: 1;
}

.timeline-content {
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
}

.timeline-time {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 2px;
}

.timeline-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.timeline-chapter {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
}

.timeline-people {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== Avatar Picker (Register Form) ===== */
.avatar-picker {
    margin-bottom: 16px;
}

.avatar-picker-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.avatar-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.avatar-item {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border-radius: var(--radius-full);
    border: 2px solid var(--gray-200);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.avatar-item:hover {
    border-color: var(--primary-light);
    background: var(--primary-lightest);
    transform: scale(1.1);
}

.avatar-item.selected {
    border-color: var(--primary);
    background: var(--primary-lightest);
    box-shadow: 0 0 0 3px rgba(184, 98, 27, 0.15);
    transform: scale(1.12);
}

/* ===== Verification Code Row ===== */
.verification-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.verification-row .auth-input {
    flex: 1;
    min-width: 0;
}

.btn-send-code {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 10px 16px;
    font-size: 14px;
    border-radius: var(--radius-sm);
    min-width: 110px;
    text-align: center;
}

.btn-send-code:disabled {
    background: var(--gray-300);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
}

/* (user-avatar-mini 和 btn-admin-entry 已合并到 user-menu-group) */

/* ===== Admin Page ===== */
.admin-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
    padding: 0 var(--space-md);
}

.admin-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) 0;
}

.admin-header h2 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    color: var(--text-primary);
}

.admin-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    background: var(--primary-lightest);
    color: var(--primary);
    border: 1px solid var(--primary-lighter);
}

/* Admin Overview Stats */
.admin-overview {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.admin-stat-card {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    text-align: center;
    transition: all var(--transition-fast);
}

.admin-stat-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.admin-stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.admin-stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    font-weight: 500;
}

/* Admin Table */
.admin-table-wrapper {
    flex: 1;
    overflow: auto;
    background: var(--bg-primary);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.admin-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.admin-table th {
    background: var(--bg-tertiary);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.admin-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--text-primary);
    vertical-align: middle;
}

.admin-table tbody tr {
    transition: background var(--transition-fast);
}

.admin-table tbody tr:hover {
    background: var(--bg-secondary);
}

.admin-table tbody tr.row-disabled {
    opacity: 0.55;
}

/* Admin User Cell */
.admin-user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-user-avatar {
    font-size: 24px;
    line-height: 1;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-lightest);
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

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

.admin-email {
    color: var(--text-muted);
    font-size: 13px;
}

/* Admin Role Badge */
.admin-role-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    font-size: 10px;
    font-weight: 600;
    background: var(--primary-lightest);
    color: var(--primary);
    vertical-align: middle;
    margin-left: 4px;
}

/* Admin Status Badge */
.admin-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
}

.admin-status-badge.active {
    background: rgba(5, 150, 105, 0.1);
    color: var(--success);
}

.admin-status-badge.disabled {
    background: rgba(220, 38, 38, 0.1);
    color: var(--error);
}

/* Admin Action Buttons */
.btn-toggle-active {
    padding: 5px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    border: 1px solid;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: transparent;
}

.btn-toggle-active.btn-disable {
    border-color: var(--error);
    color: var(--error);
}

.btn-toggle-active.btn-disable:hover {
    background: var(--error);
    color: var(--text-inverse);
}

.btn-toggle-active.btn-enable {
    border-color: var(--success);
    color: var(--success);
}

.btn-toggle-active.btn-enable:hover {
    background: var(--success);
    color: var(--text-inverse);
}

/* Admin Loading */
.admin-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    font-size: 14px;
    color: var(--text-muted);
}

/* Admin hide-mobile columns */
.hide-mobile {
    /* visible by default */
}

/* Admin responsive */
@media (max-width: 768px) {
    .admin-container {
        padding: 0 var(--space-sm);
    }

    .admin-overview {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .admin-stat-card {
        padding: var(--space-sm) var(--space-md);
    }

    .admin-stat-value {
        font-size: 22px;
    }

    .admin-table {
        font-size: 13px;
    }

    .admin-table th,
    .admin-table td {
        padding: 8px 10px;
    }

    .hide-mobile {
        display: none !important;
    }

    .admin-user-avatar {
        width: 28px;
        height: 28px;
        font-size: 18px;
    }

    .avatar-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===== Admin Dark Mode ===== */
@media (prefers-color-scheme: dark) {
    .avatar-item {
        border-color: var(--gray-300);
        background: var(--bg-tertiary);
    }

    .avatar-item:hover,
    .avatar-item.selected {
        background: var(--primary-lighter);
    }

    .btn-send-code:disabled {
        background: var(--gray-700);
        color: var(--gray-500);
    }

    .user-menu-group {
        background: var(--gray-100);
    }

    .user-admin-icon:hover {
        background: var(--primary-lighter);
    }

    .admin-stat-card {
        background: var(--bg-tertiary);
        border-color: var(--gray-200);
    }

    .admin-table-wrapper {
        background: var(--bg-tertiary);
        border-color: var(--gray-200);
    }

    .admin-table th {
        background: var(--bg-secondary);
        border-color: var(--gray-200);
    }

    .admin-table td {
        border-color: var(--gray-200);
    }

    .admin-user-avatar {
        background: var(--primary-lighter);
    }

    .admin-role-badge {
        background: var(--primary-lighter);
        color: var(--primary-light);
    }

    .admin-badge {
        background: var(--primary-lighter);
        color: var(--primary-light);
        border-color: var(--gray-300);
    }

    .admin-status-badge.active {
        background: rgba(5, 150, 105, 0.2);
    }

    .admin-status-badge.disabled {
        background: rgba(220, 38, 38, 0.2);
    }
}

/* ===== Print styles for memoir ===== */
@media print {
    .sidebar, .topbar, .chat-input-area, .btn-icon {
        display: none !important;
    }

    .main-content {
        height: auto;
    }

    .memoir-article {
        box-shadow: none;
        border: none;
    }
}
