/* The library page (library.astro): app bar, toolbar, masonry, filter sheet.
   Global on purpose — library.js builds columns and chips at runtime. Uses the
   design tokens from Base.astro and the card styles from recipe-card.css. */

.lib-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px 72px;
}

/* ---- App bar ----------------------------------------------------------- */

.lib-app {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 20px;
  padding: 20px 20px 22px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--border2);
}
.lib-app-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 760;
  letter-spacing: -0.025em;
  color: var(--text1);
}
.lib-app-sub {
  margin: 6px 0 0;
  max-width: 46ch;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text3);
}

/* ---- Toolbar ---------------------------------------------------------- */

.lib-bar {
  position: sticky;
  top: 58px;
  z-index: 30;
  margin: 0 -16px;
  padding: 0 16px;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
}
.lib-bar-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 0 14px;
}
.lib-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lib-search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}
.lib-search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text5);
  pointer-events: none;
}
.lib-search-input {
  width: 100%;
  height: 46px;
  padding: 0 16px 0 42px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text1);
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming the page on focus */
  box-shadow: var(--shadow-sm);
  appearance: none;
  -webkit-appearance: none;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}
.lib-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 26%, transparent);
}
.lib-search-input::-webkit-search-cancel-button {
  cursor: pointer;
}

.lib-filter-btn {
  height: 46px;
  padding: 0 18px;
  flex: 0 0 auto;
}
.lib-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-strong);
  color: var(--on-accent);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1;
}
.lib-badge[hidden] {
  display: none;
}

.lib-count {
  margin: 0;
  flex: 0 0 auto;
  font-size: 13.5px;
  color: var(--text4);
  font-variant-numeric: tabular-nums;
}

.lib-active {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.lib-active[hidden] {
  display: none;
}
.lib-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 11px 0 13px;
  border-radius: 999px;
  border: 1px solid var(--tint-border);
  background: var(--tint);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
.lib-chip:hover {
  border-color: var(--accent);
}
.lib-chip-clear {
  height: 30px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text3);
  font-size: 13px;
  font-weight: 620;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.lib-chip-clear:hover {
  color: var(--text1);
}

/* ---- Masonry ---------------------------------------------------------- */

.lib-content {
  margin-top: 18px;
}
/* Without script the server-rendered page still reads as a masonry. */
.lib-grid {
  column-count: 2;
  column-gap: 16px;
}
.lib-grid .lib-item {
  break-inside: avoid;
  margin-bottom: 16px;
}
.lib-grid.is-masonry {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  column-count: auto;
}
.lib-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.lib-grid.is-masonry .lib-item {
  margin-bottom: 0;
}

.lib-item {
  position: relative;
}
.lib-item .recipe-card {
  height: auto;
}

.lib-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 72px 16px;
  text-align: center;
}
.lib-empty[hidden],
.lib-empty .btn[hidden] {
  display: none;
}
.lib-empty-title {
  margin: 0;
  font-size: 20px;
  font-weight: 720;
  letter-spacing: -0.02em;
  color: var(--text1);
}
.lib-empty-sub {
  margin: 0 0 8px;
  max-width: 40ch;
  font-size: 15px;
  color: var(--text3);
}

.lib-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 28px;
  min-height: 24px;
}
.lib-loading,
.lib-retry p {
  margin: 0;
  font-size: 14px;
  color: var(--text4);
}
.lib-loading[hidden],
.lib-retry[hidden] {
  display: none;
}
.lib-retry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* ---- Filter sheet ------------------------------------------------------ */

body:has(dialog[open]) {
  overflow: hidden;
}

.lib-panel {
  position: fixed;
  inset: auto 0 0 0;
  margin: 0;
  width: 100%;
  max-width: none;
  max-height: 88dvh;
  padding: 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--card);
  color: var(--text1);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.lib-panel[open] {
  display: flex;
  flex-direction: column;
  animation: lib-sheet-up 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.lib-panel::backdrop {
  background: rgba(24, 16, 8, 0.46);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}
.lib-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}
.lib-panel-title {
  margin: 0;
  font-size: 20px;
  font-weight: 740;
  letter-spacing: -0.022em;
}
.lib-panel-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--chipbg1);
  color: var(--text2);
  cursor: pointer;
}
.lib-panel-close:hover {
  color: var(--text1);
}
.lib-panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 20px 12px;
}
.lib-group {
  margin: 0 0 22px;
  padding: 0;
  border: 0;
  min-width: 0;
}
.lib-group-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text4);
}
.lib-group-hint {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text5);
}
.lib-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.lib-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--chipbg2);
  color: var(--text2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}
.lib-option:hover {
  border-color: var(--text5);
}
.lib-option[aria-pressed='true'] {
  background: var(--tint);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.lib-option-n {
  font-size: 12px;
  font-weight: 600;
  color: var(--text5);
  font-variant-numeric: tabular-nums;
}
.lib-option[aria-pressed='true'] .lib-option-n {
  color: inherit;
  opacity: 0.8;
}
.lib-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--card);
}

@keyframes lib-sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}
@keyframes lib-sheet-in {
  from {
    transform: translateX(40px);
    opacity: 0;
  }
}

@media (min-width: 640px) {
  .lib-grid {
    column-count: 3;
  }
}
@media (min-width: 768px) {
  .lib-shell {
    padding: 0 32px 96px;
  }
  .lib-app {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    margin-top: 28px;
    padding: 22px 28px;
  }
  .lib-bar {
    top: 64px;
    margin: 0 -32px;
    padding: 0 32px;
  }
  .lib-bar-inner {
    padding-top: 26px;
  }
  .lib-panel {
    inset: 0 0 0 auto;
    width: 420px;
    max-height: none;
    height: 100dvh;
    border-radius: 24px 0 0 24px;
  }
  .lib-panel[open] {
    animation-name: lib-sheet-in;
  }
}
@media (min-width: 1000px) {
  .lib-grid {
    column-count: 4;
  }
}
