/* ========== 变量 ========== */
:root {
    --pink: #FFB5C5;
    --pink-light: #FFF0F3;
    --pink-dark: #FF8FAB;
    --blue: #A8D8EA;
    --blue-light: #E8F4F8;
    --blue-dark: #6BB7D9;
    --yellow: #FFE5A0;
    --yellow-light: #FFF9E6;
    --yellow-dark: #FFD54F;
    --green: #B5EAD7;
    --green-light: #E8F9F0;
    --green-dark: #7DD3B5;
    --purple: #C9B1FF;
    --purple-light: #F3EEFF;
    --purple-dark: #A17FFF;
    --orange: #FFDAB9;
    --orange-light: #FFF5ED;
    --orange-dark: #FFB877;

    --text-primary: #2D3748;
    --text-secondary: #718096;
    --text-light: #A0AEC0;
    --text-white: #FFFFFF;

    --bg-primary: #FFFFFF;
    --bg-secondary: #F7FAFC;
    --bg-tertiary: #EDF2F7;

    --border-color: #E2E8F0;
    --border-radius: 16px;
    --border-radius-sm: 8px;
    --border-radius-lg: 24px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --sidebar-width: 220px;
    --chat-width: 340px;
}

/* ========== 重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

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

/* ========== 密码门 ========== */
.password-gate {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #C9B1FF 0%, #A8D8EA 50%, #FFB5C5 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.gate-box {
    background: white;
    padding: 48px 40px;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    width: 360px;
    max-width: 90vw;
}

.gate-icon { font-size: 3rem; margin-bottom: 16px; }
.gate-box h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 8px; }
.gate-box > p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 20px; }

.gate-box input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 12px;
}

.gate-box input:focus { border-color: var(--purple); }

.gate-btn {
    width: 100%;
    padding: 12px;
    background: var(--purple);
    color: white;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

.gate-error {
    color: var(--pink-dark);
    font-size: 0.85rem;
    margin-top: 12px;
}

/* ========== 应用容器 ========== */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ========== 左侧边栏 ========== */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #C9B1FF 0%, #A17FFF 100%);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 24px 0;
}

.sidebar-logo {
    text-align: center;
    padding: 0 20px 32px;
    border-bottom: 1px solid rgba(255,255,255,0.3);
}

.sidebar-icon { font-size: 2.5rem; }
.sidebar-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    margin-top: 8px;
}
.sidebar-sub {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.8);
    margin-top: 4px;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--border-radius-sm);
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 0.95rem;
    margin-bottom: 4px;
    transition: all 0.2s;
}

.nav-item:hover, .nav-item.active {
    background: rgba(255,255,255,0.25);
    color: white;
}

.nav-icon { font-size: 1.2rem; }

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.3);
}

.sidebar-footer-text {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.7);
    text-align: center;
}

/* ========== 中间内容区 ========== */
.content-main {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    background: var(--bg-secondary);
}

