/* library.css
 *
 * The Library shelf — every book that exists, and how to get it.
 *
 * Roomier than the Storage panel on purpose. Storage is a management list you
 * scan and prune; the Library is a shelf you browse and choose from, so a book
 * gets a cover worth looking at and its size stated plainly before the reader
 * commits to a download.
 *
 * Row vocabulary is the approved cat-test design:
 *   cover · title/series · meta ·  ★ favourite · ℹ️ info · 📲 install · [ state ]
 *
 * Inherits the viewer's palette. No :has(), no container queries — old phones.
 */

/* ── Collection top bar — category tree (left) + search (right) ──────
   Only Story Books exists yet; the other collections are greyed evidence
   of how the wider photodharma.net site will be organised here. The bar
   takes over the sticky duty from .search-bar (which it wraps). */
/* The Library body gives up its top padding — the sticky bar owns that space,
   so no row can ever peek above it. */
#popupLibrary .popup__body { padding-top: 0; }

.lib-topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 10px;
    /* Full-bleed across the body's side padding, with its own background and
       bottom hairline — an anchored header band, never a floating strip. */
    margin: 0 -22px 12px;
    padding: 14px 22px 12px;
    background: var(--bg) url('../images/noise.png');
    border-bottom: 1px solid var(--border);
}
.lib-topbar .search-bar {
    position: static;          /* the wrapper is sticky now */
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    background: none;
}

.lib-cat { position: relative; flex: 0 0 auto; }
.lib-cat__btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 12px;
    border: 1px solid var(--border-mid);
    border-radius: 7px;
    background: var(--bg-thumb);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
    cursor: pointer;
    white-space: nowrap;
}
.lib-cat__btn:hover { border-color: var(--accent); color: var(--accent); }
.lib-cat__caret { font-size: 10px; color: var(--text-dim); }

.lib-cat__menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 195px;
    max-height: min(62vh, 430px);   /* a long tree (countries open) scrolls */
    overflow-y: auto;
    padding: 6px;
    background: var(--bg-panel);
    border: 1px solid var(--border-mid);
    border-radius: 9px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
    z-index: 5;
}
.lib-cat__menu.hidden { display: none; }
.lib-cat__item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: none;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}
.lib-cat__item:hover:not(:disabled) { background: var(--accent-dim); color: var(--accent); }
.lib-cat__item.is-active { color: var(--accent); font-weight: 600; }
.lib-cat__item:disabled { color: var(--text-muted); cursor: default; }

/* "— soon" rides only the TOP-LEVEL grey entries and the expandable parent —
   repeating it on every country would be noise; the parent has said it once. */
.lib-cat__menu > .lib-cat__item:disabled::after,
.lib-cat__item.is-soon::after { content: ' — soon'; font-size: 11px; font-style: italic; }

/* An expandable branch: looks as grey as its siblings, but unfolds. */
.lib-cat__item.is-soon { color: var(--text-muted); }
.lib-cat__item.lib-cat__parent:hover { background: var(--bg-thumb); }
.lib-cat__twirl {
    display: inline-block;
    width: 14px;
    font-size: 10px;
    color: var(--text-dim);
}
.lib-cat__sub {
    margin: 2px 0 4px 13px;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}
.lib-cat__sub.hidden { display: none; }
.lib-cat__sub .lib-cat__item { padding: 5px 8px; font-size: 12px; }
.lib-cat__note {
    display: block;
    font-size: 10px;
    font-style: italic;
    color: var(--text-muted);
    opacity: 0.85;
    line-height: 1.35;
}

