/* Project panels: the project's AI keys (Connections) — or, for a backend
   without providers, the OpenAI-only panel — and the app design system editor
   (above app-wide behavior). `project-panels.js` builds them.

   Every colour is one of the roles `styles.css` declares on `:root` and
   redeclares under `[data-theme="dark"]`, so there is no dark block here: the
   theme is the tokens, and the type and control sizes are the roles it
   declares from Studio's design system. The one literal left is the dialog's
   backdrop, because a custom property does not reach `::backdrop` in every
   browser this page supports.

   Nothing here is written from script. The shell's CSP (`style-src 'self'`)
   refuses style attributes, so state arrives as a class, `hidden`, `disabled`,
   `aria-disabled`, or a textarea's `rows`, and the rules below draw it. */

.pp-openai,
.pp-ds { min-width: 0; display: grid; gap: 8px; }
.pp-keys { min-width: 0; display: grid; gap: 12px; }
/* `styles.css` already hides `[hidden]`; repeated for the elements below that
   set a display of their own, so this file does not lean on another's rule. */
.pp-keys [hidden],
.pp-openai [hidden],
.pp-ds [hidden],
.pp-dialog [hidden] { display: none !important; }

/* ------------------------------------------------------------ shared parts */

.pp-eyebrow { margin: 0; color: var(--muted); font: var(--type-eyebrow); letter-spacing: var(--eyebrow-tracking); text-transform: uppercase; }
.pp-caption { margin: 0; color: var(--muted); font: var(--type-small); }
.pp-error { margin: 0; color: var(--bad-ink); font: var(--type-small); }
.pp-warning { margin: 0; color: var(--warn-ink); font: var(--type-small); }

/* Studio's status badge: badge type on a tinted chip. */
.pp-badge { padding: 4px 8px; border-radius: var(--radius-badge); font: var(--type-caption-strong); white-space: nowrap; }
.pp-badge.neutral { color: var(--ink-soft); background: var(--chip); }
.pp-badge.success { color: var(--ok-ink); background: var(--ok-bg); }
.pp-badge.warning { color: var(--warn-ink); background: var(--warn-bg); }

/* Title on the left, value on the right, a hairline under each — Studio's
   detail row. Values are selectable: a key's tail and a cost get copied. */
.pp-rows { margin: 0; display: grid; }
.pp-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.pp-row:last-child { border-bottom: 0; }
.pp-row dt { flex: 0 0 auto; color: var(--muted); font: var(--type-small); }
.pp-row dd { min-width: 0; margin: 0; color: var(--ink); font: var(--type-small-strong); text-align: right; overflow-wrap: anywhere; user-select: text; }

/* Studio's loading indicator is neutral; orange is kept for a chat turn at work. */
.pp-spinner { width: 12px; height: 12px; flex: 0 0 12px; display: inline-block; border: 1.5px solid var(--line-strong); border-top-color: var(--loading); border-radius: 50%; animation: pp-spin .8s linear infinite; }
@keyframes pp-spin { to { transform: rotate(360deg); } }
/* The global reduced-motion rule stops the turn; a still ring would read as a
   stray circle, so the arc goes too and the words beside it carry the state. */
@media (prefers-reduced-motion: reduce) {
  .pp-spinner { border-top-color: var(--line-strong); }
}

/* The detail pane's own control, `.compact-button`'s Secondary at 28 points; `primary`
   is the orange one, and `quiet` has no fill until hovered. */
.pp-action { height: var(--control-height); padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink); background-color: var(--selected-fill); border: 1px solid var(--selected-line); border-radius: var(--radius-button); font: var(--type-caption-strong); white-space: nowrap; cursor: pointer; }
.pp-action:hover:not(:disabled):not([aria-disabled="true"]) { background-image: linear-gradient(var(--hover), var(--hover)); }
.pp-action:active:not(:disabled):not([aria-disabled="true"]) { background-image: linear-gradient(var(--pressed), var(--pressed)); }
.pp-action.primary { color: var(--on-primary); background-color: var(--primary); border-color: transparent; }
.pp-action.primary:hover:not(:disabled):not([aria-disabled="true"]) { background-image: none; background-color: var(--primary-hover); }
.pp-action.quiet { background-color: transparent; border-color: transparent; }
/* `aria-disabled` keeps a refusing control focusable, with its reason read out
   through `aria-describedby`; `disabled` is only for work already running. Both draw
   Studio's disabled button: muted ink on the chip. */
.pp-action:disabled, .pp-action[aria-disabled="true"] { color: var(--muted); background: var(--chip); border-color: transparent; }
.pp-action:disabled { cursor: progress; }
.pp-action[aria-disabled="true"] { cursor: not-allowed; }
.pp-inline-action { justify-self: start; }

