/* =========================================================================
   The gallery controls in one line (owner, 22 Oct 2026: "change the stupid
   choose style buttons into a cleaner one line or something").

   Pulse's own file, injected by site.ts after the synced gallery.css, so a
   gallery sync can never overwrite it. It only lays out the controls the
   gallery already has: the four collection tabs become one segmented
   control, the search box sits on the same line, and the three rows of
   filter chips move into one popover (a bottom sheet on a phone).

   Colours come from the gallery's own tokens (--line, --ink, --cyan, ...),
   never from raw hex, and the motion is short and off under
   prefers-reduced-motion.
   ========================================================================= */

.apg { position: relative; margin: 0 0 2px; }
.apg-line { position: relative; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- The segmented control ---------- */
.apg-seg {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
  padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--glass);
}
.apg-seg .g-tab {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 0;
  min-height: 34px; padding: 0 14px; border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: var(--muted); font: 500 13.5px/1 var(--sans);
  text-align: center; white-space: nowrap; cursor: pointer;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.apg-seg .g-tab b { font-family: var(--sans); font-size: 13.5px; font-weight: 500; letter-spacing: 0; color: inherit; }
.apg-seg .g-tab:hover { color: var(--ink); background: var(--glass-2); border-color: transparent; }
.apg-seg .g-tab.active {
  color: var(--bg); font-weight: 600; border-color: transparent; box-shadow: none;
  background: linear-gradient(180deg, color-mix(in oklab, var(--cyan) 78%, var(--ink)), var(--cyan));
}
.apg-seg .g-tab.active b { font-weight: 600; }

/* ---------- The search box, on the same line ---------- */
.apg-searchrow { flex: 1 1 260px; min-width: 200px; max-width: 420px; }
.apg-searchrow .g-search { margin: 0; }
.apg-searchrow .g-search input { height: 40px; padding: 0 14px 0 40px; font-size: 14.5px; }
.apg-searchrow .g-search svg { left: 14px; width: 16px; height: 16px; }

.apg-iconbtn {
  display: none; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; padding: 0; border-radius: 999px;
  border: 1px solid var(--line); background: var(--glass); color: var(--muted); cursor: pointer;
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.apg-iconbtn:hover { color: var(--ink); border-color: var(--line-2); }

/* ---------- One Filters button ---------- */
.apg-filterbtn {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--glass); color: var(--ink);
  font: 500 14px/1 var(--sans); cursor: pointer; white-space: nowrap;
  transition: border-color 0.18s var(--ease), background-color 0.18s var(--ease);
}
.apg-filterbtn:hover { border-color: var(--cyan); background: var(--glass-2); }
.apg-filterbtn[aria-expanded="true"] { border-color: var(--cyan); background: var(--glass-2); }
.apg-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--cyan); color: var(--bg); font: 600 12px/1 var(--mono);
}
.apg-badge[hidden] { display: none; }

/* ---------- The popover (a bottom sheet on a phone) ---------- */
.apg-panel {
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 950;
  width: min(620px, calc(100vw - 32px)); max-height: min(70vh, 560px); overflow-y: auto;
  padding: 10px 16px 14px; border-radius: 18px; border: 1px solid var(--line-2);
  background: var(--bg-2); box-shadow: 0 30px 70px -30px color-mix(in oklab, var(--bg) 88%, transparent);
}
.apg-panel[hidden] { display: none; }
/* No room under the line (the page puts the controls low): open above it. */
.apg-panel.apg-up { top: auto; bottom: calc(100% + 10px); }
.apg-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 4px; }
.apg-panel-title { font: 600 14px/1 var(--sans); color: var(--ink); }
.apg-panel-head .apg-iconbtn { display: inline-flex; width: 34px; height: 34px; }
.apg-panel-body .g-chip-block { display: block; padding: 10px 0; border-top: 1px solid var(--line); }
.apg-panel-body .g-chip-block:first-child { border-top: 0; }
.apg-panel-body .g-chip-label { width: auto; padding-bottom: 7px; }

/* ---------- What is filtering now ---------- */
.apg-active { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 2px 0; }
.apg-active[hidden] { display: none; }
.apg-active-title { font: 500 11.5px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.apg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.apg-chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 30px; padding: 0 10px;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--glass); color: var(--ink);
  font: 500 13px/1 var(--sans); cursor: pointer;
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease);
}
.apg-chip:hover { border-color: var(--cyan); }
.apg-chip-group { color: var(--muted); font-size: 11.5px; }
.apg-chip-name { font-weight: 500; }
.apg-chip-x { color: var(--muted); font-size: 15px; line-height: 1; }
.apg-clearall {
  margin-left: auto; padding: 6px 2px; border: 0; background: none; color: var(--cyan);
  font: 600 13px/1 var(--sans); text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.apg-backdrop { display: none; }

/* The sheet owns the screen while it is open, so the My picks button steps aside. */
body.apg-sheet .g-fab { opacity: 0; pointer-events: none; }

/* ---------- A phone: the same line, the filters as a bottom sheet ---------- */
@media (max-width: 760px) {
  .apg-line { flex-wrap: wrap; gap: 8px; }
  .apg-seg { flex: 1 1 0; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .apg-seg::-webkit-scrollbar { display: none; }
  .apg-seg .g-tab { min-height: 38px; padding: 0 12px; font-size: 13px; }
  .apg-iconbtn.apg-searchbtn { display: inline-flex; }
  .apg-searchrow { display: none; }
  html.apg-search-open .apg-searchrow { display: block; flex: 1 1 100%; max-width: none; order: 5; }
  html.apg-search-open .apg-searchrow .g-search input { height: 44px; }
  .apg-filterbtn { min-height: 40px; padding: 0 12px; gap: 6px; font-size: 13.5px; }
  .apg-panel {
    position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto;
    max-height: 78vh; border-radius: 20px 20px 0 0; border-bottom: 0;
    padding: 10px 16px 18px;
  }
  /* The gallery scrolls a chip row sideways on a phone. In the sheet every chip
     shows at once, so nothing is hidden off the edge. */
  .apg-panel-body .g-chip-row { flex-wrap: wrap; overflow-x: visible; width: auto; margin: 0; padding: 0; }
  .apg-backdrop {
    display: block; position: fixed; inset: 0; z-index: 940;
    background: color-mix(in oklab, var(--bg) 76%, transparent);
  }
  .apg-backdrop[hidden] { display: none; }
  .apg-clearall { margin-left: 0; }
}

/* ---------- Motion off when the reader asked for it ---------- */
@media (prefers-reduced-motion: reduce) {
  .apg *, .apg *::before, .apg *::after { transition: none !important; animation: none !important; }
}
