/**
 * 移动端专用样式
 * 针对不同手机屏幕的适配
 */

/* ============================================
   底部导航栏样式（横向排列）
   ============================================ */

/* 底部固定导航栏 - 横向排列 */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 640px;
    margin: 0 auto;
    background: white;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: 8px 16px 12px;
    border-top: 1px solid #e5e5e5;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    z-index: 1000;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #8e8e93;
    transition: color 0.2s;
    position: relative;
    padding: 4px 0;
}

.nav-item.active {
    color: #007aff;
}

.nav-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.nav-label {
    font-size: 11px;
    font-weight: 500;
}

/* 消息红点 */
.msg-badge {
    position: absolute;
    top: -4px;
    right: 20%;
    background: #ff3b30;
    color: white;
    border-radius: 20px;
    padding: 2px 6px;
    font-size: 10px;
    min-width: 18px;
    text-align: center;
}

/* ============================================
   主内容区样式
   ============================================ */

/* 主内容区 - 为底部导航留出空间 */
.main-content {
    min-height: calc(100vh - 120px);
    padding-bottom: 70px;
}

/* ============================================
   手机屏幕适配
   ============================================ */

/* iPhone SE 等小屏幕 (375px以下) */
@media (max-width: 375px) {
    .book-card {
        margin: 8px;
        padding: 10px;
    }
    
    .book-title {
        font-size: 14px;
    }
    
    .book-author {
        font-size: 12px;
    }
    
    .nav-label {
        font-size: 10px;
    }
    
    .nav-icon {
        font-size: 20px;
    }
    
    .category-tab {
        padding: 4px 12px;
        font-size: 12px;
    }
    
    .demo-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .demo-card {
        padding: 15px;
    }
    
    .demo-card-icon {
        font-size: 36px;
    }
    
    .demo-card-title {
        font-size: 12px;
    }
}

/* 标准手机屏幕 (376px - 640px) */
@media (min-width: 376px) and (max-width: 640px) {
    .book-card {
        margin: 12px;
        padding: 14px;
    }
    
    .demo-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* 大屏幕手机 (641px以上) */
@media (min-width: 641px) {
    .app-container {
        max-width: 640px;
        margin: 0 auto;
        box-shadow: 0 0 20px rgba(0,0,0,0.1);
    }
    
    .app-footer {
        max-width: 640px;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* ============================================
   横屏模式适配
   ============================================ */

@media (orientation: landscape) {
    .book-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 12px;
    }
    
    .book-card {
        margin: 0;
    }
    
    .category-tabs {
        overflow-x: auto;
    }
}

/* ============================================
   暗色模式支持
   ============================================ */

@media (prefers-color-scheme: dark) {
    body {
        background: #000;
    }
    
    .app-container {
        background: #000;
    }
    
    .app-footer {
        background: #1c1c1e;
        border-top-color: #3a3a3c;
    }
    
    .nav-item {
        color: #8e8e93;
    }
    
    .nav-item.active {
        color: #0a84ff;
    }
    
    .book-card {
        background: #1c1c1e;
    }
    
    .book-title {
        color: #fff;
    }
    
    .book-author,
    .book-publisher {
        color: #8e8e93;
    }
    
    .category-tabs {
        background: #1c1c1e;
        border-bottom-color: #3a3a3c;
    }
    
    .category-tab {
        background: #2c2c2e;
        color: #8e8e93;
    }
    
    .category-tab.active {
        background: #0a84ff;
        color: white;
    }
    
    .demo-card {
        background: #1c1c1e;
    }
    
    .demo-card-title {
        color: #fff;
    }
    
    .demo-card-author {
        color: #8e8e93;
    }
    
    .demo-message {
        background: #1c1c1e;
    }
    
    .demo-text {
        color: #8e8e93;
    }
    
    .modal-content {
        background: #1c1c1e;
    }
    
    .modal-message {
        color: #fff;
    }
    
    .modal-buttons {
        border-top-color: #3a3a3c;
    }
    
    .modal-btn.cancel {
        color: #8e8e93;
        border-right-color: #3a3a3c;
    }
    
    .modal-btn:active {
        background: #2c2c2e;
    }
    
    .form-input,
    .form-textarea,
    .form-select {
        background: #2c2c2e;
        border-color: #3a3a3c;
        color: #fff;
    }
    
    .form-label {
        color: #fff;
    }
    
    .pagination .page-link {
        background: #2c2c2e;
        color: #0a84ff;
    }
    
    .pagination .page-link.active {
        background: #0a84ff;
        color: white;
    }
}

/* ============================================
   触摸优化
   ============================================ */

.btn,
.nav-item,
.book-card,
.menu-item,
.category-tab,
.demo-card {
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.btn:active,
.nav-item:active,
.book-card:active,
.menu-item:active,
.category-tab:active,
.demo-card:active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* ============================================
   滚动条优化
   ============================================ */

::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

@media (prefers-color-scheme: dark) {
    ::-webkit-scrollbar-track {
        background: #2c2c2e;
    }
    
    ::-webkit-scrollbar-thumb {
        background: #3a3a3c;
    }
}

/* ============================================
   加载动画
   ============================================ */

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007aff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   骨架屏加载
   ============================================ */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-color-scheme: dark) {
    .skeleton {
        background: linear-gradient(90deg, #2c2c2e 25%, #3a3a3c 50%, #2c2c2e 75%);
    }
}

/* ============================================
   底部安全区适配（iPhone X 等全面屏）
   ============================================ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .app-footer {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .main-content {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   防止iOS点击高亮
   ============================================ */

* {
    -webkit-tap-highlight-color: transparent;
}

/* ============================================
   优化表单元素在iOS上的样式
   ============================================ */

input,
textarea,
select,
button {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 0;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
}

/* ============================================
   禁用页面缩放（可选）
   ============================================ */

body {
    touch-action: manipulation;
}

/* ============================================
   图片懒加载占位
   ============================================ */

img[data-src] {
    opacity: 0;
    transition: opacity 0.3s;
}

img.loaded {
    opacity: 1;
}

/* ============================================
   空状态样式
   ============================================ */

.empty-state {
    text-align: center;
    padding: 80px 20px;
}

.empty-icon {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-text {
    font-size: 16px;
    color: #999;
}

/* ============================================
   演示卡片样式
   ============================================ */

.demo-books {
    padding: 20px;
}

.demo-message {
    text-align: center;
    padding: 40px 20px;
    background: white;
    border-radius: 16px;
    margin-bottom: 20px;
}

.demo-icon {
    font-size: 60px;
    margin-bottom: 15px;
}

.demo-text {
    font-size: 16px;
    color: #666;
    margin-bottom: 10px;
}

.demo-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
}

.demo-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.demo-card:active {
    transform: scale(0.98);
}

.demo-card-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.demo-card-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 5px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.demo-card-author {
    font-size: 12px;
    color: #999;
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.demo-card-status {
    display: inline-block;
    padding: 4px 8px;
    background: #e8f5e9;
    color: #4caf50;
    border-radius: 4px;
    font-size: 11px;
}

/* ============================================
   分页样式
   ============================================ */

.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 20px;
    flex-wrap: wrap;
}

.page-link {
    padding: 8px 12px;
    background: white;
    border-radius: 6px;
    text-decoration: none;
    color: #007aff;
    transition: all 0.2s;
}

.page-link.active {
    background: #007aff;
    color: white;
}

.page-link:active {
    opacity: 0.7;
}

/* ============================================
   图书元信息
   ============================================ */

.book-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 8px;
}

.book-owner {
    font-size: 12px;
    color: #999;
}