/* ============================================================
   shelf-shell.css — the "Shelf Shell" (sh-*) for
   pages/library.html and pages/history.html
   (see shelf-shell-suggestion.md)

   ONE skeleton for both personal-shelf pages:
     sh-identity -> sh-controlzone (sticky tabs + filters)
     -> sh-panelhead -> sh-panel (one at a time)

   Loaded AFTER css/main.css and AFTER css/series-shell.css, so it
   inherits the neutral --ss-* token scale and supersedes the old
   .rh-* / .library-layout / .lib-sidebar rules on these two pages
   only. No other page references .sh-shell, so nothing else moves.

   Rules: no purple, no gradients, no glass, no radius above 8px,
   spacing on the 4 / 8 / 12 / 16 / 24 / 32 / 48 scale only.
   ============================================================ */

/* ---------- Shell frame (mirrors .gs-shell / .st-shell) ---------- */
.sh-shell {
  max-width: var(--ss-max, 1120px);
  margin: 0 auto;
  padding: 0 16px 48px;
  color: var(--ss-text);
}
.sh-shell *,
.sh-shell *::before,
.sh-shell *::after { box-sizing: border-box; }
.sh-shell a { color: inherit; text-decoration: none; }

.sh-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---------- 1. Identity strip (mirrors .gs-identity) ---------- */
.sh-identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 24px 0 12px;
}
.sh-h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ss-text);
}
.sh-identity-meta {
  font-size: 13px;
  color: var(--ss-text-muted);
}

/* ---------- 2. Sticky control zone (mirrors .st-controlzone) ---------- */
.sh-controlzone {
  position: sticky;
  top: var(--header-height, 64px);
  z-index: 20;
  background: var(--ss-bg);
  border-bottom: 1px solid var(--ss-border);
}

/* Text tabs with a 2px underline — no pills, no gradients. */
.sh-tabs {
  display: flex;
  align-items: stretch;
  gap: 24px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.sh-tabs::-webkit-scrollbar { display: none; }

.sh-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 12px 0;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--ss-text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}
.sh-tab:hover { color: var(--ss-text); }
.sh-tab.active,
.sh-tab[aria-selected="true"] {
  color: var(--ss-text);
  border-bottom-color: var(--ss-text);
}
.sh-tab:focus-visible {
  outline: 2px solid var(--ss-border-strong);
  outline-offset: 2px;
}
/* Tab count + the inline category menu, both quiet */
.sh-tab .tab-count,
.sh-tab-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--ss-text-muted);
}
.sh-tab .tab-menu {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-height: 24px;
  border-radius: 6px;
  color: var(--ss-text-muted);
}
.sh-tab .tab-menu:hover { background: var(--ss-surface-2); color: var(--ss-text); }
/* The cross-page link tab (History <-> Library) sits after a hairline */
.sh-tab-link {
  margin-left: auto;
  padding-left: 24px;
  border-left: 1px solid var(--ss-border);
}
/* "New category" control lives on the tab rail, not in a sidebar */
.sh-tab-action {
  flex: 0 0 auto;
  align-self: center;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  background: transparent;
  color: var(--ss-text-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.sh-tab-action:hover { background: var(--ss-surface-2); color: var(--ss-text); }

/* One filter row: search, sort, density — nothing else */
.sh-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 0;
  border-top: 1px solid var(--ss-border);
}
.sh-search {
  position: relative;
  flex: 1 1 240px;
  min-width: 180px;
}
.sh-search i {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--ss-text-muted);
  pointer-events: none;
}
.sh-input,
.sh-shell input.sh-input,
.sh-shell select.sh-input {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 12px;
  background: var(--ss-surface);
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  color: var(--ss-text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}
.sh-search .sh-input { padding-left: 32px; }
.sh-input::placeholder { color: var(--ss-text-muted); }
.sh-input:focus { outline: 0; border-color: var(--ss-border-strong); }
.sh-select { flex: 0 0 auto; width: auto; min-width: 176px; cursor: pointer; }

.sh-density {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
}
.sh-density-btn {
  width: 36px;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ss-text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sh-density-btn:hover { color: var(--ss-text); }
.sh-density-btn.active {
  background: var(--ss-primary-bg);
  color: var(--ss-primary-fg);
}

/* ---------- 3. Panel head ---------- */
.sh-panelhead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 24px 0 12px;
}
.sh-panelhead-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ss-text);
}
.sh-panelhead-count {
  margin-left: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ss-text-muted);
}
.sh-panelhead-context {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ss-text-muted);
}