.section-header {
    margin-bottom: 28px;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ========== 知识库网格 ========== */
.knowledge-home { max-width: 1100px; }

.knowledge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

/* ========== 模块卡片（彩色色块） ========== */
.module-card {
    border-radius: var(--border-radius);
    padding: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    min-height: 130px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    box-shadow: var(--shadow-sm);
}

.module-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.module-card .card-bg {
    position: absolute;
    inset: 0;
    opacity: 0.15;
    font-size: 5rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 12px;
}

.module-card .card-content {
    position: relative;
    z-index: 1;
}

.module-card .card-count {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255,255,255,0.35);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.module-card .card-icon { font-size: 1.8rem; margin-bottom: 8px; }

.module-card h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.module-card p {
    font-size: 0.8rem;
    opacity: 0.9;
    color: white;
    line-height: 1.4;
}

/* 各模块颜色 */
.module-card[data-id="theory"] { background: linear-gradient(135deg, #C9B1FF, #A17FFF); }
.module-card[data-id="diagnosis"] { background: linear-gradient(135deg, #A8D8EA, #6BB7D9); }
.module-card[data-id="treatment"] { background: linear-gradient(135deg, #B5EAD7, #7DD3B5); }
.module-card[data-id="lines"] { background: linear-gradient(135deg, #FFDAB9, #FFB877); }
.module-card[data-id="contraindication"] { background: linear-gradient(135deg, #FFB5C5, #FF8FAB); }
.module-card[data-id="topics"] { background: linear-gradient(135deg, #FFE5A0, #FFD54F); color: #5D4E00; }
.module-card[data-id="topics"] h3, .module-card[data-id="topics"] p { color: #5D4E00; text-shadow: none; }
.module-card[data-id="cases"] { background: linear-gradient(135deg, #E8D5FF, #C9B1FF); }
.module-card[data-id="intro"] { background: linear-gradient(135deg, #D4F4DD, #B5EAD7); color: #2D5E3A; }
.module-card[data-id="intro"] h3, .module-card[data-id="intro"] p { color: #2D5E3A; text-shadow: none; }

/* ========== 知识库详情 ========== */
.knowledge-detail { max-width: 860px; }

.detail-header { margin-bottom: 20px; }

.back-btn {
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    margin-bottom: 12px;
    transition: all 0.2s;
}

.back-btn:hover { background: var(--bg-secondary); }

.detail-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ========== 子目录 ========== */
.sub-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sub-cat-btn {
    padding: 8px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.sub-cat-btn:hover { border-color: var(--purple); background: var(--purple-light); }
.sub-cat-btn.active { background: var(--purple); color: white; border-color: var(--purple); }

/* ========== 详情内容 ========== */
.detail-content {
    background: white;
    border-radius: var(--border-radius);
    padding: 28px;
    box-shadow: var(--shadow-sm);
}

.detail-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--purple-dark);
}

.detail-content p {
    margin-bottom: 12px;
    line-height: 1.8;
}

.editable-text {
    outline: none;
    border: 1px dashed transparent;
    border-radius: 4px;
    padding: 4px;
    margin: -4px;
    transition: all 0.2s;
    min-height: 24px;
    display: block;
    line-height: 1.8;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.editable-text:hover {
    border-color: var(--border-color);
    background: var(--bg-secondary);
}

.editable-text:focus {
    border-color: var(--purple);
    background: var(--purple-light);
}

.detail-content ul {
    padding-left: 24px;
    margin-bottom: 16px;
}

.detail-content li { margin-bottom: 8px; }

/* ========== 媒体列表 ========== */
.media-list {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.media-list h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.upload-media-btn {
    padding: 6px 12px;
    background: var(--green);
    color: white;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    margin-left: auto;
    transition: background 0.2s;
}

.upload-media-btn:hover { background: var(--green-dark); }

.media-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--border-radius-sm);
    margin-bottom: 8px;
}

.media-item .play-icon {
    width: 40px;
    height: 40px;
    background: var(--purple-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.media-item .media-info { flex: 1; }
.media-item .media-title {
    font-weight: 500;
    margin-bottom: 2px;
}

.media-item .media-duration {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.media-item img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: var(--border-radius-sm);
}

/* ========== 右侧聊天面板 ========== */
.chat-panel {
    width: var(--chat-width);
    height: 100vh;
    background: white;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.chat-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, #C9B1FF, #A17FFF);
    color: white;
}

.chat-panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.chat-toggle-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255,255,255,0.25);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: white;
}

.chat-toggle-btn:hover { background: rgba(255,255,255,0.4); }

.chat-panel.collapsed .chat-messages,
.chat-panel.collapsed .chat-input-area { display: none; }

/* ========== 聊天消息 ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-secondary);
}

.message {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}

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

.message .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.message.bot .avatar { background: var(--purple-light); }
.message.user .avatar { background: var(--blue-light); }

.message .content {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--border-radius);
    line-height: 1.6;
    font-size: 0.9rem;
}

.message.bot .content {
    background: white;
    border: 1px solid var(--border-color);
    border-top-left-radius: 4px;
}

.message.user .content {
    background: var(--blue);
    color: white;
    border-top-right-radius: 4px;
}

.message .content p { margin-bottom: 6px; }
.message .content p:last-child { margin-bottom: 0; }

/* ========== 聊天输入 ========== */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    background: white;
}

.chat-input-area textarea {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 10px 14px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 80px;
    transition: border-color 0.2s;
}

.chat-input-area textarea:focus { border-color: var(--purple); }

.send-btn {
    padding: 10px 16px;
    background: var(--purple);
    color: white;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.send-btn:hover { background: var(--purple-dark); }
.send-btn:disabled { background: var(--text-light); cursor: not-allowed; }

/* ========== 加载动画（在聊天区域内） ========== */
.loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 32px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: none;
    flex-direction: column;
    align-items: center;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-overlay p {
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

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

/* ========== 模态框 ========== */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 460px;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 300;
}

.modal-content { padding: 24px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 { font-size: 1.1rem; font-weight: 600; }

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.close-btn:hover { background: var(--border-color); }

.modal-body > p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.upload-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.upload-tab {
    flex: 1;
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.upload-tab.active {
    background: var(--purple-light);
    border-color: var(--purple);
    color: var(--purple-dark);
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-area:hover {
    border-color: var(--purple);
    background: var(--purple-light);
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 8px;
}

.upload-progress { margin-top: 16px; }

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--purple);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
}

/* ========== 响应式 ========== */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: var(--sidebar-width);
        z-index: 200;
        transition: left 0.3s ease;
    }

    .sidebar.mobile-open { left: 0; }

    .content-main {
        width: 100%;
        padding: 20px 16px;
    }

    .chat-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 55vh;
        border-left: none;
        border-top: 1px solid var(--border-color);
        z-index: 100;
    }

    .chat-panel.collapsed { max-height: 52px; }

    .knowledge-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    .module-card { min-height: 110px; padding: 16px; }
    .module-card .card-icon { font-size: 1.4rem; }
    .module-card h3 { font-size: 0.9rem; }
    .module-card p { font-size: 0.75rem; }

    .loading-overlay {
        top: auto;
        bottom: 55vh;
        left: 50%;
    }

    .detail-content { padding: 16px; }
}

@media (max-width: 600px) {
    .modal {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        border-radius: var(--border-radius) var(--border-radius) 0 0;
    }
}
