/* Reusable modal dialog (Constitution I). Rendered into the shared "modal"
   Turbo frame. Scope: global. Mobile-first. */

.modal {
  border: 0;
  padding: 0;
  max-width: 480px;
  width: calc(100% - 2 * var(--space-4));
  background: transparent;
  color: var(--text-primary);
}
.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.modal__panel {
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: var(--space-6);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  /* A growing textarea (or a long form) must never push the footer buttons off
     screen — the body can't scroll while a modal is open. */
  max-height: calc(100dvh - 2 * var(--space-6));
  overflow-y: auto;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}
.modal__title { font-size: var(--text-h2); }
.modal__close {
  background: none;
  border: 0;
  color: var(--text-secondary);
  font-size: var(--text-h3);
  cursor: pointer;
  line-height: 1;
}
.modal__close:hover { color: var(--text-primary); }

/* Wide modal (e.g. the two-column video upload). */
.modal--wide { max-width: 760px; }

/* File vs Live mode switch on the member upload form. */
.upload-form__modes {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.upload-form__modes .field-check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }

/* Upload form: single column on mobile, two columns (fields | uploads) wide. */
.upload-form__flash { margin-bottom: var(--space-4); }
.upload-form__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
}
@media (min-width: 700px) {
  .upload-form__grid { grid-template-columns: 1fr 1fr; }
}
/* Let each column shrink to its grid track instead of its content min-content
   (default min-width:auto on grid items would otherwise force horizontal overflow). */
.upload-form__col { min-width: 0; }
.upload-form__submit { margin-top: var(--space-5); }

/* Subtitle tracks: full width below the grid, one repeatable row each. */
.upload-form__subs { margin-top: var(--space-5); }

/* Row 1: language + the remove button on the card's right.
   Row 2: the file uploader, spanning the full card width. */
.subtitle-fields {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-top: var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
}
.subtitle-fields .field { margin-bottom: 0; min-width: 0; }
.subtitle-fields__lang { grid-column: 1; }
.subtitle-fields__file { grid-column: 1 / -1; }
/* A subtitle row is a supporting control, so its uploader is shorter than the
   video/thumbnail boxes above it. */
.subtitle-fields .uploader { min-height: 72px; }

.subtitle-fields__remove {
  grid-column: 2;
  /* Bottom of row 1 — level with the select, not with its label. */
  align-self: end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px; /* matches .field-input, so the two line up exactly */
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-tile);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
}
.subtitle-fields__remove .icon { width: 18px; height: 18px; }
.subtitle-fields__remove:hover { color: var(--danger); border-color: var(--danger); }

.subtitle-fields__add {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.subtitle-fields__add[hidden] { display: none; }
.subtitle-fields__add .icon { width: 16px; height: 16px; }

body.modal-open { overflow: hidden; }

/* Submit/Cancel row at the bottom of a modal form (feature 008). */
.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* PIN modal (restricted content, feature 006). */
.pin-modal__hint { color: var(--text-secondary); font-size: var(--text-meta); margin-bottom: var(--space-4); }
.pin-modal__status { display: flex; align-items: center; gap: var(--space-2); font-weight: 600; }
.pin-modal__status .icon { width: 20px; height: 20px; color: var(--success); }
/* Centered, spaced digits for the numeric PIN entry. */
.pin-modal__input {
  text-align: center;
  letter-spacing: 0.5em;
  font-size: var(--text-h3);
  padding-left: 0.5em; /* offset the trailing letter-spacing so digits stay centered */
}

/* --- Thumbnail suggestions (ffmpeg frame grabs) --- */

.thumb-suggest__intro { color: var(--text-secondary); margin-bottom: var(--space-3); }
.thumb-suggest__none { color: var(--text-tertiary); font-size: var(--text-meta); }

/* Skip / continue action sits below the frames, right-aligned. */
.thumb-suggest__skiprow {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-4);
}
.thumb-suggest__skip-form { margin: 0; }

/* Spinner shown by the lazy Turbo Frame until ffmpeg answers. */
.thumb-suggest__loading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  color: var(--text-secondary);
  font-size: var(--text-meta);
}
.thumb-suggest__loading .icon { width: 18px; height: 18px; }

.thumb-suggest__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}
.thumb-suggest__option { margin: 0; min-width: 0; cursor: pointer; display: block; }

/* The radio carries the choice into the enclosing upload form; only its
   styling is hidden, so it stays reachable by keyboard and by screen readers. */
.thumb-suggest__radio {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.thumb-suggest__pick {
  position: relative;
  display: block;
  border: 2px solid transparent;
  border-radius: var(--radius-tile);
  background: var(--surface-3);
  overflow: hidden;
}
.thumb-suggest__option:hover .thumb-suggest__pick { border-color: var(--border-strong); }
.thumb-suggest__radio:checked + .thumb-suggest__pick { border-color: var(--accent-blue); }
.thumb-suggest__radio:focus-visible + .thumb-suggest__pick {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* Fixed height rather than a 16/9 ratio: three across the modal's right-hand
   column works out to roughly 59px tall, too small to judge a frame by. */
.thumb-suggest__img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
}

/* Label strip: muted until chosen, so the selected frame is unmistakable. */
.thumb-suggest__use {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 2px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text-tertiary);
  font-size: var(--text-caption);
  font-weight: 600;
}
.thumb-suggest__radio:checked + .thumb-suggest__pick .thumb-suggest__use {
  background: var(--accent-blue);
  color: #fff;
}
.thumb-suggest__use .icon { width: 12px; height: 12px; opacity: 0; }
.thumb-suggest__radio:checked + .thumb-suggest__pick .thumb-suggest__use .icon { opacity: 1; }

/* Current thumbnail in the catalog edit modal, with its ✕ (remove) control. */
.edit-thumb { position: relative; display: inline-block; }
.edit-thumb__img {
  display: block;
  width: 100%;
  max-width: 320px;
  border-radius: var(--radius-tile);
  border: 1px solid var(--border-subtle);
}
.edit-thumb__remove {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  text-decoration: none;
}
.edit-thumb__remove .icon { width: 14px; height: 14px; }
.edit-thumb__remove:hover { background: var(--danger); }

/* Already-saved file / subtitle facts on the update step. */
.upload-form__saved {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-meta);
  color: var(--text-secondary);
  word-break: break-all;
}
.upload-form__savedicon { width: 16px; height: 16px; color: var(--success); flex: 0 0 auto; }
.upload-form__savedsubs {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: var(--space-2) 0;
  font-size: var(--text-meta);
  color: var(--text-secondary);
}
.upload-form__savedsubs li { display: flex; align-items: center; gap: var(--space-2); }
.upload-form__savedname { color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; }

/* Inline "Uploading…" note under the file picker while the draft saves. */
[data-draft-autosave-target="status"] {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
[data-draft-autosave-target="status"][hidden] { display: none; }
[data-draft-autosave-target="status"] .icon { width: 14px; height: 14px; }