/* --------------------------------------------------------------- AI keys */

/* Studio's heading, then one row per provider. A row is drawn as the Figma and
   Apple rows are drawn — `.conn-list li` in `styles.css` — so the tab reads as
   one list whichever file drew the row: raised while a key is stored, muted
   while none is, and the warning tint for a key the provider refused. */
.pp-keys-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.pp-keys-head h3 { min-width: 0; margin: 0; font: var(--type-h4); }
.pp-keys-status { margin: 0; display: flex; align-items: center; gap: 6px; color: var(--muted); font: var(--type-small); }
.pp-keys-list { margin: 0; padding: 0; display: grid; gap: 8px; list-style: none; }
.pp-key { min-width: 0; display: grid; gap: 6px; padding: 8px 12px; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-row); }
.pp-key.unreachable { background: var(--panel-muted); }
.pp-key.needs-attention { background: var(--warn-bg); border-color: var(--warn-line); }
/* The title on the left; In use and the status badge at the trailing edge. */
.pp-key-head { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.pp-key-head strong { flex: 1 1 auto; min-width: 0; color: var(--ink); font: var(--type-small-strong); }
.pp-key .pp-rows { padding: 0 2px; }
.pp-keys-failure { display: grid; gap: 8px; }

/* ---------------------------------------------------------------- OpenAI */

/* Drawn as the Figma and Apple rows are drawn — `.conn-list li` in
   `styles.css` — so the tab reads as one list whichever file drew the row. */
.pp-openai-card { display: grid; gap: 8px; padding: 8px 12px; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-row); }
.pp-openai-card.unreachable { background: var(--panel-muted); }
.pp-openai-card.needs-attention { background: var(--warn-bg); border-color: var(--warn-line); }
.pp-openai-head { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 8px; }
/* Ink on panel, so the mark inverts with the theme instead of needing a pair of
   literal colours per theme the way the provider marks do. */
