/* ============================================================
   v6 Left rail tabs — Patterns / Sounds / Songs
   ============================================================
   Injected into #patternLibrarySidebar at runtime by
   src/ui/LeftRailTabs.js. The existing patterns view stays
   untouched — it's just moved into a tab pane.
*/

@layer v6-components {

  /* ============================================================
     Song switcher — the first door in the rail
     ============================================================ */
  .v6-rail-song-switcher {
    padding: 8px 8px 6px;
    background: var(--surface-200, #111114);
    border-bottom: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
  }
  .v6-rail-song-switcher__button {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 42px;
    padding: 7px 9px;
    background: linear-gradient(135deg, rgba(139,92,246,.16), rgba(236,72,153,.08));
    border: 1px solid rgba(139,92,246,.28);
    border-radius: 9px;
    color: var(--text-primary, #fafafa);
    text-align: left;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
  }
  .v6-rail-song-switcher__button:hover {
    border-color: rgba(236,72,153,.55);
    background: linear-gradient(135deg, rgba(139,92,246,.22), rgba(236,72,153,.13));
    transform: translateY(-1px);
  }
  .v6-rail-song-switcher__button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface-200, #111114), 0 0 0 4px var(--accent-primary, #8b5cf6);
  }
  .v6-rail-song-switcher__icon {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #f0abfc;
    background: rgba(236,72,153,.16);
    border-radius: 7px;
    flex: 0 0 auto;
  }
  .v6-rail-song-switcher__copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
  }
  .v6-rail-song-switcher__label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .v6-rail-song-switcher__current {
    overflow: hidden;
    color: var(--text-secondary, #a1a1aa);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .v6-rail-song-switcher__chevron {
    color: var(--text-muted, #71717a);
    flex: 0 0 auto;
    transition: transform 120ms ease;
  }
  .v6-rail-song-switcher__button[aria-expanded="true"] .v6-rail-song-switcher__chevron {
    transform: rotate(90deg);
    color: var(--accent-primary, #8b5cf6);
  }

  /* ============================================================
     Tab bar
     ============================================================ */
  .v6-rail-tabs {
    /* Auto-fit lets us add tabs (v7 added "Library" as a 4th tab) without
       wrapping to a 2nd row — each tab takes an equal share of the width. */
    display: grid;
    grid-auto-flow: column;
    /* minmax(0, 1fr), NOT 1fr: a bare 1fr track has an AUTO minimum, so a tab
       can never shrink below its own content and four of them overflowed a
       260px rail — the "Library" tab was clipped off the right edge. This was
       masked while the layer's padding was being zeroed by the unlayered
       reset; the moment padding applied, the overflow became visible. */
    grid-auto-columns: minmax(0, 1fr);
    gap: 2px;
    padding: 6px 8px 0;
    background: var(--surface-300, #18181b);
    border-bottom: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
  }

  .v6-rail-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 2px;
    /* Never grow past the grid track. */
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;

    background: transparent;
    border: 1px solid transparent;
    border-bottom: 2px solid transparent;
    border-radius: var(--radius-sm, 4px) var(--radius-sm, 4px) 0 0;
    color: var(--text-muted, #71717a);

    font-family: var(--font-sans, system-ui);
    /* 10px with tight tracking so all four labels READ at a ~260px rail.
       At 11px/0.06em "Patterns" and "Library" ellipsized. */
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.01em;
    line-height: 1;

    cursor: pointer;
    transition: background var(--duration-fast, 120ms),
                color var(--duration-fast, 120ms),
                border-color var(--duration-fast, 120ms);
  }
  /* Four tabs share a ~260px rail, so the icon is the first thing to go: an
     ellipsized "LIBRAR" is worse than no icon. Kept in the DOM (and in the
     tooltip) rather than removed, so nothing else has to change. */
  .v6-rail-tab .v6-icon {
    display: none;
  }
  .v6-rail-tab__label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .v6-rail-tab:hover {
    background: var(--surface-400, #1f1f23);
    color: var(--text-secondary, #a1a1aa);
  }
  .v6-rail-tab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface-200, #111113), 0 0 0 4px var(--accent-primary, #8b5cf6);
  }
  .v6-rail-tab--active {
    background: var(--surface-400, #1f1f23);
    color: var(--text-primary, #fafafa);
    border-bottom-color: var(--accent-primary, #8b5cf6);
  }
  .v6-rail-tab--active .v6-icon {
    color: var(--accent-primary, #8b5cf6);
  }

  .v6-rail-tab__label {
    /* Hide labels on collapsed sidebar */
  }
  .pattern-library-sidebar.collapsed .v6-rail-tab__label { display: none; }

  /* ============================================================
     Pane container
     ============================================================ */
  .v6-rail-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  .v6-rail-pane[hidden] {
    display: none !important;
  }

  .v6-rail-pane__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 6px;
    border-bottom: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
  }
  .v6-rail-pane__title {
    margin: 0;
    font-family: var(--font-sans, system-ui);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary, #a1a1aa);
  }
  .v6-rail-pane__hint {
    font-size: 10px;
    color: var(--text-muted, #71717a);
  }

  .v6-rail-pane__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted, #71717a);
    font-size: 12px;
  }
  .v6-rail-pane__empty .v6-icon {
    color: var(--text-muted, #71717a);
    opacity: 0.45;
  }
  .v6-rail-pane__empty p {
    margin: 4px 0 0;
    font-weight: 500;
    color: var(--text-secondary, #a1a1aa);
  }
  .v6-rail-pane__empty span {
    font-size: 11px;
    color: var(--text-muted, #71717a);
  }
  .v6-rail-pane__empty strong {
    color: var(--text-secondary, #a1a1aa);
    font-weight: 600;
  }

  /* Pattern taxonomy reads as a compact filter grid instead of a loose row of
     pills. Counts stay aligned and empty categories remain available without
     making the rail jump when patterns are added. */
  .v6-rail-pane--patterns .library-categories {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 7px 8px 6px;
    background: var(--surface-300, #18181b);
    border-bottom: 1px solid var(--v6-border-faint, rgba(255,255,255,.05));
  }
  .v6-rail-pane--patterns .category-tab {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    min-width: 0;
    min-height: 27px;
    padding: 4px 7px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text-muted, #71717a);
    font-size: 10px;
    font-weight: 650;
    text-align: left;
    cursor: pointer;
  }
  .v6-rail-pane--patterns .category-tab:hover {
    background: var(--surface-400, #1f1f23);
    color: var(--text-secondary, #a1a1aa);
  }
  .v6-rail-pane--patterns .category-tab.active {
    background: rgba(139,92,246,.16);
    border-color: rgba(139,92,246,.45);
    color: #ddd6fe;
  }
  .v6-rail-pane--patterns .category-tab .category-count {
    min-width: 16px;
    padding: 1px 4px;
    border-radius: 9px;
    background: rgba(255,255,255,.07);
    color: var(--text-muted, #71717a);
    font-size: 9px;
    text-align: center;
  }
  .v6-rail-pane--patterns .library-search { padding: 8px; }
  .v6-rail-pane--patterns .library-search-input {
    min-height: 31px;
    border-radius: 7px;
  }

  /* ============================================================
     Sounds pane
     ============================================================ */
  .v6-rail-sounds__list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
  }
  .v6-rail-sounds__list::-webkit-scrollbar { width: 8px; }
  .v6-rail-sounds__list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.10); border-radius: 4px;
  }

  .v6-rail-sound {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--surface-400, #1f1f23);
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    color: var(--text-primary, #fafafa);
    text-align: left;
    cursor: pointer;
    transition: background var(--duration-fast, 120ms),
                border-color var(--duration-fast, 120ms);
  }
  .v6-rail-sound:hover {
    background: var(--surface-500, #27272b);
    border-color: var(--accent-primary, #8b5cf6);
  }
  .v6-rail-sound__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-primary, #8b5cf6);
    border-radius: var(--radius-sm, 4px);
    flex-shrink: 0;
  }
  .v6-rail-sound__name {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .v6-rail-sound__wave {
    font-family: var(--font-mono, monospace);
    font-size: 10px;
    color: var(--text-muted, #71717a);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
  }

  /* v13 — debounced sound search above the list */
  .v6-rail-sounds__search {
    padding: 6px 6px 0;
  }
  .v6-rail-sounds__search-input {
    width: 100%;
    padding: 6px 10px;
    background: var(--surface-400, #1f1f23);
    border: 1px solid var(--border-default, rgba(255,255,255,0.1));
    border-radius: var(--radius-sm, 4px);
    color: var(--text-primary, #fafafa);
    font-size: 12px;
  }
  .v6-rail-sounds__search-input:focus {
    outline: none;
    border-color: var(--accent-primary, #8b5cf6);
  }

  /* v13 — audition button + "Use" affordance share a row */
  .v6-rail-sound-row {
    display: flex;
    align-items: stretch;
    gap: 4px;
  }
  .v6-rail-sound-row .v6-rail-sound {
    flex: 1;
    min-width: 0;
  }
  .v6-rail-sound__use {
    flex-shrink: 0;
    padding: 0 10px;
    background: var(--surface-400, #1f1f23);
    border: 1px solid var(--border-default, rgba(255,255,255,0.1));
    border-radius: var(--radius-sm, 4px);
    color: var(--text-secondary, #a1a1aa);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--duration-fast, 120ms),
                border-color var(--duration-fast, 120ms),
                color var(--duration-fast, 120ms);
  }
  .v6-rail-sound__use:hover {
    background: var(--surface-500, #27272b);
    border-color: var(--accent-primary, #8b5cf6);
    color: var(--text-primary, #fafafa);
  }

  /* v13 — inline 5-part chooser opened by "Use" */
  .v6-rail-sound-chooser {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: var(--surface-500, #27272b);
    border: 1px solid var(--accent-primary, #8b5cf6);
    border-radius: var(--radius-sm, 4px);
  }
  .v6-rail-sound-chooser__label {
    flex-basis: 100%;
    font-size: 10px;
    color: var(--text-muted, #71717a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .v6-rail-sound-chooser__part {
    padding: 4px 8px;
    background: var(--surface-400, #1f1f23);
    border: 1px solid var(--border-default, rgba(255,255,255,0.1));
    border-radius: var(--radius-sm, 4px);
    color: var(--text-primary, #fafafa);
    font-size: 11px;
    cursor: pointer;
    transition: background var(--duration-fast, 120ms),
                border-color var(--duration-fast, 120ms);
  }
  .v6-rail-sound-chooser__part:hover {
    background: var(--surface-300, #18181b);
    border-color: var(--accent-primary, #8b5cf6);
  }

  /* ============================================================
     Songs pane
     ============================================================ */
  .v6-rail-songs__list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
  }
  .v6-rail-songs__list::-webkit-scrollbar { width: 8px; }
  .v6-rail-songs__list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.10); border-radius: 4px;
  }

  .v6-rail-song {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--surface-400, #1f1f23);
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    color: var(--text-primary, #fafafa);
    text-align: left;
    cursor: pointer;
    transition: background var(--duration-fast, 120ms),
                border-color var(--duration-fast, 120ms),
                transform var(--duration-instant, 50ms);
  }
  .v6-rail-song:hover {
    background: var(--surface-500, #27272b);
    border-color: var(--v6-border-strong, rgba(255,255,255,0.14));
    transform: translateX(2px);
  }
  .v6-rail-song:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--surface-200, #111113), 0 0 0 4px var(--accent-primary, #8b5cf6);
  }
  .v6-rail-song--active {
    background: var(--surface-500, #27272b);
    border-color: var(--accent-primary, #8b5cf6);
  }
  .v6-rail-song__bar {
    width: 4px;
    height: 28px;
    border-radius: 2px;
    flex-shrink: 0;
    box-shadow: 0 0 6px currentColor;
  }
  .v6-rail-song__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  .v6-rail-song__name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary, #fafafa);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .v6-rail-song__meta {
    font-family: var(--font-mono, monospace);
    font-size: 10px;
    color: var(--text-muted, #71717a);
    letter-spacing: 0.02em;
  }
  .v6-rail-song__active-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-success, #22c55e);
    border-radius: 50%;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
    flex-shrink: 0;
  }

  .v6-rail-songs__new {
    flex-shrink: 0;
  }
  .v6-rail-songs__back {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: auto;
    padding: 5px 6px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text-muted, #71717a);
    font-size: 10px;
    cursor: pointer;
  }
  .v6-rail-songs__back:hover {
    color: var(--text-primary, #fafafa);
    background: var(--surface-500, #27272b);
    border-color: var(--v6-border, rgba(255,255,255,.08));
  }

  /* Song cards keep a quiet, low-contrast leading rail in dark mode. The
     active state is communicated by the card border and dot, so the edge
     never competes with the playing timeline. */
  .v6-rail-song__bar { opacity: .72; box-shadow: none; }
  .v6-rail-song--active .v6-rail-song__bar { opacity: 1; }

  /* ============================================================
     Ideas / seed library — compact cards that scale to a large catalogue
     ============================================================ */
  .v6-rail-library__filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px;
    padding: 7px 8px;
    border-bottom: 1px solid var(--v6-border-faint, rgba(255,255,255,.05));
  }
  .v6-rail-library__select {
    min-width: 0;
    height: 28px;
    padding: 0 7px;
    background: var(--surface-400, #1f1f23);
    border: 1px solid var(--v6-border, rgba(255,255,255,.08));
    border-radius: 6px;
    color: var(--text-secondary, #a1a1aa);
    font-size: 11px;
  }
  .v6-rail-library__select:focus {
    outline: none;
    border-color: var(--accent-primary, #8b5cf6);
  }
  .v6-rail-library__list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 7px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(188px, 1fr));
    align-content: start;
    gap: 7px;
    scrollbar-width: thin;
  }
  .v6-rail-seed {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 9px;
    background: color-mix(in srgb, var(--surface-400, #1f1f23) 92%, white 2%);
    border: 1px solid var(--v6-border, rgba(255,255,255,.08));
    border-radius: 8px;
    transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
  }
  .v6-rail-seed:hover {
    background: var(--surface-500, #27272b);
    border-color: rgba(139,92,246,.48);
    transform: translateY(-1px);
  }
  .v6-rail-seed__head {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }
  .v6-rail-seed__type {
    flex: 0 0 auto;
    padding: 2px 5px;
    color: #c4b5fd;
    background: rgba(139,92,246,.15);
    border-radius: 4px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
  }
  .v6-rail-seed__name {
    min-width: 0;
    overflow: hidden;
    color: var(--text-primary, #fafafa);
    font-size: 12px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .v6-rail-seed__rating {
    margin-left: auto;
    color: #fbbf24;
    font-size: 10px;
    white-space: nowrap;
  }
  .v6-rail-seed__meta {
    min-height: 27px;
    overflow: hidden;
    color: var(--text-muted, #71717a);
    font-size: 10px;
    line-height: 1.35;
    text-overflow: ellipsis;
  }
  .v6-rail-seed__mini {
    display: flex;
    align-items: center;
    min-height: 28px;
    padding: 4px;
    background: var(--surface-200, #111114);
    border-radius: 5px;
    overflow: hidden;
  }
  .v6-rail-seed__mini svg,
  .v6-rail-seed__mini canvas { max-width: 100%; }
  .v6-rail-seed__actions {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: auto;
  }
  .v6-rail-seed__notes {
    margin-right: auto;
    color: var(--text-muted, #71717a);
    font-size: 10px;
  }
  .v6-rail-seed__btn {
    min-height: 26px;
    padding: 3px 7px;
    font-size: 10px;
  }
  .v6-rail-seed__btn[data-action="use"] { color: #fff; }

  @media (max-width: 520px) {
    .v6-rail-library__list { grid-template-columns: 1fr; }
  }

  @media (prefers-reduced-motion: reduce) {
    .v6-rail-song-switcher__button,
    .v6-rail-song-switcher__chevron,
    .v6-rail-song { transition: none; }
  }
}
