/* Files tab */
.files-panel {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

/* Two-pane layout: source folder tree (RTL: right) + library (fills rest). */
.files-panel--with-tree {
  flex-direction: row;
  align-items: flex-start;
  gap: var(--s-4);
}

.files-panel--with-tree .files-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

/* ── Source folder tree ─────────────────────────────────────────────────── */
.local-tree {
  flex: 0 0 300px;
  width: 300px;
  position: sticky;
  top: var(--s-3);
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 160px);
  padding: var(--s-3);
  gap: var(--s-2);
}

.local-tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.local-tree-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
}

.local-tree-head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.local-tree-path {
  display: block;
  font-size: 11.5px;
  color: var(--text-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 4px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: left;
}

.local-tree-filter {
  width: 100%;
  font-size: 13px;
}

.local-tree-connect {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: var(--s-3) 0;
}

.local-tree-connect-text {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-muted);
}

.local-tree-hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

.local-tree-error {
  font-size: 12px;
  color: var(--danger, #c44);
  background: color-mix(in srgb, var(--danger, #c44) 8%, transparent);
  border-radius: var(--r-sm);
  padding: 6px 8px;
  line-height: 1.4;
}

.local-tree-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 calc(var(--s-3) * -1) calc(var(--s-3) * -1);
  padding: 0 4px var(--s-2);
}

.local-tree-empty {
  padding: var(--s-4) var(--s-2);
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.local-tree-node {
  display: flex;
  flex-direction: column;
}

.local-tree-folder-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  border-radius: var(--r-sm);
  transition: background 0.1s;
}

.local-tree-folder-row:hover {
  background: var(
    --surface-hover,
    color-mix(in srgb, var(--accent) 7%, transparent)
  );
}

.local-tree-folder,
.local-tree-file {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: start;
  padding: 5px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.local-tree-folder {
  flex: 1;
  min-width: 0;
  width: auto;
}

.local-tree-folder-row .local-tree-folder:hover {
  background: transparent;
}

.local-tree-file:hover {
  background: var(
    --surface-hover,
    color-mix(in srgb, var(--accent) 7%, transparent)
  );
}

.local-tree-folder-import {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  margin-inline-end: 4px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  opacity: 0;
  transition:
    opacity 0.1s,
    color 0.1s,
    background 0.1s;
}

.local-tree-folder-row:hover .local-tree-folder-import,
.local-tree-folder-import:focus-visible {
  opacity: 1;
}

.local-tree-folder-import:hover {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.local-tree-caret,
.local-tree-folder-icon,
.local-tree-file-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-3);
}

.local-tree-folder-icon {
  color: var(--accent);
}

.local-tree-folder-name,
.local-tree-file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.local-tree-folder-name {
  font-weight: 600;
}

.local-tree-folder-count {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  padding: 0 6px;
}

.local-tree-file-icon {
  color: var(--text-muted);
}

.local-tree-file--video .local-tree-file-icon {
  color: var(--accent);
}

.local-tree-file-dur {
  flex-shrink: 0;
  font-size: 10.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.local-tree-file-add {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-3);
  opacity: 0;
  transition: opacity 0.1s;
}

.local-tree-file:hover .local-tree-file-add {
  opacity: 1;
  color: var(--accent);
}

@media (max-width: 860px) {
  .files-panel--with-tree {
    flex-direction: column;
  }

  .local-tree {
    position: static;
    width: 100%;
    flex-basis: auto;
    max-height: 420px;
  }
}

/* ── Add-to-project modal ───────────────────────────────────────────────── */
.modal:has(.add-local-modal) {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  max-width: 440px;
  width: min(440px, 96vw);
  max-height: min(92vh, 860px);
  min-height: 0;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}

.modal.modal-lg:has(.add-local-modal--video) {
  max-width: 680px;
  width: min(680px, 96vw);
}

.add-local-modal {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
  direction: rtl;
}

.add-local-modal .modal-header {
  padding: var(--s-4) var(--s-5);
  margin-bottom: 0;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
  background: var(--surface);
}

.add-local-modal .modal-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.add-local-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

/* Video: media right, controls left (RTL grid) */
.add-local-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 252px);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.add-local-media-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #000;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.add-local-media-col .vplayer-wrap {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 278px;
  border-radius: 0;
  max-width: none;
  margin: 0;
  align-items: stretch;
  background: transparent;
}

