/* ══════════════════════════════════════════════════════════════════════
   Relations Panel — shared styling
   ══════════════════════════════════════════════════════════════════════

   Canonical vocabulary for "related chords" and "related scales" panels.
   Used by BOTH:

     • Scale Explorer route (#route-scale-explorer)
     • Scales + Chords routes (v2 skin — the only skin now)

   The SOURCE OF TRUTH for visuals lives here — no duplicates elsewhere.
   When tweaking the relations-panel look, change this file, not
   scale-explorer.css or scales-v2.css.

   Rules are written unscoped so the same classes render identically
   wherever they appear.  Variables (--accent, --surface-2, --border,
   --text-2, --text-3, --r-sm, --font, etc.) are inherited from the
   global :root in site.css.

   Vocabulary:

     .rel-body                  panel body padding (inside a .relations-panel or card)
     .rel-grid                  legacy flat pill list (span tags)
     .rel-tag                   single pill tag (.rt-name, .rt-roots inside)
     .rel-toolbar               expand/collapse-all row
     .rel-acc                   accordion wrapper
       .rel-acc-header            row holding toggle + optional column ctrl
       .rel-acc-toggle            chevron + label + count button
       .rel-acc-chevron           rotates on .open
       .rel-acc-label             title text
       .rel-acc-count             count in parens
       .rel-acc-body              hidden until .rel-acc--open
     .rel-col-ctrl              − [n] + column widget
       .rel-col-minus/plus/input
     .rel-family-grid           multi-column grid driven by --rel-cols
       .rel-family-section        one family column
         .rel-family-label          family header with accent underline
         .rel-type-rows             stack of type rows
           .rel-type-row              row: badge + roots
             .rel-type-badge          type name (e.g. "Major 7")
             .rel-type-badge--formula monospace variant for unnamed scales
             .rel-type-roots          accent-coloured list
               .rel-root-link         clickable root
               .rel-root-sep          comma separator
     .rel-unnamed-row           legacy

   ══════════════════════════════════════════════════════════════════════ */

/* ── Panel body (inside an existing card/panel) ─────────────────────── */
.relations-panel .rel-body { padding: var(--space-lg) var(--space-xl); }

/* ── Flat pill list (legacy — still used in a few places) ─────────── */
.rel-grid { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-top: var(--space-xs); }
.rel-tag {
  font-size: var(--font-xs);
  padding: var(--space-2xs) var(--space-sm);
  background: var(--surface-2);
  border: var(--border-w, 1px) solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--t-fast, .12s);
}
.rel-tag:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.rel-tag:hover .rt-roots,
.rel-tag:hover .rt-name { color: rgba(255,255,255,0.8); }
.rel-tag .rt-name {
  color: var(--text-2);
  font-style: italic;
  margin-left: var(--space-xs);
}
.rel-tag .rt-name::before { content: '('; }
.rel-tag .rt-name::after  { content: ')'; }
.rel-tag .rt-roots {
  color: var(--text-2);
  margin-left: 0.2143rem;
  font-weight: var(--weight-semibold);
}

/* ── Expand/Collapse-all toolbar ───────────────────────────────────── */
.rel-toolbar { display: flex; gap: var(--space-xs); }
.rel-toolbar button {
  font-size: var(--font-xs); font-weight: var(--weight-semibold);
  padding: var(--space-2xs) var(--space-sm);
  border: var(--border-w, 1px) solid var(--border);
  border-radius: var(--r-sm, var(--radius-sm));
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: background var(--t-fast, .15s);
}
.rel-toolbar button:hover { background: var(--surface-2); color: var(--text); }

/* ── Accordion Sections ────────────────────────────────────────────── */
.rel-acc { border-bottom: none; margin-bottom: var(--space-xs); }
.rel-acc + .rel-acc { border-top: var(--border-w-thick, 2px) solid var(--border); padding-top: var(--space-xs); }
.rel-acc-toggle {
  display: flex; align-items: center; gap: var(--space-xs);
  width: 100%;
  padding: var(--space-sm) 0;
  background: none; border: none;
  cursor: pointer;
  font-size: var(--font-sm); font-weight: var(--weight-semibold); color: var(--text);
  text-align: left;
  font-family: var(--font);
}
.rel-acc-toggle:hover { color: var(--accent); }
.rel-acc-chevron {
  display: inline-block;
  font-size: 0.6429rem;     /* ~9 px */
  color: var(--text-3);
  transition: transform var(--t-normal, .2s);
  width: 0.7143rem; text-align: center;
}
.rel-acc-chevron.open { transform: rotate(90deg); }
.rel-acc-count {
  font-weight: var(--weight-normal);
  color: var(--text-3);
  font-size: var(--font-sm);
}
.rel-acc-body {
  padding-bottom: var(--space-sm);
  border-top: var(--border-w, 1px) solid var(--border);
  margin-top: var(--space-2xs);
  padding-top: var(--space-sm);
}