/* ---------- 4. Panels ---------- */
.sh-panel { display: block; }
.sh-panel[hidden] { display: none !important; }
.sh-shell .tab-content { display: none; }
.sh-shell .tab-content.active { display: block; }

/* Group label (History date buckets) — same device Settings uses */
.sh-group {
  padding: 24px 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ss-text-muted);
}
.sh-group:first-child { padding-top: 8px; }

/* ---------- The one row component ---------- */
.sh-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 12px 0;
  border-top: 1px solid var(--ss-border);
  color: var(--ss-text);
}
.sh-list > .sh-row:first-child,
.sh-group + .sh-list > .sh-row:first-child { border-top: 1px solid var(--ss-border); }
.sh-row:hover { background: var(--ss-surface); }

.sh-row-cover {
  flex: 0 0 auto;
  width: 48px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--ss-surface-2);
}
.sh-row-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.sh-row-main { min-width: 0; flex: 1 1 auto; }
.sh-row-title {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ss-text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.sh-row-meta {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ss-text-muted);
  overflow-wrap: anywhere;
}
/* One neutral tag variant — no colour coding */
.sh-row-tag {
  font-size: 13px;
  color: var(--ss-text-muted);
}
.sh-row-control {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sh-row-action {
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ss-ghost-fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sh-row-action:hover { background: var(--ss-ghost-bg-hover); color: var(--ss-text); }
.sh-row-action:focus-visible { outline: 2px solid var(--ss-border-strong); outline-offset: 2px; }

/* ---------- The same data as a poster tile ---------- */
.sh-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 16px;
}
.sh-tile { position: relative; min-width: 0; }
.sh-tile-cover {
  display: block;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: var(--ss-surface-2);
  border: 1px solid var(--ss-border);
}
.sh-tile-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sh-tile-title {
  margin: 8px 0 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ss-text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.sh-tile-meta {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ss-text-muted);
}
.sh-tile .sh-row-action {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  min-height: 32px;
  background: var(--ss-bg);
  border: 1px solid var(--ss-border);
}
.sh-tile .sh-row-action.sh-row-action-alt { right: 40px; }

/* Density is one attribute on the panel */
.sh-items[data-density="grid"] {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 16px;
}
.sh-items[data-density="list"] { display: block; }

/* ---------- Empty / loading states ---------- */
.sh-panel-empty {
  padding: 48px 16px;
  text-align: center;
  border: 1px solid var(--ss-border);
  border-radius: 8px;
  color: var(--ss-text-muted);
}
.sh-panel-empty i { font-size: 20px; }
.sh-panel-empty h3 {
  margin: 8px 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ss-text);
}
.sh-panel-empty p { margin: 0; font-size: 13px; }

.sh-skel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--ss-border);
}
.sh-skel .sh-row-cover { width: 48px; height: 64px; }
.sh-skel-line {
  height: 12px;
  border-radius: 6px;
  background: var(--ss-surface-2);
}

.sh-sentinel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 0;
  font-size: 13px;
  color: var(--ss-text-muted);
}
.sh-sentinel[hidden] { display: none; }
.sh-sentinel .spinner-sm { width: 16px; height: 16px; border-width: 2px; }

/* ---------- Buttons: the same three variants as .gs-btn ---------- */
.sh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.sh-btn i { font-size: 14px; }
.sh-btn:disabled { opacity: .55; cursor: not-allowed; }
.sh-btn:focus-visible { outline: 2px solid var(--ss-border-strong); outline-offset: 2px; }
.sh-btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.sh-btn-primary { background: var(--ss-primary-bg); color: var(--ss-primary-fg); }
.sh-btn-primary:hover:not(:disabled) { background: var(--ss-primary-bg-hover); }
.sh-btn-secondary {
  background: var(--ss-secondary-bg);
  color: var(--ss-secondary-fg);
  border-color: var(--ss-secondary-border);
}
.sh-btn-secondary:hover:not(:disabled) { background: var(--ss-secondary-bg-hover); }
.sh-btn-ghost { background: transparent; color: var(--ss-ghost-fg); }
.sh-btn-ghost:hover:not(:disabled) { background: var(--ss-ghost-bg-hover); color: var(--ss-text); }