/* ── The shelf ──────────────────────────────────────────────────── */
.lib-books {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.lib-series {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 18px 2px 8px;
}
.lib-series:first-child { padding-top: 4px; }

/* ── A book row ─────────────────────────────────────────────────── */
.lib-book {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s;
}
.lib-book:hover {
    background: var(--accent-dim, rgba(200, 169, 110, .12));
    border-color: var(--border-mid);
}

/* Catalogued, but not yet converted — listed so the shelf tells the truth
   about what the collection IS, dimmed so it is plainly not on offer. */
.lib-book.lib-state-unready { opacity: 0.45; }
.lib-book.lib-state-unready:hover { background: transparent; border-color: transparent; }
.lib-book.lib-state-unready .lib-cover { filter: grayscale(1); }

/* Cover — real posters are 16:9, so a landscape frame. */
.lib-cover {
    flex: 0 0 auto;
    width: 72px;
    height: 41px;
    object-fit: cover;
    border-radius: 5px;
    border: 1px solid var(--border-mid);
    background: linear-gradient(150deg, var(--bg-thumb), #000);
}
/* bhikkhu-sumedha's cover is the one portrait photo among 32 landscape
   posters — center-cropping it into this 16:9 frame cut the head off
   entirely. Bias the crop to the top instead, wherever this cover renders
   (also .book-facts__cover in viewer.css and .sm-cover in storage-manager.css). */
img[src*="bhikkhu-sumedha/cover.jpg"] { object-position: center top; }

.lib-cover--none {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--accent);
}

.lib-meta {
    /* basis 0, not auto. flex-wrap on .lib-book wraps an item whose BASIS
       doesn't fit before it will shrink it, and an auto basis here is the
       title's full un-truncated width — so under 900px the text column
       dropped onto its own line and left the cover stranded above it.
       min-width:0 alone can't prevent that; a zero basis can. */
    flex: 1 1 0;
    min-width: 0;                  /* lets the title truncate instead of pushing */
}
.lib-title {
    flex: 1 1 auto;
    min-width: 0;                  /* lets the title truncate inside .lib-title-row */
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lib-subtitle {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lib-style {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 1px;
}
.lib-info {
    font-size: 11.5px;
    color: var(--text-dim);
    margin-top: 3px;
}
.lib-info .lib-on { color: var(--ok); }
.lib-online-link { color: var(--accent); text-decoration: none; }
.lib-online-link:hover { text-decoration: underline; }

/* The alternate-quality choice (e.g. "Data saver 13 MB") used to be joined
   into .lib-info's plain "158 posters · 198 MB" text with a · separator —
   it read as just another stat, not the clickable alternate download choice
   it actually is. A real small pill/badge on its own line reads as
   actionable instead of informational. */
/* Unused since the alternate size became a real .lib-state button. */
.lib-quality-pill {
    display: inline-block;
    margin-top: 5px;
    padding: 2px 9px;
    border: 1px solid var(--accent);
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}
.lib-quality-pill:hover { background: var(--accent-dim, rgba(200, 169, 110, 0.18)); }

/* ── Action strip ───────────────────────────────────────────────── */
.lib-actions {
    /* NEVER shrink. With flex-shrink:1 the browser splits the overflow between
       this strip and .lib-meta in proportion to their content widths, so a row
       with a long title gave its strip less room than a row with a short one —
       every row negotiated its own button positions and the columns went
       ragged. No width is set and none should be: every slot in the strip is
       already a fixed size (32px icon or 128px button) and an absent one is
       emitted as a same-size placeholder, so content width is identical on
       every row. A hardcoded width would just duplicate that sum and go stale
       the moment a button size changes. .lib-meta (min-width:0) takes the
       slack. */
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

/* Square icon chips: ★ favourite · ℹ️ info · 📲 install */
.lib-icon {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-family: inherit;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid var(--border-mid);
    border-radius: 8px;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}
.lib-icon:hover { color: var(--accent); border-color: var(--accent); }
.lib-icon-star.is-on {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim, rgba(200, 169, 110, .16));
}

/* 🍂 recommended — a marker, not a button (system / Bhante set), so it reads as
   gold and does not invite a tap. */
.lib-recommend {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent-dim, rgba(200, 169, 110, .16));
    cursor: default;
}
/* Same 32px slot when a row has no leaf, so ℹ️ and the action button after it
   still land in the same column as rows that do — invisible, not absent. */
.lib-recommend--hidden {
    visibility: hidden;
    border-color: transparent;
    background: transparent;
}

/* Same 32px slot when a row has no star (unready) or no info button —
   same reasoning as .lib-recommend--hidden above. */
.lib-icon--hidden { visibility: hidden; border-color: transparent; }

/* ── Chapters — expanding a multi-chapter book into starrable sub-entries ──
   Same 32px square chip as the ★/🍂/ℹ️ icons in the action strip — same row,
   same visual language, not a smaller/differently-shaped button of its own. */
.lib-chapters-toggle {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-mid);
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s, transform .15s;
}
.lib-chapters-toggle:hover { color: var(--accent); border-color: var(--accent); }
/* Collapsed points right — the standard disclosure-triangle cue (macOS
   Finder, VS Code's sidebar) — and rotates to point down once open, since
   that is the direction the chapter list actually appears in. */
.lib-chapters-toggle[aria-expanded="true"] { transform: rotate(90deg); }

.lib-chapters {
    margin: 2px 0 8px 56px;   /* aligns under the title, past the cover column */
    border-left: 1px solid var(--border-mid);
    padding-left: 10px;
}
/* Same grouping heading as Contents (.toc-group), at this list's scale. */
.lib-chapters__group {
    margin: 10px 0 2px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim);
}
.lib-chapters__group:first-child { margin-top: 2px; }

