/*
 * library-panel.css: the "Global library" panel (library-panel.js).
 *
 * Every layout rule is scoped under body.library-enabled, which
 * library-panel.js sets only when the navigation payload sets
 * library_enabled. With the flag off the panel, the overlay and the header
 * button stay [hidden] and nothing here applies, so the shell is unchanged.
 *
 * Mobile-first: below 64rem the panel is a full-height drawer behind the
 * header "Global library" button. From 64rem it is a third column of
 * .dashboard-main (a flex row), open by default and collapsible to a rail.
 * Colors come from the shell's theme tokens, so dark and light both work.
 */

.library-panel[hidden],
.library-overlay[hidden],
.library-toggle[hidden] {
  display: none !important;
}

/* ---- header button (phone / narrow) ---- */
body.library-enabled .library-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  width: auto;
  padding: 0 0.625rem;
  min-height: var(--touch-min, 2.75rem);
  font-size: 0.8125rem;
  white-space: nowrap;
}

/* ---- drawer (default, below 64rem) ---- */
body.library-enabled .library-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 96;
  opacity: 0;
  transition: opacity var(--transition-normal);
}
body.library-enabled .library-overlay.is-visible { opacity: 1; }

body.library-enabled .library-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 28rem;
  display: flex;
  flex-direction: column;
  background: var(--dash-bg-secondary);
  border-left: 0.0625rem solid var(--dash-border);
  box-shadow: var(--shadow-lg);
  color: var(--dash-text-primary);
  z-index: 97;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--transition-smooth), visibility var(--transition-smooth);
}
body.library-enabled .library-panel.is-open {
  transform: translateX(0);
  visibility: visible;
  /* Visible at once on open (an interpolated visibility stays "hidden" at
     the start, so focus() into the drawer would silently fail); hiding on
     close still waits for the slide-out via the base rule. */
  transition: transform var(--transition-smooth), visibility 0s;
}

.library-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--header-height);
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  border-bottom: 0.0625rem solid var(--dash-border);
  flex-shrink: 0;
}
.library-panel-title {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--dash-text-primary);
}

.library-collapse-btn,
.library-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-width: var(--touch-min, 2.75rem);
  min-height: var(--touch-min, 2.75rem);
  padding: 0 0.5rem;
  border: 0.0625rem solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--dash-text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.library-collapse-btn:hover,
.library-close-btn:hover {
  background: var(--dash-bg-hover);
  color: var(--dash-text-primary);
}
.library-collapse-btn { display: none; }

.library-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 0.75rem 1rem 1rem;
  gap: 0.75rem;
}

/* ---- tabs ---- */
.library-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 0.0625rem solid var(--dash-border);
  overflow-x: auto;
}
/* The body scrolls as a whole; its children keep their natural height (a
   shrinkable overflow child collapses to zero height in a flex column). */
.library-panel-body > * { flex-shrink: 0; }
.library-tabs[hidden] { display: none; }
.library-tab {
  min-height: var(--touch-min, 2.75rem);
  padding: 0 0.875rem;
  border: 0;
  border-bottom: 0.125rem solid transparent;
  background: transparent;
  color: var(--dash-text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
}
.library-tab:hover { color: var(--dash-text-primary); }
.library-tab.is-active,
.library-tab[aria-selected="true"] {
  color: var(--dash-text-primary);
  border-bottom-color: var(--dash-accent);
  font-weight: 600;
}

/* ---- filters ---- */
.library-tabpanel { display: flex; flex-direction: column; gap: 0.75rem; }
.library-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.library-filters[hidden],
.library-field[hidden] { display: none; }
.library-field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.library-field-search { grid-column: 1 / -1; }
.library-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--dash-text-secondary);
}
.library-search,
.library-select {
  width: 100%;
  min-height: var(--touch-min, 2.75rem);
  padding: 0 0.75rem;
  border: 0.0625rem solid var(--dash-border);
  border-radius: var(--radius-md);
  background: var(--dash-bg-primary);
  color: var(--dash-text-primary);
  font-size: 0.875rem;
}
.library-search:focus,
.library-select:focus {
  outline: none;
  border-color: var(--dash-accent);
  box-shadow: 0 0 0 0.1875rem var(--dash-accent-glow);
}

