/* =====================================================
   AI智能聊天 - 参考ChatGPT极简布局
   ===================================================== */

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

/* Specific body override for chat page */
body.ai-chat-page {
    padding-top: 0 !important;
    height: 100vh;
    overflow: hidden;
}

/* Hide global navbar on mobile for chat page */
@media (max-width: 768px) {
    body.ai-chat-page .navbar {
        display: none !important;
    }
}

/* Mobile input simplification */
@media (max-width: 768px) {
    .input-actions-inline {
        display: none !important;
    }
}

/* ==================== 主容器 ==================== */
.main-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #f9fafb;
    position: relative;
    overflow: hidden;
}

/* Specific body override for chat page */
body.ai-chat-page {
    padding-top: 0 !important;
    height: 100vh;
    overflow: hidden;
}

/* ==================== 聊天主容器 ==================== */
.chat-main-container {
    display: flex;
    flex: 1;
    height: 100vh;
    overflow: hidden;
}

/* ==================== 侧边栏 ==================== */
.chat-sidebar {
    width: 260px;
    min-width: 260px;
    background: linear-gradient(180deg, #f3e8ff 0%, #faf5ff 15%, #ffffff 30%);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: all 0.3s ease;
    border-right: 1px solid #e5e7eb;
}

.chat-sidebar.collapsed {
    width: 60px;
    min-width: 60px;
    overflow: visible;
}

.sidebar-toggle {
    position: absolute;
    right: -12px;
    top: 16px;
    width: 24px;
    height: 24px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    color: #6b7280;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: #f3f4f6;
    color: #111827;
}

.sidebar-header {
    padding: 16px 12px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: none;
}

.chat-sidebar.collapsed .sidebar-header,
.chat-sidebar.collapsed .current-chat-section,
.chat-sidebar.collapsed .chat-history {
    display: none;
}

.sidebar-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.sidebar-header h5 {
    color: #111827;
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar-header h5 i {
    color: #6b7280;
    font-size: 16px;
}

.back-home-link {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    background: #f3f4f6;
    border: none;
    border-radius: 6px;
    transition: all 0.2s;
    text-decoration: none;
    font-size: 16px;
}

.back-home-link:hover {
    background: #e5e7eb;
    color: #111827;
}

.sidebar-header .btn {
    width: 100%;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #374151;
    padding: 10px 12px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s;
    cursor: pointer;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.sidebar-header .btn:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
}

.sidebar-header .btn i {
    font-size: 16px;
}

.ai-status {
    display: none;
}

/* 当前对话 */
.current-chat-section {
    padding: 8px 12px;
    border-bottom: none;
}

.current-chat-section h6 {
    color: #6b7280;
    font-size: 12px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.current-chat-item {
    background: transparent;
    padding: 8px 12px;
    border-radius: 8px;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.current-chat-item:hover {
    background: #f3f4f6;
}

.current-chat-item.active {
    background: #e5e7eb;
}

.current-chat-item i {
    color: #6b7280;
    font-size: 16px;
}

.current-chat-text {
    flex: 1;
    min-width: 0;
}

.current-chat-text span {
    display: block;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.current-chat-text small {
    display: none;
}

/* 历史记录 */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.chat-history h6 {
    color: #6b7280;
    font-size: 12px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item {
    background: transparent;
    padding: 10px 12px;
    border-radius: 8px;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
}

.history-item:hover {
    background: #f3f4f6;
}

.history-item.active {
    background: #e5e7eb;
}

.history-item i {
    color: #9ca3af;
    font-size: 16px;
    display: none;
}

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

.history-title {
    font-size: 14px;
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    color: #111827;
}

.history-meta {
    display: none;
}

.delete-session-btn {
    position: absolute;
    right: 8px;
    opacity: 0;
    transition: opacity 0.2s;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
}

.history-item:hover .delete-session-btn {
    opacity: 1;
}

.delete-session-btn:hover {
    color: #ef4444;
}

.history-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
    padding: 20px 10px;
}

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

.chat-history::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* ==================== 主聊天区域 ==================== */
.chat-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    background: white;
    padding: 32px 0;
}

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

.chat-messages-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.chat-messages {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* 消息样式 - 参考ChatGPT */
.message {
    display: flex;
    gap: 8px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    /* Styles for guest/user messages */
    display: flex;
}

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

.ai-message .message-avatar {
    background: #19c37d;
}

.user-message .message-avatar {
    background: #9333ea;
}

.message-content {
    flex: 1;
    max-width: calc(100% - 60px);
}

/* 关键：AI消息无背景，用户消息浅灰背景 */
.message-bubble {
    padding: 0;
    border-radius: 0;
    line-height: 1.75;
    font-size: 16px;
    word-wrap: break-word;
    background: transparent;
}

.ai-message .message-bubble {
    background: #f9fafb;
    padding: 12px 16px;
    border-radius: 18px;
    color: #374151;
}

.user-message .message-bubble {
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: 18px;
    color: #111827;
    max-width: 70%;
    margin-left: auto;
}

.message-text {
    margin: 0;
}

.message-time {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 8px;
    display: block;
}

.user-message .message-time {
    text-align: right;
}

/* 欢迎消息 */
.welcome-content {
    padding: 0;
}

.welcome-title {
    font-size: 24px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 16px;
}

.welcome-content p {
    color: #6b7280;
    margin-bottom: 24px;
    line-height: 1.75;
    font-size: 16px;
}

.capabilities h6 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #111827;
}

.capability-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.capability-item {
    background: #f9fafb;
    padding: 16px;
    border-radius: 12px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    transition: all 0.2s;
    border: 1px solid #e5e7eb;
}

.capability-item:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.capability-item i {
    color: #10a37f;
    font-size: 20px;
    margin-top: 2px;
}

.capability-item span {
    font-size: 14px;
    font-weight: 400;
    color: #374151;
    line-height: 1.5;
}

.welcome-footer {
    color: #9ca3af;
    font-size: 14px;
    margin-top: 16px;
}

/* Markdown */
.message-text h1,
.message-text h2,
.message-text h3 {
    margin: 16px 0 12px;
    font-weight: 600;
    color: #111827;
}

.message-text h1 {
    font-size: 24px;
}

.message-text h2 {
    font-size: 20px;
}

.message-text h3 {
    font-size: 18px;
}

.message-text h4 {
    font-size: 16px;
    margin: 12px 0 8px;
    font-weight: 600;
    color: #111827;
}

.message-text h5 {
    font-size: 14px;
    margin: 10px 0 6px;
    font-weight: 700;
    color: #374151;
}

.message-text ul,
.message-text ol {
    padding-left: 24px;
    margin: 12px 0;
}

.message-text li {
    margin: 8px 0;
    line-height: 1.75;
}

.message-text p {
    margin: 12px 0;
}

.message-text code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
    color: #ef4444;
}

.user-message .message-text code {
    background: #e5e7eb;
}

.message-text pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 16px 0;
}

.message-text pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

/* ==================== 输入区域 - 参考ChatGPT ==================== */
.chat-input-area {
    background: white;
    border-top: none;
    padding: 16px 0 24px;
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
}

/* 输入框 - 简化版 */
.input-main {
    flex: 1;
    position: relative;
    min-width: 0;
}

.input-box {
    position: relative;
    width: 100%;
}

.chat-input {
    width: 100%;
    border: 2px solid #d1d5db;
    background: white;
    outline: none;
    resize: vertical;
    font-size: 18px;
    line-height: 1.6;
    min-height: 80px;
    max-height: 300px;
    font-family: inherit;
    color: #111827;
    padding: 16px 20px;
    border-radius: 16px;
    transition: all 0.2s;
}

.chat-input:focus {
    border-color: #9ca3af;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.05);
}

.chat-input::placeholder {
    color: #9ca3af;
}

/* 工具栏 */
.input-toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.toolbar-group {
    display: flex;
    gap: 4px;
}

.toolbar-btn {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 20px;
}

.toolbar-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.toolbar-label {
    display: none;
}

/* 隐藏内联动作 */
.input-actions-inline {
    display: none;
}

.input-send {
    flex-shrink: 0;
}

.send-btn {
    width: 52px;
    height: 52px;
    background: #111827;
    border: none;
    border-radius: 50%;
    color: white;
    font-weight: 500;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.send-btn:hover {
    background: #374151;
}

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

.send-btn i {
    margin-left: 2px;
}

.send-label {
    display: none;
}

.input-status {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    justify-content: center;
}

.char-count {
    font-size: 12px;
    color: #9ca3af;
    text-align: center;
}

/* ==================== 消息操作按钮 ==================== */
.message-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 0;
}

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-actions .btn {
    padding: 6px 10px;
    font-size: 12px;
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    color: #6b7280;
    transition: all 0.2s;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.message-actions .btn:hover {
    background: #f3f4f6;
    color: #111827;
}

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }

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

    .chat-messages-container {
        padding: 24px 0;
    }

    .chat-messages {
        padding: 0 16px;
        gap: 24px;
    }

    .capability-grid {
        grid-template-columns: 1fr;
    }

    .chat-input-area {
        padding: 16px 0 24px;
    }

    .input-wrapper {
        padding: 0 16px;
    }
}

/* 移动端专用组件样式 - 先定义通用隐藏 */
.mobile-chat-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1100; /* 高于全局导航栏 1000 */
}

/* 响应式辅助调整 */
@media (max-width: 768px) {
    .mobile-chat-header {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 60px !important;
        background: #ffffff !important;
        color: #374151 !important;
        z-index: 10000 !important; /* Ultra high priority */
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
        align-items: center;
        justify-content: space-between;
        padding: 0 15px;
    }
    
    .chat-main-area {
        height: calc(100vh - 60px) !important;
        margin-top: 60px !important;
        position: relative;
        z-index: 10;
        background: #f9fafb;
    }

    .chat-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 280px;
        height: 100vh;
        z-index: 1200;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }
    
    .chat-sidebar.mobile-open {
        left: 0 !important;
    }
}

.mobile-menu-btn, .mobile-new-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #374151;
}

.mobile-header-title {
    font-weight: 600;
    font-size: 16px;
    color: #111827;
    flex: 1;
    min-width: 0;
    text-align: center;
    padding: 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 950;
    backdrop-filter: blur(2px);
}

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

/* Toast */
.toast {
    min-width: 250px;
}


.toast-header {
    background: rgba(16, 163, 127, 0.1);
    border-bottom: 1px solid rgba(16, 163, 127, 0.2);
}