/* T2 — Library (src/studio/library/*): the left panel on pages 1–3.
   Sizes and colours are the design's (html/01–03, layer "Library"). The
   panel's width, border and background are the shell's; this file draws
   what is inside it. */

.lib {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100%;
  padding: 16px 12px;
  color: var(--st-text);
  font-family: var(--st-font);
}

.lib-sections { display: contents; }

.lib :where(button, a, input):focus-visible {
  outline: 2px solid var(--st-accent);
  outline-offset: var(--st-focus-offset, 1px);
}

.lib-icon { width: 14px; height: 14px; flex: none; }

/* ---- Header and search ------------------------------------------------------ */

.lib-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.lib-head__title {
  margin: 0;
  font: 600 15px/normal var(--st-font);
  color: var(--st-text);
}

.lib-head__collapse.st-icon-btn--outlined { background: none; }
.lib-head__collapse .st-icon { width: 15px; height: 15px; }

.lib-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 8px 0 12px;
  border-radius: 10px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-surface);
  color: var(--st-text-faint);
  cursor: text;
}
.lib-search:focus-within { outline-color: var(--st-line-strong); }
.lib-search > .lib-icon { width: 15px; height: 15px; }

.lib-search__input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: var(--st-text);
  font: 400 13px/normal var(--st-font);
}
.lib-search__input::placeholder { color: var(--st-text-faint); opacity: 1; }
.lib-search__input { --st-focus-ring-style: none; }
/* The input's ring moves to its box, which the design already frames: one ring. */
.lib-search:has(.lib-search__input:focus-visible) { outline: 2px solid var(--st-accent); outline-offset: -1px; }
.lib-search__input::-webkit-search-cancel-button { display: none; }

/* ---- Sections --------------------------------------------------------------- */

.lib-section {
  container: lib-section / inline-size;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lib-section__head {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 4px;
}

.lib-section__toggle {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  /* The label is never clipped or overlapped: the actions go icon-only first (P72). */
  min-width: max-content;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: var(--st-text-faint);
  font: 500 10px/normal var(--st-font-mono);
  letter-spacing: 1.3px;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}
.lib-section__toggle:hover { color: var(--st-text-dim); }
.lib-section__chevron { transition: transform 0.15s; }
.lib-section__toggle[aria-expanded='false'] .lib-section__chevron { transform: rotate(-90deg); }

.lib-section__body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lib-section__body[hidden] { display: none; }

.lib-divider {
  flex: none;
  width: 100%;
  height: 1px;
  margin: 0;
  border: 0;
  background: var(--st-line);
}

.lib-new {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: none;
  color: var(--st-text-dim);
  font: 400 11px/normal var(--st-font);
  cursor: pointer;
}
.lib-new:hover { background: var(--st-surface-2); color: var(--st-text); }
.lib-new .lib-icon { width: 12px; height: 12px; }

/* ---- Empty states and notes ------------------------------------------------- */

.lib-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px;
  border-radius: 10px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  color: var(--st-text-faint);
  text-align: center;
}
.lib-empty .lib-icon { width: 16px; height: 16px; }
.lib-empty__title { margin: 0; color: var(--st-text-dim); font: 500 12.5px/normal var(--st-font); }
.lib-empty__body { margin: 0; color: var(--st-text-faint); font: 400 11.5px/17px var(--st-font); }

.lib-note {
  margin: 0;
  padding: 6px 10px;
  color: var(--st-text-faint);
  font: 400 12px/17px var(--st-font);
}

/* ---- Songs ------------------------------------------------------------------ */

.lib-list,
.lib-nest,
.lib-folders,
.lib-tags {
  margin: 0;
  padding: 0;
  list-style: none;
}

.lib-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lib-item__link,
.lib-item--unavailable {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 8px;
  border-radius: 10px;
  outline: 1px solid transparent;
  outline-offset: -0.5px;
  color: inherit;
  text-decoration: none;
}
.lib-item__link:hover { background: var(--st-surface); }
.lib-item__link[aria-current='true'] {
  outline-color: var(--st-line-strong);
  background: var(--st-surface-2);
}
.lib-item__link[aria-current='true']:focus-visible { outline-color: var(--st-accent); }

.lib-art {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: color-mix(in srgb, var(--st-on-accent) 80%, transparent);
}
.lib-art .lib-icon { width: 15px; height: 15px; }
.lib-art--0 { background: linear-gradient(-135deg, var(--st-art-rose) 14.6%, var(--st-art-violet) 85.4%); }
.lib-art--1 { background: linear-gradient(-135deg, var(--st-art-amber) 14.6%, var(--st-art-red) 85.4%); }
.lib-art--2 { background: linear-gradient(-135deg, var(--st-art-teal) 14.6%, var(--st-art-blue) 85.4%); }
.lib-art--3 { background: linear-gradient(-135deg, var(--st-art-lime) 14.6%, var(--st-art-sky) 85.4%); }

.lib-item--processing .lib-art { opacity: 0.7; color: var(--st-on-accent); }
.lib-item--processing .lib-art .lib-icon { width: 16px; height: 16px; }

.lib-spin { animation: lib-spin 1s linear infinite; }
/* Demo screenshots are frozen, so the spinner is too. */
html[data-demo]:not([data-demo='']) .lib-spin { animation: none; }
@media (prefers-reduced-motion: reduce) { .lib-spin { animation: none; } }
@keyframes lib-spin { to { transform: rotate(360deg); } }

.lib-item__meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.lib-item--processing .lib-item__meta { gap: 5px; }