.add-local-media-col .vplayer-video {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  object-fit: contain;
}

.add-local-side,
.add-local-options {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  background: var(--surface-2);
}

.add-local-side {
  overflow-y: auto;
  padding: var(--s-3) var(--s-4);
  border-inline-start: 1px solid var(--divider);
}

.add-local-side .export-form-row,
.add-local-options .export-form-row {
  gap: 8px;
  padding: var(--s-3) 0;
}

.add-local-side .export-form-row:first-child,
.add-local-options .export-form-row:first-child {
  padding-top: 0;
}

.add-local-side .export-form-row:last-child,
.add-local-options .export-form-row:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.add-local-side .export-form-label,
.add-local-options .export-form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: -0.01em;
}

.add-local-side .export-segment,
.add-local-side .cselect-trigger,
.add-local-options .export-segment,
.add-local-options .cselect-trigger {
  width: 100%;
}

.add-local-side .field-hint,
.add-local-options .field-hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.add-local-side .prep-trim-bar {
  gap: 6px;
}

.add-local-side .prep-trim-actions {
  gap: 4px;
}

.add-local-side .prep-trim-actions .btn {
  flex: 1;
  min-width: 0;
  padding-inline: 6px;
}

/* Image / audio preview */
.add-local-preview.lightbox-body {
  flex-shrink: 0;
  padding: var(--s-3) var(--s-5);
  background: var(--surface-2);
}

.add-local-preview--image {
  display: flex;
  align-items: center;
  justify-content: center;
}

.add-local-preview--image .lightbox-media {
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
}

.add-local-preview--audio {
  padding-block: var(--s-4);
}

.add-local-preview .aplayer {
  width: 100%;
  direction: ltr;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  background: var(--surface);
}

.add-local-options {
  padding: var(--s-3) var(--s-5) var(--s-4);
  border-top: 1px solid var(--divider);
}

.add-local-role {
  padding-top: 2px;
}

.add-local-role .export-segment {
  width: 100%;
}

.add-local-modal .modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: 0;
  padding: var(--s-3) var(--s-5);
  flex-shrink: 0;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

@media (max-width: 640px) {
  .add-local-split {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .add-local-side {
    border-inline-start: none;
    border-top: 1px solid var(--divider);
    order: 2;
  }

  .add-local-media-col {
    order: 1;
    min-height: min(40vh, 320px);
  }

  .add-local-modal .modal-header,
  .add-local-preview.lightbox-body,
  .add-local-options,
  .add-local-side,
  .add-local-modal .modal-footer {
    padding-inline: var(--s-4);
  }
}

/* Local source folder (per-project) — compact link strip only */
.local-source-panel {
  padding: var(--s-3) var(--s-4);
}

.local-source-compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
}

.local-source-compact-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
}

.local-source-path {
  flex: 1 1 120px;
  min-width: 0;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}

.local-source-sort-btn {
  margin-inline-start: auto;
}

.local-source-hint {
  margin: var(--s-2) 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.badge.local-badge {
  font-size: 10px;
  padding: 2px 6px;
  margin-inline-start: 6px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border-radius: var(--r-sm);
}

.badge.folder-badge {
  font-size: 10px;
  padding: 2px 6px;
  margin-inline-start: 4px;
  flex-shrink: 0;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--surface-pressed);
  color: var(--text-2);
  border-radius: var(--r-sm);
}

