/* ============================================================
   v6 Full-width app bar + AI strip
   ============================================================
   The top of the page becomes one bar that spans logo → song
   identity → session actions. The old per-section header (which
   was buried inside .main-content) is gone — only this bar remains
   above .daw-layout.

   Below the editor's transport, a SECOND strip groups the
   generative (Compose / Quick AI / Refine) and output (Export /
   Clear) buttons so they no longer fight the transport for space.
*/

@layer v6-shell {

  /* Body becomes 3 stacked rows: brand bar | DAW | statusbar. */
  body.v6-app-bar-active {
    display: grid !important;
    grid-template-rows: var(--v6-app-bar-h, 56px) 1fr var(--statusbar-h, 26px);
    grid-template-columns: 1fr;
    min-height: 100vh;
  }
  /* The bar itself is grid-row 1 / column 1. The .daw-layout falls
     into row 2 naturally. Status bar (already pinned by shell.css)
     stays in row 3.                                                   */
  .v6-app-bar {
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(220px, 0.7fr) minmax(280px, 1.6fr) minmax(280px, 0.7fr);
    align-items: center;
    gap: 16px;
    height: var(--v6-app-bar-h, 56px);
    padding: 0 18px;
    background: linear-gradient(180deg,
      var(--surface-300, #18181b) 0%,
      var(--surface-200, #111113) 100%);
    border-bottom: 1px solid var(--v6-border-strong, rgba(255, 255, 255, 0.14));
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.40);
    z-index: var(--z-sticky, 200);
    position: relative;
  }

  /* The .daw-layout no longer needs min-height: 100vh — let it fill
     the row 2 cell. Override the legacy rule. */
  body.v6-app-bar-active .daw-layout {
    grid-row: 2;
    min-height: 0 !important;
    height: 100%;
    overflow: hidden;
  }
  /* shell.css puts the statusbar in grid-row 2; with the new 3-row body
     it must move to row 3. */
  body.v6-app-bar-active > .v6-statusbar {
    grid-row: 3 !important;
  }

  /* ============================================================
     Left — brand
     ============================================================ */
  .v6-app-bar__brand {
    display: flex;
    align-items: center;
    min-width: 0;
  }
  .v6-app-bar__logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary, #fafafa);
    padding: 4px 8px 4px 4px;
    border-radius: 8px;
    transition: background var(--duration-fast, 120ms);
  }
  .v6-app-bar__logo:hover {
    background: rgba(255, 255, 255, 0.04);
  }
  .v6-app-bar__logo-img {
    display: block;
    height: 32px;
    width: 32px;
    border-radius: 6px;
  }
  .v6-app-bar__logo-text {
    font-family: var(--font-sans, system-ui);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(180deg,
      var(--accent-primary, #8b5cf6) 0%,
      var(--accent-secondary, #ec4899) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
  }

  /* ============================================================
     Center — song identity (the focal point)
     ============================================================ */
  .v6-app-bar__center {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
  }
  .v6-song-identity {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    max-width: 100%;
  }
  .v6-song-name-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
  }
  .v6-song-name {
    font-family: var(--font-sans, system-ui);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #fafafa);
    letter-spacing: -0.01em;
    line-height: 1.1;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: text;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background var(--duration-fast, 120ms),
                border-color var(--duration-fast, 120ms);
  }
  .v6-song-name:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--v6-border, rgba(255, 255, 255, 0.10));
  }
  .v6-song-name[contenteditable="true"] {
    background: var(--surface-400, #1f1f23);
    border-color: var(--accent-primary, #8b5cf6);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.25);
    outline: none;
  }
  .v6-song-name__pencil {
    display: inline-flex;
    align-items: center;
    color: var(--text-muted, #71717a);
    opacity: 0.2;
    transition: opacity var(--duration-fast, 120ms);
    cursor: pointer;
  }
  .v6-song-name-row:hover .v6-song-name__pencil {
    opacity: 0.85;
  }
  .v6-song-name__pencil:hover {
    color: var(--accent-primary, #8b5cf6);
  }

  .v6-song-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted, #71717a);
    font-family: var(--font-sans, system-ui);
  }
  .v6-song-status .save-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }
  .v6-song-status .save-status::before {
    content: '●';
    font-size: 8px;
    color: var(--text-muted, #71717a);
  }
  .v6-song-status .save-status--saved::before {
    color: var(--accent-success, #22c55e);
  }
  .v6-song-status .save-status--unsaved::before {
    color: var(--accent-warning, #f59e0b);
    animation: v6-save-pulse 1.6s ease-in-out infinite;
  }
  @keyframes v6-save-pulse {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1.0; }
  }

  /* ============================================================
     Right — session actions
     ============================================================ */
  .v6-app-bar__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
  }
  .v6-session-group {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--v6-border, rgba(255, 255, 255, 0.10));
    border-radius: 999px;
    padding: 2px;
    gap: 2px;
  }
  .v6-session-group .btn {
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    height: 28px;
    padding: 0 10px;
  }
  .v6-session-group .btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--v6-border-strong, rgba(255, 255, 255, 0.18));
  }
  .v6-session-group .btn .v6-icon {
    width: 13px;
    height: 13px;
  }
  .v6-app-bar__user {
    display: inline-flex;
    align-items: center;
  }

  /* ============================================================
     v6 sidebar toolbar — replaces the deleted "Pattern Library" h2
     ============================================================ */
  .v6-sidebar-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.04));
  }
  .v6-sidebar-toolbar__spacer {
    flex: 1;
  }
  .v6-sidebar-toolbar .sidebar-collapse-btn {
    height: 24px;
    width: 24px;
    padding: 0;
  }

  /* Hide the old .sidebar-title flow if it sneaks back via legacy CSS. */
  .pattern-library-sidebar .sidebar-header { display: none !important; }

  /* ============================================================
     Responsive — collapse the center identity at small widths
     ============================================================ */
  @media (max-width: 1100px) {
    .v6-app-bar {
      grid-template-columns: auto 1fr auto;
    }
    .v6-song-status {
      display: none;
    }
  }
  @media (max-width: 900px) {
    .v6-app-bar__logo-text { display: none; }
    .v6-session-group .btn-text { display: none; }
  }
}

/* ============================================================
   v6 AI strip — second toolbar row below the transport
   ============================================================ */
@layer v6-components {

  .v6-ai-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 14px;
    background: linear-gradient(180deg,
      rgba(139, 92, 246, 0.06) 0%,
      rgba(0, 0, 0, 0.20) 100%);
    border-top: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.04));
    border-bottom: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.04));
  }
  .v6-ai-strip__group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }
  .v6-ai-strip__group--generative {
    /* Generative actions get a subtle pill background to read as a group */
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--v6-border-faint, rgba(255, 255, 255, 0.04));
    border-radius: 999px;
  }
  .v6-ai-strip__group--output {
    /* Output cluster (Export / Clear) — destination-flavored, on the right */
  }

  /* Slightly subdue the third gen button so two accents don't fight. */
  .v6-ai-strip #refineBtn {
    background: linear-gradient(180deg,
      rgba(139, 92, 246, 0.18),
      rgba(139, 92, 246, 0.08));
    border: 1px solid var(--accent-primary, #8b5cf6);
    color: var(--text-primary, #fafafa);
  }
  .v6-ai-strip #refineBtn:hover {
    background: linear-gradient(180deg,
      rgba(139, 92, 246, 0.30),
      rgba(139, 92, 246, 0.15));
  }

  /* Hide the legacy .utility-controls if any leftover rule resurrects it. */
  .playback-bar > .utility-controls { display: none !important; }
}
