/* Library screen: header/toolbar, three view modes, filter panel, bulk bar. */

.library-header { margin-bottom: var(--space-4); }
.library-title-row { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-3); }
.library-title-row h1 { margin: 0; }
.library-count { color: var(--text-muted); font-size: var(--fs-sm); }

.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.library-toolbar .search-input-wrap { flex: 1 1 220px; min-width: 0; }
.library-toolbar .toolbar-spacer { flex: 1 1 auto; }

.filter-btn { position: relative; }
.filter-btn .filter-count {
  position: absolute; top: -6px; inset-inline-end: -6px;
  background: var(--accent); color: #fff; border-radius: 50%;
  font-size: 0.65rem; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
}

.view-switcher { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.view-switcher button {
  background: var(--surface); border: none; padding: 0.5rem 0.65rem; cursor: pointer; color: var(--text-muted);
  min-height: var(--tap-min); min-width: var(--tap-min); border-inline-end: 1px solid var(--border-strong);
}
.view-switcher button:last-child { border-inline-end: none; }
.view-switcher button[aria-pressed="true"] { background: var(--accent-tint); color: var(--accent); }

.view-tabs { display: flex; gap: var(--space-2); overflow-x: auto; margin-bottom: var(--space-3); padding-bottom: 2px; }
.view-tabs a {
  padding: 0.4rem 0.9rem; border-radius: var(--radius-pill); background: var(--surface);
  border: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text); white-space: nowrap; min-height: var(--tap-min); display: inline-flex; align-items: center;
}
.view-tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

/* ---------- Card view ---------- */
/* `minmax(0, 1fr)`, not `1fr`.
 *
 * A bare `1fr` track is `minmax(auto, 1fr)`, and that `auto` minimum is the
 * grid item's MIN-CONTENT width. So a card holding one thing that cannot
 * shrink -- a select with a long option, a wrapping actions row -- pushes the
 * track wider than the grid box, the card overflows the viewport, and
 * `body { overflow-x: hidden }` then clips the right-hand side instead of
 * showing it. That is exactly what happened on the mobile Archive screen: the
 * track resolved to 400px inside a 360px grid, the page measured 415 CSS px
 * wide, and the card's controls were cut off.
 *
 * `minmax(0, 1fr)` gives the track a real zero minimum, so it can never grow
 * past its share of the container and the content inside wraps or ellipses as
 * it was written to. */
.library-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
@media (min-width: 640px) { .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* Three columns only once a card is wide enough for its own controls to sit
   on one line; below that, two readable cards beat three cramped ones. */
@media (min-width: 1280px) { .library-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.item-card { display: flex; gap: var(--space-3); max-width: 100%; position: relative; }
.item-card .seq { color: var(--text-faint); font-size: var(--fs-xs); flex-shrink: 0; width: 1.5rem; text-align: end; padding-top: 0.15rem; }
.item-card .select-box { flex-shrink: 0; padding-top: 0.15rem; }
.item-card img.thumb { width: 88px; height: 66px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); flex-shrink: 0; }
.item-card .item-body { flex: 1; min-width: 0; } /* min-width:0 lets a flex child shrink below its content size so .url-line's ellipsis works instead of the card stretching */
.item-card .meta { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 0.15rem; display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.item-card .title { font-weight: 600; color: var(--text); }
.item-card .description { color: var(--text-muted); font-size: var(--fs-sm); margin: 0.35rem 0 0; overflow-wrap: anywhere; }
.item-card .actions-row { margin-top: var(--space-2); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); font-size: var(--fs-sm); }
.item-card .actions-row button, .item-card .actions-row a { background: none; border: none; padding: 0; cursor: pointer; color: var(--text-muted); font: inherit; min-height: auto; }
.item-card .actions-row button:hover, .item-card .actions-row a:hover { color: var(--accent); }
.item-card .fav-star { font-size: 1.1rem; line-height: 1; background: none; border: none; cursor: pointer; color: var(--text-faint); padding: 0.2rem; min-height: auto; }
.item-card .fav-star.is-favorite { color: var(--warning); }
.collection-badge { display: inline-flex; align-items: center; gap: 0.2rem; }
.collection-badge button { font-size: 0.9rem; line-height: 1; padding: 0 0.1rem; min-height: auto; }
.item-card select.inline-select { font-size: var(--fs-sm); padding: 0.25rem 0.4rem; min-height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); max-width: 12rem; }