/* Sub-level accordions (legacy) */
.rel-acc--sub { border-bottom: none; margin-left: var(--space-md); }
.rel-acc--sub .rel-acc-toggle { font-size: var(--font-sm); font-weight: var(--weight-semibold); padding: var(--space-xs) 0; color: var(--text-2); }
.rel-acc--sub .rel-acc-toggle:hover { color: var(--accent); }
.rel-acc--sub .rel-acc-body { padding-bottom: var(--space-xs); }

/* Accordion header row (toggle + column ctrl) */
.rel-acc-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm);
}
/* Hide column control when accordion is collapsed */
.rel-acc:not(.rel-acc--open) .rel-col-ctrl { display: none; }

/* ── Column control (−  [n]  +) inline in accordion header ─────────── */
.rel-col-ctrl {
  display: inline-flex; align-items: center; gap: 0;
  border: var(--border-w, 1px) solid var(--border);
  border-radius: var(--r-sm, var(--radius-sm));
  overflow: hidden;
  flex-shrink: 0;
}
.rel-col-minus,
.rel-col-plus {
  width: 1.7143rem; height: 1.5714rem;     /* ~24x22 px */
  border: none; background: var(--surface);
  color: var(--text-2);
  font-size: var(--font-sm); font-weight: var(--weight-semibold);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-fast, .12s);
}
.rel-col-minus:hover,
.rel-col-plus:hover { background: var(--surface-2); color: var(--text); }
.rel-col-input {
  width: 1.7143rem; height: 1.5714rem;
  border: none;
  border-left: var(--border-w, 1px) solid var(--border);
  border-right: var(--border-w, 1px) solid var(--border);
  background: var(--surface-2);
  text-align: center;
  font-size: var(--font-xs); font-weight: var(--weight-semibold);
  color: var(--text);
  font-family: var(--font);
  padding: 0;
}

/* ── Family grid (chord families / cardinality buckets as columns) ──
   --rel-cols sets the desired column count; columns wrap when they'd
   shrink below ~150px so narrow viewports stay readable.               */
/* APPROACH B (owner 2026-07-12): the members-only chord categories fold
   into ONE faded block behind a single gate — it must span the full grid
   width (not sit in one auto-fill track), and its faded sections keep the
   same multi-column tiling as the free grid above. */
.rel-gated-block { grid-column: 1 / -1; }
.rel-gated-block > .fly-faded-block {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0 20px;
  margin-top: var(--space-sm);
}

.rel-family-grid {
  display: grid;
  /* Column min is raised to 200px so the widest uppercase family label
     ("NON-STRICT TRIADS (37)", "SHELL VOICINGS (NO5)") fits on one row
     with its count intact.  auto-fill then reflows to fewer columns
     whenever the container can't host the current --rel-cols at 200px. */
  grid-template-columns: repeat(
    auto-fill,
    minmax(
      max(200px, calc((100% - (var(--rel-cols, 6) - 1) * 20px) / var(--rel-cols, 6))),
      1fr
    )
  );
  gap: 0 20px;
  /* Top-align family columns so each sizes to its own content rather
     than stretching to the tallest in its row.  Per user 2026-06-13:
     "top align everything". */
  align-items: start;
}

/* ── Type-badge + roots layout ─────────────────────────────────────── */
.rel-family-section { margin-bottom: var(--space-xs); }
.rel-family-section:last-child { margin-bottom: 0; }
.rel-family-label {
  font-size: var(--font-xs); font-weight: var(--weight-bold);
  line-height: var(--leading-normal, 1.5);
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text);
  padding: var(--space-xs) var(--space-sm);
  margin-bottom: var(--space-2xs);
  background: var(--surface-2);
  border-bottom: var(--border-w-thick, 2px) solid var(--accent);
  border-radius: var(--r-sm, var(--radius-sm)) var(--r-sm, var(--radius-sm)) 0 0;
  /* Title + count stay welded on a single line — never wrap the count
     to its own row.  If a column can't fit the full label the grid
     track drops to the next row (see .rel-family-grid below).         */
  white-space: nowrap;
  box-sizing: border-box;
}
/* Outside a grid (standalone), keep label compact */
.rel-family-section:not(.rel-family-grid > *) > .rel-family-label {
  display: inline-block;
}
/* T36 — Slash chord section: dimmer accent so they read as a side
   category, not equal-weight with native chord families. */
