/* 基础样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* 头部样式 */
.header {
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
}

.logo a {
    font-size: 1.5rem;
    font-weight: bold;
    color: #007bff;
    text-decoration: none;
}

.nav ul {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav a {
    color: #333;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s;
}

.nav a:hover {
    color: #007bff;
}

.search-box {
    display: flex;
    gap: 0.5rem;
}

.search-box input {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 200px;
}

.search-box button {
    padding: 0.5rem 1rem;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
}

.search-box button:hover {
    background: #0056b3;
}

/* 主要内容区域 */
.main {
    padding: 2rem 0;
}

.content-wrapper {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
}

.content-area {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 页面标题 */
.page-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #007bff;
}

.page-header h1 {
    color: #333;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.category-description {
    color: #666;
    font-size: 1.1rem;
}

/* 子分类标签 */
.subcategory-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.subcategory-tabs .tab {
    padding: 0.5rem 1rem;
    background: #f8f9fa;
    color: #666;
    text-decoration: none;
    border-radius: 20px;
    transition: all 0.3s;
    font-size: 0.9rem;
}

.subcategory-tabs .tab:hover,
.subcategory-tabs .tab.active {
    background: #007bff;
    color: white;
}

/* 电子书网格 */
.books-grid {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.books-grid[data-columns="3"] {
    grid-template-columns: repeat(3, 1fr);
}

.books-grid[data-columns="4"] {
    grid-template-columns: repeat(4, 1fr);
}

.books-grid[data-columns="5"] {
    grid-template-columns: repeat(5, 1fr);
}

.book-item {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s, box-shadow 0.3s;
}

.book-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.book-cover {
    position: relative;
    aspect-ratio: 3/4;
    overflow: hidden;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.no-cover {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 2rem;
    font-weight: bold;
}

.book-info {
    padding: 1rem;
}

.book-title {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.book-title a {
    color: #333;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-title a:hover {
    color: #007bff;
}

.book-author,
.book-category {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.25rem;
}

/* 电子书详情页 */
.book-detail {
    max-width: 800px;
}

.book-header {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
}

.book-cover-large {
    flex-shrink: 0;
    width: 200px;
}

.book-cover-large img {
    width: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.no-cover-large {
    width: 200px;
    height: 267px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 3rem;
    font-weight: bold;
    border-radius: 8px;
}

.book-meta h1 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #333;
}

.book-meta p {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.book-description {
    margin-bottom: 2rem;
}

.book-description h3 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.3rem;
}

.description-content {
    line-height: 1.8;
    color: #555;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 书籍描述中的图片响应式处理 */
.description-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 确保所有富文本内容中的图片都响应式 */
.book-description img,
.description-content img {
    max-width: 100% !important;
    display: block;
    margin: 1rem auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 只有没有明确宽高设置的图片才使用auto */
.book-description img:not([width]):not([height]),
.description-content img:not([width]):not([height]) {
    width: auto !important;
    height: auto !important;
}

/* 有明确宽度设置的图片保持宽度，高度自适应 */
.book-description img[width],
.description-content img[width] {
    height: auto !important;
}

/* 有明确高度设置但没有宽度的图片保持高度，宽度自适应 */
.book-description img[height]:not([width]),
.description-content img[height]:not([width]) {
    width: auto !important;
}
.footer a {
    color: #ccc;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s;
}

.footer a:hover {
    color: #007bff;
}

/* 移动设备上的图片优化 */
@media (max-width: 768px) {
    .description-content img,
    .book-description img {
        max-width: 100% !important;
        margin: 0.5rem auto;
        border-radius: 4px;
    }
}

.download-section {
    background: #f8f9fa;
    padding: 2rem;
    border-radius: 8px;
    margin-top: 2rem;
}

.download-section h3 {
    margin-bottom: 1rem;
    color: #333;
}

.download-links {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.download-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.format-tag {
    background: #007bff;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}

.download-link {
    color: #007bff;
    text-decoration: none;
    font-weight: 500;
}

.download-link:hover {
    text-decoration: underline;
}

.password-required {
    padding: 2rem;
    background: white;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.password-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.qr-section {
    flex: 1;
    text-align: center;
}

.form-section {
    flex: 1;
}

.password-required .qr-code {
    margin-bottom: 0;
}

.password-required .form-group {
    margin-bottom: 1rem;
}

.password-required .submit-btn {
    width: 100%;
}

@media (max-width: 768px) {
    .password-layout {
        flex-direction: column;
        text-align: center;
    }
    
    .password-required .qr-code {
        margin-bottom: 1rem;
    }
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #fff;
    margin: 10% auto;
    padding: 0;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

.modal-body {
    padding: 2rem;
}

.qr-code {
    text-align: center;
    margin-bottom: 2rem;
}

.qr-code img {
    width: 150px;
    height: 150px;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.form-group small {
    color: #666;
    font-size: 0.9rem;
}

.submit-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
}

.submit-btn:hover {
    background: #0056b3;
}

/* 侧边栏 */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.sidebar-widget {
    background: #fff;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.sidebar-widget h3 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.2rem;
    border-bottom: 2px solid #007bff;
    padding-bottom: 0.5rem;
}

.category-list {
    list-style: none;
}

.category-list li {
    margin-bottom: 0.5rem;
}

.category-list a {
    color: #666;
    text-decoration: none;
    transition: color 0.3s;
}

.category-list a:hover {
    color: #007bff;
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    background: #f8f9fa;
    color: #666;
    padding: 0.25rem 0.75rem;
    border-radius: 15px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.tag:hover {
    background: #007bff;
    color: white;
}

.random-books {
    list-style: none;
}

.random-books li {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
}

.random-books li:last-child {
    border-bottom: none;
}

.random-books a {
    color: #666;
    text-decoration: none;
    font-size: 0.9rem;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.random-books a:hover {
    color: #007bff;
}

/* 广告位 */
.content-ad,
.ad-widget {
    margin: 2rem 0;
    text-align: center;
}

.ad-content {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 4px;
    border: 1px dashed #ddd;
    color: #666;
    font-size: 0.9rem;
}

/* 友情链接 */
.friend-links {
    background: #fff;
    padding: 1rem 0;
    margin-top: 1rem;
}

.friend-links h3 {
    text-align: center;
    margin-bottom: 0.8rem;
    color: #333;
}

.links-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.1rem;
    margin-bottom: 0.5rem;
}

.links-grid a {
    padding: 0.3rem 0.2rem;
    text-decoration: none;
    color: #007bff;
    transition: color 0.3s;
    white-space: nowrap;
    font-size: 0.9rem;
}

.links-grid a:hover {
    color: #0056b3;
    text-decoration: underline;
}

.apply-link-small {
    font-size: 0.75em;
    color: #6c757d;
    text-decoration: none;
    margin-left: 8px;
    font-weight: normal;
}

.apply-link-small:hover {
    color: #007bff;
    text-decoration: underline;
}

/* 分页 */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 2rem 0;
}

.page-link {
    padding: 0.5rem 1rem;
    background: #fff;
    color: #007bff;
    text-decoration: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: all 0.3s;
}

.page-link:hover,
.page-link.current {
    background: #007bff;
    color: white;
}

/* 表单样式 */
.apply-form {
    max-width: 600px;
    margin: 0 auto;
}

.form-notice {
    background: #e7f3ff;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    border-left: 4px solid #007bff;
}

.form-notice h3 {
    margin-bottom: 1rem;
    color: #333;
}

.important-notice {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.important-notice h4 {
    color: #856404;
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.important-notice p {
    color: #856404;
    margin-bottom: 0.5rem;
}

.link-info {
    background: #f8f9fa;
    padding: 0.8rem;
    border-radius: 4px;
    margin-top: 0.8rem;
    border-left: 3px solid #28a745;
}

.link-info p {
    margin-bottom: 0.3rem;
    color: #495057;
    font-size: 0.9rem;
}

.form-notice ul {
    margin-left: 1.5rem;
}

.form-notice li {
    margin-bottom: 0.5rem;
    color: #666;
}

.link-form {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.cancel-btn {
    background: #6c757d;
    color: white;
    padding: 0.75rem 2rem;
    text-decoration: none;
    border-radius: 4px;
    text-align: center;
}

.cancel-btn:hover {
    background: #545b62;
}

/* 消息提示 */
.flash-messages {
    margin-bottom: 2rem;
}

.flash-message {
    background: #d4edda;
    color: #155724;
    padding: 1rem;
    border-radius: 4px;
    border: 1px solid #c3e6cb;
    margin-bottom: 1rem;
}

.flash-message.error {
    background: #f8d7da;
    color: #721c24;
    border-color: #f5c6cb;
}

.no-content {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.no-download {
    text-align: center;
    color: #666;
    font-style: italic;
}

/* 底部 */
.footer {
    background: #333;
    color: #fff;
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer-content {
    text-align: center;
}

.footer-content p {
    margin-bottom: 0.5rem;
    color: #ccc;
}

.bottom-ad {
    background: #f8f9fa;
    padding: 2rem 0;
    text-align: center;
}


/* 全局图片响应式处理 */
.content img,
.book-content img,
.article-content img,
.rich-text img {
    max-width: 100% !important;
    display: block;
    margin: 1rem auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 只有没有明确宽高设置的图片才使用auto */
.content img:not([width]):not([height]),
.book-content img:not([width]):not([height]),
.article-content img:not([width]):not([height]),
.rich-text img:not([width]):not([height]) {
    width: auto !important;
    height: auto !important;
}

/* 有明确宽度设置的图片保持宽度，高度自适应 */
.content img[width],
.book-content img[width],
.article-content img[width],
.rich-text img[width] {
    height: auto !important;
}

/* 有明确高度设置但没有宽度的图片保持高度，宽度自适应 */
.content img[height]:not([width]),
.book-content img[height]:not([width]),
.article-content img[height]:not([width]),
.rich-text img[height]:not([width]) {
    width: auto !important;
}

/* 防止内容溢出 */
.book-detail,
.content-wrapper,
.main-content {
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav ul {
        flex-wrap: wrap;
        justify-content: center;
        gap: 1rem;
    }
    
    .search-box {
        width: 100%;
        justify-content: center;
    }
    
    .search-box input {
        flex: 1;
        max-width: 300px;
    }
    
    .content-wrapper {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .books-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1rem;
    }
    
    .book-header {
        flex-direction: column;
        text-align: center;
    }
    
    .book-cover-large {
        align-self: center;
    }
    
    .subcategory-tabs {
        justify-content: center;
    }
    
    .links-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .form-actions {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .books-grid {
        grid-template-columns: 1fr !important;
    }
    
    .links-grid {
        grid-template-columns: 1fr;
    }
    
    .pagination {
        flex-wrap: wrap;
    }
}
