/* Studio's Translations inspector tab and its two dialogs (`translations.js`).

   Every colour is one of the roles `styles.css` defines on `:root` and redefines under
   `[data-theme="dark"]`, so both themes follow from the page's own switch and nothing here
   repeats a palette. The one literal is the backdrop, which `.modal-backdrop` also keeps
   the same in both themes: a custom property does not reach `::backdrop` in every
   browser this page supports.

   The page serves `style-src 'self'`, so the script never writes a style attribute.
   Everything that changes at runtime is a class, `hidden`, `readonly`, or `disabled`, and
   the growing text fields grow through `field-sizing` rather than a height set in script.

   Sizes are the type roles styles.css declares from Studio's design system — h4 block
   headings, small rows and notes, badge-type badges — and the dialogs follow `.modal`'s,
   so the tab reads as one of its neighbours. */

.translations-tab [hidden],
.translation-dialog [hidden] { display: none !important; }

/* ------------------------------------------------------------------ the tab */

.translations-tab { display: flex; flex-direction: column; gap: 12px; padding: 16px 0; }

/* The heading, then the icon-only Refresh immediately before "+". */
.translations-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.translations-title { margin: 0; color: var(--ink); font: var(--type-h4); }
.translations-title:focus { outline: none; }
.translations-tools { display: flex; align-items: center; gap: 6px; }
.translations-tool { font-size: 14px; }
.translations-tool:disabled { cursor: not-allowed; opacity: .48; }
.translations-tool:disabled:hover { background: transparent; }

.translations-icon { width: 13px; height: 13px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
/* "Translate pending" is its words alone, at the full width, as Studio's is. */
.translations-run { width: 100%; }
.translations-run:disabled { cursor: not-allowed; }
.translations-hint { margin: 0; color: var(--muted); font: var(--type-small); }

.translations-body { display: flex; flex-direction: column; gap: 12px; }
.translations-note { font: var(--type-small); }

/* A small ring beside the sentence, as the native progress indicator is. The page's
   reduced-motion rule stops it turning. */
.translations-progress { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ink-soft); font: var(--type-small); }
.translations-progress::before { content: ""; width: 12px; height: 12px; flex: 0 0 12px; border: 1.5px solid var(--line-strong); border-top-color: var(--loading); border-radius: 50%; animation: translations-spin .8s linear infinite; }
@keyframes translations-spin { to { transform: rotate(360deg); } }

.translations-languages { margin: 0; color: var(--ink-soft); font: var(--type-small); user-select: text; overflow-wrap: anywhere; }
.translations-eyebrow { margin: 4px 0 -2px; color: var(--muted); font: var(--type-eyebrow); letter-spacing: var(--eyebrow-tracking); text-transform: uppercase; }
.translations-group { display: flex; flex-direction: column; gap: 8px; }
.translations-group-name { margin: 0; color: var(--ink); font: var(--type-h4); overflow-wrap: anywhere; }
.translations-blocker { margin: 0; color: var(--ink-soft); font: var(--type-small); }
.translations-texts { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }

/* One registered text: its English, its context, the missing-context mark, and how many
   locales still wait. The whole card opens the editor. */
.translations-row { width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px 12px; color: var(--ink); background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-row); text-align: left; cursor: pointer; }
.translations-row:hover:not(:disabled) { border-color: var(--selected-line-strong); }
.translations-row:disabled { cursor: default; opacity: .48; }
.translations-row-line { width: 100%; display: flex; align-items: baseline; gap: 6px; }
.translations-row-english { flex: 1 1 auto; min-width: 0; font: var(--type-small-strong); overflow-wrap: anywhere; }
.translations-row-chevron { flex: 0 0 auto; color: var(--muted); font-size: 12px; line-height: 1; }
.translations-row-context { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; color: var(--ink-soft); font: var(--type-small); overflow-wrap: anywhere; }

/* Missing context is the one yellow mark in this tab. Pending is not a warning, so it
   keeps the neutral badge. */
.translations-needs { display: inline-flex; align-items: center; gap: 6px; color: var(--warn-ink); font: var(--type-caption-strong); }
.translations-needs-dot { width: 6px; height: 6px; flex: 0 0 6px; background: var(--warn-mark); border-radius: 50%; }

.translations-badge { display: inline-flex; align-items: center; padding: 4px 8px; color: var(--ink-soft); background: var(--chip); border: 0; border-radius: var(--radius-badge); font: var(--type-caption-strong); white-space: nowrap; }
/* The editor's "Needs context", beside the Context label: Studio's warning badge. */
.translations-badge.warning { color: var(--warn-ink); background: var(--warn-bg); }

.translations-messages, .translations-job { display: flex; flex-direction: column; gap: 6px; }
.translations-messages:empty, .translations-job:empty { display: none; }
.translations-error { margin: 0; color: var(--bad-ink); font: var(--type-small); overflow-wrap: anywhere; }
.translations-notice { margin: 0; color: var(--ink-soft); font: var(--type-small); }
.translations-job-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--ink); font: var(--type-small); }
.translations-job-line strong { font-weight: 600; }

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

/* Native modal dialogs. They are as tall as what they hold and no taller, capped to the
   viewport less a margin; past the cap the body scrolls while the heading and the
   actions stay put. The width is the native sheet's 560 points. */