.rel-family-section--slash > .rel-family-label {
  border-bottom-color: var(--text-muted, #888);
  /* No italic — matches the regular family-label weight so columns line
     up vertically with the Chords Contained accordion above. */
  /* These titles are chord SYMBOLS (m7b5, m7) — uppercasing them is
     wrong (m7→M7 reads as a different chord).  Drop the caps + letter-
     spacing and lean on extra weight to keep them reading as titles.
     Per user 2026-06-13. */
  text-transform: none;
  letter-spacing: 0;
  font-weight: var(--weight-bold, 700);
}

/* Family/group tag inside the type-section label (slash columns only).
   Subdued so the chord-type name reads as primary. */
.rel-family-label-sub {
  font-weight: var(--weight-medium);
  color: var(--text-3, #888);
  letter-spacing: 0;
  text-transform: none;
  font-size: var(--font-xs);
}

/* When the slash section uses the "no badge column" layout, the
   .rel-type-roots fragment spans the full row instead of column 2 of
   the invisible 2-col grid. */
.rel-type-roots--full {
  grid-column: 1 / -1;
}
/* .rel-type-rows is laid out as an invisible two-column grid: column 1
   holds every .rel-type-badge (sized to the widest badge in the section)
   and column 2 holds the .rel-type-roots list.  .rel-type-row uses
   `display: contents` so its children promote into the grid — this keeps
   the JS markup unchanged while gaining perfect alignment across rows.   */
.rel-type-rows {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: var(--space-sm);
  row-gap: 0.2143rem;
  padding: 0 var(--space-2xs);
  /* Top-align the type badge with the first line of its (possibly
     multi-line) value list.  Per user 2026-06-13: "top align everything". */
  align-items: start;
}
.rel-type-row {
  display: contents;
}
.rel-type-badge {
  font-size: var(--font-sm); font-weight: var(--weight-semibold);
  color: var(--text);
  white-space: nowrap;
  padding: 0.2143rem 0;
  line-height: var(--leading-normal, 1.5);
}
.rel-type-badge--formula {
  font-family: var(--font-mono, 'SF Mono', 'Consolas', monospace);
  font-size: var(--font-xs); font-weight: var(--weight-medium);
  color: var(--text-2);
}
.rel-type-roots {
  font-size: var(--font-sm);
  color: var(--accent);
  font-weight: var(--weight-medium);
  padding: 0.2143rem 0;
  line-height: var(--leading-normal, 1.5);
}
.rel-root-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: opacity var(--t-fast, .12s);
}
/* Picker mode emits a <button> instead of an <a> (e.g. Fretboard Lab) —
   strip native button chrome so it reads as the same inline link. */
button.rel-root-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
}
.rel-root-link:hover {
  text-decoration: underline;
  opacity: 0.8;
}
.rel-root-sep {
  color: var(--text-3);
  font-weight: var(--weight-normal);
}
/* Unnamed scales grid within a family section (legacy) */
.rel-unnamed-row { margin-top: var(--space-xs); }

/* ══════════════════════════════════════════════════════════════════════
   PANEL STYLE VARIANTS  —  html[data-rel-style="…"]
   ══════════════════════════════════════════════════════════════════════
   Admin-settable, app-wide visual styles for the "…-contained" relations
   panels.  Driven by FretlyDisplayConfig.containedPanelStyle →
   <html data-rel-style>.  Catalog + apply helper:
   assets/js/shared/music-page/contained-panel-styles.js.  PHP whitelist:
   api/display-config.php.

     classic  — base look above (no overrides; orange names, accent rules).
     clean    — soft cards, calm neutral symbols, orange-on-hover, masonry.
     compact  — denser type + tighter rows, classic palette.
     minimal  — no card chrome, hairline headers, monochrome symbols.
     framed   — bordered family cards with an accent-dot header.

   Variants only ADD overrides; the DOM + JS renderer are unchanged so the
   single shared module (route-relations-panels.js) feeds every style.
   ══════════════════════════════════════════════════════════════════════ */

/* ── Clean (default) ─────────────────────────────────────────────────── */
/* Top-aligned responsive grid (NOT masonry): each card sits at the top of
   its row track so rows line up cleanly.  Inherits grid-template-columns +
   --rel-cols from the base .rel-family-grid rule. */
