/* 全局重置与变量 */
:root {
    /* 极简清新配色 */
    --primary-color: #2c3e50; /* 深岩灰，沉稳 */
    --accent-color: #3498db; /* 亮蓝，仅用于强调 */
    --bg-color: #f8fafc; /* 极浅灰背景，护眼 */
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    
    --border-color: #e2e8f0;
    --divider-color: #f1f5f9;
    
    --success-color: #10b981;
    --danger-color: #ef4444;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    
    --radius-md: 8px;
    --radius-lg: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased; /* 让字体更清晰 */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* 移动端允许 body 滚动 */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
    }
    
    .container {
        min-height: 100vh; /* 改为最小高度，允许内容超出 */
        height: auto;
    }
}

/* 布局容器 */
.container {
    display: flex;
    height: 100vh;
    max-width: 100%;
    background: var(--bg-color);
}

/* 侧边栏 - 极简白风格 */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    transition: all 0.3s ease;
    justify-content: space-between;
}

.logo {
    padding: 0 12px 24px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--divider-color);
}

.logo h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.5px;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.nav-item {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 15px;
    color: var(--text-secondary);
    transition: all 0.2s;
    font-weight: 500;
}

.nav-item:hover {
    background-color: var(--bg-color);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: #eff6ff; /* 极浅蓝背景 */
    color: var(--accent-color);
}

.nav-item .icon {
    font-size: 18px;
    filter: grayscale(100%); /* 图标去色，更素雅 */
    opacity: 0.7;
}

.nav-item.active .icon {
    filter: none;
    opacity: 1;
}

/* 侧边栏底部用户信息 */
.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid var(--divider-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-color);
    border-radius: var(--radius-md);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s;
}

.btn-logout:hover {
    color: var(--danger-color);
}

/* 主内容区域 */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 32px 48px;
    background: var(--bg-color);
    position: relative; /* 为定位元素做参照 */
}

/* 标题栏 */
.tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding-bottom: 0;
    border-bottom: none;
}

.tab-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

/* 按钮 - 扁平化 */
.btn-primary {
    background-color: var(--text-primary); /* 深色按钮 */
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    background-color: black;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: white;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: var(--bg-color);
    color: var(--text-primary);
    border-color: #cbd5e1;
}

/* 模块通用容器 - 白色卡片 */
.chat-container, .image-container {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.chat-container {
    height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
}

/* 聊天气泡 - 类似 iMessage/微信 风格 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background-color: #ffffff;
}

.message {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
}

.message-label {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 6px;
    margin-left: 4px;
}

/* 区分发送者对齐方式 */
.message:has(.message-user) .message-label {
    align-self: flex-end;
    margin-right: 4px;
}

.message-user {
    align-self: flex-end;
    background-color: var(--text-primary); /* 深色气泡 */
    color: white;
    padding: 12px 18px;
    border-radius: 18px 18px 4px 18px;
    max-width: 75%;
    line-height: 1.5;
    font-size: 15px;
    box-shadow: var(--shadow-sm);
}

.message-ai {
    align-self: flex-start;
    background-color: #f1f5f9; /* 浅灰气泡 */
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: 18px 18px 18px 4px;
    max-width: 75%;
    line-height: 1.5;
    font-size: 15px;
    border: 1px solid transparent; /* 保持对齐 */
}

.chat-input-container {
    padding: 20px;
    background: white;
    border-top: 1px solid var(--divider-color);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input-container textarea {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-color);
    font-size: 14px;
    resize: none;
    min-height: 48px;
    transition: all 0.2s;
}

.chat-input-container textarea:focus {
    outline: none;
    background-color: white;
    border-color: var(--text-primary); /* 聚焦变深色 */
    box-shadow: 0 0 0 2px rgba(44, 62, 80, 0.1);
}

/* 欢迎页更简约 */
.welcome-message {
    padding-top: 60px;
    text-align: center;
}
.welcome-message h3 {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 20px;
    margin-bottom: 8px;
}
.welcome-message p {
    color: var(--text-secondary);
}
.model-info {
    font-size: 13px;
    color: var(--text-light);
    margin-top: 20px;
}
.model-info span {
    color: var(--accent-color);
    font-weight: 500;
}

/* 输入控件美化 */
.header-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.model-selector label, .size-selector label {
    color: var(--text-secondary);
    font-size: 13px;
    margin-right: 8px;
}

select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary);
    background-color: white;
    cursor: pointer;
}