.translation-dialog {
  width: min(560px, calc(100vw - 48px));
  max-width: none;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  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. */
.translation-dialog[open] { display: flex; flex-direction: column; animation: translation-dialog-in .3s ease-in-out; }
.translation-dialog::backdrop { background: rgba(0,0,0,.4); }
@keyframes translation-dialog-in { from { opacity: 0; } }

.translation-dialog-frame { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin: 0; }
.translation-dialog-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 24px 24px 8px; }
.translation-dialog-title { flex: 1 1 auto; margin: 0; min-width: 0; font: var(--type-h1); overflow-wrap: anywhere; }
.translation-dialog-title:focus { outline: none; }
/* `StudioFormView`'s mark while the form works, between the title and the close button. */
.translation-dialog-working { width: 12px; height: 12px; flex: 0 0 12px; border: 1.5px solid var(--line-strong); border-top-color: var(--loading); border-radius: 50%; animation: translations-spin .8s linear infinite; }
.translation-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; }
.translation-dialog-close:hover:not(:disabled) { background: var(--hover); }
.translation-dialog-close:disabled { color: var(--muted); cursor: not-allowed; }

.translation-dialog-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 16px; padding: 12px 24px 16px; overflow-y: auto; overscroll-behavior: contain; }

/* Messages sit directly above the actions, outside the scrolling body, so an error is
   never scrolled away from the button it is about. They get a quarter of the viewport
   before they scroll on their own, as the native footer does. */
.translation-dialog-foot { flex: 0 0 auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 24px 24px; }
.translation-dialog-messages { max-height: 25vh; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.translation-dialog-messages:not(:has(> :not([hidden]))) { display: none; }
/* Equal columns whatever the labels say. */
.translation-dialog-actions { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.translation-dialog-actions .button { width: 100%; min-width: 0; font: var(--type-body); }
.translation-dialog-actions .button-quiet { background-color: var(--panel-muted); border-color: var(--line); }
.translation-dialog-actions .button:disabled { cursor: not-allowed; }

.translation-dialog-copy { margin: 0; color: var(--ink-soft); font: var(--type-body); }
.translation-dialog-copy.muted { color: var(--muted); }
.translation-dialog-caption { margin: 0; color: var(--muted); font: var(--type-small); }
.translation-dialog-notice { margin: 0; color: var(--ink-soft); font: var(--type-small); }
.translation-dialog-error { margin: 0; padding: 12px; color: var(--bad-ink); background: var(--bad-bg); border-radius: var(--radius-button); font: var(--type-small); overflow-wrap: anywhere; }
.translation-dialog-group { margin: 0; color: var(--ink-soft); font: var(--type-label); overflow-wrap: anywhere; }

/* English is read-only: the design source owns it. */
.translation-english { display: flex; flex-direction: column; gap: 8px; }
.translation-eyebrow { color: var(--muted); font: var(--type-eyebrow); letter-spacing: var(--eyebrow-tracking); text-transform: uppercase; }
.translation-english-text { margin: 0; padding: 12px; color: var(--ink); background: var(--panel-muted); border-radius: var(--radius-button); font: var(--type-body); white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }

.translation-field { display: flex; flex-direction: column; gap: 8px; }
/* The field's title in label type, with the Context field's badge beside it. */
.translation-field-head { display: flex; align-items: center; gap: 8px; }
.translation-field-label { color: var(--ink); font: var(--type-label); }
/* `StudioTranslationMultilineFieldView`: the inset surface, the strong line and a 7-point
   radius, three lines tall, growing to eight and scrolling inside itself past that. */
.translation-field-input { width: 100%; min-height: calc(3 * 18px + 26px); max-height: calc(8 * 18px + 26px); padding: 12px; color: var(--ink); background: var(--inset); border: 1px solid var(--line-strong); border-radius: var(--radius-button); font: var(--type-body); resize: none; overflow-y: auto; overflow-wrap: anywhere; }
@supports (field-sizing: content) {
  .translation-field-input { field-sizing: content; }
}
.translation-field-input::placeholder { color: var(--muted); }
.translation-field-input:focus { outline: none; border-color: var(--focus); }
.translation-field-input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
/* Read-only while a save is in flight: typing waits, and focus stays where it was. */
.translation-field-input[readonly] { color: var(--muted); cursor: progress; }
.translation-locales { display: flex; flex-direction: column; gap: 16px; }
.translation-locale-status { align-self: flex-start; }

/* Add text's list, or what stands in for it: progress, a failure with Try again under
   it, or that the design changed. */
.translation-candidates-host { display: flex; flex-direction: column; gap: 8px; }
.translation-candidates-retry { align-self: flex-start; }
.translation-candidates-retry:disabled { cursor: not-allowed; }
.translation-candidates { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.translation-candidate { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-row); }
.translation-candidate-text { flex: 1 1 auto; min-width: 0; color: var(--ink); font: var(--type-body); overflow-wrap: anywhere; user-select: text; }
.translation-candidate > :not(.translation-candidate-text) { flex: 0 0 auto; }
.translation-candidate-add:disabled { cursor: not-allowed; }

@media (max-width: 560px) {
  .translation-dialog { width: calc(100vw - 24px); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); }
  .translation-dialog-head { padding: 20px 16px 8px; }
  .translation-dialog-body { padding: 12px 16px; }
  .translation-dialog-foot { padding: 4px 16px 20px; }
}
