/* ═══════════════════════════════════════════════════════════════
   KissBooK Bibliotheque — Library Pages (inside the book)
   Comic grid, search, drafts, TOC, filters
   Uses KissBooK Design System tokens
   ═══════════════════════════════════════════════════════════════ */

/* ── Local Variables ── */
:root {
    --kbb-card-bg: rgba(255, 255, 255, 0.05);
    --kbb-card-hover: rgba(255, 255, 255, 0.08);
    --kbb-card-radius: 12px;
    --kbb-lib-transition: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ══════════════════════════════════════════
   COMIC GRID
   ══════════════════════════════════════════ */
.kbb-comic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    padding: 4px 0;
}

.kbb-comic-card {
    background: var(--kbb-card-bg);
    border-radius: var(--kbb-card-radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.25s var(--kbb-lib-transition),
                box-shadow 0.25s var(--kbb-lib-transition);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.kbb-comic-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4),
                0 0 0 1px rgba(56, 189, 248, 0.15),
                0 0 20px rgba(56, 189, 248, 0.08);
}

.kbb-comic-cover {
    aspect-ratio: 2 / 3;
    background-size: cover;
    background-position: center;
    background-color: var(--kb-slate-700, #334155);
    position: relative;
    overflow: hidden;
}

.kbb-comic-cover::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
    pointer-events: none;
}

.kbb-comic-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    backdrop-filter: blur(4px);
    z-index: 2;
}

.kbb-comic-info {
    padding: 10px;
}

.kbb-comic-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--kb-white, #ffffff);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 4px;
}