.file-item-name-row .badge {
  margin-inline-start: 0;
}

.files-library-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.files-folder-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.files-folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  cursor: pointer;
  transition:
    border-color 0.12s,
    background 0.12s,
    color 0.12s;
  max-width: 100%;
}

.files-folder-chip:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.files-folder-chip.is-active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
  font-weight: 600;
}

.files-folder-chip-count {
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  padding: 0 6px;
  line-height: 1.5;
}

.files-folder-chip.is-active .files-folder-chip-count {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.files-folder-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.files-folder-group-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: start;
  padding: 8px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.1s;
}

.files-folder-group-head:hover {
  background: var(--surface-hover);
}

.files-folder-group-caret,
.files-folder-group-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-3);
}

.files-folder-group-icon {
  color: var(--accent);
}

.files-folder-group-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: end;
}

.files-folder-group-count {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-pressed);
  border-radius: var(--r-pill);
  padding: 0 7px;
}

.files-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  box-shadow: var(--shadow-xs);
  transition:
    border-color 0.12s ease,
    background 0.12s ease;
}

/* Drag a file over a media section → highlight it as a drop target. */
.files-section.is-drop-over {
  border-color: var(--accent);
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}

.files-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--divider);
}

.files-section-head.files-section-head--collapsed {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.files-section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  text-align: inherit;
  font: inherit;
  color: inherit;
  border-radius: var(--r-sm);
}

.files-section-toggle:hover {
  color: var(--text);
}

.files-section-toggle:hover .files-section-caret {
  color: var(--text-2);
}

.files-section-caret {
  display: flex;
  flex-shrink: 0;
  color: var(--text-3);
}

.files-section.is-collapsed .files-section-body {
  display: none;
}

.files-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.files-section-count {
  background: var(--surface-pressed);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--r-pill);
}

.files-empty {
  padding: var(--s-5);
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--s-3);
}

.file-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.15s;
}

.file-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}

.file-item-thumb {
  aspect-ratio: 16/9;
  background: var(--surface-pressed);
  cursor: pointer;
  overflow: hidden;
}

.file-item-thumb img,
.file-item-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-item-info {
  padding: var(--s-3);
  flex: 1;
  min-width: 0;
}

.file-item-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  min-width: 0;
}

.file-item-name-row .file-item-name {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
  border-radius: 3px;
  padding: 1px 3px;
  margin: -1px -3px;
  transition: background 0.12s;
}

.file-item-name:hover {
  background: var(--surface-hover);
}

.file-item-name-input {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-hover);
  border: 1.5px solid var(--accent);
  border-radius: 3px;
  padding: 1px 5px;
  outline: none;
  width: 100%;
  min-width: 0;
}

.file-item-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.file-item-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 6px;
  border-top: 1px solid var(--divider);
  background: var(--surface);
}

.audio-item {
  flex-direction: column;
  gap: 0;
  padding: 0;
  cursor: pointer;
}

.audio-item:hover:not(.is-main) {
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}

.audio-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-2);
  padding: var(--s-3);
}

.audio-item-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.audio-item .file-item-info {
  padding: 0;
  flex: 1;
  min-width: 0;
}

.audio-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

/* ── Audio library: main soundtrack (editor timeline) ───────────────────── */
.audio-main-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
  pointer-events: none;
}

.audio-item .aplayer {
  cursor: default;
}

.audio-item.is-main {
  outline: 1.5px solid var(--accent);
  border-radius: var(--r-2, 8px);
}

/* ── Audio chooser (audio-driven video models) ──────────────────────────── */
.video-card-footer .video-audio-field {
  margin-bottom: var(--s-1);
}

.audio-chooser {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--divider);
  border-radius: var(--r-2, 8px);
  background: var(--surface);
}

/* RTL: play sits on the right of the track name (first in row = inline-end). */
.audio-chooser-track {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: 1;
  min-width: 0;
  direction: rtl;
}

