/* 
 * 文件下载站 - 前端样式
 * 绿色主题、响应式、兼容 Android 4+
 */

:root {
    --primary-color: #1e90ff;
    --primary-dark: #1873cc;
    --primary-light: #5db3ff;
    --secondary-color: #2d3436;
    --text-color: #333;
    --light-text: #666;
    --border-color: #e0e0e0;
    --bg-color: #f5f5f5;
    --white: #fff;
    --success: #00b968;
    --danger: #ff6b6b;
    --warning: #ffa502;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 页头 */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 12px 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 12px;
}

.header-title {
    padding: 8px 0;
}

.header-title h1 {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
}

.header-search {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.search-input {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    background-color: rgba(255, 255, 255, 0.9);
    color: var(--text-color);
    outline: none;
    min-height: 44px;
}

.search-input::placeholder {
    color: #999;
}

.search-btn {
    padding: 10px 20px;
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.3s ease;
    white-space: nowrap;
}

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

/* 分类导航 */
.category-nav {
    background-color: var(--white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0;
    overflow-x: auto;
    padding: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.category-nav::-webkit-scrollbar {
    display: none;
}

.category-btn {
    flex-shrink: 0;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--light-text);
    font-size: 14px;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    min-height: 48px;
}

.category-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.category-btn:active {
    background-color: var(--bg-color);
}

/* 主内容区域 */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 12px 40px 12px;
    min-height: calc(100vh - 280px);
}

/* 文件列表 */
.file-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    width: 100%;
}

.file-item {
    background-color: var(--white);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    min-height: 180px;
    word-break: break-all;
}

.file-item:active {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.file-icon {
    width: 60px;
    height: 60px;
    background-color: var(--bg-color);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin: 0 auto 8px;
    font-weight: bold;
    color: var(--primary-color);
}

.file-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
}

.file-meta {
    font-size: 12px;
    color: var(--light-text);
    margin-top: 4px;
}

.file-size {
    display: block;
    margin-bottom: 4px;
}

.file-downloads {
    display: block;
    color: var(--primary-color);
}

.file-category {
    display: inline-block;
    background-color: var(--bg-color);
    color: var(--primary-color);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 11px;
    margin-top: 6px;
}

/* 加载状态 */
.loading-tip,
.empty-tip,
.error-tip {
    text-align: center;
    padding: 40px 20px;
    color: var(--light-text);
}

.loading-tip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.empty-tip p,
.error-tip p {
    font-size: 16px;
    margin: 20px 0;
}

.retry-btn {
    padding: 10px 24px;
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    min-height: 44px;
}

.retry-btn:active {
    background-color: var(--primary-dark);
}

/* 分页 */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background-color: var(--white);
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

.page-btn {
    padding: 8px 16px;
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.3s ease;
}

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

.page-btn:active:not(:disabled) {
    background-color: var(--primary-dark);
}

.page-info {
    font-size: 14px;
    color: var(--light-text);
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background-color: var(--white);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

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

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    word-break: break-word;
}

.modal-body {
    padding: 16px;
}

.file-info-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-weight: 600;
    color: var(--text-color);
    font-size: 13px;
}

.info-value {
    color: var(--light-text);
    font-size: 13px;
    word-break: break-all;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.btn-download {
    flex: 1;
    padding: 12px;
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.3s ease;
}

.btn-download:active {
    background-color: var(--primary-dark);
}

.btn-cancel {
    flex: 1;
    padding: 12px;
    background-color: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.3s ease;
}

.btn-cancel:active {
    background-color: #ddd;
}

/* 页脚 */
.footer {
    background-color: var(--secondary-color);
    color: var(--white);
    padding: 20px 12px;
    text-align: center;
    margin-top: 40px;
    font-size: 12px;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer p {
    margin: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .header-title h1 {
        font-size: 20px;
    }

    .file-list {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }

    .file-item {
        padding: 10px;
        min-height: 170px;
    }

    .file-name {
        font-size: 12px;
    }

    .main-content {
        padding: 12px 8px 40px 8px;
    }

    .modal-content {
        max-width: 90%;
    }

    .info-row {
        grid-template-columns: 70px 1fr;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 8px 0;
    }

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

    .header-search {
        gap: 6px;
        margin-top: 8px;
    }

    .search-input,
    .search-btn {
        min-height: 40px;
        font-size: 13px;
    }

    .category-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .category-btn {
        padding: 10px 12px;
        font-size: 13px;
        min-height: 44px;
    }

    .file-list {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }

    .file-item {
        padding: 8px;
        min-height: 150px;
    }

    .file-icon {
        width: 50px;
        height: 50px;
        font-size: 28px;
        margin: 0 auto 6px;
    }

    .file-name {
        font-size: 12px;
        margin-bottom: 4px;
    }

    .file-meta {
        font-size: 11px;
    }

    .main-content {
        padding: 8px 6px 40px 6px;
        min-height: calc(100vh - 250px);
    }

    .pagination {
        gap: 8px;
        padding: 12px;
    }

    .page-btn {
        padding: 6px 12px;
        font-size: 13px;
        min-height: 40px;
    }

    .page-info {
        font-size: 13px;
    }

    .modal-content {
        border-radius: 12px;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 12px;
    }

    .modal-header h2 {
        font-size: 16px;
    }

    .info-row {
        grid-template-columns: 60px 1fr;
        gap: 6px;
        padding: 6px 0;
    }

    .info-label,
    .info-value {
        font-size: 12px;
    }

    .btn-download,
    .btn-cancel {
        font-size: 13px;
        min-height: 40px;
    }

    .footer {
        font-size: 11px;
        padding: 12px 8px;
    }
}

/* 针对 Android 4+ 优化 */
body {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

input,
button,
textarea,
select {
    font-size: 16px;
}

a {
    -webkit-user-select: none;
    user-select: none;
    color: var(--primary-color);
    text-decoration: none;
}

button {
    -webkit-user-select: none;
    user-select: none;
}

/* 防止缩放问题 */
@media (min-width: 768px) {
    .file-list {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

@media (min-width: 1024px) {
    .file-list {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    .main-content {
        padding: 20px;
    }
}