select:hover {
    border-color: #cbd5e1;
}

select:focus {
    outline: none;
    border-color: var(--text-primary);
}

/* 生图页面 */
.image-container {
    padding: 30px;
}

.image-input-section textarea {
    width: 100%;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-color);
    font-size: 15px;
    margin-bottom: 20px;
    transition: all 0.2s;
}

.image-input-section textarea:focus {
    background: white;
    border-color: var(--text-primary);
    outline: none;
}

.image-result {
    border: 2px dashed var(--border-color);
    background: var(--bg-color);
    border-radius: var(--radius-md);
    min-height: 400px;
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.generated-image {
    max-width: 100%;
    max-height: 600px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    object-fit: contain;
}

.image-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.size-selector {
    display: flex;
    align-items: center;
}

.image-info {
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
    box-shadow: var(--shadow-sm);
    width: 100%;
}

.ai-badge {
    background: #e2e8f0;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 100px;
    letter-spacing: 0.5px;
}

/* 生图历史 */
.image-history-item {
    background: white;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: all 0.2s;
    border: 1px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.image-history-item:hover {
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    border-color: var(--border-color);
}

.image-history-content {
    flex: 1;
    min-width: 0; /* 允许内容收缩 */
}

.btn-delete-image {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
    flex-shrink: 0;
    opacity: 0.6;
}

.btn-delete-image:hover {
    opacity: 1;
    background-color: #fee2e2;
    transform: scale(1.1);
}

.history-image-thumb {
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: contain;
    border-radius: 6px;
    margin-top: 8px;
    cursor: pointer;
    background-color: #f8fafc; /* 添加背景色，当图片比例不一致时填充空白 */
}

/* 备忘录 - 瀑布流卡片 */
.memo-container {
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: hidden; /* 使用 hidden 确保滚动正常工作 */
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
}

.memo-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memo-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: all 0.2s;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0; /* 防止卡片被压缩 */
    flex-grow: 0; /* 防止卡片扩展 */
}

.memo-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

.memo-card h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.memo-card p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    margin: 0;
}

.memo-card-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--divider-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.memo-date {
    font-size: 12px;
    color: var(--text-light);
}

.btn-icon {
    color: var(--text-light);
    font-size: 16px;
    padding: 6px;
    border-radius: 4px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background-color: #f1f5f9;
    color: var(--text-primary);
}

.btn-delete:hover {
    color: var(--danger-color);
    background-color: #fef2f2;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--divider-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close {
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
}

.close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 16px;
}

.form-group input {
    width: 100%;
    border: none;
    outline: none;
    padding: 8px 0;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-bottom-color: var(--border-color);
}

.form-group textarea {
    width: 100%;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-secondary);
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--divider-color);
    background: var(--bg-color);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 加载动画简约版 */