.audio-chooser-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: start;
}

.audio-chooser-play-wrap {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.audio-chooser-preview-audio {
  display: none;
}

/* ── Audio picker modal ─────────────────────────────────────────────────── */
.modal:has(.audio-picker-modal) {
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 720px);
  overflow: hidden;
  min-height: 0;
}

.audio-picker-modal {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.audio-picker-modal .modal-header.audio-picker-header {
  flex-shrink: 0;
  margin-bottom: 0;
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--divider);
}

.audio-picker-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-4) 0 0;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.audio-picker-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
  flex-shrink: 0;
}

.audio-picker-quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 96px;
  padding: var(--s-3);
  border: 1.5px dashed var(--border-strong, var(--border));
  border-radius: var(--r-md, 10px);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  transition:
    border-color 0.15s,
    background 0.15s,
    transform 0.12s var(--ease-out);
}

.audio-picker-quick-btn:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}

.audio-picker-quick-btn:active {
  transform: scale(0.98);
}

.audio-picker-quick-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-pressed);
  color: var(--text-muted);
  transition: color 0.15s;
}

.audio-picker-quick-btn:hover .audio-picker-quick-icon {
  color: var(--accent);
}

.audio-picker-quick-btn--ai .audio-picker-quick-icon {
  color: var(--accent);
}

.audio-picker-quick-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.audio-picker-quick-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

.audio-picker-library {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.audio-picker-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-inline: 2px;
  flex-shrink: 0;
}

.audio-picker-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 2px;
  margin: -2px;
}

.audio-picker-empty {
  padding: var(--s-5) var(--s-4);
  text-align: center;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--r-md, 10px);
  background: var(--surface-pressed);
}

.audio-picker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md, 10px);
  background: var(--surface);
  overflow: hidden;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.audio-picker-row:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.audio-picker-row.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent);
}

.audio-picker-row-select {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: start;
  font: inherit;
  color: inherit;
  transition: background 0.12s;
}

.audio-picker-row:hover .audio-picker-row-select {
  background: color-mix(in srgb, var(--accent) 3%, transparent);
}

/* .audio-picker-row.is-selected .audio-picker-row-select {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
} */

.audio-picker-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.audio-picker-row-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.audio-picker-row-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

.audio-picker-row-play {
  align-self: center;
  margin-inline: 6px 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-pressed);
  flex-shrink: 0;
}

.audio-picker-row-play:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-pressed));
  color: var(--accent);
}

.audio-picker-preview-audio {
  display: none;
}

@media (max-width: 480px) {
  .audio-picker-quick {
    grid-template-columns: 1fr;
  }

  .audio-picker-quick-btn {
    flex-direction: row;
    justify-content: flex-start;
    min-height: 0;
    text-align: start;
    padding: var(--s-3) var(--s-4);
  }
}

.files-section-actions {
  display: flex;
  gap: var(--s-2, 6px);
  flex-wrap: wrap;
}

/* ── Speech creator (AI narration / TTS) modal ──────────────────────────── */
.speech-creator-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-3);
}
.speech-creator-body .field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 6px);
}
.speech-suggestions {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 6px);
}
.speech-suggestions:empty {
  display: none;
}

.speech-suggestion-card .speech-suggestion-block-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted, #888);
  margin-top: 8px;
  margin-bottom: 3px;
}

.speech-suggestion-card .speech-suggestion-block-label:first-of-type {
  margin-top: 0;
}

.speech-suggestion-style-block {
  margin-top: 2px;
}

.suggestion-card-style {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-2, var(--text));
  font-style: italic;
}
.speech-voice-hint {
  font-size: 11.5px;
  color: var(--text-muted, #888);
  line-height: 1.45;
  margin-top: 4px;
}

.speech-voice-hint:empty {
  display: none;
}

.speech-cartoon-design-btn {
  margin-top: 8px;
  align-self: flex-start;
}

.cartoon-voice-lead {
  font-size: 13px;
  color: var(--text-2, var(--text));
  line-height: 1.5;
  margin: 0 0 var(--s-3, 12px);
}

.cartoon-voice-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted, #888);
  padding: var(--s-4, 16px) 0;
}