.kbb-comic-meta {
    font-size: 0.7rem;
    color: var(--kb-slate-400, #94a3b8);
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: center;
}

.kbb-comic-stats {
    font-size: 0.7rem;
    color: var(--kb-slate-400, #94a3b8);
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.kbb-comic-stats span {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.kbb-comic-author {
    font-size: 0.7rem;
    color: var(--kb-slate-500, #64748b);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ══════════════════════════════════════════
   SEARCH & FILTERS
   ══════════════════════════════════════════ */
.kbb-search-bar {
    display: flex;
    flex-direction: row;
    background: var(--kb-slate-800, #1e293b);
    border-radius: 8px;
    padding: 8px 12px;
    gap: 8px;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: border-color 0.2s;
}

.kbb-search-bar:focus-within {
    border-color: var(--kb-primary, #38bdf8);
}

.kbb-search-icon {
    font-size: 14px;
    color: var(--kb-slate-500, #64748b);
    flex-shrink: 0;
}

.kbb-search-input {
    background: transparent;
    border: none;
    color: var(--kb-white, #ffffff);
    flex: 1;
    outline: none;
    font-size: max(16px, 13px);
    font-family: inherit;
    min-width: 0;
}

.kbb-search-input::placeholder {
    color: var(--kb-slate-500, #64748b);
}

.kbb-filter-bar {
    display: flex;
    flex-direction: row;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.kbb-filter-select {
    background: var(--kb-slate-700, #334155);
    color: var(--kb-white, #ffffff);
    border: 1px solid var(--kb-slate-600, #475569);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s;
    appearance: auto;
}

.kbb-filter-select:hover,
.kbb-filter-select:focus {
    border-color: var(--kb-primary, #38bdf8);
}

.kbb-filter-select option {
    background: var(--kb-slate-800, #1e293b);
    color: #fff;
}

/* ══════════════════════════════════════════
   SECTION HEADERS
   ══════════════════════════════════════════ */
.kbb-section-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--kb-white, #ffffff);
    padding-left: 12px;
    border-left: 3px solid var(--kb-primary, #38bdf8);
    display: flex;
    align-items: center;
    gap: 8px;
}

.kbb-section-title .kbb-section-icon {
    font-size: 1.1em;
}

.kbb-section-count {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--kb-slate-500, #64748b);
    margin-left: 4px;
}

/* ══════════════════════════════════════════
   ACTION BUTTONS
   ══════════════════════════════════════════ */
.kbb-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1.4;
}

.kbb-btn:active {
    transform: scale(0.97);
}

.kbb-btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.kbb-btn-primary:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.kbb-btn-danger {
    background: var(--kb-danger, #ef4444);
    color: #fff;
}

.kbb-btn-danger:hover {
    opacity: 0.9;
}

.kbb-btn-ghost {
    background: transparent;
    border: 1px solid var(--kb-slate-600, #475569);
    color: var(--kb-slate-300, #cbd5e1);
}

.kbb-btn-ghost:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--kb-slate-500, #64748b);
}

.kbb-btn-sm {
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: 6px;
}

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

/* ══════════════════════════════════════════
   DRAFT CARDS (Atelier)
   ══════════════════════════════════════════ */
.kbb-draft-card {
    display: flex;
    flex-direction: row;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    padding: 10px;
    gap: 12px;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.kbb-draft-card:hover {
    background: rgba(255, 255, 255, 0.06);
}

.kbb-draft-thumb {
    width: 60px;
    height: 84px;
    border-radius: 6px;
    flex-shrink: 0;
    background: var(--kb-slate-700, #334155);
    overflow: hidden;
}

.kbb-draft-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.kbb-draft-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.kbb-draft-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--kb-white, #ffffff);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kbb-draft-meta {
    font-size: 0.75rem;
    color: var(--kb-slate-400, #94a3b8);
}

.kbb-draft-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* ══════════════════════════════════════════
   TABLE OF CONTENTS (Page 1)
   ══════════════════════════════════════════ */
.kbb-toc-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kbb-toc-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    cursor: pointer;
    gap: 12px;
    transition: background 0.2s var(--kbb-lib-transition),
                transform 0.2s var(--kbb-lib-transition);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.kbb-toc-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(4px);
}

.kbb-toc-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
    width: 36px;
    text-align: center;
}

.kbb-toc-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--kb-white, #ffffff);
    flex: 1;
}

.kbb-toc-arrow {
    font-size: 14px;
    color: var(--kb-slate-500, #64748b);
    transition: transform 0.15s;
}

.kbb-toc-item:hover .kbb-toc-arrow {
    transform: translateX(3px);
    color: var(--kb-primary, #38bdf8);
}

/* ══════════════════════════════════════════
   EMPTY STATES
   ══════════════════════════════════════════ */
.kbb-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--kb-slate-500, #64748b);
}

.kbb-empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    display: block;
    opacity: 0.5;
}

.kbb-empty-text {
    font-size: 0.9rem;
    line-height: 1.5;
    max-width: 300px;
    margin: 0 auto;
}

.kbb-empty .kbb-btn {
    margin-top: 16px;
}

/* ══════════════════════════════════════════
   LOADING STATE
   ══════════════════════════════════════════ */
.kbb-loading {
    text-align: center;
    padding: 30px;
    color: var(--kb-slate-500, #64748b);
}

.kbb-loading-spinner {
    width: 28px;
    height: 28px;
    margin: 0 auto 10px;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-top-color: var(--kb-primary, #38bdf8);
    border-radius: 50%;
    animation: kbbLibSpin 0.8s linear infinite;
}

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

/* ══════════════════════════════════════════
   LOAD MORE BUTTON
   ══════════════════════════════════════════ */
.kbb-load-more-wrap {
    text-align: center;
    padding: 16px 0;
}

.kbb-load-more {
    padding: 10px 28px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--kb-slate-300, #cbd5e1);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.kbb-load-more:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--kb-primary, #38bdf8);
    color: #fff;
}

/* ══════════════════════════════════════════
   LIKE BUTTON
   ══════════════════════════════════════════ */
.kbb-like-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 2px;
    transition: transform 0.2s;
    color: var(--kb-slate-500, #64748b);
}

.kbb-like-btn:hover {
    transform: scale(1.2);
}

.kbb-like-btn.liked {
    color: var(--kb-danger, #ef4444);
    animation: kbbLikePop 0.3s ease;
}

@keyframes kbbLikePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */
@media (max-width: 768px) {
    .kbb-comic-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .kbb-comic-card:hover {
        transform: translateY(-2px);
    }

    .kbb-section-title {
        font-size: 1rem;
    }

    .kbb-draft-card {
        padding: 8px;
        gap: 8px;
    }

    .kbb-draft-thumb {
        width: 48px;
        height: 67px;
    }

    .kbb-toc-item {
        padding: 10px 12px;
        gap: 10px;
    }

    .kbb-toc-icon {
        font-size: 1.2rem;
    }

    .kbb-filter-bar {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .kbb-comic-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .kbb-comic-card {
        display: flex;
        flex-direction: row;
    }

    .kbb-comic-cover {
        width: 80px;
        aspect-ratio: auto;
        height: 112px;
        flex-shrink: 0;
        border-radius: var(--kbb-card-radius) 0 0 var(--kbb-card-radius);
    }

    .kbb-comic-info {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}
