/* ============================================================
   Sketch a few bars — launcher modal + the floating ready card
   ============================================================

   These rules used to be a runtime-injected <style> block inside
   MidiLlmModal.js. That worked, but it meant the one AI surface with
   a paid GPU behind it was also the one with no stylesheet, no cache
   busting and no way to see its design next to its siblings.

   THE LAYER MATTERS. polish.css:655-698 styles `.modal-overlay` and
   `.modal-dialog` with UNLAYERED `!important` declarations. For
   important declarations the cascade runs in REVERSE layer order, so
   an `!important` rule inside a layer beats an unlayered one — which
   is why the dialog sizing below lives in `@layer v6-polish` (the
   last layer declared in polish.css:32) and carries `!important`,
   exactly as song-browser.css does for the same reason.

   Everything that is ours alone — the card, the internals — needs
   none of that and sits in v6-components as ordinary CSS.
   ============================================================ */

@layer v6-polish {
  /* Narrower than the 560px default: this is a description box and
     three controls, not a browser. */
  body .modal-overlay .midillm-dialog {
    width: min(520px, calc(100vw - 48px)) !important;
  }
}

@layer v6-components {

  /* ============================================================
     Launcher modal
     ============================================================ */
  .midillm-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 2px;
  }

  .midillm-sub {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary, #a1a1aa);
  }

  .midillm-health {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary, #a1a1aa);
  }
  .midillm-health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #71717a;
    flex: 0 0 8px;
  }
  .midillm-health-dot--ok { background: #10b981; }
  .midillm-health-dot--down { background: #ef4444; }
  .midillm-recheck {
    margin-left: auto;
    padding: 2px 8px;
    font: inherit;
    font-size: 11px;
    color: var(--accent-primary, #8b5cf6);
    background: transparent;
    border: 1px solid var(--border-default, rgba(255, 255, 255, 0.1));
    border-radius: 4px;
    cursor: pointer;
  }
  .midillm-recheck:hover { color: var(--text-primary, #fafafa); }

  .midillm-label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
    color: var(--text-secondary, #a1a1aa);
  }
  /* Helper text sits UNDER its control, in the label, so it is announced
     with it rather than floating as an orphan sentence. */
  .midillm-help {
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-tertiary, #71717a);
  }

  .midillm-prompt {
    padding: 9px 11px;
    border-radius: 6px;
    min-height: 78px;
    resize: vertical;
    background: var(--surface-300, #18181b);
    color: var(--text-primary, #fafafa);
    border: 1px solid var(--border-default, rgba(255, 255, 255, 0.1));
    font: inherit;
    line-height: 1.45;
  }
  .midillm-prompt:focus {
    outline: none;
    border-color: var(--accent-primary, #8b5cf6);
  }

  .midillm-select {
    padding: 7px 9px;
    border-radius: 6px;
    background: var(--surface-300, #18181b);
    color: var(--text-primary, #fafafa);
    border: 1px solid var(--border-default, rgba(255, 255, 255, 0.1));
    font: inherit;
  }

  .midillm-check {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 4px 8px;
    font-size: 12px;
    color: var(--text-secondary, #a1a1aa);
    cursor: pointer;
  }
  .midillm-check .midillm-help { grid-column: 2; }

  .midillm-advanced {
    border-top: 1px solid var(--border-default, rgba(255, 255, 255, 0.08));
    padding-top: 10px;
  }
  .midillm-advanced > summary {
    font-size: 12px;
    color: var(--text-secondary, #a1a1aa);
    cursor: pointer;
    user-select: none;
  }
  .midillm-advanced > summary:hover { color: var(--text-primary, #fafafa); }
  .midillm-advanced-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 12px;
  }

  /* `[hidden]` is a USER-AGENT rule (`display:none`), so any author rule that
     sets `display` beats it. `.btn` is `inline-flex` and these rows are `flex`,
     which is how a hidden Accept/Reject pair ended up rendering on a modal that
     had generated nothing. Anything toggled by the `hidden` property in this
     component needs an author-level rule to match. */
  .midillm-footer .btn[hidden],
  .midillm-takes[hidden],
  .midillm-recheck[hidden],
  .v6-sketch-card__takes[hidden],
  .v6-sketch-card__details[hidden] { display: none; }

  .midillm-takes { display: flex; gap: 6px; flex-wrap: wrap; }
  .midillm-take {
    padding: 5px 11px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 14px;
    background: var(--surface-400, #1f1f23);
    color: var(--text-secondary, #a1a1aa);
    border: 1px solid var(--border-default, rgba(255, 255, 255, 0.1));
  }
  .midillm-take:hover { color: var(--text-primary, #fafafa); }
  .midillm-take--active {
    background: var(--accent-primary, #8b5cf6);
    color: #fff;
    border-color: var(--accent-primary, #8b5cf6);
  }

  .midillm-status {
    font-size: 12px;
    color: var(--text-secondary, #a1a1aa);
    margin: 0;
    line-height: 1.45;
  }
  .midillm-status--error { color: var(--accent-secondary, #ec4899); }

  .midillm-footer {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
  }
  /* The price sits opposite the button that spends it. */
  .midillm-cost {
    margin-right: auto;
    font-size: 11px;
    color: var(--text-tertiary, #71717a);
  }

  /* ============================================================
     Sketch ready card — a POPOVER, not a modal
     ============================================================
     It must never cover the timeline it is pointing at: the whole
     reason it exists is that the old full-screen modal hid the bars
     it had just written. Top-centre, narrow, and out of the way of
     the transport at the bottom.
     ============================================================ */
  .v6-sketch-card {
    position: fixed;
    top: 76px;
    left: 50%;
    transform: translate(-50%, -12px);
    z-index: 8000; /* under a real modal (9000), over the arranger */
    width: min(440px, calc(100vw - 32px));
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(180deg,
      var(--surface-300, #18181b) 0%,
      var(--surface-200, #111113) 100%);
    color: var(--text-primary, #fafafa);
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 12px;
    box-shadow:
      0 20px 50px rgba(0, 0, 0, 0.6),
      0 0 0 1px rgba(139, 92, 246, 0.12) inset;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
  .v6-sketch-card--visible {
    opacity: 1;
    transform: translate(-50%, 0);
  }

  .v6-sketch-card__head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
  }
  .v6-sketch-card__title {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
  }
  .v6-sketch-card__close {
    flex: 0 0 auto;
    padding: 0 4px;
    font: inherit;
    font-size: 14px;
    line-height: 1;
    color: var(--text-tertiary, #71717a);
    background: transparent;
    border: none;
    cursor: pointer;
  }
  .v6-sketch-card__close:hover { color: var(--text-primary, #fafafa); }

  .v6-sketch-card__meta {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary, #a1a1aa);
  }

  .v6-sketch-card__details > summary {
    font-size: 11px;
    color: var(--text-tertiary, #71717a);
    cursor: pointer;
    user-select: none;
  }
  .v6-sketch-card__details > summary:hover { color: var(--text-secondary, #a1a1aa); }
  .v6-sketch-card__detail {
    margin: 6px 0 0;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-secondary, #a1a1aa);
  }

  .v6-sketch-card__takes { display: flex; gap: 6px; flex-wrap: wrap; }
  .v6-sketch-card__take {
    min-width: 30px;
    padding: 4px 10px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    border-radius: 12px;
    background: var(--surface-400, #1f1f23);
    color: var(--text-secondary, #a1a1aa);
    border: 1px solid var(--border-default, rgba(255, 255, 255, 0.1));
  }
  .v6-sketch-card__take:hover { color: var(--text-primary, #fafafa); }
  .v6-sketch-card__take--active {
    background: var(--accent-primary, #8b5cf6);
    color: #fff;
    border-color: var(--accent-primary, #8b5cf6);
  }

  .v6-sketch-card__actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
  }
  /* Remove is the only destructive exit, so it reads as one — without
     shouting, because it is also a perfectly ordinary thing to want. */
  .v6-sketch-card__remove { margin-left: auto; }
  .v6-sketch-card__remove:hover {
    color: var(--accent-secondary, #ec4899);
    border-color: var(--accent-secondary, #ec4899);
  }

  .v6-sketch-card__newsong {
    align-self: flex-start;
    padding: 0;
    font: inherit;
    font-size: 11px;
    color: var(--accent-primary, #8b5cf6);
    background: transparent;
    border: none;
    text-decoration: underline;
    cursor: pointer;
  }
  .v6-sketch-card__newsong:hover { color: var(--text-primary, #fafafa); }

  /* ============================================================
     Progress card additions (cancel + elapsed)
     ============================================================ */
  .v6-comp-viz__foot {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    min-height: 22px;
  }
  .v6-comp-viz__elapsed {
    flex: 1;
    font-size: 11px;
    color: var(--text-tertiary, #71717a);
  }
  .v6-comp-viz__cancel {
    padding: 3px 10px;
    font: inherit;
    font-size: 11px;
    color: var(--text-secondary, #a1a1aa);
    background: transparent;
    border: 1px solid var(--border-default, rgba(255, 255, 255, 0.18));
    border-radius: 5px;
    cursor: pointer;
  }
  .v6-comp-viz__cancel:hover { color: var(--text-primary, #fafafa); }
  .v6-comp-viz__cancel:disabled { opacity: 0.5; cursor: default; }

  @media (prefers-reduced-motion: reduce) {
    .v6-sketch-card { transition: none; }
  }
}
