/* ==================== 基础变量 ==================== */
:root {
    --primary: #5B7FFF;
    --primary-dark: #4A6FE3;
    --primary-light: #EEF2FF;
    --accent: #FFB940;
    --success: #22C55E;
    --success-light: #DCFCE7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --info: #3B82F6;
    --info-light: #DBEAFE;
    --bg: #F0F2F5;
    --card-bg: #FFFFFF;
    --text: #1E293B;
    --text-muted: #64748B;
    --text-light: #94A3B8;
    --border: #E2E8F0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
                 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ==================== 登录页 ==================== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.auth-card {
    background: white;
    border-radius: 20px;
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    text-align: center;
}

.auth-logo { font-size: 56px; margin-bottom: 8px; }
.auth-title { font-size: 28px; font-weight: 700; color: var(--text); }
.auth-subtitle { font-size: 14px; color: var(--text-muted); margin: 4px 0 28px; }

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.auth-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.auth-form { text-align: left; }

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.auth-hint {
    margin-top: 20px;
    padding: 12px;
    background: var(--info-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
}

/* ==================== 按钮 ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

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

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #16A34A; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #DC2626; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover:not(:disabled) { background: #D97706; }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #CBD5E1; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: rgba(0,0,0,0.05); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ==================== 主应用框架 ==================== */
.app-page { min-height: 100vh; }

.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 12px rgba(91,127,255,0.3);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 8px; }
.header-logo { font-size: 24px; }
.header-title { font-size: 18px; font-weight: 700; }

.header-right { display: flex; align-items: center; gap: 12px; }

.header-points {
    background: rgba(255,255,255,0.2);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.header-user { font-size: 14px; font-weight: 500; }

.header-right .btn-ghost { color: rgba(255,255,255,0.85); }
.header-right .btn-ghost:hover { background: rgba(255,255,255,0.15); color: white; }

/* ==================== 标签栏 ==================== */
.tab-bar {
    display: flex;
    gap: 0;
    background: white;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

.tab {
    padding: 14px 20px;
    border: none;
    background: none;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab:hover { color: var(--primary); }

.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-badge {
    background: var(--danger);
    color: white;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
    vertical-align: top;
}

/* ==================== 内容区 ==================== */
.app-content { padding: 24px; max-width: 1200px; margin: 0 auto; }
.view { animation: fadeIn 0.3s ease; }

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

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.view-header h2 { font-size: 20px; }

/* ==================== 筛选栏 ==================== */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
}

.search-input:focus { outline: none; border-color: var(--primary); }

.filter-select {
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: white;
    cursor: pointer;
}

.filter-select:focus { outline: none; border-color: var(--primary); }

/* ==================== 书籍卡片 ==================== */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.book-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.book-cover {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: var(--bg);
}

.book-cover-placeholder {
    width: 100%;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.book-info { padding: 12px 14px; flex: 1; display: flex; flex-direction: column; gap: 4px; }

.book-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author { font-size: 13px; color: var(--text-muted); }
.book-uploader { font-size: 12px; color: var(--text-light); margin-top: 4px; }

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

/* ==================== 徽章 ==================== */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success { background: var(--success-light); color: #166534; }
.badge-danger { background: var(--danger-light); color: #991B1B; }
.badge-warning { background: var(--warning-light); color: #92400E; }
.badge-info { background: var(--info-light); color: #1E40AF; }
.badge-secondary { background: #F1F5F9; color: var(--text-muted); }

.badge-category {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-size: 11px;
}

/* ==================== 模态框 ==================== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 18px; font-weight: 700; }

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover { background: var(--bg); }

.modal-body { padding: 24px; overflow-y: auto; }

/* ==================== 书籍详情 ==================== */
.book-detail { display: flex; gap: 20px; flex-wrap: wrap; }

.book-detail-cover {
    width: 140px;
    height: 200px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.book-detail-cover img { width: 100%; height: 100%; object-fit: cover; }

.book-detail-info { flex: 1; min-width: 200px; }

.book-detail-info h2 { font-size: 20px; margin-bottom: 8px; }

.book-detail-row {
    display: flex;
    margin-bottom: 6px;
    font-size: 14px;
}

.book-detail-row .label {
    width: 70px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.book-detail-desc {
    margin-top: 12px;
    font-size: 14px;
    color: var(--text);
    line-height: 1.6;
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.book-detail-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

/* ==================== 借阅列表 ==================== */
.section-title {
    font-size: 16px;
    font-weight: 600;
    margin: 24px 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}

.section-title:first-child { margin-top: 0; }

.record-list { display: flex; flex-direction: column; gap: 12px; }

.record-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.record-info { flex: 1; min-width: 200px; }

.record-title { font-size: 15px; font-weight: 600; }
.record-meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.record-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ==================== 表格 ==================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.data-table th,
.data-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.data-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tbody tr:hover { background: #F8FAFC; }
.data-table .rank-cell { font-weight: 700; font-size: 16px; }

.rank-1 { color: #F59E0B; }
.rank-2 { color: #94A3B8; }
.rank-3 { color: #B45309; }

.points-positive { color: var(--success); font-weight: 600; }
.points-negative { color: var(--danger); font-weight: 600; }
.points-zero { color: var(--text-muted); }

/* ==================== 管理面板 ==================== */
.admin-section { margin-bottom: 32px; }

.admin-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.admin-section-header h3 { font-size: 16px; }

.pending-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    border-left: 4px solid var(--warning);
}

.pending-card.return { border-left-color: var(--info); }

/* ==================== 空状态 ==================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .empty-text { font-size: 15px; }

/* ==================== Toast ==================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: white;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    max-width: 360px;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
.toast-warning { background: var(--warning); }

/* ==================== 统计卡片 ==================== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ==================== 响应式 ==================== */
@media (max-width: 768px) {
    .app-header { padding: 10px 16px; }
    .header-title { display: none; }
    .app-content { padding: 16px; }
    .tab-bar { padding: 0 8px; }
    .tab { padding: 12px 14px; font-size: 14px; }

    .book-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
    .book-cover, .book-cover-placeholder { height: 140px; }

    .filter-bar { flex-direction: column; }
    .search-input, .filter-select { width: 100%; }

    .book-detail { flex-direction: column; align-items: center; text-align: center; }
    .book-detail-row { justify-content: center; }
    .book-detail-row .label { width: auto; margin-right: 4px; }
    .book-detail-actions { justify-content: center; }

    .record-card { flex-direction: column; align-items: stretch; }
    .record-actions { justify-content: stretch; }
    .record-actions .btn { flex: 1; }

    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px; }

    .toast-container { right: 12px; left: 12px; }
    .toast { max-width: none; }
}

/* ==================== 上传表单 ==================== */
.upload-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 600px) {
    .upload-form .form-row { grid-template-columns: 1fr; }
}

/* ==================== 加载中 ==================== */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

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

/* ==================== 借阅历史 ==================== */
.history-list { margin-top: 16px; }

.history-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
}

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