/* ══════════════════════════════════════════════════════════════
   EPUB Reader — Global Styles (Home, Book Details, Stats)
   Uses CSS custom properties for dark/light theming.
   Google Font: Inter | Icons: Material Icons Round
   ══════════════════════════════════════════════════════════════ */

@import url('/static/css/theme.css');
@import url('/static/css/components.css');

/* ── Reset & Base ──────────────────────────────────────────── */

html {
    scroll-behavior: smooth;
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Header ────────────────────────────────────────────────── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.header-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 8px;
    flex-shrink: 0;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* (Icon Button defined in components.css) */

/* ── Container ─────────────────────────────────────────────── */
.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

/* ── Library Hero ──────────────────────────────────────────── */
.library-hero {
    padding: 32px 0 24px;
    text-align: center;
}

.library-hero h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ── NF Book Grid (NovelFire style) ────────────────────────── */
.nf-book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}

.nf-book-card {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 2 / 3;
    display: block;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
    background: #111;
}

.nf-book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.5);
}

.nf-book-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

.nf-book-gradient {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60%;
    background: linear-gradient(to top, rgba(15,15,15,1) 0%, rgba(15,15,15,0.8) 40%, transparent 100%);
    z-index: 2;
}

.nf-book-content {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 12px;
    box-sizing: border-box;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nf-book-status-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nf-book-rank {
    background: #c27821; /* Gold/Orange for rank */
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
}

.nf-book-status {
    background: rgba(14, 38, 64, 0.9);
    border: 1px solid #1e40af;
    color: #93c5fd;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 4px;
    border-radius: 4px;
    text-transform: uppercase;
    line-height: 1.2;
}

.nf-book-title {
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    white-space: normal;
}

.nf-book-tags {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    white-space: nowrap;
    align-items: center;
    scrollbar-width: none;
}
.nf-book-tags::-webkit-scrollbar {
    display: none;
}

.nf-book-tags .material-icons-round {
    font-size: 10px;
    color: #9ca3af;
}

.nf-book-tag {
    background: rgba(255, 255, 255, 0.2);
    color: #d1d5db;
    font-size: 9px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

@media (max-width: 600px) {
    .nf-book-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 12px;
    }
}

/* ── Legacy Book List (kept for reference) ─────────────────── */
.book-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.book-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

.book-card:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateX(4px);
}

.book-card-icon {
    flex-shrink: 0;
    width: 48px;
    height: 64px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
    font-size: 24px;
    overflow: hidden;
    position: relative;
}

.book-card-icon img.book-cover-img,
.book-detail-icon img.book-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.book-card-info {
    flex: 1;
    min-width: 0;
}

.book-card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    color: var(--text-secondary);
    font-size: 13px;
}

.meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.meta-item .material-icons-round {
    font-size: 16px;
}

.book-card-arrow {
    color: var(--text-secondary);
    font-size: 22px;
    flex-shrink: 0;
    transition: color var(--transition);
}

.book-card:hover .book-card-arrow {
    color: var(--accent);
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 80px 20px;
}

.empty-icon {
    font-size: 64px;
    color: var(--border);
    margin-bottom: 16px;
    display: block;
}

.empty-state h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ── Upload Zone ───────────────────────────────────────────── */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 30px 20px;
    margin: 20px auto;
    max-width: 500px;
    cursor: pointer;
    background: var(--surface);
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: var(--surface-hover);
    color: var(--accent);
}

.upload-zone .material-icons-round {
    font-size: 40px;
}

.upload-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 20px auto;
    color: var(--text-secondary);
}

.spinning {
    animation: spin 1s linear infinite;
    font-size: 32px;
    color: var(--accent);
}

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

/* ── Book Detail Card ──────────────────────────────────────── */
.book-detail-card {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 32px;
}

.book-detail-icon {
    flex-shrink: 0;
    width: 80px;
    height: 110px;
    border-radius: var(--radius-sm);
    background: linear-gradient(150deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-white);
    overflow: hidden;
    position: relative;
}

.book-detail-icon .material-icons-round {
    font-size: 36px;
}

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

.book-detail-info h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.3;
}

.book-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

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

/* (Primary & Outline Buttons defined in components.css) */

/* ── Section Header ────────────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-header .material-icons-round {
    font-size: 20px;
    color: var(--accent);
}

.section-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Chapter List ──────────────────────────────────────────── */
.chapter-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.chapter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    transition: background var(--transition), padding-left var(--transition);
}

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

.chapter-item:hover {
    background: var(--surface-hover);
    padding-left: 22px;
}

.chapter-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chapter-number {
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
    min-width: 28px;
    flex-shrink: 0;
}

.chapter-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-arrow {
    color: var(--text-secondary);
    font-size: 20px;
    flex-shrink: 0;
}

/* ── Stats Page ────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    transition: border-color var(--transition);
}

.stat-card:hover {
    border-color: var(--accent);
}

.stat-icon {
    font-size: 32px;
    color: var(--accent);
    margin-bottom: 8px;
    display: block;
}

.stat-value {
    font-size: 42px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
    line-height: 1.1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Stats Table ───────────────────────────────────────────── */
.books-table-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.books-table {
    width: 100%;
    border-collapse: collapse;
}

.books-table th {
    background: var(--bg);
    padding: 14px 18px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.books-table td {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.books-table tr:last-child td {
    border-bottom: none;
}

.books-table tr:hover td {
    background: var(--surface-hover);
}

.table-book-title {
    font-weight: 600;
    margin-bottom: 2px;
}

.table-book-author {
    color: var(--text-secondary);
    font-size: 13px;
}

.chapter-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 26px;
    padding: 0 8px;
    border-radius: 13px;
    background: rgba(108, 138, 255, 0.15);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 640px) {
    .container {
        padding: 16px 14px 40px;
    }

    .library-hero h1 {
        font-size: 22px;
    }

    .book-detail-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 24px 18px;
    }

    .book-detail-meta {
        justify-content: center;
    }

    .book-detail-actions {
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .books-table th:nth-child(3),
    .books-table td:nth-child(3) {
        display: none;
    }

    .book-card {
        padding: 14px 16px;
        gap: 12px;
    }

    .book-card-icon {
        width: 42px;
        height: 42px;
    }
}