/* ---------- Modals / pickers / inline menus, re-tokenised ---------- */
.yv-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.yv-modal[hidden] { display: none; }
.yv-modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); opacity: 0; transition: opacity 120ms ease; }
.yv-modal.is-open .yv-modal-backdrop { opacity: 1; }
.yv-modal-card {
  position: relative; width: 100%; max-width: 420px;
  background: var(--ss-bg); color: var(--ss-text);
  border: 1px solid var(--ss-border);
  border-radius: 8px; padding: 16px;
  box-shadow: var(--ss-shadow);
  transform: translateY(8px); opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
}
.yv-modal-card-lg { max-width: 560px; }
.yv-modal.is-open .yv-modal-card { transform: none; opacity: 1; }
.yv-modal-title { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.yv-modal-sub { margin: 0 0 12px; color: var(--ss-text-muted); font-size: 13px; }
.yv-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.yv-field { display: block; margin-bottom: 8px; }
.yv-field-label { display: block; font-size: 13px; color: var(--ss-text-muted); margin-bottom: 4px; }
.yv-required { color: var(--error, #f87171); font-weight: 600; }
.yv-modal .yv-input,
.yv-modal input.yv-input {
  width: 100%; min-height: 44px; padding: 12px;
  background: var(--ss-surface); color: var(--ss-text);
  border: 1px solid var(--ss-border); border-radius: 8px;
  font: inherit; outline: none;
}
.yv-modal .yv-input:focus { border-color: var(--ss-border-strong); }
.yv-input-error { border-color: var(--error, #f87171) !important; }

.yv-picker-search { position: relative; margin-bottom: 8px; }
.yv-picker-search i { position: absolute; top: 50%; left: 12px; transform: translateY(-50%); color: var(--ss-text-muted); }
.yv-picker-search .yv-input { padding-left: 32px; }
.yv-picker-list { max-height: 55vh; overflow: auto; border: 1px solid var(--ss-border); border-radius: 8px; }
.yv-picker-empty { padding: 16px; text-align: center; color: var(--ss-text-muted); font-size: 13px; }
.yv-picker-row {
  display: grid; grid-template-columns: 20px 44px 1fr auto;
  align-items: center; gap: 12px;
  padding: 8px 12px; cursor: pointer;
  border-top: 1px solid var(--ss-border);
}
.yv-picker-row:first-child { border-top: 0; }
.yv-picker-row:hover { background: var(--ss-surface); }
.yv-picker-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--ss-primary-bg); }
.yv-picker-row img { width: 44px; height: 58px; object-fit: cover; border-radius: 8px; background: var(--ss-surface-2); }
.yv-picker-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.yv-picker-badge { font-size: 13px; color: var(--ss-text-muted); }

.yv-inline-menu {
  position: absolute; z-index: 1100;
  background: var(--ss-bg); color: var(--ss-text);
  border: 1px solid var(--ss-border);
  border-radius: 8px; padding: 4px; min-width: 160px;
  box-shadow: var(--ss-shadow);
}
.yv-inline-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 0; background: transparent; color: inherit;
  text-align: left; border-radius: 8px; cursor: pointer;
  font: inherit; font-size: 14px; white-space: nowrap;
}
.yv-inline-menu button:hover { background: var(--ss-surface); }
.yv-inline-menu button.danger { color: var(--error, #f87171); }

/* ---------- Responsive: one column, scroll-snapping tab rail ---------- */
@media (max-width: 720px) {
  .sh-identity { padding: 16px 0 12px; }
  .sh-tabs {
    gap: 16px;
    scroll-snap-type: x proximity;
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent 100%);
    mask-image: linear-gradient(to right, #000 88%, transparent 100%);
  }
  .sh-tab { scroll-snap-align: start; }
  .sh-tab-link { margin-left: 0; padding-left: 16px; }
  .sh-search { flex: 1 1 100%; }
  .sh-select { flex: 1 1 auto; min-width: 0; }
  .sh-items[data-density="grid"],
  .sh-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
}