.lib-chapters__note {
    padding: 6px 0;
    color: var(--text-dim);
    font-size: 12px;
}
.lib-chapter {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    border-radius: 6px;
    cursor: pointer;
}
.lib-chapter:hover { background: var(--bg-thumb); }
.lib-chapter__star {
    width: 26px;
    height: 26px;
    font-size: 13px;
}
.lib-chapter__label { min-width: 0; }
.lib-chapter__title {
    font-size: 13px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lib-chapter__pages {
    font-size: 11px;
    color: var(--text-dim);
}

/* The two pinned float sections read in the accent, a step above a plain series. */
.lib-series--fav,
.lib-series--rec { color: var(--accent); }

/* A quiet credit to the wider collection, at the foot of the shelf. */
.lib-credit {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 11.5px;
    color: var(--text-dim);
}

/* The state / action chip — one button whose look changes with state. Fixed
   width (not just min-width) so every row's Read button is the same box as
   every other row's, and same for Download — text length must never change
   where the NEXT slot starts, or "same button same place" breaks the moment
   one row's label is longer than another's. */
.lib-state {
    width: 128px;
    max-width: 100%;
    text-align: center;
    padding: 7px 10px;
    font-size: 12.5px;
    font-weight: 500;
    font-family: inherit;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid var(--border-mid);
    border-radius: 8px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}
/* Download says "⬇ Download"/"⬇ Data saver" at rest, same as every other
   action-strip label — short and constant, same behaviour at every screen
   width. Hovering (or keyboard-focusing) swaps in the size instead, rather
   than showing both at once or cutting it at a screen-width breakpoint. */
.lib-state__detail { display: none; }
.lib-state--get:hover .lib-state__label,
.lib-state--get:focus-visible .lib-state__label { display: none; }
.lib-state--get:hover .lib-state__detail,
.lib-state--get:focus-visible .lib-state__detail { display: inline; }
.lib-state--get {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim, rgba(200, 169, 110, .14));
}
.lib-state--get:hover { color: #1a1109; background: var(--accent); }

/* Brief landing highlight for the Save panel's "go to this book in the
   Catalogue" link (libraryUI.focusBook) — fades on its own after 1.6s (see
   the setTimeout there), same pattern as the Manager's .sm-book--focused. */
.lib-book--focused { background: var(--accent-dim, rgba(200, 169, 110, .22)); }
.lib-state--focused {
    box-shadow: 0 0 0 2px var(--accent);
    background: var(--accent);
    color: #1a1109;
}
.lib-state--read { color: var(--text); }
.lib-state--read:hover { color: var(--accent); border-color: var(--accent); }
.lib-state--saved {
    color: var(--ok);
    border-color: transparent;
    background: var(--ok-dim);
    cursor: default;
}
/* Confirmatory, not interactive — same "on device" green as Read Now, but
   disabled so it never reads as a second tappable action. */
.lib-state--downloaded {
    color: var(--ok);
    border-color: transparent;
    background: var(--ok-dim);
    cursor: default;
    opacity: 1;
}
.lib-state--cache { color: var(--text-dim); }
.lib-state--cache:hover { color: var(--accent); border-color: var(--accent); }
.lib-state--soon {
    color: var(--text-dim);
    border-style: dashed;
    cursor: default;
    font-style: italic;
}
/* Same 148px slot when a row has no read or no download action — keeps
   .lib-actions the same total width in every state, so it lines up the same
   way against the row's right edge regardless of how many real buttons it holds. */
.lib-state--hidden {
    visibility: hidden;
    border-color: transparent;
    background: transparent;
    cursor: default;
}

/* Cancel, under the download bar */
.lib-btn-cancel {
    padding: 7px 12px;
    font-size: 12px;
    font-family: inherit;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid var(--border-mid);
    border-radius: 8px;
    cursor: pointer;
}
.lib-btn-cancel:hover { color: var(--accent); border-color: var(--accent); }

/* ── Download progress — one bar for the whole book ─────────────── */
.lib-progress { width: 150px; max-width: 100%; }
/* Same bar inside the download popup, which sets its own width. */
.lib-progress--popup { width: 100%; }
.lib-progress-track {
    height: 5px;
    border-radius: 3px;
    background: var(--bg-input, rgba(128, 128, 128, .18));
    overflow: hidden;
}
.lib-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width .3s ease;    /* eased so a burst of images doesn't jerk it */
}
.lib-progress-label {
    margin-top: 5px;
    font-size: 11px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
}