.lib-item__title {
  overflow: hidden;
  color: var(--st-text);
  font: 500 13px/normal var(--st-font);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.lib-item--unavailable .lib-item__title { color: var(--st-text-dim); }

.lib-item__sub {
  overflow: hidden;
  color: var(--st-text-faint);
  font: 400 10.5px/normal var(--st-font-mono);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.lib-item__sub--busy { color: var(--st-accent-ink); font-size: 10px; }

.lib-item__sub--warn {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--st-stem-drums);
  font: 400 11px/normal var(--st-font);
}
.lib-item__sub--warn .lib-icon { width: 11px; height: 11px; }

/* A small button in the warning's colour (P72: no underlined-text actions), New's shape at the line's height.
   Inside a clipping line (.lib-item__sub hides its overflow), so the focus ring is drawn inside. */
.lib-item__reimport {
  --st-focus-offset: -2px;
  height: 18px;
  padding: 0 6px;
  border: 0;
  border-radius: 5px;
  outline: 1px solid color-mix(in srgb, currentColor 40%, transparent);
  outline-offset: -0.5px;
  background: none;
  color: inherit;
  font: 500 11px/normal var(--st-font);
  cursor: pointer;
}
.lib-item__reimport:hover { background: var(--st-surface-2); }

.lib-item__playing {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: var(--st-ok-strong);
}

.lib-progress {
  display: block;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: var(--st-line-strong);
  overflow: hidden;
}
.lib-progress__fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--st-accent);
}

/* ---- Folders ---------------------------------------------------------------- */

.lib-folders {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lib-folder-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lib-folder {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--st-text-dim);
  font: 400 13px/normal var(--st-font);
  text-align: left;
  cursor: pointer;
}
.lib-folder:hover { background: var(--st-surface); color: var(--st-text); }
.lib-folder__icon { color: var(--st-stem-drums); }
.lib-folder__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.lib-folder__count { color: var(--st-text-faint); font: 400 11px/normal var(--st-font-mono); }

.lib-folder--new { cursor: default; background: var(--st-surface); }
.lib-folder__input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--st-text);
  font: inherit;
}
.lib-folder__input { --st-focus-ring-style: none; }
.lib-folder--new:has(.lib-folder__input:focus-visible) { outline: 2px solid var(--st-accent); outline-offset: -1px; }

.lib-folder__items { padding-left: 16px; }
.lib-folder__items[hidden] { display: none; }

.lib-nest {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-left: 8px;
  border-left: 1px solid var(--st-line);
}
.lib-nest .lib-item__link { padding: 8px 10px; }

/* ---- Tags ------------------------------------------------------------------- */

.lib-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 5px;
  padding: 2px 4px;
}

.lib-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  border: 0;
  border-radius: 14px;
  outline: 1px solid var(--st-line);
  outline-offset: -0.5px;
  background: var(--st-surface);
  cursor: pointer;
}
.lib-tag:hover { outline-color: var(--st-line-strong); }
.lib .lib-tag:focus-visible { outline-color: var(--st-accent); }
.lib-tag__name { color: var(--st-text-dim); font: 400 12px/normal var(--st-font); white-space: nowrap; }
.lib-tag__count { color: var(--st-text-faint); font: 400 10px/normal var(--st-font-mono); }

.lib-tag[aria-pressed='true'] {
  outline-color: color-mix(in srgb, var(--st-accent) 33%, transparent);
  background: color-mix(in srgb, var(--st-accent) 12.5%, transparent);
}
.lib-tag[aria-pressed='true'] .lib-tag__name { color: var(--st-accent-ink); }

/* "See all history" (Recent, decision 62) and "Manage storage" (Stem collections, decision 71) look like New.
   When a header row is too tight for its label and the actions' text, the actions keep only their icon
   and show their tooltip (P72); with the text shown the tooltip would repeat it. The widths are the
   section's, measured: label, 6px gaps and 4px padding, plus 4px to spare. The label never shrinks. */
.lib-see-all { margin-left: auto; text-decoration: none; white-space: nowrap; }
.lib-section__head > .lib-new { flex: none; justify-content: center; }
.lib-section__head > .lib-new > .st-tip { display: none; }
@container lib-section (max-width: 187px) {
  [data-section='recent'] .lib-see-all { padding: 0 6px; }
  [data-section='recent'] .lib-see-all > span:not(.st-tip) { display: none; }
  [data-section='recent'] .lib-see-all > .st-tip { display: revert; }
}
@container lib-section (max-width: 332px) {
  [data-section='collections'] .lib-see-all { padding: 0 6px; }
  [data-section='collections'] .lib-see-all > span:not(.st-tip) { display: none; }
  [data-section='collections'] .lib-see-all > .st-tip { display: revert; }
}
/* New goes too: at 240px beside Manage storage, at 210px alone (signed out, a demo). */
@container lib-section (max-width: 240px) {
  .lib-see-all ~ .lib-new { padding: 0 6px; }
  .lib-see-all ~ .lib-new > span:not(.st-tip) { display: none; }
  .lib-see-all ~ .lib-new > .st-tip { display: revert; }
}
@container lib-section (max-width: 210px) {
  [data-section='collections'] .lib-new { padding: 0 6px; }
  [data-section='collections'] .lib-new > span:not(.st-tip) { display: none; }
  [data-section='collections'] .lib-new > .st-tip { display: revert; }
}
/* The narrowest Library (220px): the row gives up its padding and 2px of each gap. */
@container lib-section (max-width: 208px) {
  [data-section='collections'] .lib-section__head { gap: 4px; padding: 0; }
}