.cartoon-voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-3, 12px);
}

.cartoon-voice-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: var(--s-3, 12px);
  border: 1px solid var(--divider);
  border-radius: var(--radius, 8px);
  background: var(--surface-2, var(--surface));
}

.cartoon-voice-card-title {
  font-size: 13px;
  font-weight: 600;
}

.cartoon-voice-error {
  color: var(--danger, #c44);
  font-size: 13px;
}

.speech-creator-hint {
  font-size: 11.5px;
  color: var(--text-muted, #888);
  line-height: 1.4;
}
.speech-creator-result {
  display: flex;
  flex-direction: column;
  gap: var(--s-2, 6px);
  padding: var(--s-3);
  border: 1px solid var(--divider);
  border-radius: var(--radius, 8px);
  background: var(--surface-2, var(--surface));
}
.speech-creator-result[hidden] {
  display: none;
}
.speech-creator-result-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2, var(--text));
}
.speech-creator-result-meta {
  font-size: 11.5px;
  color: var(--text-muted, #888);
}
.speech-creator-result-audio {
  width: 100%;
  height: 36px;
  margin-top: 2px;
}
.speech-creator-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  padding-top: var(--s-2, 6px);
  border-top: 1px solid var(--divider);
}
.speech-price {
  font-size: 12.5px;
  color: var(--text-muted, #888);
  font-variant-numeric: tabular-nums;
}

/* ── AI Object Eraser modal ─────────────────────────────────────────────── */
.modal.modal-lg:has(.ime-modal) {
  max-width: min(1180px, 98vw);
  width: min(1180px, 98vw);
  max-height: min(92dvh, 900px);
  height: min(92dvh, 900px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ime-modal {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
}

.ime-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--divider);
  margin-bottom: 0;
}

.ime-title-wrap {
  min-width: 0;
}

.ime-header .modal-title {
  font-size: 17px;
  font-weight: 650;
}

.ime-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(560px, 72vw);
}

.ime-status {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  color: #c62828;
  background: rgba(198, 40, 40, 0.08);
  border-bottom: 1px solid rgba(198, 40, 40, 0.2);
  padding: var(--s-2) var(--s-4);
}

.ime-status[hidden] {
  display: none;
}

.ime-stage {
  flex: 1;
  min-height: 0;
  margin: var(--s-2) var(--s-4);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #e6e6ec 25%, transparent 25%),
    linear-gradient(-45deg, #e6e6ec 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6e6ec 75%),
    linear-gradient(-45deg, transparent 75%, #e6e6ec 75%);
  background-size: 18px 18px;
  background-position:
    0 0,
    0 9px,
    9px -9px,
    -9px 0;
  background-color: #f1f1f5;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.ime-canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: var(--s-3);
}

.ime-view-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
  max-height: 100%;
}

.ime-view {
  display: block;
  cursor: none;
  border-radius: var(--r-sm);
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.22);
  touch-action: none;
}

.ime-cursor {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  border: 2px solid rgba(255, 255, 255, 0.98);
  border-radius: 50%;
  background: rgba(255, 45, 85, 0.22);
  box-shadow:
    0 0 0 1.5px rgba(0, 0, 0, 0.6),
    0 0 0 3.5px rgba(255, 45, 85, 0.3);
  transform: translate3d(-9999px, -9999px, 0) translate(-50%, -50%);
  will-change: transform;
  z-index: 4;
  transition:
    width 0.06s ease,
    height 0.06s ease;
}