/* ── Install nudge / offline notice ─────────────────────────────── */
.lib-nudge,
.lib-offline {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    margin-bottom: 14px;
    border-radius: 10px;
    border: 1px solid var(--accent);
    background: var(--accent-dim, rgba(200, 169, 110, .12));
}
.lib-nudge-text,
.lib-offline {
    flex: 1 1 auto;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-dim);
}
.lib-btn-install {
    flex: 0 0 auto;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: var(--bg);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.lib-empty {
    padding: 20px 2px;
    font-size: 13px;
    color: var(--text-dim);
}

/* ── Medium screens ──────────────────────────────────────────────
   Before the row needs to wrap at all, tighten the fixed button width —
   labels are already short and constant at every width, so this is just
   compactness, not a content change. */
@media (max-width: 51.25em) {
    .lib-state { width: 104px; padding: 7px 6px; }
}

/* A row offering BOTH download sizes carries five controls plus four icons.
   That never fits beside the text — the panel is capped near 792px and the
   strip alone wants 682px — so this row is two-line at every width, for the
   same reason and in the same shape as the narrow-screen rule below. */
.lib-book--two-sizes { flex-wrap: wrap; }
.lib-book--two-sizes .lib-actions {
    width: 100%;
    padding-left: 84px;            /* line up under the title, past the cover */
    justify-content: flex-start;
    margin-top: 2px;
}

/* ── Narrow screens ─────────────────────────────────────────────
   Below 560px the row cannot hold cover + text + buttons side by side, so the
   action strip drops under the text rather than squeezing the title to nothing. */
@media (max-width: 56.25em) {
    /* Was 560px. Between 560 and ~900 the row still held cover + text + strip
       on one line with nothing left to give: the buttons are fixed-width and
       .lib-meta is min-width:0, so the title absorbed the whole shortfall.
       Measured in Firefox at a 584px row — strip 476px, title 0px. Wide
       screens are untouched; this only moves where the existing collapse
       starts. */
    .lib-book { flex-wrap: wrap; }
    .lib-actions {
        width: 100%;
        padding-left: 84px;        /* line up under the title, past the cover */
        justify-content: flex-start;
    }
    .lib-progress { flex: 1 1 auto; width: auto; }
    /* Safe to actually collapse an empty read/download slot here (not just
       hide it) — .lib-actions is pinned to a fixed left edge via padding at
       this width, not flush against the row's right edge like on a wide
       screen, so a row with only one button doesn't drag anything else out
       of position by using less space. */
    .lib-state--hidden { display: none; }
}

@media (pointer: coarse) {
    .lib-state { padding: 9px 12px; font-size: 13px; }
    .lib-icon { width: 34px; height: 34px; }
}
