/* ==================== Generation Library ==================== */

.library-layout {
    position: fixed;
    /* Sits to the right of the persistent sidebar. Tied to
     * var(--sidebar-width) so any nav-width change propagates here
     * automatically (was hardcoded 56px which overlapped the
     * 64px-then-80px sidebar). */
    inset: 0 0 0 var(--sidebar-width, 80px);
    transition: left 0.16s ease;
    display: flex;
    flex-direction: column;
    /* Center every child column reliably. The header/toolbar rows are flex
     * items, so the default align-items:stretch (combined with their max-width)
     * was leaving their margin:auto centering inconsistent vs the grid's block
     * children — making the toolbar sit left while the grid sat centered. */
    align-items: center;
    background: var(--bg-secondary, #f7f7fa);
    z-index: 100;
    /* The WHOLE panel scrolls (header included) — the header must NOT stay
       pinned. Previously only the grid scrolled (overflow:hidden here + the grid
       was the scroller), which kept the header fixed at the top. */
    overflow-x: hidden;
    overflow-y: auto;
    /* Reserve the scrollbar gutter symmetrically so the centered column stays
       truly centered (Windows classic ~17px scrollbar otherwise nudges it left). */
    scrollbar-gutter: stable both-edges;
}

/* Center every fixed row (header · type tabs · toolbar · recent bar) into the
   SAME content column as the grid, so the whole page reads centered like the
   other pages instead of stretching edge-to-edge on wide monitors. */
.library-header,
.library-toprow,
.library-toolbar,
.library-recent-bar {
    max-width: 1320px;   /* matches the Media Library design's centered content column */
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    box-sizing: border-box;
}
/* Wrapper that left-aligns the (compact) type-tabs pill within the column. */
.library-toprow { padding: 12px 28px 0; }
/* Right cluster — result count + Select pinned to the far right (Select last). */
.library-toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.library-toolbar-right .library-sub { margin-left: 0; }

.library-header {
    padding: 20px 28px 16px;
    background: #fff;
    border-bottom: 1px solid var(--border-subtle, #e6e6ec);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}
.library-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary, #1a1a2e);
}
/* Primary actions — right side of the title row. Mirrors .vlib-header-controls
   so the Image + Video libraries share identical button positions. */
.library-header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
/* Toolbar strip below the header. Mirrors .vlib-toolbar exactly (padding,
   border, gap) for cross-page continuity. */
.library-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 28px;
    background: #fff;
    margin: 0;
}
/* Count — pinned to the far right of the toolbar (mirrors .vlib-meta). */
.library-sub {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted, #9ca3af);
    white-space: nowrap;
}

/* "Showing winners only" memento — full-width banner sitting between
   the title row and the grid. Soft amber tint + star icon ties it
   visually to the ★ Pick action in Studio that controls what lands
   here. The flex-basis:100% breaks it onto its own row inside the
   flex-wrap header. */
.library-memento {
    flex-basis: 100%;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #fffbeb 0%, #fff 100%);
    border: 1px solid #fde68a;
    border-radius: 10px;
    font-size: 12.5px;
    color: #78350f;
    line-height: 1.45;
}
.library-memento strong {
    color: #92400e;
    font-weight: 700;
}
.library-memento-icon {
    flex-shrink: 0;
    color: #f59e0b;
    fill: #fcd34d;
    margin-top: 1px;
}

.library-filters {
    margin-left: auto;
    display: flex;
    gap: 8px;
    align-items: center;
}
.library-search {
    border: 1px solid var(--border-subtle, #e6e6ec);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    flex: 1 1 200px;    /* grows into spare room; a 240 basis wrapped the toolbar at 1320 */
    min-width: 160px;
    max-width: 360px;
    outline: none;
    font-family: inherit;
}
.library-search:focus {
    border-color: #5B53E8;
    box-shadow: var(--focus-ring);
}
.library-model-filter {
    border: 1px solid var(--border-subtle, #e6e6ec);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    background: #fff;
    outline: none;
    font-family: inherit;
    min-width: 150px;   /* 180 pushed the toolbar one control past 1320px — "Select" wrapped alone */
}

/* ---- Grid (masonry) ----
   .library-grid is the SCROLL container (fixed height via flex:1). The columns
   live on an INNER .library-masonry whose height is content-driven — a multicol
   container with a fixed height would flow horizontally (newspaper style) and
   create horizontal scroll, so the columns must sit on an auto-height child. */
.library-grid {
    /* NOT its own scroller anymore — the whole .library-layout scrolls so the
       header scrolls away with it. Just a full-width content block (its children
       still center at max-width:1320). */
    width: 100%;
    padding: 16px 0 64px;
}
/* Center the scrolling content into one column + pad it (matches other pages)
   instead of stretching edge-to-edge. Each row (date header, masonry, sentinel)
   is capped to the shared max-width and centered. */
.library-grid > * {
    max-width: 1320px;   /* matches the centered header/toolbar column above */
    margin-left: auto;
    margin-right: auto;
    padding-left: 28px;
    padding-right: 28px;
    box-sizing: border-box;
}
.library-masonry {
    /* CSS grid with 1fr columns that FILL the centered content column (matches
       the Media Library design's repeat(auto-fill, minmax(…,1fr))). Filling the
       row edge-to-edge is what keeps it visually centered: the tiles line up
       with the full-width date header above them and the whole column is centered
       on the page via the .library-grid > * max-width + auto margins. (The old
       fixed-width + justify-content:center floated the tiles mid-column, leaving
       the off-center gap the user saw.) 210px min → 5 per row on the 1320px-max
       column (was 178px = 6); the cap keeps it from ever reaching 6, and it
       reflows to fewer columns on narrow viewports automatically. */
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr));
    gap: 14px;
    align-items: start;
}
/* In grid mode spacing comes from `gap`; drop the multicol-era bottom margin. */
.library-masonry > .library-tile { margin-bottom: 0; }
.library-empty {
    column-span: all;
    text-align: center;
    color: var(--text-muted, #888);
    padding: 80px 20px;
    font-size: 14px;
    line-height: 1.6;
}

/* Loading animation shown while media is fetched (initial scan + cold-project Drive background scan). */
.library-loading {
    column-span: all;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; padding: 70px 20px; color: var(--text-muted, #888);
}
.library-loading-spin {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid var(--border-color, #e5e7eb); border-top-color: var(--accent, #5B53E8);
    animation: library-spin 0.8s linear infinite;
}
.library-loading-text { font-size: 13px; font-weight: 500; }
@keyframes library-spin { to { transform: rotate(360deg); } }

/* Card (Media Library design): white, rounded, hairline border, lifts on hover.
   Square thumbnail on top + an info row underneath. */
.library-tile {
    position: relative;        /* anchors the select-mode ::before overlay */
    background: #fff;
    border: 1px solid #E9EAEE;
    border-radius: 13px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    transition: border-color 0.12s, box-shadow 0.12s;
    display: flex;
    flex-direction: column;
}
.library-tile:hover { border-color: #D9D5F7; box-shadow: 0 4px 14px rgba(91, 83, 232, 0.08); }

/* Square thumbnail — media fills it (object-fit:cover) so every format crops to
   a uniform tile; the full, uncropped media is shown in the modal on click. */
.library-tile-thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--bg-tertiary, #f0f1f5);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.library-tile-thumb > img,
.library-tile-thumb > video {
    width: 100%; height: 100%; object-fit: cover; display: block;
}
/* Media couldn't load (expired Drive link / permission) → labelled placeholder. */
.library-tile-thumb.is-media-failed > img,
.library-tile-thumb.is-media-failed > video { display: none; }
.library-tile-thumb.is-media-failed::after {
    content: 'Preview unavailable';
    font-size: 11px; color: var(--text-muted, #9ca3af);
}

/* Info row UNDER the thumbnail: title (2-line) + source badge · dims · date. */
.library-tile-info { padding: 10px 11px 11px; }
.library-tile-title {
    font-size: 12.5px; font-weight: 600; line-height: 1.35; color: #2A3343;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; min-height: 34px;
}
.library-tile-metarow { margin-top: 7px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.library-tile-src { font-size: 9.5px; font-weight: 700; padding: 2px 6px; border-radius: 5px; line-height: 1.4; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }   /* "Drive · <source name>" — long names ellipsised, full on hover */
.library-tile-src.is-gdrive { color: #1A73E8; background: #E8F0FE; }
.library-tile-src.is-csv { color: #5B6473; background: #F1F2F4; }
.library-tile-src.is-ai { color: #5B53E8; background: #EEEDFC; }
.library-tile-src.is-product { color: #0F8A5F; background: #E4F6EE; }
.library-tile-src.is-upload { color: #0E7490; background: #E0F4F8; }
/* "N ads" badge — videos that already have Meta ads created from them (mirrors the Video
 * Library pill). Filled Meta-blue so it reads as an active state, distinct from the Drive
 * source pill's light-blue tint. */
.library-tile-ads { font-size: 9.5px; font-weight: 700; padding: 2px 6px; border-radius: 5px; line-height: 1.4; color: #fff; background: #1877F2; }
/* "Published → {ad}" link — a Meta ad was created FROM this generation in the
 * Studio/Library. Clickable (opens the ad in Ads Manager); the green dot reads as
 * a "live/published" signal, distinguishing it from the flat "N ads" pill above. */
.library-tile-adlink { display: inline-flex; align-items: center; gap: 4px; max-width: 170px; font-size: 9.5px; font-weight: 700; padding: 2px 7px; border-radius: 5px; line-height: 1.4; color: #fff; background: #1877F2; text-decoration: none; cursor: pointer; }
.library-tile-adlink:hover { background: #0e5fc0; }
.library-tile-adlink-dot { width: 5px; height: 5px; border-radius: 50%; background: #7CFC9B; box-shadow: 0 0 0 2px rgba(255,255,255,.25); flex: 0 0 auto; }
.library-tile-adlink-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Live Meta performance chip ($ spent · ROAS / results) rolled up from the ads
 * this creative was published as. Green = profitable (ROAS ≥ 1×), amber = below
 * breakeven; neutral for spend/clicks/sales-count with no ROAS. */
.library-tile-perf { font-size: 9.5px; font-weight: 700; padding: 2px 6px; border-radius: 5px; line-height: 1.4; color: #334155; background: #EEF1F6; white-space: nowrap; }
.library-tile-perf.is-good { color: #0B7A53; background: #E5F6EE; }
.library-tile-perf.is-bad  { color: #B45309; background: #FEF3E2; }
/* "Link" badge — this item's Drive description carries a destination URL (hover shows it,
 * click opens it). Pairs with the toolbar "Has link" filter. Green so it reads as a
 * destination/commerce signal, distinct from the source + ads pills. */
.library-tile-link { display: inline-flex; align-items: center; gap: 3px; font-size: 9.5px; font-weight: 700; padding: 2px 6px; border-radius: 5px; line-height: 1.4; color: #0B7A53; background: #E5F6EE; cursor: pointer; }
.library-tile-link:hover { background: #D2F0E2; }
/* "Has link" toolbar toggle — default OFF; indigo when active (mirrors the Select toggle). */
.library-toolbar .library-link-toggle { display: inline-flex; align-items: center; gap: 6px; }
.library-toolbar .library-link-toggle.is-on { background: #5B53E8; border-color: #5B53E8; color: #fff; }
.library-toolbar .library-link-toggle.is-on:hover { background: #4f46e5; }

/* Ad filter — compact segmented pill (All / With ads / No ads). Matches the toolbar
   button height; segments share one bordered container, active segment = indigo. */
.library-toolbar .library-adseg { display: inline-flex; align-items: stretch; border: 1px solid var(--border, #e0e0e6); border-radius: 8px; overflow: hidden; background: #fff; }
.library-toolbar .library-adseg__btn { border: 0; background: transparent; color: var(--text-secondary, #6b7280); font-size: 12px; font-weight: 500; padding: 8px 10px; cursor: pointer; white-space: nowrap; line-height: 1; }
.library-toolbar .library-adseg__btn + .library-adseg__btn { border-left: 1px solid var(--border, #e0e0e6); }
.library-toolbar .library-adseg__btn:hover { background: var(--bg-hover, #f3f4f6); color: var(--text-primary, #1a1a1a); }
.library-toolbar .library-adseg__btn.is-on { background: #5B53E8; color: #fff; }
.library-toolbar .library-adseg__btn.is-on:hover { background: #4f46e5; }

/* Size-count badge — top-right pill on the thumbnail (only when not selecting
 * and the group holds more than one size/variant). */
.library-tile-sizes {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.72);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    z-index: 2;
}
.library-tile-sizes svg { width: 12px; height: 12px; }

/* Modal "Create Meta Ad" button — branded Facebook blue so the action
 * is recognisable next to the neutral grey "Save to assets" /
 * "Edit in Canvas" / etc. Sits at the TOP of the modal action stack
 * because pushing a creative to a paid platform is the most
 * consequential thing in this list. */
.library-modal-meta-btn {
    background: #1877f2 !important;
    border-color: #1877f2 !important;
    color: #fff !important;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
}
.library-modal-meta-btn:hover {
    background: #166fe5 !important;
    border-color: #166fe5 !important;
    color: #fff !important;
}
.library-modal-meta-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
/* Dimensions + date in the card's info row (was the old hover-overlay text). */
.library-tile-dims {
    font-size: 10px;
    color: #6B7280;
    font-variant-numeric: tabular-nums;
}
.library-tile-date {
    margin-left: auto;
    font-size: 10px;
    color: #646B78;
}
/* Project line (All-projects view only, js/library/library.js _projectLineEl): its OWN row under
   the title so the owning project is readable at a glance — it used to be a 9.5px chip at the end
   of the crowded metarow and wrapped out of sight. One chip per project the item belongs to. */
.library-tile-projline { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.library-tile-projline .cb-proj-tag { font-size: 11px; padding: 2px 8px; max-width: 100%; }
.library-modal-projline { display: flex; flex-wrap: wrap; gap: 6px; margin: -10px 0 18px; }
.library-modal-projline .cb-proj-tag { font-size: 12px; padding: 3px 9px; max-width: 100%; }
.cb-proj-tag-more { background: #f3f4f6; color: #5b6473; cursor: help; }

/* ---- Infinite scroll sentinel + end marker ----
 * Live as full-width grid children so the grid (which IS the scroll container)
 * fires the IntersectionObserver as the user scrolls.
 */
.library-sentinel {
    column-span: all;
    padding: 32px 16px 20px;
    color: var(--text-muted, #888);
    font-size: 12px;
}
.library-sentinel-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-subtle, #e6e6ec);
    border-top-color: #5B53E8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.library-end {
    column-span: all;
    padding: 24px 16px 28px;
    text-align: center;
    color: var(--text-muted, #aaa);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ---- Modal ---- */
.library-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 32px;
}
.library-modal {
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 360px;
    max-width: 1200px;
    max-height: 90vh;
    width: 100%;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
}
.library-modal-media {
    background: #0a0a14;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 360px;
}
.library-modal-media img,
.library-modal-media video {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    display: block;
}
/* Drive /preview player (iframe) — fills the modal stage; Drive's player
   centers + letterboxes the video to its own aspect inside this box. */
.library-modal-iframe {
    width: 100%;
    height: min(80vh, 720px);
    border: 0;
    display: block;
    background: #000;
}
.library-modal-side {
    padding: 24px;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}
.library-modal-title {
    margin: 0 32px 4px 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #1a1a2e);
}
.library-modal-date {
    font-size: 11px;
    color: var(--text-muted, #888);
    margin-bottom: 18px;
}
.library-modal-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted, #aaa);
    margin: 12px 0 6px;
}
.library-modal-prompt {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary, #1a1a2e);
    background: var(--bg-tertiary, #f0f1f5);
    padding: 12px 14px;
    border-radius: 8px;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 8px;
}
/* "Ads from this video" rows (Library + Video Library modals). These vlib-ad-* classes
   had NO stylesheet (the code comment "load globally" was stale) — so the rows rendered
   unstyled: full-size thumbnails overflowing the side panel. Compact list row: small
   thumbnail + name/sub + status pill + Ads-Manager link. */
.vlib-ad-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--border, #ECEDF1);
}
.vlib-ad-row:last-child { border-bottom: none; }
.vlib-ad-thumb {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-tertiary, #f0f1f5);
}
.vlib-ad-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.vlib-ad-name {
    font-size: 13px; font-weight: 600; color: var(--text-primary, #1a1a2e);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vlib-ad-sub {
    font-size: 11px; color: var(--text-muted, #888);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vlib-ad-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.vlib-ad-status {
    font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    padding: 2px 7px; border-radius: 999px;
}
.vlib-ad-status.is-active { background: #e6f7ef; color: #137a47; }
.vlib-ad-status.is-paused { background: var(--bg-tertiary, #f0f1f5); color: var(--text-muted, #888); }
.vlib-ad-date { font-size: 11px; color: var(--text-muted, #aaa); }
.vlib-ad-link {
    font-size: 11px; font-weight: 600; color: var(--accent, #2563eb);
    text-decoration: none; margin-top: 2px; align-self: flex-start;
}
.vlib-ad-link:hover { text-decoration: underline; }

/* Product-details panel (Products tab tiles) — field rows with clickable link values. */
.library-modal-fields {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}
.library-modal-field {
    display: flex;
    gap: 10px;
    align-items: baseline;
    font-size: 12.5px;
    line-height: 1.45;
}
.library-modal-field-k {
    flex: 0 0 96px;
    color: var(--text-muted, #888);
    font-weight: 600;
}
.library-modal-field-v {
    color: var(--text-primary, #1a1a2e);
    word-break: break-word;
    min-width: 0;
}
.library-modal-field-link {
    color: var(--accent, #5B53E8);
    text-decoration: none;
    word-break: break-all;
}
.library-modal-field-link:hover { text-decoration: underline; }
.library-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.library-modal-actions .btn {
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    font-size: 12px;
}
.library-modal-delete {
    margin-top: 8px;
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}
.library-modal-delete:hover {
    background: #fee2e2;
    border-color: #ef4444;
}

@media (max-width: 800px) {
    .library-modal {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
}

/* ============================================================================
 * Library multi-select — "Select" mode
 *
 * Lives in library.css (instead of ads-wizard.css) because:
 *   1. Higher specificity — rules use .library-grid .library-tile.is-selected
 *      so they reliably beat .library-tile:hover (same specificity 0,0,2,0
 *      but later rule needs to be in the same file load to be deterministic).
 *   2. Co-located with the rest of the tile styles, so future edits to
 *      tile geometry can't break the multi-select overlay.
 * ============================================================================ */

/* "Select" toggle in the toolbar */
.library-toolbar .library-select-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.library-toolbar .library-select-toggle.is-active {
    background: #5B53E8;
    border-color: #5B53E8;
    color: #fff;
}
.library-toolbar .library-select-toggle.is-active:hover {
    background: #4f46e5;
    border-color: #4f46e5;
}

/* When in select mode, every tile gets a subtle dim overlay so users see
 * we're in a different mode. The ::before sits ABOVE the image (z-index:2)
 * but below the checkbox (z-index:3). pointer-events:none lets clicks pass
 * through to the tile container. */
.library-grid .library-tile.is-select-mode {
    cursor: pointer;
}
.library-grid .library-tile.is-select-mode::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.18);
    z-index: 2;
    pointer-events: none;
    border-radius: inherit;
    transition: background 0.12s;
}
/* Higher specificity than :hover — ensures the blue ring stays visible
 * even when the cursor is over the selected tile. !important on the
 * box-shadow because :hover defines a competing shadow at the same
 * specificity (0,0,2,0) and Chrome's cascade order can flip if the
 * stylesheets are loaded in a different order on cold start. */
.library-grid .library-tile.is-selected::before {
    background: rgba(99, 102, 241, 0.28);
}
.library-grid .library-tile.is-selected {
    box-shadow: 0 0 0 4px #5B53E8, 0 12px 28px rgba(99, 102, 241, 0.35) !important;
    border-color: #5B53E8 !important;
    transform: translateY(-1px);
}
.library-grid .library-tile.is-selected:hover {
    /* Override the generic :hover — keep the blue ring */
    box-shadow: 0 0 0 4px #5B53E8, 0 12px 28px rgba(99, 102, 241, 0.45) !important;
    border-color: #5B53E8 !important;
}

/* Checkbox in the corner of every tile in select mode */
/* Select checkbox — top-RIGHT rounded square (design), clears the top-left
   type badge. Empty box when unselected; filled indigo with a check when picked. */
.library-tile-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    width: 20px;
    height: 20px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.85);
    border: 2px solid #fff;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    color: #fff;
    transition: background 0.12s, border-color 0.12s;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
}
.library-grid .library-tile.is-select-mode .library-tile-checkbox {
    display: flex;
}
.library-grid .library-tile.is-selected .library-tile-checkbox {
    background: #5B53E8;
    border-color: #5B53E8;
    color: #fff;
}

/* Floating action bar (bottom of viewport when items are selected).
 * position:fixed → escapes any parent overflow. z-index:200 sits above
 * the library-layout (z-index:100) and above the sidebar (z-index:10).
 * pointer-events:none on the hidden state so it never intercepts clicks. */
.library-select-bar {
    position: fixed;
    left: calc(var(--sidebar-width, 80px) + 24px);
    right: 24px;
    bottom: 24px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 14px;
    padding: 14px 20px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 200;
    transform: translateY(0);
    transition: transform 0.2s, opacity 0.2s;
}
.library-select-bar.is-hidden {
    transform: translateY(140%);
    opacity: 0;
    pointer-events: none;
}
.library-select-count {
    font-size: 13.5px;
    font-weight: 600;
    color: #111827;
    flex: 1;
}
.library-select-count strong {
    color: #5B53E8;
    font-weight: 700;
}
.library-select-actions {
    display: flex;
    gap: 8px;
}
.library-select-actions .btn-primary {
    background: #1877f2;          /* Meta blue */
    border-color: #1877f2;
    color: #fff;
}
.library-select-actions .btn-primary:hover {
    background: #166fe5;
    border-color: #166fe5;
}
/* Phone: the actions ran past the right edge (count + buttons on one unbreakable row). Let the
   buttons take their own full-width row and share it. */
@media (max-width: 640px) {
    .library-select-bar { left: calc(var(--sidebar-width, 56px) + 10px); right: 10px; bottom: 12px; padding: 12px 14px; flex-wrap: wrap; gap: 10px; }
    .library-select-count { flex: 1 1 100%; }
    .library-select-actions { flex: 1 1 100%; flex-wrap: wrap; }
    .library-select-actions .btn { flex: 1 1 auto; justify-content: center; }
}

/* ============================================================================
 * Approval history button (header) + modal
 * ----------------------------------------------------------------------------
 * Button sits next to the Select toggle in the library header. The modal
 * opens lazily from `approval-history.js`. Inherits `.modal-overlay` /
 * `.modal` base styles from app.css.
 * ============================================================================ */

.library-header-controls .library-approval-history-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary, #5B6473);
    background: transparent;          /* outlined: border, no background */
    border: 1px solid var(--border, #E2E4EA);
    border-radius: 9px;
    padding: 8px 13px;
    cursor: pointer;
}
.library-header-controls .library-approval-history-btn:hover { background: #F4F5F7; color: var(--text-primary, #14171F); }
.library-header-controls .library-approval-history-btn svg { width: 14px; height: 14px; }

.approval-history-overlay {
    /* Slightly higher than the standard modal stack so it can sit on
       top of a Library tile modal if one is open. */
    z-index: 1100;
}
.approval-history-modal {
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    padding: 20px 22px 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.approval-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}
.approval-history-title {
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
}
.approval-history-sub {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.4;
    margin: 0 0 14px;
}
.approval-history-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

/* Empty / loading / error state — shared shell */
.approval-history-empty {
    text-align: center;
    padding: 40px 16px;
    color: #6b7280;
}
.approval-history-empty-title {
    font-size: 15px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}
.approval-history-empty-sub {
    font-size: 13px;
    line-height: 1.45;
    max-width: 380px;
    margin: 0 auto;
}

/* List */
.approval-history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.approval-history-item {
    border: 1px solid #e6e6ec;
    border-radius: 10px;
    padding: 12px 14px;
    background: #fff;
    transition: border-color 0.12s, background-color 0.12s;
}
.approval-history-item:hover {
    border-color: #c7d2fe;
}
.approval-history-item.is-expired {
    background: #fafafb;
    opacity: 0.85;
}
.approval-history-item-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}
.approval-history-item-title-wrap {
    flex: 1 1 auto;
    min-width: 0;
}
.approval-history-item-title {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}
.approval-history-item-meta {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.4;
}

/* Expiry pill (right side of header row) */
.approval-history-expiry {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.approval-history-expiry.is-expired {
    background: #f3f4f6;
    color: #6b7280;
}

/* Status counts row — colored pills, one per non-zero bucket */
.approval-history-status-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.approval-history-stat {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}
.approval-history-stat.is-approved {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
}
.approval-history-stat.is-rejected {
    background: rgba(239, 68, 68, 0.10);
    color: #b91c1c;
}
.approval-history-stat.is-pending {
    background: #f3f4f6;
    color: #4b5563;
}

/* Action buttons row */
.approval-history-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.approval-history-action {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.approval-history-action.approval-history-wa {
    background: #25D366;
    color: #fff;
    border-color: #25D366;
}
.approval-history-action.approval-history-wa:hover {
    background: #1ebe5b;
    border-color: #1ebe5b;
}

/* ── Source toggle (AI / Drive) + Manage sources button ─────────────────── */
.library-src-toggle {
    display: inline-flex;
    border: 1px solid var(--border-subtle, #e6e6ec);
    border-radius: 8px;
    overflow: hidden;
}
.library-src-btn {
    border: 0;
    background: #fff;
    color: var(--text-secondary, #4b5563);
    font-size: 12.5px;
    font-weight: 600;
    padding: 8px 13px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.library-src-btn + .library-src-btn { border-left: 1px solid var(--border-subtle, #e6e6ec); }
.library-src-btn:hover { background: #f6f7fb; color: #111827; }
.library-src-btn.is-active { background: #5B53E8; color: #fff; }
/* Per-source count badge inside each pill (All sources 22 · Drive 8 · …). */
.library-src-btn { display: inline-flex; align-items: center; gap: 7px; }
.library-src-count {
    font-size: 11px; font-weight: 700;
    background: var(--bg-tertiary, #eef0f4); color: var(--text-secondary, #6b7280);
    border-radius: 999px; padding: 1px 7px; min-width: 18px; text-align: center;
    transition: background 0.12s, color 0.12s;
}
.library-src-btn.is-active .library-src-count { background: rgba(255, 255, 255, 0.24); color: #fff; }
.library-src-count:empty { display: none; }
.library-manage-btn { display: inline-flex; align-items: center; }
/* Subtle "Manage in Sources →" link — replaces the removed per-library
   Manage-sources button (source management now lives in the Sources page). */
.library-sources-link {
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent;          /* outlined: border, no background */
    border: 1px solid var(--border, #E2E4EA); cursor: pointer;
    color: var(--text-secondary, #5B6473); font-size: 13px; font-weight: 600;
    border-radius: 9px; padding: 8px 13px; white-space: nowrap;
}
.library-sources-link:hover { background: #F4F5F7; color: var(--text-primary, #14171F); }

/* ── Manage Image Sources modal ─────────────────────────────────────────── */
.imgsrc-modal .modal-header { align-items: flex-start; }
.imgsrc-sub { font-size: 12.5px; color: var(--text-muted, #6b7280); margin-top: 4px; line-height: 1.45; }
.imgsrc-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 12px; }
.imgsrc-gbanner { font-size: 12.5px; padding: 9px 12px; border-radius: 8px; background: #f3f4f6; color: #374151; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.imgsrc-gbanner.is-ok   { background: #ecfdf3; color: #027a48; }
.imgsrc-gbanner.is-warn { background: #fffaeb; color: #b54708; }
.imgsrc-gbanner.is-cta  { background: #eef2ff; color: #3730a3; }
.imgsrc-seg { display: inline-flex; border: 1px solid var(--border-subtle, #e6e6ec); border-radius: 8px; overflow: hidden; align-self: flex-start; }
.imgsrc-seg-btn { border: 0; background: #fff; color: #4b5563; font-size: 12.5px; font-weight: 600; padding: 8px 13px; cursor: pointer; }
.imgsrc-seg-btn + .imgsrc-seg-btn { border-left: 1px solid var(--border-subtle, #e6e6ec); }
.imgsrc-seg-btn.is-active { background: #5B53E8; color: #fff; }
.imgsrc-add-row { display: flex; gap: 8px; align-items: center; }
.imgsrc-url { flex: 1 1 auto; min-width: 0; padding: 9px 12px; border: 1px solid var(--border-subtle, #e2e5ee); border-radius: 8px; font-size: 13px; }
.imgsrc-label { flex: 0 0 150px; padding: 9px 12px; border: 1px solid var(--border-subtle, #e2e5ee); border-radius: 8px; font-size: 13px; }
.imgsrc-url:focus, .imgsrc-label:focus { outline: none; border-color: #5B53E8; box-shadow: var(--focus-ring); }
.imgsrc-msg { font-size: 12px; min-height: 16px; }
.imgsrc-msg.is-pending { color: #6b7280; }
.imgsrc-msg.is-ok   { color: #027a48; }
.imgsrc-msg.is-warn { color: #b54708; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.imgsrc-msg.is-err  { color: #b42318; }
.imgsrc-list-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: #646B78; margin-top: 4px; }
.imgsrc-list { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.imgsrc-empty { font-size: 12.5px; color: #646B78; padding: 10px 0; }
.imgsrc-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid #eef0f3; border-radius: 8px; }
.imgsrc-badge { flex: 0 0 auto; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.imgsrc-badge-drive { background: #eef2ff; color: #4f46e5; }
.imgsrc-badge-csv { background: #f3e8ff; color: #7e22ce; }
.imgsrc-row-info { flex: 1; min-width: 0; }
.imgsrc-row-label { font-size: 13px; color: #1f2937; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imgsrc-row-url { font-size: 11px; color: #646B78; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imgsrc-del { flex: 0 0 auto; background: none; border: 1px solid #fecaca; color: #b91c1c; font-size: 12px; padding: 3px 9px; border-radius: 6px; cursor: pointer; }
.imgsrc-del:hover { background: #fef2f2; }

/* ── Recent bar (last-7-days strip, Generated mode w/ Drive sources) ────── */
.library-recent-bar {
    flex-basis: 100%;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle, #e6e6ec);
}
.library-recent-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted, #9ca3af);
    margin-bottom: 8px;
}
.library-recent-strip {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 6px;
    scrollbar-width: thin;
}
.library-recent-cell {
    flex: 0 0 auto;
    width: 92px;
    cursor: pointer;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-subtle, #e6e6ec);
    background: var(--bg-tertiary, #f0f1f5);
    transition: transform 0.12s, border-color 0.12s;
}
.library-recent-cell:hover { transform: translateY(-2px); border-color: #5B53E8; }
.library-recent-cell img { width: 100%; height: 72px; object-fit: cover; display: block; }
.library-recent-date {
    display: block;
    padding: 3px 6px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    text-align: center;
}

/* Drive refresh button — icon-only, matches the manage button height */
.library-drive-refresh { display: inline-flex; align-items: center; justify-content: center; padding: 8px 10px; }

/* CSV source format hint (image-sources editor) */
.imgsrc-csv-hint { font-size: 11.5px; color: var(--text-muted, #888); line-height: 1.5; margin: 2px 0 8px; }
.imgsrc-csv-hint code { background: #eef2ff; color: #4338ca; padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.imgsrc-csv-hint-note { color: #646B78; }

/* "Select a project to manage sources" hint (All-projects header) — mirrors
   the Video Library's .vlib-needs-project so both libraries read identically. */
.library-needs-project { font-size: 12px; color: var(--text-muted, #9ca3af); max-width: 340px; line-height: 1.4; align-self: center; }

/* ============================================================================
   MEDIA LIBRARY (Media Library.dc.html) — title/subtitle, media-type tabs,
   date-group headers, and per-tile media-type + video-play badges.
   ============================================================================ */

/* Title + subtitle */
.library-title-wrap { display: flex; flex-direction: column; gap: 3px; }
.library-subtitle { margin: 0; font-size: 13.5px; color: var(--text-secondary, #6B7280); line-height: 1.4; max-width: 640px; }

/* Media-type tabs — segmented pill: All Media / Images / Videos */
.library-type-tabs {
    display: inline-flex; align-items: center; gap: 6px;
    background: #ECEDF1; border-radius: 11px; padding: 4px;
    margin: 0; width: fit-content;
    /* On phones the three tabs are wider than the column: scroll the strip itself instead of
       letting it widen .library-layout (overflow hidden), which a focus/click then scrolled
       sideways and pushed the whole toolbar off screen. */
    max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.library-type-tabs::-webkit-scrollbar { display: none; }
.library-type-tab {
    display: inline-flex; align-items: center; gap: 7px;
    font: inherit; font-size: 13px; font-weight: 600; color: #6B7280;
    background: transparent; border: none; border-radius: 8px;
    padding: 7px 14px; cursor: pointer;
    transition: background .12s ease, color .12s ease;
    /* Keep each tab on one line so the strip scrolls instead of "All Media" breaking in two on phones. */
    white-space: nowrap; flex: 0 0 auto;
}
.library-type-tab svg { color: #6B7280; flex: 0 0 auto; }
.library-type-tab:hover { color: #14171F; }
.library-type-tab.is-active { background: #FFFFFF; color: #14171F; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12); }
.library-type-tab.is-active svg { color: var(--accent, #5B53E8); }
.library-type-tab__count {
    font-size: 11px; font-weight: 700; color: #646B78;
    background: #E6E8EC; padding: 1px 7px; border-radius: 999px;
}
.library-type-tab.is-active .library-type-tab__count { color: var(--accent, #5B53E8); background: var(--accent-subtle, #EEEDFC); }

/* Date-group header — uppercase label · count · hairline rule */
.library-date-head { display: flex; align-items: center; gap: 10px; margin: 6px 0 13px; }
.library-date-head__label { font-size: 12px; font-weight: 700; letter-spacing: .05em; color: #646B78; text-transform: uppercase; }
.library-date-head__count { font-size: 12px; color: #646B78; }
.library-date-head__rule { flex: 1; height: 1px; background: var(--border-subtle, #ECEDF1); }

/* Per-tile media-type badge (top-left) + video play affordance (bottom-right) */
.library-tile-type {
    position: absolute; top: 8px; left: 8px; z-index: 2;
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 9.5px; font-weight: 700; color: #fff;
    background: rgba(20, 23, 31, 0.72); padding: 3px 7px; border-radius: 999px;
    pointer-events: none;
}
.library-tile-type svg { width: 11px; height: 11px; }
/* In select mode the checkbox owns the top-left corner — hide the type badge. */
.library-grid .library-tile.is-select-mode .library-tile-type { display: none; }
.library-tile-play {
    position: absolute; bottom: 8px; right: 8px; z-index: 2;
    width: 30px; height: 30px; border-radius: 50%;
    background: rgba(255, 255, 255, 0.92); color: #14171F;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

/* ── Active-filter chips (M2) — between the toolbar and the grid ──────────── */
/* "Filtered:" chip bar REMOVED (user 2026-07-13) — redundant with the controls
   themselves showing the active state. Don't re-add. */

/* ── "Hide from library" + session Undo bar (M3) ──────────────────────────── */
.library-hiddenbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px dashed var(--border, #e2e4ea); border-radius: 10px; background: var(--bg-secondary, #f7f8fa); color: var(--text-secondary, #6b7280); font-size: 12.5px; }
.library-hiddenbar__btn { border: none; background: none; color: var(--accent, #5b53e8); font-size: 12.5px; font-family: inherit; cursor: pointer; padding: 0; }
.library-hiddenbar__btn:hover { text-decoration: underline; }
.library-hide-btn { color: var(--text-secondary, #6b7280); }

/* ── Lightbox prev/next + position (M4) ───────────────────────────────────── */
.library-modal-media { position: relative; }
.library-modal-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 38px; height: 56px; border: none; border-radius: 10px; background: rgba(17, 17, 17, 0.45); color: #fff; font-size: 26px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: 0.75; transition: opacity 0.15s ease, background 0.15s ease; z-index: 2; }
.library-modal-nav:hover { opacity: 1; background: rgba(17, 17, 17, 0.65); }
.library-modal-nav--prev { left: 10px; }
.library-modal-nav--next { right: 10px; }
.library-modal-pos { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); padding: 3px 10px; border-radius: 999px; background: rgba(17, 17, 17, 0.55); color: #fff; font-size: 11.5px; font-variant-numeric: tabular-nums; z-index: 2; pointer-events: none; }

/* ── Loading skeleton tiles (M8) — flow in the real grid columns ──────────── */
.library-tile--skeleton { pointer-events: none; cursor: default; }
.library-skel { display: block; border-radius: 8px; background: linear-gradient(90deg, var(--border, #eef0f4) 25%, var(--bg-secondary, #f7f8fa) 50%, var(--border, #eef0f4) 75%); background-size: 200% 100%; animation: libShimmer 1.4s ease-in-out infinite; }
.library-skel--thumb { aspect-ratio: 1 / 1; width: 100%; border-radius: 12px; }
.library-skel-info { padding: 10px 4px 6px; display: flex; flex-direction: column; gap: 6px; }
.library-skel--line { height: 11px; width: 85%; }
.library-skel--short { width: 55%; }
@keyframes libShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .library-skel { animation: none; } }

/* ── Whole-PAGE loading skeleton (app.js loadLibrary, 2026-07-13) — shown ONLY on the
   FIRST visit while the module imports; a cached revisit paints the real chrome
   synchronously (no skeleton, no flash). Shaped like the page it becomes: header +
   type tabs + toolbar + a tile grid whose columns MATCH .library-masonry EXACTLY
   (210px min / 14px gap / 1320 column / 28px side padding) so the handoff to the
   in-grid M8 skeletons doesn't shift a pixel. Reuses the .library-skel shimmer. */
.library-pageskel { max-width: 1320px; margin: 0 auto; padding: 26px 28px 64px; }
.library-pageskel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.library-pageskel-title { width: 220px; height: 24px; }
.library-pageskel-sub { margin-top: 9px; width: 320px; max-width: 60vw; height: 12px; }
.library-pageskel-pills { display: flex; gap: 8px; flex: 0 0 auto; }
.library-pageskel-pill { width: 96px; height: 36px; border-radius: 9px; }
.library-pageskel-tabs { display: flex; gap: 8px; margin-top: 20px; }
.library-pageskel-tab { width: 108px; height: 34px; border-radius: 999px; }
.library-pageskel-toolbar { display: flex; gap: 8px; margin-top: 14px; }
.library-pageskel-search { width: 280px; max-width: 40vw; height: 36px; border-radius: 9px; }
.library-pageskel-grid { margin-top: 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: 14px; align-items: start; }

/* ── Possible-duplicate badge (M10) ───────────────────────────────────────── */
.library-tile-dup { display: inline-flex; align-items: center; height: 16px; padding: 0 6px; border-radius: 999px; background: rgba(217, 119, 6, 0.1); color: #b45309; font-size: 10px; font-weight: 600; letter-spacing: 0.02em; }

/* ── Manual uploads — drag & drop + progress panel (library-media.php) ────── */
/* Upload button sits with the header controls; icon + label like Drive refresh. */
.library-upload-btn { display: inline-flex; align-items: center; gap: 6px; }

/* Full-viewport drop overlay — appears while dragging files over the Library. */
.library-dropzone { position: fixed; inset: 0; z-index: 1200; background: rgba(91, 83, 232, 0.10); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.library-dropzone-inner { pointer-events: none; background: #fff; border: 2px dashed var(--accent, #5B53E8); border-radius: 16px; padding: 36px 56px; text-align: center; color: var(--accent, #5B53E8); box-shadow: 0 18px 50px rgba(20, 24, 40, 0.18); }
.library-dropzone-title { margin-top: 10px; font-size: 18px; font-weight: 700; }
.library-dropzone-sub { margin-top: 4px; font-size: 12.5px; font-weight: 500; color: #5B6473; }

/* Bottom-right upload progress panel — one row per file. */
.library-upload-panel { position: fixed; right: 18px; bottom: 18px; z-index: 1300; width: 320px; max-height: 46vh; overflow-y: auto; background: #fff; border: 1px solid #E3E5EA; border-radius: 12px; box-shadow: 0 14px 40px rgba(20, 24, 40, 0.16); padding: 10px 12px; }
.library-upload-panel-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 700; color: #1E2330; padding-bottom: 6px; border-bottom: 1px solid #EFF0F3; margin-bottom: 6px; }
.library-upload-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 12px; }
.library-upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #3A4152; flex: 1 1 auto; }
.library-upload-state { flex: 0 0 auto; font-weight: 600; color: #646B78; }
.library-upload-state.is-busy { color: var(--accent, #5B53E8); }
.library-upload-state.is-ok { color: #0F8A5F; }
.library-upload-state.is-error { color: #C0392B; }

/* ── Unreadable-source banner ──────────────────────────────────────────────
   Shown when a configured source (Drive folder, CSV) cannot be READ. This is
   deliberately loud: the failure it reports used to be completely invisible —
   gdrive_list_media logged a 403/404 server-side and returned an empty array,
   so the Library rendered an empty grid that looked exactly like "no media
   yet", and Drive items that had been there simply vanished with no reason.
   Amber, not red: the media is not lost, the folder just isn't readable. */
.lib-srcerr {
    margin: 0 0 14px;
    padding: 11px 13px;
    border: 1px solid #F0D9A8;
    border-left: 3px solid #E0A030;
    border-radius: 9px;
    background: #FDF8EE;
    color: #6B4E17;
    font-size: 13px;
    line-height: 1.5;
}
.lib-srcerr[hidden] { display: none; }   /* explicit: the element is display:block otherwise */
.lib-srcerr__row + .lib-srcerr__row { margin-top: 7px; padding-top: 7px; border-top: 1px solid #F3E6CC; }
.lib-srcerr__row strong { color: #4A360F; }

/* ── ⭐ Favourites — the per-tile star + the toolbar filter (schema v104) ──────────────────────
   The star sits in the tile's top-right corner (the checkbox owns that spot only in select mode,
   where the star is not rendered at all). Hidden until hover on an unstarred tile so a plain grid
   stays clean; ALWAYS visible once starred, so a shortlist reads at a glance. */
.library-tile-fav {
    position: absolute; top: 8px; right: 8px; z-index: 4;
    width: 26px; height: 26px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border: none; border-radius: 50%;
    background: rgba(20, 23, 31, 0.55);
    color: #fff; cursor: pointer;
    opacity: 0; transform: scale(.92);
    transition: opacity .12s, transform .12s, background .12s, color .12s;
}
.library-tile-fav svg { width: 15px; height: 15px; display: block; }
.library-tile:hover .library-tile-fav,
.library-tile-fav:focus-visible { opacity: 1; transform: scale(1); }
.library-tile-fav:hover { background: rgba(20, 23, 31, 0.78); }
/* Starred: always shown, amber fill — the one state that must survive a glance. */
.library-tile-fav.is-on {
    opacity: 1; transform: scale(1);
    background: rgba(255, 255, 255, 0.94);
    color: #E0A526;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.22);
}
.library-tile-fav.is-on:hover { background: #fff; color: #C98F16; }
.library-tile-fav:disabled { cursor: default; opacity: .6; }
/* A tile whose star sits under the "N sizes" badge: nudge that badge down so both are readable. */
.library-tile:hover .library-tile-sizes, .library-tile-fav.is-on ~ .library-tile-sizes { top: 40px; }

/* Toolbar filter — same shape as "Has link"; amber when ON so it reads as the star's filter. */
.library-toolbar .library-fav-toggle { display: inline-flex; align-items: center; gap: 6px; }
.library-toolbar .library-fav-toggle.is-on { background: #E0A526; border-color: #E0A526; color: #fff; }
.library-toolbar .library-fav-toggle.is-on:hover { background: #C98F16; border-color: #C98F16; }
.library-fav-count {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 17px; height: 17px; padding: 0 5px; margin-left: 2px;
    border-radius: 999px; font-size: 10.5px; font-weight: 700;
    background: rgba(20, 23, 31, 0.10); color: inherit;
}
.library-fav-toggle.is-on .library-fav-count { background: rgba(255, 255, 255, 0.28); }
