/* css/style.css - 完整版 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    position: relative;
    width: 100%;
    height: 100vh;
    height: -webkit-fill-available;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 聊天容器 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background-color: #fff;
    position: relative;
    overflow: hidden;
}

/* 头部 */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 10;
    flex-shrink: 0;
    width: 100%;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.3);
}

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

.menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s;
}

.menu-btn:active {
    background-color: rgba(255,255,255,0.2);
}

/* 置顶广告 */
.top-ad {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    position: relative;
    flex-shrink: 0;
    width: 100%;
}

.top-ad .ad-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.top-ad img {
    width: 60px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
}

.top-ad .ad-text {
    color: #6c757d;
    font-size: 14px;
}

.close-ad {
    background: none;
    border: none;
    color: #adb5bd;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 8px;
}

/* 消息区域 */
.messages-wrapper {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background-color: #f8f9fa;
    padding: 16px;
    min-height: 0;
    height: 100%;
    width: 100%;
}

.messages-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100%;
}

.messages-container:empty {
    min-height: 100%;
    display: flex;
    align-items: flex-end;
}

/* 加载更多 */
.loading-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    color: #6c757d;
    font-size: 14px;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e9ecef;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* 底部输入区 */
.input-area {
    flex-shrink: 0;
    padding: 10px 16px;
    background-color: white;
    border-top: 1px solid #e9ecef;
    width: 100%;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    background-color: #f1f3f5;
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    border: 1px solid #dee2e6;
}

.message-input {
    flex: 1;
    border: none;
    background: none;
    padding: 8px 0;
    font-size: 16px;
    outline: none;
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 侧边栏 */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100%;
    background-color: white;
    z-index: 101;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
}

.sidebar.active {
    right: 0;
}

.sidebar-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.sidebar-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid white;
    object-fit: cover;
}

.sidebar-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.close-sidebar {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
}

.sidebar-menu {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    color: #495057;
    cursor: pointer;
    transition: background-color 0.3s;
    border-bottom: 1px solid #f1f3f5;
}

.menu-item:active {
    background-color: #f8f9fa;
}

.menu-item i {
    width: 24px;
    color: #667eea;
    font-size: 18px;
}

.menu-item span {
    flex: 1;
    font-size: 16px;
}

.menu-item .toggle-switch {
    width: 44px;
    height: 24px;
    background-color: #ced4da;
    border-radius: 12px;
    position: relative;
    transition: background-color 0.3s;
}

.menu-item .toggle-switch.active {
    background-color: #667eea;
}

.menu-item .toggle-switch::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: left 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.menu-item .toggle-switch.active::after {
    left: 22px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid #e9ecef;
    color: #adb5bd;
    font-size: 14px;
    text-align: center;
}

/* 弹窗广告 */
.popup-ad-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.popup-ad {
    background-color: white;
    border-radius: 16px;
    width: 100%;
    max-width: 320px;
    overflow: hidden;
    animation: popupIn 0.3s ease;
}

@keyframes popupIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.popup-ad-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.popup-ad-header span {
    font-weight: 600;
    font-size: 16px;
}

.close-popup {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.close-popup:active {
    background: rgba(255,255,255,0.3);
}

.popup-ad-content {
    cursor: pointer;
}

.popup-ad-content img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    display: block;
}

.popup-ad-text {
    padding: 40px;
    text-align: center;
    color: #6c757d;
    background-color: #f8f9fa;
}

.popup-ad-footer {
    padding: 12px 16px;
    border-top: 1px solid #e9ecef;
}

.not-show-today {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #6c757d;
    cursor: pointer;
}

.not-show-today input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* ===== 消息相关样式 ===== */

/* 消息项 */
.message-item {
    display: flex;
    gap: 10px;
    animation: messageSlide 0.3s ease;
    width: 100%;
}

.message-item.bot:first-child {
    margin-top: auto;
}

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

/* 机器人消息 */
.message-item.bot {
    flex-direction: row;
}