/* ---- status + list ---- */
.library-status {
  margin: 0;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  background: var(--dash-bg-tertiary);
  color: var(--dash-text-secondary);
  font-size: 0.875rem;
}
.library-status[hidden] { display: none; }
.library-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.library-list[aria-busy="true"] { opacity: 0.6; }
.library-item {
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem;
  border: 0.0625rem solid var(--dash-border);
  border-radius: var(--radius-lg);
  background: var(--dash-bg-elevated);
}
.library-item-icon {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--dash-bg-tertiary);
  color: var(--dash-accent);
  font-size: 0.9375rem;
}
.library-item-main { min-width: 0; }
.library-item-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--dash-text-primary);
}
.library-item-desc {
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--dash-text-secondary);
}
.library-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--dash-text-tertiary);
}
.library-chip {
  padding: 0.125rem 0.5rem;
  border-radius: 62.4375rem;
  background: var(--dash-bg-tertiary);
  color: var(--dash-text-secondary);
  text-transform: capitalize;
}
.library-item-actions {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.library-item-note {
  margin: 0;
  font-size: 0.75rem;
  color: var(--dash-text-muted);
}
.library-added {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--dash-accent);
}
.library-btn {
  min-height: 2.25rem;
  padding: 0 0.875rem;
  border-radius: var(--radius-md);
  border: 0.0625rem solid var(--dash-border);
  background: var(--dash-bg-tertiary);
  color: var(--dash-text-primary);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.library-btn:hover { background: var(--dash-bg-hover); border-color: var(--dash-border-hover); }
.library-btn:disabled { opacity: 0.6; cursor: progress; }
.library-add-btn {
  background: var(--dash-accent);
  border-color: var(--dash-accent);
  color: #fff;
}
.library-add-btn:hover { background: var(--dash-accent-hover); border-color: var(--dash-accent-hover); }

.library-panel button:focus-visible,
.library-toggle:focus-visible {
  outline: 0.125rem solid var(--dash-accent);
  outline-offset: 0.125rem;
}

/* Phones (the shell's 48rem breakpoint): icon-only, the size of every other
   header icon. With its label the button was 6.5rem wide and pushed the App
   Store, theme and user menu off a 375px screen (2026-11-18). The label stays
   in the accessibility tree (visually hidden), and the button also carries
   aria-label and title "Global library". */
@media (max-width: 48rem) {
  body.library-enabled .library-toggle {
    width: var(--touch-min, 2.75rem);
    padding: 0;
    gap: 0;
  }
  body.library-enabled .library-toggle span {
    position: absolute;
    width: 0.0625rem;
    height: 0.0625rem;
    margin: -0.0625rem;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
}

/* ---- desktop: a third column ---- */
@media (min-width: 64rem) {
  body.library-enabled .library-toggle,
  body.library-enabled .library-overlay,
  body.library-enabled .library-close-btn { display: none !important; }

  body.library-enabled .library-panel {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    width: 22rem;
    max-width: none;
    min-width: 22rem;
    flex: 0 0 22rem;
    box-shadow: none;
    transform: none;
    visibility: visible;
    z-index: 30;
    transition: width var(--transition-smooth), min-width var(--transition-smooth), flex-basis var(--transition-smooth);
  }
  body.library-enabled .library-collapse-btn { display: inline-flex; }

  body.library-enabled .library-panel.is-collapsed {
    width: 3.5rem;
    min-width: 3.5rem;
    flex-basis: 3.5rem;
  }
  body.library-enabled .library-panel.is-collapsed .library-panel-header {
    flex-direction: column;
    padding: 0.5rem 0.25rem;
  }
  body.library-enabled .library-panel.is-collapsed .library-panel-title,
  body.library-enabled .library-panel.is-collapsed .library-panel-body { display: none; }
  body.library-enabled .library-panel.is-collapsed .library-collapse-btn {
    flex-direction: column;
    padding: 0.5rem 0.25rem;
    font-size: 0.6875rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.library-enabled .library-panel,
  body.library-enabled .library-overlay { transition: none; }
}