.ime-cursor.is-erase {
  background: rgba(255, 255, 255, 0.25);
  box-shadow:
    0 0 0 1.5px rgba(0, 0, 0, 0.6),
    0 0 0 3.5px rgba(120, 120, 130, 0.4);
}

.ime-ai-loading {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(20, 20, 24, 0.55);
  backdrop-filter: blur(3px);
  border-radius: inherit;
}

/* `hidden` must win over the explicit display below. */
.ime-ai-loading[hidden],
.ime-controls[hidden] {
  display: none;
}

.ime-ai-loading-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
}

.ime-ai-loading-icon .toast-ai-lottie-wrap {
  width: 56px;
  height: 56px;
}

.ime-ai-loading-icon .toast-ai-lottie {
  width: 56px !important;
  height: 56px !important;
}

.ime-ai-loading-icon .toast-ai-fallback-icon {
  width: 40px;
  height: 40px;
  color: #c4b5fd;
}

.ime-ai-loading-text {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.ime-toolbar {
  flex-shrink: 0;
  padding: var(--s-2) var(--s-4) var(--s-3);
  border-top: 1px solid var(--divider);
  background: var(--surface);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.ime-controls {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-width: min-content;
}

.ime-spacer {
  flex: 1 1 12px;
  min-width: 8px;
}

.ime-controls .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* Segmented tool toggle */
.ime-tool-group {
  display: inline-flex;
  background: var(--surface-pressed);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}

.ime-tool {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: calc(var(--r-md) - 3px);
  cursor: pointer;
  transition: all 0.12s;
}

.ime-tool:hover {
  color: var(--text);
}

.ime-tool.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-xs);
}

.ime-size {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  flex-shrink: 0;
}

.ime-size-label {
  font-weight: 600;
}

.ime-range {
  width: 120px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.ime-size-val {
  min-width: 3ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--text);
  font-size: 14px;
}

.ime-apply {
  min-width: 130px;
  justify-content: center;
}

.ime-hold {
  touch-action: none;
  user-select: none;
}

.ime-hold.is-pressed {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 720px) {
  .modal.modal-lg:has(.ime-modal) {
    width: 100vw;
    max-width: 100vw;
    max-height: 92dvh;
    height: 92dvh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }

  .modal.modal-lg:has(.ime-modal)::before {
    display: none;
  }

  .ime-modal {
    height: 100%;
  }

  .ime-header {
    padding: var(--s-2) var(--s-3);
  }

  .ime-stage {
    margin: var(--s-2) var(--s-3);
  }

  .ime-status {
    padding: var(--s-2) var(--s-3);
    font-size: 12px;
  }

  .ime-toolbar {
    padding: var(--s-2) var(--s-3)
      max(var(--s-2), env(safe-area-inset-bottom, 0px));
    overflow-x: visible;
  }

  .ime-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    row-gap: var(--s-2);
    width: 100%;
    min-width: 0;
  }

  .ime-spacer {
    flex: 0 0 100%;
    width: 100%;
    height: 0;
  }

  /* שורה 1 - עריכה: כלים + גודל ממלאים את כל הרוחב */
  .ime-tool-group {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
  }

  .ime-tool-group .ime-tool {
    flex: 1;
    justify-content: center;
  }

  .ime-size {
    flex: 1 1 0;
    min-width: 0;
  }

  /* שורה 1 - תוצאה: שלושת הכפתורים הראשונים */
  .ime-controls:not(:has(.ime-tool-group)) > .btn:nth-child(-n + 3) {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
  }

  /* שורה 2 - רק גודל הכפתור, לא מותחים */
  .ime-spacer ~ .btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    justify-content: center;
  }

  /* יישור שורה 2 לצד הפעולות (כמו בדסקטופ) */
  .ime-spacer + .btn {
    margin-inline-start: auto;
  }

  .ime-tool {
    padding: 6px 10px;
    font-size: 12px;
  }

  .ime-range {
    flex: 1;
    width: auto;
    max-width: none;
  }
}