/* 用户消息 */
.message-item.user {
    flex-direction: row-reverse;
}

/* 头像 */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid #e9ecef;
}

.user .message-avatar {
    display: none;
}

/* 消息内容区 */
.message-content-wrapper {
    max-width: 85%;
    display: flex;
    flex-direction: column;
}

.user .message-content-wrapper {
    align-items: flex-end;
}

/* 消息气泡 */
.message-bubble {
    background-color: white;
    border-radius: 18px;
    padding: 10px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    position: relative;
    word-break: break-word;
    font-size: 15px;
}

.bot .message-bubble {
    border-top-left-radius: 4px;
    background-color: white;
}

.user .message-bubble {
    border-top-right-radius: 4px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* 消息时间 */
.message-time {
    font-size: 11px;
    color: #adb5bd;
    margin-top: 4px;
    margin-left: 8px;
    margin-right: 8px;
}

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

/* 搜索查询文字 */
.search-query {
    margin-bottom: 8px;
    font-size: 14px;
    color: #495057;
    font-weight: 500;
}

/* 资源列表容器 - 紧凑布局 */
.resources-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}

/* 资源项 - 紧凑 */
.resource-item {
    display: flex;
    gap: 8px;
    padding: 6px 8px;
    background-color: #f8f9fa;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
    border: 1px solid #e9ecef;
}

.resource-item:active {
    background-color: #e9ecef;
}

.resource-image-container {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
}

.resource-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background-color: #dee2e6;
}

.resource-image.loading {
    opacity: 0.5;
}

/* 资源图片文字 */
.resource-image-text {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    border-radius: 4px;
    flex-shrink: 0;
}

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

.resource-title {
    font-weight: 600;
    font-size: 14px;
    color: #212529;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vip-badge {
    display: inline-block;
    background: #ffc107;
    color: #212529;
    font-size: 9px;
    padding: 2px 4px;
    border-radius: 8px;
    margin-left: 6px;
    vertical-align: middle;
    font-weight: 500;
}

.resource-meta {
    display: flex;
    gap: 8px;
    font-size: 11px;
    color: #6c757d;
    margin-bottom: 2px;
}

.resource-meta span {
    display: flex;
    align-items: center;
    gap: 3px;
}

.resource-meta i {
    font-size: 10px;
}

.resource-category {
    font-size: 10px;
    color: #667eea;
    background-color: rgba(102, 126, 234, 0.1);
    padding: 2px 4px;
    border-radius: 8px;
    display: inline-block;
}

/* 分页控件 - 不换行 */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 8px 0 4px;
    padding: 4px 6px;
    background-color: #f8f9fa;
    border-radius: 6px;
    flex-wrap: nowrap;
    gap: 4px;
}

.pagination-btn {
    background: none;
    border: 1px solid #dee2e6;
    padding: 4px 8px;
    border-radius: 14px;
    font-size: 12px;
    color: #495057;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
    transition: all 0.2s;
    white-space: nowrap;
}

.pagination-btn:not(:disabled):active {
    background-color: #667eea;
    color: white;
    border-color: #667eea;
}

.pagination-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
    margin: 0 2px;
}

/* 消息底部文字广告 */
.message-text-ads {
    margin-top: 8px;
    padding: 6px 8px;
    background-color: #fff3cd;
    border-radius: 6px;
    border-left: 3px solid #ffc107;
}

.text-ad-item {
    padding: 4px 0;
    cursor: pointer;
    transition: opacity 0.2s;
    border-bottom: 1px solid #ffe69c;
}

.text-ad-item:last-child {
    border-bottom: none;
}

.text-ad-item:active {
    opacity: 0.7;
}

.text-ad-item a {
    text-decoration: none;
    font-size: 13px;
    display: block;
}

/* 加载状态 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: #adb5bd;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* 错误提示 */
.error-message {
    color: #dc3545;
    font-size: 14px;
    padding: 8px;
    background-color: #f8d7da;
    border-radius: 6px;
    margin: 4px 0;
}