.loading {
    border: 2px solid #e2e8f0;
    border-top-color: var(--text-primary);
    width: 16px;
    height: 16px;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ICP备案信息 */
.icp-footer {
    position: fixed;
    bottom: 0;
    right: 0;
    padding: 8px 16px;
    background: transparent;
    text-align: center;
    z-index: 50;
}

.icp-footer a {
    color: var(--text-light);
    text-decoration: none;
    font-size: 12px;
    transition: color 0.2s;
}

.icp-footer a:hover {
    color: var(--text-secondary);
    text-decoration: underline;
}

/* 移动端顶部导航栏 */
.mobile-header {
    display: none; /* 桌面端默认隐藏 */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* 确保模态框在移动端最上层 */
@media (max-width: 768px) {
    .modal {
        z-index: 9999 !important;
    }
    
    .mobile-sidebar-overlay {
        z-index: 9998;
    }
    
    .sidebar.active {
        z-index: 9999;
    }
}

.mobile-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.mobile-menu-toggle {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    line-height: 1;
}

/* =========================================
   📱 移动端适配 (Max-width: 768px)
   ========================================= */
@media (max-width: 768px) {
    body {
        /* 防止iOS点击高亮 */
        -webkit-tap-highlight-color: transparent;
    }

    /* 显示移动端顶部导航 */
    .mobile-header {
        display: flex;
    }

    .container {
        flex-direction: column;
        padding-top: 56px; /* 为顶部导航栏留出空间 */
    }

    /* 侧边栏改为抽屉式 */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px; /* 默认隐藏 */
        width: 260px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
        border-right: 1px solid var(--border-color);
        padding: 24px 16px;
        flex-direction: column;
        justify-content: flex-start;
    }

    .sidebar.active {
        left: 0;
    }

    .mobile-sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }

    .mobile-sidebar-overlay.active {
        display: block;
    }

    .logo {
        display: none; /* 移动端隐藏Logo（顶部导航已显示） */
    }

    /* 移动端隐藏用户信息区域 */
    .user-info {
        display: none;
    }

    .nav-menu {
        flex-direction: column;
        gap: 4px;
        margin-top: 20px;
    }

    .nav-item {
        flex-direction: row;
        gap: 12px;
        padding: 12px 16px;
        font-size: 15px;
        border-radius: var(--radius-md);
        width: 100%;
        justify-content: flex-start;
    }
    
    .nav-item .icon {
        font-size: 18px;
        margin-bottom: 0;
    }

    /* 主内容区域适配 */
    .main-content {
        padding: 16px;
        min-height: calc(100vh - 56px); /* 最小高度，允许内容超出 */
        padding-bottom: 16px; /* 恢复底部内边距 */
        margin-top: 56px;
        overflow-y: auto; /* 允许垂直滚动 */
        -webkit-overflow-scrolling: touch; /* iOS 平滑滚动 */
    }

    /* 标题栏调整 */
    .tab-header {
        margin-bottom: 16px;
    }

    .tab-header h1 {
        font-size: 18px;
    }
    
    /* 聊天页面适配 */
    .chat-layout {
        flex-direction: column;
    }
    
    .conversation-sidebar {
        display: none; /* 手机端默认隐藏侧边栏，改为抽屉式或独立页面 */
    }
    
    .chat-container {
        height: calc(100vh - 140px); /* 调整高度 */
        border: none;
        background: transparent;
        box-shadow: none;
    }
    
    .chat-messages {
        padding: 16px;
        background: transparent;
    }
    
    .chat-input-container {
        padding: 12px;
        background: var(--bg-color); /* 与背景一致 */
    }
    
    /* 气泡调整 */
    .message-user, .message-ai {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 14px;
    }

    /* 生图页面适配 */
    .image-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .image-controls button {
        width: 100%;
    }
    
    .image-result {
        min-height: 300px;
    }

    /* 图片历史记录适配 */
    .image-history-item {
        padding: 12px;
    }
    
    .btn-delete-image {
        padding: 6px 10px;
        font-size: 20px;
    }

    /* 备忘录适配 */
    .memo-list {
        padding: 8px;
        gap: 8px;
    }
    
    .memo-card {
        padding: 16px;
    }

    /* 模态框适配 */
    .modal-content {
        width: 95%;
        max-height: 85vh;
    }

    /* 登录/注册页面适配 */
    .auth-card {
        width: 90% !important;
        padding: 24px !important;
    }

    /* ICP备案信息移动端适配 - 在全局隐藏，只在profile页显示 */
    .icp-footer {
        display: none;
    }
}