html[data-rel-style="clean"] .rel-family-grid {
  align-items: start;
  gap: 14px;
}
html[data-rel-style="clean"] .rel-family-section {
  background: var(--surface-2);
  border: var(--border-w, 1px) solid var(--border);
  border-radius: var(--radius-lg, 12px);
  padding: var(--space-sm) var(--space-md, 12px);
  margin-bottom: 14px;
}
html[data-rel-style="clean"] .rel-family-label {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  /* Slightly-less-subtle divider beneath the family title.  Per user
     2026-06-13: "a slightly less subtle one below the section titles". */
  border-bottom: var(--border-w, 1px) solid var(--border, #e0ddd5);
  border-radius: 0;
  padding: 0 0 var(--space-2xs);
  margin-bottom: var(--space-xs);
  color: var(--text-2);
  letter-spacing: 0.05em;
  white-space: normal;
}
/* Orange accent dot before the family name (prototype parity). */
html[data-rel-style="clean"] .rel-family-label::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
  flex: 0 0 auto;
}
/* Count sits flush right in the card header. */
html[data-rel-style="clean"] .rel-family-label .rel-acc-count { margin-left: auto; }
html[data-rel-style="clean"] .rel-type-badge { color: var(--text-2); font-weight: var(--weight-medium, 500); }
html[data-rel-style="clean"] .rel-type-roots,
html[data-rel-style="clean"] .rel-root-link {
  color: var(--text-2);
  font-weight: var(--weight-normal, 400);
  /* Monospace symbols so superscripts (maj7, b5, #11) align — prototype look. */
  font-family: var(--font-mono, ui-monospace, 'SF Mono', Menlo, Consolas, monospace);
}
html[data-rel-style="clean"] .rel-root-link:hover { color: var(--accent); opacity: 1; text-decoration: none; }
html[data-rel-style="clean"] .rel-root-sep { color: var(--text-3); }
/* Subtle hairline between chord-type rows.  Promote each row to a
   subgrid item so ONE line spans the full row even when the value list
   wraps to two lines; the badge/value column alignment is inherited
   from the parent .rel-type-rows grid (max-content 1fr).  Per user
   2026-06-13: "add subtle separator lines". */
html[data-rel-style="clean"] .rel-type-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: start;
  padding-bottom: 0.2143rem;
  border-bottom: var(--border-w, 1px) solid
    color-mix(in srgb, var(--border, #e0ddd5) 55%, transparent);
}
html[data-rel-style="clean"] .rel-type-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
/* Slash-chord card titles are chord SYMBOLS (m7b5, m7) — never all-caps.
   Lowercase + tight, and a touch larger/darker/bolder so they still read
   as titles without the caps that would corrupt the symbol.  Per user
   2026-06-13. */
html[data-rel-style="clean"] .rel-family-section--slash > .rel-family-label {
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--font-sm);
  font-weight: var(--weight-bold, 700);
  color: var(--text-1, #1a1a18);
}

/* ── Compact ─────────────────────────────────────────────────────────── */
html[data-rel-style="compact"] .rel-family-grid { gap: 0 14px; }
html[data-rel-style="compact"] .rel-family-label {
  font-size: var(--font-2xs, 11px);
  padding: var(--space-2xs) var(--space-xs);
}
html[data-rel-style="compact"] .rel-type-rows { row-gap: 0; column-gap: var(--space-xs); }
html[data-rel-style="compact"] .rel-type-badge,
html[data-rel-style="compact"] .rel-type-roots { font-size: var(--font-xs); padding: 0.1rem 0; }

/* ── Minimal ─────────────────────────────────────────────────────────── */
html[data-rel-style="minimal"] .rel-family-label {
  background: transparent;
  border-bottom: none;
  border-radius: 0;
  padding: 0 0 0.1429rem;
  color: var(--text-3);
  font-weight: var(--weight-semibold);
}
html[data-rel-style="minimal"] .rel-family-section {
  padding-bottom: var(--space-xs);
  border-bottom: var(--border-w, 1px) solid var(--border);
  margin-bottom: var(--space-sm);
}
html[data-rel-style="minimal"] .rel-type-roots,
html[data-rel-style="minimal"] .rel-root-link { color: var(--text-2); }
html[data-rel-style="minimal"] .rel-root-link:hover { color: var(--accent); opacity: 1; }

/* ── Framed ──────────────────────────────────────────────────────────── */
html[data-rel-style="framed"] .rel-family-grid { row-gap: 14px; align-items: start; }
html[data-rel-style="framed"] .rel-family-section {
  background: var(--surface);
  border: var(--border-w, 1px) solid var(--border);
  border-radius: var(--radius-lg, 12px);
  padding: var(--space-sm) var(--space-md, 12px);
}
html[data-rel-style="framed"] .rel-family-label {
  background: transparent;
  border-bottom: none;
  border-radius: 0;
  padding: 0 0 var(--space-2xs);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: normal;
}
html[data-rel-style="framed"] .rel-family-label::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
}