/* 空状态 */
.empty-message {
    color: #6c757d;
    font-size: 13px;
    padding: 16px;
    text-align: center;
    background-color: #f8f9fa;
    border-radius: 6px;
}

/* 提示信息 */
.toast-message {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0,0,0,0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 1000;
    animation: toastIn 0.3s ease;
    max-width: 80%;
    text-align: center;
    white-space: nowrap;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* 资源详情页样式 */
.resource-detail-page {
    max-width: 100%;
    min-height: 100vh;
    background-color: #f8f9fa;
}

.detail-header {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.back-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.back-btn:active {
    background: rgba(255,255,255,0.3);
}

.detail-header h2 {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.detail-content {
    padding: 16px;
}

.resource-info-card {
    background-color: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.resource-info-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #212529;
}

.resource-description {
    color: #6c757d;
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 12px;
}

.resource-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0;
}

.tag {
    background-color: #e9ecef;
    color: #495057;
    padding: 4px 8px;
    border-radius: 14px;
    font-size: 12px;
}

.resource-meta-large {
    display: flex;
    gap: 16px;
    color: #6c757d;
    font-size: 13px;
    margin-top: 8px;
}

/* 下载链接列表 */
.download-links-section {
    background-color: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.download-links-section h3 {
    font-size: 16px;
    margin-bottom: 12px;
    color: #212529;
    display: flex;
    align-items: center;
    gap: 8px;
}

.download-link-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s;
}

.download-link-item:last-child {
    border-bottom: none;
}

.download-link-item:active {
    background-color: #f8f9fa;
}

.link-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.link-icon.video { background-color: #e3f2fd; color: #1976d2; }
.link-icon.audio { background-color: #fce4ec; color: #c2185b; }
.link-icon.image { background-color: #e8f5e8; color: #388e3c; }
.link-icon.archive { background-color: #fff3e0; color: #f57c00; }
.link-icon.disk { background-color: #ede7f6; color: #512da8; }
.link-icon.other { background-color: #f1f3f5; color: #6c757d; }

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

.link-type {
    font-weight: 600;
    font-size: 14px;
    color: #212529;
    margin-bottom: 2px;
}

.link-desc {
    font-size: 12px;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-url {
    font-size: 11px;
    color: #adb5bd;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-action {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #f1f3f5;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #495057;
    flex-shrink: 0;
    font-size: 14px;
}

/* 工具类 */
.hidden {
    display: none !important;
}

/* 手机端适配 */
@media (max-width: 480px) {
    .chat-header {
        padding: 8px 12px;
    }
    
    .header-title {
        font-size: 16px;
    }
    
    .messages-wrapper {
        padding: 12px;
    }
    
    .message-content-wrapper {
        max-width: 90%;
    }
    
    .message-bubble {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .resource-image-container,
    .resource-image-text {
        width: 36px;
        height: 36px;
    }
    
    .resource-image-text {
        font-size: 16px;
    }
    
    .resource-title {
        font-size: 13px;
    }
    
    .pagination-btn {
        padding: 3px 6px;
        font-size: 11px;
    }
    
    .pagination-info {
        font-size: 11px;
    }
    
    .input-area {
        padding: 8px 12px;
    }
    
    .message-input {
        font-size: 14px;
        padding: 6px 0;
    }
    
    .send-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .detail-header {
        padding: 8px 12px;
    }
    
    .detail-header h2 {
        font-size: 16px;
    }
    
    .detail-content {
        padding: 12px;
    }
    
    .download-link-item {
        padding: 8px 10px;
    }
    
    .link-icon {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    .link-type {
        font-size: 13px;
    }
    
    .link-desc {
        font-size: 11px;
    }
}

/* 防止滚动穿透 */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* 安全区域适配 */
@supports (padding: max(0px)) {
    .chat-header {
        padding-top: max(12px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    
    .input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    
    .messages-wrapper {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}