/* ---------- Compact list view ---------- */
.library-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); }
.library-list-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0.6rem var(--space-3); border-bottom: 1px solid var(--border);
  min-height: calc(var(--tap-min) + 8px);
}
.library-list-row:last-child { border-bottom: none; }
.library-list-row .seq { color: var(--text-faint); font-size: var(--fs-xs); width: 1.5rem; text-align: end; flex-shrink: 0; }
.library-list-row .title-col { flex: 1; min-width: 0; }
.library-list-row .title-col .title { font-weight: 600; display: block; }
.library-list-row .title-col .meta { color: var(--text-muted); font-size: var(--fs-xs); }
.library-list-row .row-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }

/* ---------- "More actions" menu (list + table rows) ---------- */
.row-menu { position: relative; display: inline-flex; }
.row-menu-panel {
  position: absolute; inset-inline-end: 0; top: calc(100% + 0.3rem);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); min-width: 190px; padding: var(--space-2); z-index: var(--z-drawer);
}
.row-menu-panel[hidden] { display: none; }
.row-menu-panel .menu-item {
  display: block; width: 100%; text-align: start; background: none; border: none;
  padding: 0.55rem 0.7rem; border-radius: var(--radius-sm); font-size: var(--fs-sm);
  color: var(--text); cursor: pointer; min-height: var(--tap-min);
}
.row-menu-panel .menu-item:hover { background: var(--surface-2); }
.row-menu-panel .menu-item.danger { color: var(--danger); }
.row-menu-panel form { margin: 0; }
.row-menu-panel select.inline-select { width: 100%; margin-bottom: var(--space-2); }
.btn-icon.fav-star-btn { color: var(--text-faint); }
.btn-icon.fav-star-btn.is-favorite { color: var(--warning); }

/* ---------- Table view (desktop only) ---------- */
table.data-table td.col-fav { text-align: center; width: 2.5rem; }
table.data-table td.col-actions { text-align: end; white-space: nowrap; }

/* Table view is a desktop-only mode -- the switcher button that selects it
   is hidden below the breakpoint (plan: "no desktop tables forced onto
   mobile"), and JS also falls back to card view if a stored preference of
   "table" is read on a narrow viewport. */
[data-set-view="table"][data-desktop-only-view] { display: none; }
@media (min-width: 768px) {
  [data-set-view="table"][data-desktop-only-view] { display: inline-flex; }
}

/* One view visible at a time; JS toggles [hidden] on [data-view-panel]. */
[data-view-panel][hidden] { display: none; }

/* ---------- Filter sheet contents ---------- */
.filter-section { margin-bottom: var(--space-4); }
.filter-section h3 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 var(--space-2); }
.filter-options { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.filter-option-label {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.4rem 0.75rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill); font-size: var(--fs-sm); cursor: pointer; min-height: var(--tap-min);
}
.filter-option-label input { margin: 0; }
.filter-option-label:has(input:checked) { background: var(--accent-tint); border-color: var(--accent); color: var(--accent); }
.filter-actions { display: flex; gap: var(--space-2); margin-top: var(--space-5); position: sticky; bottom: 0; background: var(--surface); padding-top: var(--space-3); }
.filter-actions .btn { flex: 1; }

.date-range-custom { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.date-range-custom .field { flex: 1; margin-bottom: 0; }

/* ---------- Bulk selection bar ---------- */
.bulk-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  background: var(--text);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  box-shadow: var(--shadow-md);
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .count { font-weight: 600; white-space: nowrap; }
.bulk-bar .btn-secondary { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.3); color: #fff; }
.bulk-bar .btn-secondary:hover { background: rgba(255,255,255,0.22); }
.bulk-bar .clear-selection { margin-inline-start: auto; color: #fff; background: none; border: none; cursor: pointer; font-size: var(--fs-sm); min-height: var(--tap-min); }

@media (max-width: 767px) {
  .bulk-bar { bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
}

.quick-save-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); }
.quick-save-form .field { margin-bottom: 0; flex: 1 1 220px; }