/* ── Filter toolbar (live search + category tabs) ────────────────────
   Built by route-relations-panels.js _buildRelToolbar; sits at the top of
   an accordion body.  Tokens only — adapts to theme + style variant. */
.rel-toolbar2 {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin: 0 0 var(--space-sm);
}
.rel-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.rel-tab {
  font-family: var(--font);
  font-size: var(--font-xs);
  padding: 4px 12px;
  border-radius: 999px;
  border: var(--border-w, 1px) solid var(--border);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-fast, .12s), color var(--t-fast, .12s);
}
.rel-tab:hover { background: var(--surface-2); color: var(--text); }
.rel-tab--on {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong, var(--border-2, var(--border)));
  font-weight: var(--weight-semibold);
}
.rel-search {
  margin-left: auto;
  height: 1.857rem;          /* ~26px */
  min-width: 8rem;
  max-width: 13rem;
  font-family: var(--font);
  font-size: var(--font-xs);
  padding: 0 var(--space-sm);
  border: var(--border-w, 1px) solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
}

/* ── Admin "Set as default" button (scale page settings → Admin) ─────── */
.rel-style-setdefault {
  margin-top: var(--space-sm);
  font-size: var(--font-xs);
  font-weight: var(--weight-semibold);
  padding: var(--space-2xs) var(--space-md, 12px);
  border: var(--border-w, 1px) solid var(--border);
  border-radius: var(--r-sm, var(--radius-sm));
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t-fast, .12s), color var(--t-fast, .12s);
}
.rel-style-setdefault:hover { background: var(--surface-2); color: var(--text); }
.rel-style-setdefault--saved { border-color: var(--accent); color: var(--accent); }

/* ══════════════════════════════════════════════════════════════════════
   Scales route v2 — sibling info-panels on the same row when they fit
   ══════════════════════════════════════════════════════════════════════
   When .info-panels-row wraps the three scale-relation panels
   (chords, sub-scales, parent-scales), each child flexes to a minimum
   width derived from its column count.  If the viewport is wide enough
   to hold the total columns, siblings share a row; otherwise they wrap
   below each other.  Only v2 emits this wrapper — v1 panels stack
   as before.                                                              */
.info-panels-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--panel-gap, 16px);
  margin-bottom: var(--panel-gap, 16px);
}
.info-panels-row > .info-panel {
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
  width: 100%;
}

/* ══════════════════════════════════════════════════════════════════════
   Scales route v2 — sub-scales panel: two side-by-side CARDS (Phase 8O)
   ══════════════════════════════════════════════════════════════════════
   `#subScalesPanel` is declared as an `.info-panel` in app.php so that on
   v1 it looks like a single card containing both sections.  Under v2 we
   want two distinct cards ("Scales Contained in This Scale" and "Scales
   Containing This Scale") sitting side-by-side.  To get there:

     • Neutralise the outer .info-panel card styling on #subScalesPanel
       itself — no bg / border / padding / shadow — so only the inner
       .info-panel--rel-card children render as cards.
     • Lay the inner cards out with auto-fit grid: when two 380-px tracks
       fit, they share a row; otherwise the second wraps below.
     • scales.js (v2 branch) wraps each .rel-acc in a fresh .info-panel
       .info-panel--rel-card div before appending.                         */
/* `#route-scales` is included in the selector to match the specificity
   of `#route-scales .info-panel` in
   scales-v2.css — without it, that generic v2 card-styling rule would
   win (specificity 1,2,1 vs 1,1,0) and #subScalesPanel would render as
   a visible white card wrapping its two inner rel-cards.  When the two
   inner cards have unequal content heights, the visible wrapper card
   would extend below the shorter one and look like a third empty card
   sitting below the relation cards.  Boosting specificity here strips
   the wrapper styling so only the inner cards render as cards.          */
#route-scales #subScalesPanel {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  overflow: visible;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  column-gap: 20px;
  row-gap: 8px;
  /* `align-items: stretch` (default for grid) makes both inner cards
     fill the row's full height, so the "Scales Contained" and "Scales
     Containing" cards always render at the same height — even when
     one has more rows of content than the other. */
  align-items: stretch;
}
/* Inner relation cards — each one is a real .info-panel, so it already
   inherits bg/border/padding/shadow from the global rule.  We only need
   to kill its default top-margin (the grid gap owns spacing here) and
   make sure each card stretches to match the grid track height.         */
#route-scales #subScalesPanel > .info-panel--rel-card {
  margin-top: 0;
  height: 100%;
  box-sizing: border-box;
}