.pp-mark { width: 28px; height: 28px; display: grid; place-items: center; color: var(--panel); background: var(--ink); border-radius: var(--radius-icon); font: var(--type-caption-strong); }
.pp-openai-card.unreachable .pp-mark { opacity: .65; }
.pp-openai-copy { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.pp-openai-copy strong { font: var(--type-small-strong); }
.pp-openai-copy small { color: var(--muted); font: var(--type-caption); }
.pp-openai-copy small.warning { color: var(--warn-ink); }
.pp-openai-card .pp-rows { padding: 0 2px; }
.pp-attention { margin: 0; color: var(--warn-ink); font: var(--type-small); }
.pp-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.pp-usage { display: grid; gap: 4px; }
.pp-usage-empty { margin: 0; color: var(--ink-soft); font: var(--type-small); }

/* --------------------------------------------------------- design system */

/* The section is drawn once the project's settings have been read, as Studio draws
   it; before that the script hides the host, so neither the block nor its divider
   shows. `.pp-ds-unavailable` stands in for it when this panel's own read failed: the
   read's sentence, in the warning ink Studio gives a project's failure, and Retry. */
.pp-ds-section,
.pp-ds-unavailable { min-width: 0; display: grid; gap: 8px; }

/* The heading and Generate share one line, Generate at the trailing edge. */
.pp-ds-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pp-ds-head h3 { min-width: 0; margin: 0; font: var(--type-h4); }
.pp-ds-head h3:focus { outline: none; }
.pp-ds-status { margin: 0; display: flex; align-items: center; gap: 6px; color: var(--muted); font: var(--type-small); }

/* A growing field rather than an editor with a mode: six lines to start, as tall
   as the document up to thirty, and scrolling inside itself past that — Studio's
   `visibleLines(6...30)`. `field-sizing` grows it where it exists; elsewhere the
   script sets `rows`. Disabled, it takes the chip fill as Studio's field does. */
.pp-ds-input {
  width: 100%;
  min-height: 132px;
  min-height: calc(6lh + 26px);
  max-height: 566px;
  max-height: calc(30lh + 26px);
  padding: 12px;
  color: var(--ink);
  background: var(--panel-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius-button);
  font: var(--type-body);
  resize: none;
  overflow-y: auto;
  field-sizing: content;
}
.pp-ds-input::placeholder { color: var(--muted); }
.pp-ds-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.pp-ds-input:disabled { color: var(--muted); background: var(--chip); cursor: not-allowed; }

/* The latest saved version, read beside the kept draft rather than instead of
   it: a fixed window, as Studio's, that scrolls a long document in place. Studio
   stacks the warning, the eyebrow, the window and the two choices in the section
   itself, with no card around them. */
.pp-ds-conflict { display: grid; gap: 8px; }
.pp-ds-latest { height: 180px; margin: 0; padding: 12px; overflow: auto; color: var(--ink); background: var(--panel-muted); border-radius: var(--radius-button); font: var(--type-mono); white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.pp-ds-latest.empty { color: var(--muted); font: var(--type-small); font-style: italic; }
.pp-ds-latest:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.pp-ds-choices { display: grid; gap: 8px; }
/* Save and Cancel take equal halves of the row. */
.pp-ds-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pp-ds-actions .pp-action,
.pp-ds-choices .pp-action { width: 100%; }

/* --------------------------------------------------------------- dialogs */

/* A native modal `<dialog>`: the browser centers it in the top layer and makes
   the page behind inert. It fits its content up to the viewport; the heading
   and the footer stay put while only the body scrolls. */
.pp-dialog {
  width: min(480px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
}
/* Studio's presentation: a cross-fade over a black scrim at 40%, no blur, no shadow. */
.pp-dialog[open] { display: flex; animation: pp-dialog-in .3s ease-in-out; }
.pp-dialog::backdrop { background: rgba(0, 0, 0, .4); }
@keyframes pp-dialog-in { from { opacity: 0; } }
.pp-dialog-frame { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pp-dialog-head { flex: 0 0 auto; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 24px 24px 0; }
.pp-dialog-head h2 { flex: 1 1 auto; min-width: 0; margin: 0; font: var(--type-h1); }
/* Studio's mark while the form works: in the header, between the title and Close. */
.pp-dialog-progress { align-self: center; }
.pp-dialog-close { width: var(--icon-button); height: var(--icon-button); flex: 0 0 var(--icon-button); display: grid; place-items: center; padding: 0; color: var(--ink); background: transparent; border: 0; border-radius: var(--radius-icon); font-size: 17px; line-height: 1; cursor: pointer; }
.pp-dialog-close:hover:not(:disabled) { background: var(--hover); }
.pp-dialog-close:disabled { color: var(--muted); cursor: progress; }
.pp-dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 8px; padding: 16px 24px; }
.pp-dialog-lead { margin: 0 0 8px; color: var(--ink-soft); font: var(--type-body); }
/* A provider's caption under the lead, in Studio's muted caption type. */
.pp-dialog-note { margin: -4px 0 8px; color: var(--muted); font: var(--type-caption); }
/* Each field's eyebrow over its input, the groups spaced as the body's rows. */
.pp-field-group { display: grid; gap: 4px; }
/* Studio's text field, as `.text-field` draws it. */
.pp-field { width: 100%; height: var(--control-height); padding: 0 12px; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-button); font: var(--type-body); }
.pp-field:focus { border-color: var(--selected-line-strong); }
.pp-field::placeholder { color: var(--muted); }
.pp-field:disabled { color: var(--muted); background: var(--chip); cursor: progress; }
/* Messages sit directly above the actions they are about, and a long one
   scrolls within a quarter of the viewport so the actions never leave. */
.pp-dialog-foot { flex: 0 0 auto; display: grid; gap: 12px; padding: 0 24px 24px; }
.pp-dialog-messages { max-height: 25vh; overflow-y: auto; display: grid; gap: 8px; }
.pp-problem { margin: 0; color: var(--warn-ink); font: var(--type-small); }
.pp-form-error { margin: 0; padding: 12px; color: var(--bad-ink); background: var(--bad-bg); border-radius: var(--radius-button); font: var(--type-small); }
/* Every footer action takes an equal share of the row. */
.pp-dialog-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
/* Studio's dialog buttons: 28 points, body type; the dismissal in the Cancel role, the
   answer in the primary orange, and a destructive answer in the primary role's danger
   colours — as `.modal-actions` draws them. */
.pp-button { height: var(--control-height); min-width: 0; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: var(--radius-button); font: var(--type-body); cursor: pointer; transition: background-color .16s ease, border-color .16s ease, color .16s ease; }
.pp-button.primary { color: var(--on-primary); background: var(--primary); }
.pp-button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.pp-button.primary:active:not(:disabled) { background: var(--primary-pressed); }
.pp-button:disabled { color: var(--muted); background: var(--chip); border-color: transparent; cursor: not-allowed; }
.pp-button.secondary { color: var(--ink); background-color: var(--panel-muted); border-color: var(--line); }
.pp-button.secondary:hover:not(:disabled) { background-image: linear-gradient(var(--hover), var(--hover)); }
.pp-button.danger { color: var(--on-danger); background: var(--danger); }
.pp-button.danger:hover:not(:disabled) { background: var(--danger-hover); }

@media (max-width: 560px) {
  .pp-dialog-head { padding: 20px 16px 0; }
  .pp-dialog-body { padding: 12px 16px; }
  .pp-dialog-foot { padding: 0 16px 20px; }
}
