/* static/css/ranking/ranking.css - 完整版 */

/* ========== CSS 變數 ========== */
:root {
    --primary: #667eea;
    --primary-light: #764ba2;
    --primary-rgb: 102, 126, 234;
}

[data-gender="female"] {
    --primary: #e83e8c;
    --primary-light: #ffb6c1;
    --primary-rgb: 232, 62, 140;
}

/* ========== 排行榜首頁 ========== */
.ranking-home {
    padding: 20px 0;
    background: #f5f7fa;
}

.ranking-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 40px 0;
    margin-bottom: 30px;
    border-radius: 0 0 20px 20px;
}

.ranking-header .row {
    row-gap: 15px;
}

.ranking-header h1 {
    color: white;
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 10px;
}

.ranking-header .update-time {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

.ranking-header .rule-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 0.9rem;
}

.ranking-header .rule-link:hover {
    color: white;
    text-decoration: underline;
}

.ranking-header .d-flex.align-items-center.gap-3 {
    flex-wrap: wrap;
    row-gap: 8px;
}

/* 時間選擇器 */
.time-selector {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
}

.time-btn {
    padding: 8px 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    color: white;
    border-radius: 20px;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.time-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.time-btn.active {
    background: white;
    color: var(--primary);
    border-color: white;
}

/* 性別切換 */
.gender-tabs {
    display: flex;
    gap: 5px;
    background: rgba(255, 255, 255, 0.15);
    padding: 5px;
    border-radius: 25px;
    flex-wrap: nowrap;        /* ✅ 不換行 */
}

.gender-tab {
    padding: 6px 14px;
    border-radius: 20px;
    color: black;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;           /* ✅ 不壓縮 */
    transition: all 0.2s;
}

.gender-tab:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.gender-tab.active {
    background: white;
    color: #333;
    font-weight: 600;
}

.gender-tab .fa-mars { color: #3a86ff; }
.gender-tab.active .fa-mars { color: #3a86ff; }
.gender-tab .fa-venus { color: #e83e8c; }
.gender-tab.active .fa-venus { color: #e83e8c; }

/* 榜單網格 */
.ranking-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

@media (max-width: 1200px) {
    .ranking-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .ranking-grid {
        grid-template-columns: 1fr;
    }
}

/* 榜單卡片 */
.rank-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    transition: all 0.2s;
}

.rank-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.rank-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rank-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
}

.rank-card-title i {
    font-size: 1.3rem;
}

.rank-card-more {
    color: #999;
    font-size: 0.85rem;
    text-decoration: none;
    transition: color 0.2s;
    white-space: nowrap;
}

.rank-card-more:hover {
    color: var(--primary);
}

.rank-card-body {
    padding: 12px 0;
}

.rank-card-footer {
    padding: 12px 20px;
    border-top: 1px solid #f0f0f0;
    text-align: center;
}

.rank-card-footer .btn-view-all {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}

.rank-card-footer .btn-view-all:hover {
    text-decoration: underline;
}

/* 排行榜列表項 */
.rank-item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    transition: background 0.15s;
}

.rank-item:hover {
    background: #f8f9fa;
}

.rank-number {
    width: 32px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #999;
    text-align: center;
    flex-shrink: 0;
}

.rank-number.top-1 { color: #FFD700; font-size: 1.4rem; }
.rank-number.top-2 { color: #C0C0C0; font-size: 1.3rem; }
.rank-number.top-3 { color: #CD7F32; font-size: 1.2rem; }

.rank-content {
    flex: 1;
    min-width: 0;
}

.rank-title {
    font-weight: 500;
    color: #333;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    margin-bottom: 4px;
}

.rank-title:hover {
    color: var(--primary);
}

.rank-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.8rem;
    color: #999;
}

.rank-author {
    color: #666;
}

.rank-value {
    font-weight: 600;
    color: var(--primary);
    margin-left: auto;
    flex-shrink: 0;
    font-size: 0.9rem;
}

.rank-trend {
    font-size: 0.8rem;
    margin-left: 5px;
}

.rank-trend.up { color: #e74c3c; }
.rank-trend.down { color: #27ae60; }
.rank-trend.same { color: #999; }

/* 用戶排行榜項 */
.rank-user-item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    transition: background 0.15s;
}

.rank-user-item:hover {
    background: #f8f9fa;
}

.rank-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center;
    background: #e0e0e0;
    margin-right: 12px;
    flex-shrink: 0;
}

.rank-user-info {
    flex: 1;
    min-width: 0;
}

.rank-user-name {
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.rank-user-level {
    font-size: 0.75rem;
    color: #999;
}

.rank-user-points {
    font-weight: 600;
    color: var(--primary);
    flex-shrink: 0;
    font-size: 0.9rem;
}

/* ========== 排行榜佈局 ========== */
.ranking-layout {
    display: flex;
    gap: 20px;
}

@media (max-width: 992px) {
    .ranking-layout {
        flex-direction: column;
    }
}

/* ========== 左側選單 ========== */
.ranking-sidebar-menu {
    width: 200px;
    flex-shrink: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    position: sticky;
    top: 20px;
    height: fit-content;
}

.ranking-sidebar-menu .menu-header {
    padding: 16px 20px;
    font-weight: 600;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
}

.ranking-sidebar-menu .menu-item {
    display: block;
    padding: 12px 20px;
    color: #666;
    text-decoration: none;
    transition: all 0.15s;
    border-bottom: 1px solid #f5f5f5;
}

.ranking-sidebar-menu .menu-item:last-child {
    border-bottom: none;
}

.ranking-sidebar-menu .menu-item:hover {
    background: #f8f9fa;
    color: var(--primary);
}

.ranking-sidebar-menu .menu-item.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
}

.ranking-sidebar-menu .menu-item i {
    width: 24px;
    margin-right: 8px;
}

@media (max-width: 992px) {
    .ranking-sidebar-menu {
        width: 100%;
        position: static;
    }
    
    .ranking-sidebar-menu .menu-item {
        display: inline-block;
        border-bottom: none;
    }
}

/* 右側主內容 */
.ranking-main {
    flex: 1;
    min-width: 0;
}

/* ========== 排行榜詳情頁 ========== */
.ranking-detail {
    padding: 20px 0;
}

.detail-header {
    margin-bottom: 30px;
}

.detail-header h2 {
    font-size: 1.8rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.detail-header .sub-title {
    color: #999;
    font-size: 0.9rem;
}

.rank-info {
    color: #666;
    font-size: 0.9rem;
}

.rank-info span {
    font-weight: 600;
    color: var(--primary);
}

/* 排序選項 */
.sort-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: white;
    border-radius: 8px;
}

.sort-option {
    padding: 6px 16px;
    border-radius: 20px;
    color: #666;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
    background: #f5f5f5;
}

.sort-option:hover {
    background: #e0e0e0;
    color: #333;
}

.sort-option.active {
    background: var(--primary);
    color: white;
}

/* 時間選擇器（詳情頁） */
.time-selector {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.time-selector-inline {
    display: flex;
    gap: 5px;
    background: #f5f5f5;
    padding: 4px;
    border-radius: 20px;
}

.time-btn-inline {
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 0.85rem;
    color: #666;
    text-decoration: none;
    transition: all 0.15s;
}

.time-btn-inline:hover {
    background: #e0e0e0;
    color: #333;
}

.time-btn-inline.active {
    background: var(--primary);
    color: white;
}

/* 篩選側邊欄 */
.filter-sidebar {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    position: sticky;
    top: 20px;
}

.filter-section {
    margin-bottom: 24px;
}

.filter-section:last-child {
    margin-bottom: 0;
}

.filter-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #666;
    margin-bottom: 8px;
    display: block;
}

.filter-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #333;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.filter-select:hover {
    border-color: var(--primary);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

.filter-options {
    max-height: 300px;
    overflow-y: auto;
}

.filter-option {
    display: block;
    padding: 8px 0;
    color: #666;
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.15s;
    border-bottom: 1px solid #f5f5f5;
}

.filter-option:last-child {
    border-bottom: none;
}

.filter-option:hover {
    color: var(--primary);
}

.filter-option.active {
    color: var(--primary);
    font-weight: 500;
}

/* 篩選器區域 */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
    background: white;
    border-radius: 12px;
    margin-bottom: 20px;
}

.filter-bar .filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-bar .filter-label {
    font-size: 0.85rem;
    color: #999;
}

.filter-bar .filter-select {
    padding: 6px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
}

.filter-bar .filter-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* 排名資訊欄 */
.rank-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 0 5px;
}

.rank-count {
    color: #666;
    font-size: 0.9rem;
}

.rank-count span {
    font-weight: 600;
    color: var(--primary);
}

/* 小說列表 */
.ranking-list {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.ranking-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s;
}

.ranking-item:last-child {
    border-bottom: none;
}

.ranking-item:hover {
    background: #fafafa;
}

.ranking-item .rank-number {
    width: 50px;
    font-size: 1.3rem;
    font-weight: 700;
    color: #999;
    text-align: center;
    flex-shrink: 0;
}

.ranking-item .rank-number.top-1 { color: #FFD700; font-size: 1.6rem; }
.ranking-item .rank-number.top-2 { color: #C0C0C0; font-size: 1.5rem; }
.ranking-item .rank-number.top-3 { color: #CD7F32; font-size: 1.4rem; }

.ranking-item .book-cover {
    width: 60px;
    height: 80px;
    margin-right: 16px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    background: #f0f0f0;
}

.ranking-item .book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.ranking-item .book-info {
    flex: 1;
    min-width: 0;
}

.ranking-item .book-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.ranking-item .book-title a {
    color: #333;
    text-decoration: none;
}

.ranking-item .book-title a:hover {
    color: var(--primary);
}

.ranking-item .book-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 6px;
}

.ranking-item .book-meta .author { color: #666; }
.ranking-item .book-meta .category { color: var(--primary); }

.ranking-item .book-meta .status {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
}

.ranking-item .book-meta .status.ongoing {
    background: #e3f2fd;
    color: #1976d2;
}

.ranking-item .book-meta .status.finished {
    background: #e8f5e9;
    color: #388e3c;
}

.ranking-item .book-desc {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ranking-item .book-stats {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 0.85rem;
}

.ranking-item .book-stats .hot-count {
    color: #e74c3c;
    font-weight: 500;
}

.ranking-item .book-stats .trend { font-weight: 500; }
.ranking-item .book-stats .trend.up { color: #e74c3c; }
.ranking-item .book-stats .trend.down { color: #27ae60; }

.ranking-item .book-actions {
    flex-shrink: 0;
    margin-left: 20px;
}

.ranking-item .action-buttons {
    display: flex;
    gap: 8px;
}

.ranking-item .btn-add,
.ranking-item .btn-read {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.ranking-item .btn-add {
    background: #f0f0f0;
    color: #666;
}

.ranking-item .btn-add:hover {
    background: #e0e0e0;
}

.ranking-item .btn-read {
    background: var(--primary);
    color: white;
}

.ranking-item .btn-read:hover {
    filter: brightness(0.9);
}

/* 讀者/作者積分榜詳情頁 */
.points-ranking-list {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

.points-ranking-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s;
}

.points-ranking-item:last-child {
    border-bottom: none;
}

.points-ranking-item:hover {
    background: #fafafa;
}

.points-ranking-item .rank-number {
    width: 60px;
    font-size: 1.3rem;
    font-weight: 700;
    color: #999;
    text-align: center;
    flex-shrink: 0;
}

.points-ranking-item .user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center;
    background: #e0e0e0;
    margin-right: 16px;
    flex-shrink: 0;
}

.points-ranking-item .user-info {
    flex: 1;
    min-width: 0;
}

.points-ranking-item .user-name-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.points-ranking-item .user-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    transition: color 0.15s;
}

.points-ranking-item .reader-badge,
.points-ranking-item .author-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.points-ranking-item .user-stats {
    display: flex;
    gap: 20px;
    font-size: 0.85rem;
    color: #999;
    margin-top: 4px;
}

.points-ranking-item .user-points {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
    margin-left: 20px;
}

/* 用戶頭像連結 */
.user-avatar-link {
    display: block;
    flex-shrink: 0;
    text-decoration: none;
}

.user-avatar-link:hover .user-avatar {
    opacity: 0.8;
    transform: scale(1.05);
    transition: all 0.2s;
}

.user-name-link {
    text-decoration: none;
    color: inherit;
}

.user-name-link:hover .user-name {
    color: var(--primary);
    text-decoration: underline;
}

.points-avatar-placeholder {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #764ba2, var(--primary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 20px;
    text-transform: uppercase;
    flex-shrink: 0;
}

/* 分頁 */
.ranking-pagination {
    margin-top: 30px;
}

.ranking-pagination .pagination {
    gap: 5px;
}

.ranking-pagination .page-link {
    border-radius: 8px;
    padding: 10px 18px;
    color: #666;
    border: 1px solid #e0e0e0;
}

.ranking-pagination .page-link:hover {
    background: #f5f5f5;
    color: var(--primary);
}

.ranking-pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* 空狀態 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

/* ========== 響應式 ========== */
@media (max-width: 1200px) {
    .ranking-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .ranking-item {
        flex-wrap: wrap;
    }
    
    .ranking-item .book-actions {
        width: 100%;
        margin-left: 0;
        margin-top: 10px;
        display: flex;
        justify-content: flex-end;
    }
}

@media (max-width: 992px) {
    .ranking-layout {
        flex-direction: column;
    }
    
    .ranking-sidebar-menu {
        width: 100%;
        position: static;
    }
    
    .ranking-sidebar-menu .menu-item {
        display: inline-block;
        border-bottom: none;
    }
    
    .ranking-header h1 {
        font-size: 2rem;
    }
}

@media (max-width: 768px) {
    .ranking-grid {
        grid-template-columns: 1fr;
    }
    
    .gender-tab {
        padding: 5px 10px;
        font-size: 0.75rem;
    }
    
    .time-btn {
        padding: 6px 14px;
        font-size: 0.8rem;
    }
    
    .ranking-header h1 {
        font-size: 1.5rem;
    }
    
    .ranking-header {
        padding: 25px 0;
    }
    
    .ranking-item {
        flex-wrap: wrap;
        padding: 12px 15px;
    }
    
    .ranking-item .book-cover {
        width: 50px;
        height: 65px;
        margin-right: 12px;
    }
    
    .ranking-item .book-title {
        font-size: 1rem;
    }
    
    .ranking-item .book-meta {
        gap: 8px;
        font-size: 0.8rem;
    }
    
    .ranking-item .book-actions {
        width: 100%;
        margin-left: 0;
        margin-top: 10px;
        display: flex;
        justify-content: flex-end;
    }
    
    .ranking-item .btn-add,
    .ranking-item .btn-read {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
    
    .detail-header .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
    }
    
    .time-selector-inline {
        margin-top: 10px;
    }
}

/* 手機上只縮小字體，不換行 */
@media (max-width: 768px) {
    .gender-tab {
        padding: 4px 8px;
        font-size: 0.7rem;
    }
    
    .time-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    .ranking-header {
        padding: 25px 0;
    }
}