/* ============================================
   AI+玄学 · 玄明子命理咨询 —— 样式表
   ============================================ */

/* ---------- CSS 变量 ---------- */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-sidebar: #12121f;
    --bg-input: #1e1e35;
    --bg-message-user: #2d1b69;
    --bg-message-ai: #1a1a2e;
    --bg-hover: #252545;
    --bg-card: #1e1e35;

    --text-primary: #e8e6f0;
    --text-secondary: #9b97b0;
    --text-muted: #6b6780;

    --accent: #7c5cbf;
    --accent-hover: #9370db;
    --accent-glow: rgba(124, 92, 191, 0.3);

    --border: #2a2a45;
    --border-light: #353555;

    --sidebar-width: 280px;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

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

/* ---------- App 容器 ---------- */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ============================================
   侧边栏
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.new-chat-btn {
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: 1px dashed var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition);
}

.new-chat-btn:hover {
    border-color: var(--accent);
    color: var(--accent-hover);
    background: var(--accent-glow);
}

/* ---------- 对话列表 ---------- */
.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
    transition: background var(--transition);
}

.conv-item:hover {
    background: var(--bg-hover);
}

.conv-item.active {
    background: var(--bg-hover);
    border-left: 3px solid var(--accent);
}

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

.conv-item.active .conv-item-title {
    color: var(--text-primary);
}

.conv-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all var(--transition);
    flex-shrink: 0;
}

.conv-item:hover .conv-item-delete {
    opacity: 1;
}

.conv-item-delete:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* ---------- 侧边栏底部 ---------- */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.sidebar-footer-text {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* ============================================
   主内容区
   ============================================ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.menu-toggle {
    display: none;
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 50;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    padding: 8px;
    cursor: pointer;
    transition: all var(--transition);
}

.menu-toggle:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ---------- 聊天区 ---------- */
.chat-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* ---------- 欢迎页 ---------- */
.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}

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

.welcome-screen h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--accent), #c084fc, #e879f9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 40px;
}

.welcome-hints {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 500px;
    width: 100%;
}

.hint-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 16px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.hint-card:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.hint-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

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

/* ---------- 消息容器 ---------- */
.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

/* ---------- 消息气泡 ---------- */
.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

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

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

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

.message.assistant .message-avatar {
    background: linear-gradient(135deg, #2d1b69, #7c5cbf);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #1e3a5f, #2563eb);
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.7;
    font-size: 14px;
}

.message.assistant .message-content {
    background: var(--bg-message-ai);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
}

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

/* ---------- AI 消息中的 Markdown 样式 ---------- */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 12px 0 8px;
    color: var(--accent-hover);
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 15px; }

.message-content p {
    margin-bottom: 8px;
}

.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content strong {
    color: #c084fc;
}

.message-content code {
    background: rgba(124, 92, 191, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

.message-content table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    font-size: 13px;
}

.message-content th {
    background: var(--bg-hover);
    color: var(--accent-hover);
}

/* ---------- 打字指示器 ---------- */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

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

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ---------- 输入区 ---------- */
.input-area {
    padding: 16px 20px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
}

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

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    line-height: 1.5;
    padding: 4px 0;
}

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

.send-btn {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

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

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.send-btn.stop-mode {
    background: #ef4444;
    animation: pulse-stop 1.5s ease-in-out infinite;
}

.send-btn.stop-mode:hover {
    background: #dc2626;
}

@keyframes pulse-stop {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.input-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

/* ---------- 遮罩层 ---------- */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

.overlay.active {
    display: block;
}

/* ============================================
   响应式设计
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        transform: translateX(-100%);
    }

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

    .menu-toggle {
        display: flex;
    }

    .welcome-hints {
        grid-template-columns: 1fr;
    }

    .message-content {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .welcome-screen h1 {
        font-size: 22px;
    }

    .messages-container {
        padding: 12px;
    }
}
