/* ============================================================
   Media AI Box - Polish layer
   ----------------------------------------------------------------
   - Refined scrollbars (Apple-style, thinner, on-hover)
   - Unified dropdown / select styling site-wide
   - Compact "add follow image" form in style tab
   - Job status bar (fixed-bottom global progress)
   - Inline spinner for buttons
   ============================================================ */

/* ============ Scrollbars (global refresh) ============ */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(60, 60, 67, 0.18);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background-color 0.2s var(--ease-out);
}
::-webkit-scrollbar-thumb:hover {
  background-color: rgba(60, 60, 67, 0.32);
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:active {
  background-color: rgba(60, 60, 67, 0.45);
  background-clip: padding-box;
}
::-webkit-scrollbar-corner {
  background: transparent;
}
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(60, 60, 67, 0.22) transparent;
}

/* ============ Selects / dropdowns (unified) ============ */
.select {
  appearance: none;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%236e6e73' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1.5 1.5l4.5 4.5 4.5-4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  background-size: 10px 7px;
  padding-inline-start: 32px;
  padding-inline-end: 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  font-weight: 500;
  cursor: pointer;
  transition:
    border-color 0.15s var(--ease-out),
    box-shadow 0.15s var(--ease-out),
    background-color 0.15s;
}
.select:hover {
  border-color: var(--border-strong);
  background-color: var(--surface-hover);
}
.select:focus {
  border-color: var(--accent);
  background-color: var(--surface);
  box-shadow: var(--shadow-focus);
}
.select::-ms-expand {
  display: none;
}
.select option {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  padding: 8px 10px;
}
.select-sm {
  background-position: left 9px center;
  padding-inline-start: 26px;
  padding-inline-end: 10px;
}

/* Dropdown menu (custom) */
.dropdown-menu {
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow:
    0 14px 40px -10px rgba(0, 0, 0, 0.18),
    0 2px 6px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border: 1px solid var(--border);
  padding: 5px;
}
.dropdown-item {
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-weight: 500;
  transition: background 0.12s var(--ease-out);
}
.dropdown-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ============ Custom select (button trigger + body-mounted menu) ============ */
.cselect-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-xs);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: -0.005em;
  transition:
    border-color 0.15s var(--ease-out),
    background 0.15s var(--ease-out),
    box-shadow 0.15s var(--ease-out);
}
.cselect-trigger:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.cselect-trigger:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}
.cselect-trigger.open {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}
.cselect-trigger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.cselect-trigger-label {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cselect-trigger-chevron {
  display: inline-flex;
  align-items: center;
  color: var(--text-3);
  flex-shrink: 0;
  transition: transform 0.18s var(--ease-out);
}
.cselect-trigger.open .cselect-trigger-chevron {
  transform: rotate(180deg);
  color: var(--accent);
}

/* The menu lives on <body> via position: fixed (set inline) */
.cselect-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow:
    0 18px 48px -12px rgba(0, 0, 0, 0.22),
    0 2px 6px rgba(0, 0, 0, 0.06);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 9999;
  animation: cselectIn 0.15s var(--ease-out);
  font-family: inherit;
}
@keyframes cselectIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.cselect-option {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: start;
  white-space: nowrap;
  transition: background 0.1s;
  justify-content: space-between;
}
.cselect-option:hover {
  background: var(--surface-hover);
}
.cselect-option.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
/* Non-selectable category header inside a grouped dropdown (e.g. video models). */
.cselect-group-header {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted, #888);
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
}
.cselect-group-header:not(:first-child) {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--divider);
}
.cselect-option-label {
  flex-shrink: 0;
}
.cselect-option-hint {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Video model list: show full label + hint (price, ♪) without clipping */
.cselect-menu--video-models .cselect-option-hint {
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}
.cselect-option-hint-inner {
  display: inline-flex;
  align-items: center;
  gap: 0;
  max-width: 100%;
}
.cselect-audio-icon {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  color: var(--text-2);
}
.cselect-audio-icon--conditional {
  color: var(--text-muted);
  opacity: 0.55;
}
.cselect-option.active .cselect-audio-icon--conditional {
  color: var(--text-muted);
  opacity: 0.65;
}
/* .cselect-option-hint::before {
  content: "·";
  margin-inline-end: 6px;
  color: var(--text-muted);
} */
.cselect-option.active .cselect-option-hint {
  color: var(--accent);
  opacity: 0.85;
}

.cselect-option-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
}

.cselect-option-row .cselect-option {
  flex: 1;
  min-width: 0;
}

.cselect-option-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 34px;
  margin: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-pressed);
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color 0.12s,
    border-color 0.12s,
    background 0.12s;
}

.cselect-option-preview:hover:not(:disabled) {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, var(--surface-pressed));
}

.cselect-option-preview:disabled {
  opacity: 0.55;
  cursor: wait;
}

.cselect-option-preview--text {
  width: auto;
  min-width: 38px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.cselect-option-row:has(.cselect-option.active) .cselect-option-preview {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.cselect-menu--voices {
  min-width: min(100%, 320px);
}

/* ============ Inline spinner inside buttons ============ */
.btn-inline-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  margin-inline-end: 6px;
}
.btn-secondary .btn-inline-spinner,
.btn-ghost .btn-inline-spinner {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--text);
}

/* ============ Style tab: tiles-grid with inline add tile ============ */
.card-compact {
  padding: var(--s-4);
}
.card-header-compact {
  margin-bottom: var(--s-3);
}

.card-compact .elem-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--s-2);
}
.card-compact .elem-tile {
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.card-compact .elem-tile-img {
  aspect-ratio: 1;
  background-size: cover;
  background-position: center;
  background-color: var(--surface-pressed);
  position: relative;
}
.card-compact .elem-tile-img-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 20px;
}
.card-compact .elem-tile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  gap: 4px;
  min-height: 26px;
}
.card-compact .elem-tile-name {
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-compact .elem-remove-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.card-compact .elem-remove-btn:hover {
  background: var(--surface-pressed);
  color: var(--red);
}

/* ── Inline "add" tile ───────────────────────────── */
.elem-tile-add {
  border: 1.5px dashed var(--border-strong);
  background: transparent;
  transition:
    border-color 0.15s,
    background 0.15s;
}
.elem-tile-add:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.elem-tile-add-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-3);
}
.elem-tile-add-plus {
  font-size: 24px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.elem-tile-add:hover .elem-tile-add-plus {
  color: var(--accent);
}
.elem-tile-name-hint {
  color: var(--text-3) !important;
  font-style: normal;
}
.elem-tile-footer-hint {
  justify-content: center;
}
.elem-tile-footer-edit {
  gap: 4px;
}
.elem-tile-save-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent, #7c5cfc);
  color: #fff;
  border: none;
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.elem-tile-save-btn:hover {
  opacity: 0.85;
}

/* ── Add character modal ── */
.add-char-modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding-block: 20px;
}
.add-char-preview {
  width: 160px;
  height: 160px;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  border: 2px solid var(--border);
}
.add-char-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  align-self: flex-start;
  width: 100%;
}
.add-char-name-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
}
.add-char-name-input:focus {
  border-color: var(--accent);
}
.elem-tile-img-clear {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  font-size: 10px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.elem-tile-add .elem-tile-img:hover .elem-tile-img-clear {
  opacity: 1;
}
.elem-tile-name-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
  padding: 0;
  font-family: inherit;
}
.elem-tile-name-input::placeholder {
  color: var(--text-muted);
}

/* ============ AI generation toast (magic) ============ */
.toast.toast-ai {
  --ai-ring-w: 1.5px;
  --ai-radius: 12px;
  --_toast-color: transparent;
  position: relative;
  isolation: isolate;
  overflow: visible;
  padding: 10px 12px 10px 14px;
  gap: 10px;
  min-width: 260px;
  max-width: 380px;
  align-items: center;
  border: none;
  border-radius: var(--ai-radius);
  /* Fully opaque fill - ring is a separate layer, not transparent rgba */
  background-color: var(--surface);
  background-image: linear-gradient(
    135deg,
    color-mix(in srgb, var(--surface) 92%, #ede9fe) 0%,
    var(--surface) 45%,
    color-mix(in srgb, var(--surface) 94%, #f5f3ff) 100%
  );
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.13),
    0 1px 4px rgba(0, 0, 0, 0.07),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 0 28px rgba(139, 92, 246, 0.05);
  animation: toastIn 0.28s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Spinning border ring - solid colors, pixel-aligned to the toast edge */
.toast.toast-ai::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: var(--ai-ring-w);
  --ai-shimmer: 0deg;
  /* Colors flow along the border; the toast itself never rotates */
  background: conic-gradient(
    from var(--ai-shimmer),
    #c4b5fd 0deg 240deg,
    #ddd6fe 265deg,
    #f5f3ff 278deg,
    #8b5cf6 292deg,
    #7c3aed 308deg,
    #c4b5fd 325deg 360deg
  );
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  animation: aiToastBorderFlow 2.8s linear infinite;
}

@property --ai-shimmer {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

/* Soft violet aura - sits behind the toast, not inside it */
.toast.toast-ai::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: calc(var(--ai-radius) + 6px);
  z-index: -1;
  background: radial-gradient(
    ellipse 90% 80% at 50% 50%,
    rgba(139, 92, 246, 0.14),
    transparent 72%
  );
  pointer-events: none;
  animation: aiToastAura 3.2s ease-in-out infinite;
}

.toast.toast-ai > * {
  position: relative;
  z-index: 1;
}

@keyframes aiToastBorderFlow {
  to {
    --ai-shimmer: 360deg;
  }
}

@keyframes aiToastAura {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.9;
  }
}

@keyframes aiIconGlow {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

.toast-ai-text {
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}

.toast-ai-timer {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  opacity: 0.7;
  margin-inline-start: auto;
  padding-inline-start: 8px;
  flex-shrink: 0;
  align-self: center;
}

/* Lottie sparkle - soft magical glow behind icon */
.toast-ai-lottie-wrap {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.toast-ai-lottie-wrap::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(167, 139, 250, 0.35) 0%,
    rgba(139, 92, 246, 0.08) 55%,
    transparent 72%
  );
  animation: aiIconGlow 2.4s ease-in-out infinite;
}

.toast-ai-lottie {
  width: 22px !important;
  height: 22px !important;
  margin: 0 !important;
  position: relative;
  z-index: 1;
}

.toast-ai-fallback-icon {
  color: #8b5cf6;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .toast.toast-ai::before {
    animation: none;
    --ai-shimmer: 280deg;
  }
  .toast.toast-ai::after,
  .toast-ai-lottie-wrap::before {
    animation: none;
    opacity: 0.7;
  }
}

/* ============ Job status chips (live inside #toastContainer) ============ */
/* Each chip is a sticky toast - uses the existing .toast layout from
   main.css, with status-aware accents below. */
.toast.job-chip {
  /* Match the toast container width while still allowing icon+text layout */
  gap: var(--s-2);
  align-items: center;
}
.toast.job-chip-running {
  border-color: rgba(0, 113, 227, 0.25);
}
.toast.job-chip-done {
  border-color: rgba(52, 199, 89, 0.35);
  background: rgba(52, 199, 89, 0.06);
}
.toast.job-chip-error {
  border-color: rgba(255, 59, 48, 0.35);
  background: rgba(255, 59, 48, 0.06);
}
.job-chip-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.toast.job-chip-done .job-chip-icon {
  background: var(--green);
  color: white;
}
.toast.job-chip-error .job-chip-icon {
  background: var(--red);
  color: white;
}
.job-chip-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 113, 227, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.job-chip-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.job-chip-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.005em;
}
.job-chip-meta {
  font-size: 11px;
  color: var(--text-3);
}
.toast.job-chip-done .job-chip-meta {
  color: #1a7a2f;
}
.toast.job-chip-error .job-chip-meta {
  color: #b4291f;
}

/* ============ AI image creator modal ============ */
.ai-modal-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-4);
}
.ai-modal-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.ai-modal-textarea {
  min-height: 100px;
  resize: vertical;
}
.ai-modal-textarea.fix {
  min-height: 90px;
}

/* Mode toggle - segmented control at top of the modal (create vs fix) */
.ai-modal-mode-toggle {
  display: inline-flex;
  align-self: flex-start;
  background: var(--surface-pressed);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.ai-modal-mode-toggle .mode-pill {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  background: transparent;
  border: none;
  border-radius: calc(var(--r-md) - 3px);
  padding: 7px 16px;
  cursor: pointer;
  transition:
    background 0.15s var(--ease-out),
    color 0.15s var(--ease-out),
    box-shadow 0.15s var(--ease-out);
  letter-spacing: -0.005em;
}
.ai-modal-mode-toggle .mode-pill:hover:not(.active):not(:disabled) {
  color: var(--text);
}
.ai-modal-mode-toggle .mode-pill.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
.ai-modal-mode-toggle .mode-pill:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Textarea loading overlay */
.ai-textarea-wrap {
  position: relative;
}
.ai-textarea-wrap.loading .ai-modal-textarea {
  opacity: 0.45;
  pointer-events: none;
}
.ai-textarea-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}
.ai-textarea-spinner-ring {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ai-spin 0.7s linear infinite;
  display: block;
}
@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}
.ai-textarea-spinner-label {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
}

/* Bottom action row - model/quality (physical right) · button+price (physical left) */
.ai-modal-action-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 4px 6px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  padding-top: var(--s-3);
  border-top: 1px solid var(--divider);
  container-type: inline-size;
  container-name: ai-modal-action;
}
.ai-modal-action-row-controls {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1 1 0;
  overflow: hidden;
  /* RTL: flex-start = physical right edge of the row */
  justify-content: flex-start;
}
.ai-modal-action-row .duration-group {
  flex: 1 1 0;
  min-width: 0;
  gap: 3px;
  overflow: hidden;
}
.ai-modal-action-row .cselect-trigger {
  width: 100%;
  min-width: 0;
  max-width: none;
  padding: 6px 8px;
  font-size: 12px;
  gap: 3px;
}
.ai-modal-action-row .cselect-trigger-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-modal-action-row .generate-btn-with-price {
  flex: 0 0 auto;
  flex-shrink: 0;
  margin-inline-start: auto;
  gap: 6px;
  min-width: 0;
}

@container ai-modal-action (max-width: 36rem) {
  .ai-modal-action-row .duration-label {
    display: none;
  }

  .ai-modal-action-row-controls {
    gap: 3px;
  }

  .ai-modal-action-row .cselect-trigger {
    padding: 5px 6px;
    font-size: 11px;
  }

  .ai-modal-action-row .generate-btn-with-price {
    gap: 4px;
  }

  .ai-modal-action-row .video-generate-btn {
    padding: 5px 8px;
    font-size: 11px;
  }
}
/* Price chip only - same button placement as before */
.generate-btn-with-price {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-inline-start: auto;
  direction: ltr;
}
.generate-btn-with-price .video-generate-btn {
  margin-inline-start: 0;
  direction: rtl; /* keep icon+label order; wrapper is ltr only for [btn][price] */
}
.generate-btn-price {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  white-space: nowrap;
  direction: ltr;
  flex-shrink: 0;
}

/* References row (persistent characters from style tab) */
.ai-modal-refs {
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  height: 130px;
  overflow: hidden;
}
.ai-modal-settings {
  height: auto;
  min-height: 0;
  overflow: visible;
}
.ai-modal-refs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.ai-modal-refs-empty {
  background: transparent;
  border-style: dashed;
  border-color: var(--border-strong);
}
.ai-modal-refs-empty-hint {
  font-size: 12px;
  color: var(--text-3);
}
.ai-modal-refs-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.ai-modal-ref {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: 84px;
}
.ai-modal-ref img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  display: block;
}
.ai-modal-ref-name {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}

/* Start-frame checkbox row (above refs box, end-frame only) */
.ai-modal-refs-section {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}
.ai-modal-start-check-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}

/* Ref item with checkbox */
.ai-modal-ref-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  max-width: 84px;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.ai-modal-ref-item input[type="checkbox"] {
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  z-index: 1;
}
.ai-modal-ref-item img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 2px solid var(--accent);
  background: var(--surface);
  display: block;
  transition:
    opacity 0.15s,
    border-color 0.15s;
}
.ai-modal-ref-item.excluded img {
  opacity: 0.35;
  border-color: var(--border);
}
.ai-modal-ref-item .ai-modal-ref-name {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-2);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 80px;
}
.ai-modal-ref-item.excluded .ai-modal-ref-name {
  color: var(--text-3);
  text-decoration: line-through;
}

/* Style-tab settings - single horizontal row */
.ai-modal-settings-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.ai-modal-setting-chip {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 220px;
  padding: 5px 10px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  transition:
    opacity 0.15s,
    border-color 0.15s;
}
.ai-modal-setting-chip-wide {
  max-width: 200px;
}
.ai-modal-setting-chip-grow {
  flex: 1 1 auto;
  max-width: 280px;
  min-width: 120px;
}
.ai-modal-setting-check {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.ai-modal-setting-check input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
}
.ai-modal-setting-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}
.ai-modal-setting-control {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1 1 auto;
}
.ai-modal-setting-control .cselect-trigger {
  width: 100%;
  min-width: 72px;
  max-width: 120px;
  font-size: 12px;
  padding: 4px 8px;
}
.ai-modal-setting-value {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}
.ai-modal-setting-chip.excluded {
  opacity: 0.55;
  border-style: dashed;
}
.ai-modal-setting-chip.excluded .ai-modal-setting-value {
  color: var(--text-3);
  text-decoration: line-through;
}
.ai-modal-setting-chip.excluded .ai-modal-setting-control {
  opacity: 0.45;
  pointer-events: none;
}

/* "What will be sent" preview */
.ai-modal-send-preview {
  background: var(--accent-soft);
  border: 1px solid rgba(0, 113, 227, 0.22);
  border-radius: var(--r-md);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-modal-send-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}
.ai-modal-send-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ai-modal-send-model {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid rgba(0, 113, 227, 0.22);
  border-radius: var(--r-pill);
  padding: 2px 10px;
}
.ai-modal-send-refs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.ai-modal-send-ref-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--r-xs);
  border: 1px solid var(--surface);
  background: var(--surface);
  display: block;
  box-shadow: var(--shadow-xs);
}
.ai-modal-send-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ai-modal-send-tag {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 2px 9px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-modal-send-tag-style {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(0, 113, 227, 0.2);
}
.ai-modal-send-style-tags {
  margin-top: -2px;
}
.ai-modal-send-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-modal-send-prompt {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.55;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  max-height: 96px;
  overflow-y: auto;
  direction: ltr;
  text-align: start;
  font-family: "SF Mono", Consolas, monospace;
}
.ai-modal-send-prompt.is-he {
  direction: rtl;
  font-family: inherit;
}
.ai-modal-send-prompt em {
  font-family: inherit;
  font-style: italic;
  color: var(--text-muted);
}

/* Result panel inside modal */
.ai-modal-result {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.ai-modal-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.ai-modal-result-badge {
  font-size: 10px;
  font-weight: 700;
  color: white;
  background: var(--green);
  border-radius: var(--r-pill);
  padding: 3px 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ai-modal-result-meta {
  font-size: 11px;
  color: var(--text-3);
}
.ai-modal-result-img {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: #000;
  border-radius: var(--r-md);
  display: block;
}
.ai-modal-result-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.ai-modal-result-actions .btn {
  flex: 1 1 auto;
  min-width: 120px;
}
/* "You are editing this image" preview at the top of fix mode */
.ai-modal-editing-preview {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  background: var(--surface-2);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
}
.ai-modal-editing-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  display: block;
}
.ai-modal-editing-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ai-modal-editing-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ai-modal-editing-hint {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
}

/* ============================================================
   RESPONSIVE / MOBILE - Media AI Box
   Breakpoints:
     960px → tablet  (nav collapses to drawer)
     768px → mobile  (full layout rework)
     480px → phone   (compact tweaks)
   ============================================================ */

/* ─── Missing base utility ─── */
/* input-big used in new-project modal */
.input-big {
  font-size: 17px;
  font-weight: 500;
  padding: 12px var(--s-4);
  border-radius: var(--r-md);
  letter-spacing: -0.015em;
}

/* mobile topbar: hidden on desktop */
.mobile-topbar {
  display: none;
}

/* project-header-bottom: tabs + editor button together */
.project-header-bottom {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

/* ─── Tablet & below (≤960px): nav drawer ─── */
@media (max-width: 960px) {
  /* App shell: single column */
  #app-shell {
    grid-template-columns: 1fr;
  }

  /* Side nav: fixed right-side drawer (RTL app) */
  .side-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0; /* physical right - same as inset-inline-start in RTL */
    left: auto; /* prevent any LTR offset */
    width: min(280px, 85vw);
    z-index: 502;
    transform: translateX(100%);
    transition: transform 0.18s var(--ease-out);
    box-shadow: none;
    overflow-y: auto;
    padding-top: var(--s-6);
    border-inline-start: none;
    border-left: 1px solid var(--border);
    will-change: transform;
  }

  .side-nav.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* Dim backdrop when nav is open */
  body:has(.side-nav.open)::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 500;
    pointer-events: auto;
  }

  /* Main area: full width, content scrollable */
  .main-area {
    min-width: 0;
    width: 100%;
  }

  .content-area {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* leave room at top for fixed topbar (52px) */
    padding: calc(52px + var(--s-4)) var(--s-5) var(--s-8);
  }

  /* Full-width fixed topbar */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 501;
  }

  .mobile-brand-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    flex: 1;
    min-width: 0;
  }

  .mobile-topbar-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
    border-radius: 6px;
    flex-shrink: 0;
    margin-inline-end: var(--s-4);
  }

  .mobile-toggle {
    display: flex !important;
    position: static;
    inset-inline-end: unset;
    top: unset;
    z-index: unset;
    width: 36px;
    height: 36px;
    min-width: 36px;
    touch-action: manipulation;
    /* background: var(--surface-pressed); */
    /* border: 1px solid var(--border); */
    /* border-radius: var(--r-sm); */
    font-size: 22px;
    flex-shrink: 0;
    margin-right: var(--s-1);
  }

  /* Workspace: no fixed heights, prevent overflow */
  .shots-layout {
    min-height: unset;
  }

  .shots-layout > * {
    min-width: 0;
    overflow-x: hidden;
  }

  .shot-rail,
  .shot-stage,
  .videos-panel {
    position: static;
    height: auto;
  }

  .shot-rail {
    max-height: 240px;
  }

  /* Project header: wrappable */
  .project-header {
    padding: var(--s-3) var(--s-4);
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  /* Usage: one-row stats + scrollable history table */
  .usage-stats-grid {
    grid-template-columns: 1.5fr repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .usage-stat-box {
    padding: var(--s-2);
    min-width: 0;
  }

  .usage-history-section {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Editor: proper layout with fixed 52px topbar ── */
  .content-area:has(.editor-shell) {
    padding: calc(52px + var(--s-2)) var(--s-2) var(--s-2);
    overflow: hidden;
  }

  .editor-shell {
    height: calc(100dvh - 52px - var(--s-4));
    min-height: unset;
    grid-template-rows: 1fr minmax(200px, 40%);
  }
}

/* ─── Mobile (≤768px): full layout rework ─── */
@media (max-width: 768px) {
  .content-area {
    padding: calc(52px + var(--s-3)) var(--s-3) var(--s-8);
  }

  /* ── Home ── */
  .home-header {
    flex-direction: column;
    align-items: flex-start;
    padding: var(--s-4) 0 var(--s-3);
    gap: var(--s-3);
  }

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

  /* Always show delete button (no hover on touch) */
  .project-delete-btn {
    opacity: 1;
  }

  /* ── Shot rail → header above, shots scroll horizontally ── */
  .shot-rail {
    flex-direction: column;
    max-height: none;
    padding: var(--s-2) var(--s-3) 0;
    overflow: visible;
  }

  .rail-list {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    margin-top: var(--s-2);
    flex: 1;
    gap: var(--s-2);
    padding-bottom: var(--s-2);
    scrollbar-width: none;
  }

  .rail-list::-webkit-scrollbar {
    display: none;
  }

  .rail-item {
    flex-shrink: 0;
    flex-direction: column;
    align-items: center;
    min-width: 68px;
    max-width: 80px;
    padding: var(--s-2) var(--s-1);
    gap: 4px;
  }

  .rail-thumb {
    width: 60px;
    height: 44px;
    border-radius: var(--r-sm);
  }

  .rail-info,
  .rail-delete-btn {
    display: none;
  }

  .rail-insert {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 22px;
    padding: 0 2px;
    margin: 0;
    opacity: 0.9;
    gap: 3px;
  }

  .rail-insert-line {
    width: 1px;
    height: 16px;
    flex: 0 0 auto;
  }

  .rail-insert-plus {
    width: 20px;
    height: 20px;
  }

  .rail-add-btn {
    flex-shrink: 0;
    align-self: center;
    margin-top: 0;
    margin-inline-start: var(--s-2);
  }

  /* ── Shot stage ── */
  .shot-stage {
    height: auto;
    overflow-x: hidden;
    overflow-y: visible;
    padding-inline-end: 0;
  }

  /* ── Videos panel ── */
  .videos-panel {
    max-height: 50vh;
    overflow-y: auto;
  }

  /* ── Project header: stack title, then tabs+button row ── */
  .project-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .project-header-bottom {
    align-self: stretch;
    justify-content: space-between;
  }

  .project-header-tabs .wtab {
    flex: 1;
    text-align: center;
  }

  /* ── Stage bar: allow wrapping ── */
  .stage-bar {
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  /* ── Prompt card head: wrap actions below ── */
  .prompt-card-head {
    flex-wrap: wrap;
  }

  /* ── Frame chooser: stack slots vertically on mobile so buttons fit ── */
  .frame-chooser {
    grid-template-columns: 1fr;
    gap: var(--s-2);
  }

  .frame-arrow {
    transform: rotate(-90deg);
    height: 18px;
    font-size: 14px;
  }

  .frame-slot {
    max-height: unset;
    overflow: hidden;
  }

  /* On touch/mobile: icon chips always visible (handled in workspace-layout.css) */

  /* Mobile: hide text label, keep icon visible */
  .frame-slot-action-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    gap: 0;
  }

  .frame-slot-action-btn .fsab-label {
    display: none;
  }

  /* Empty slot */
  .frame-slot-empty-btns {
    gap: 3px;
    padding: 5px;
  }

  .frame-slot-hint-text {
    font-size: 9px;
  }

  .frame-slot-icon {
    width: 18px;
    height: 18px;
  }

  .frame-slot-icon svg {
    width: 14px;
    height: 14px;
  }

  .frame-slot-btn-row {
    gap: 4px;
    flex-wrap: nowrap;
    width: 100%;
  }

  /* Icon-only empty-slot buttons on mobile */
  .frame-slot-btn-row .btn {
    width: 24px;
    height: 24px;
    padding: 0;
    min-height: 0;
    min-width: 0;
    font-size: 0; /* hide text */
    flex: 0 0 auto;
    justify-content: center;
    border-radius: 5px;
  }

  /* Keep the icon inside visible */
  .frame-slot-btn-row .btn .ui-icon {
    font-size: initial;
  }

  .frame-slot-empty {
    min-height: unset;
    padding: var(--s-2) var(--s-1);
    gap: 4px;
  }

  .frame-slot-empty-icon {
    width: 28px;
    height: 28px;
    font-size: 15px;
    margin: 0;
  }

  .frame-slot-empty-label {
    font-size: 9px;
  }

  .frame-slot-empty-actions {
    gap: 4px;
    max-width: 100%;
  }

  .frame-slot-empty-actions .btn {
    font-size: 11px;
    padding: 4px 6px;
    white-space: nowrap;
  }

  /* Video settings: row 1 = controls (fill width), row 2 = price + button (fill width) */
  .video-settings-row {
    flex-wrap: wrap;
    gap: 4px 0;
  }

  /* Row 1: controls take the full width and divide it equally */
  .video-settings-row-controls {
    flex: 1 1 100%;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .video-settings-row .duration-group {
    flex: 1 1 0;
    min-width: 0;
    gap: 2px;
  }

  .video-settings-row .duration-group--model {
    flex: 0 0 auto;
    min-width: 0;
  }

  .video-settings-row .duration-group--model .cselect-trigger {
    width: auto;
  }

  .video-settings-row .duration-label {
    display: none;
  }

  .video-settings-row .duration-group .cselect-trigger {
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 5px 6px;
    font-size: 11px;
    gap: 3px;
  }

  .video-settings-row .duration-group--model .cselect-trigger-label {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Row 2: price + button take the full width, button stretches */
  .video-settings-row .generate-btn-with-price {
    flex: 1 1 100%;
    margin-inline-start: 0;
    margin-top: 4px;
    justify-content: flex-end;
  }

  .video-settings-row .generate-btn-with-price .video-generate-btn {
    flex: 1;
    justify-content: center;
    padding: 7px 10px;
    font-size: 12px;
  }

  /* ── Modals → bottom sheet ── */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--s-5) var(--s-5)
      max(var(--s-5), env(safe-area-inset-bottom, var(--s-5)));
  }

  .modal.modal-lg {
    max-width: 100%;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--s-4) var(--s-4)
      max(var(--s-4), env(safe-area-inset-bottom, var(--s-4)));
  }

  /* VFX studio: fixed header + scrollable body (not whole-sheet scroll) */
  .modal:has(.vfx-modal),
  .modal.modal-lg:has(.vfx-modal) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: min(92dvh, 92vh);
    min-height: 0;
    padding: 0;
  }

  /* Audio picker: scroll the list only, not the whole bottom sheet */
  .modal:has(.audio-picker-modal),
  .modal:has(.add-local-modal),
  .modal.modal-lg:has(.add-local-modal--video) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 88vh;
    min-height: 0;
    padding: 0;
  }

  .modal:has(.global-library-modal) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 88vh;
    min-height: 0;
  }

  /* Drag handle at top of bottom-sheet modal */
  .modal::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border-strong);
    border-radius: var(--r-pill);
    margin: 0 auto var(--s-4);
  }

  /* Modal footer: buttons stay in one row, wrap only if very narrow */
  .modal-footer {
    flex-wrap: wrap;
    gap: var(--s-2);
    margin-top: var(--s-4);
    padding-top: var(--s-3);
  }

  .modal-footer .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
  }

  /* ── New Project modal ── */
  .np-pending-row {
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  .np-pending-row .input {
    flex: 1 1 100%;
    min-width: 0;
  }

  /* ── Editor: full mobile overhaul ── */
  /* Page container: pull bottom padding tight; respect device safe area */
  .content-area:has(.editor-shell) {
    padding: calc(52px + var(--s-2)) var(--s-2)
      env(safe-area-inset-bottom, var(--s-2));
  }

  /* Shell: grow to fill viewport, give preview more room than timeline */
  .editor-shell {
    height: calc(
      100dvh - 52px - var(--s-2) - env(safe-area-inset-bottom, var(--s-2))
    );
    grid-template-rows: 1fr minmax(185px, 38%);
  }

  /* Back button: 40 × 40 touch target */
  .editor-back-btn {
    width: 40px;
    height: 40px;
  }

  /* Transport: taller bar with finger-sized buttons */
  .preview-transport {
    height: 50px;
    padding: 0 10px;
    gap: 8px;
  }

  .tr-play {
    width: 50px;
    height: 38px;
  }

  .tr-btn,
  .tr-fullscreen {
    width: 38px;
    height: 38px;
  }

  /* Scrub: thicker track + always-visible handle (no hover on touch) */
  .tr-scrub {
    height: 6px;
  }

  .tr-scrub-handle {
    width: 16px;
    height: 16px;
    opacity: 1;
  }

  .tr-timecode {
    min-width: 80px;
    font-size: 11px;
  }

  /* Timeline tools bar: scrollable icon strip */
  .timeline-tools-bar {
    gap: 4px;
    padding: 4px 8px;
    min-height: 44px;
  }

  /* Hide text labels - icons are sufficient on small screens */
  .tb-btn-label {
    display: none;
  }

  /* Compact tool buttons: icon-only, square-ish touch target */
  .tb-btn {
    min-width: 34px;
    padding: 7px;
  }

  .tb-mobile-only {
    display: inline-flex;
  }

  .tb-segment .tb-btn {
    min-width: 34px;
  }

  /* BPM number input triggers the number keyboard and crowds the bar - hide it.
     The beat-sync button (in the same tb-group) stays visible. */
  .tb-bpm-group {
    display: none;
  }

  /* Shorter zoom slider so it doesn't dominate the bar */
  .tb-zoom input[type="range"] {
    width: 54px;
  }

  /* History buttons: square touch target */
  .tb-history-btn {
    width: 32px;
    height: 32px;
  }

  /* Export: icon-only square button on mobile (match the other tool buttons) */
  .tb-export {
    height: 34px;
    width: 34px;
    padding: 0;
    gap: 0;
    justify-content: center;
  }

  /* Hide the "ייצוא" caption - the download icon is enough on small screens */
  .tb-export span {
    display: none;
  }

  /* Smooth kinetic scroll for the tracks area */
  .timeline-scroll {
    -webkit-overflow-scrolling: touch;
  }

  /* Playhead drag handle: wider for finger precision */
  .tl-playhead-handle {
    width: 18px;
    height: 18px;
  }

  /* Track rows: slightly tighter to show more tracks on a small viewport */
  .track-row.video .track-label,
  .track-row.video .track-content {
    min-height: 50px;
    height: 50px;
  }

  .track-row.audio .track-label,
  .track-row.audio .track-content {
    min-height: 38px;
    height: 38px;
  }

  .color-popover,
  .tx-popover {
    width: calc(100vw - var(--s-6));
    max-width: 340px;
  }

  .export-radio-group {
    grid-template-columns: 1fr 1fr;
  }

  /* ── Image creator controls: single column ── */
  .img-creator-controls {
    grid-template-columns: 1fr;
  }

  /* AI modal action row: single row, squeeze to fit */
  .ai-modal-action-row {
    flex-wrap: nowrap;
    gap: 4px;
    padding-top: var(--s-2);
    overflow: hidden;
  }

  .ai-modal-action-row-controls {
    flex-wrap: nowrap;
    flex: 1 1 0;
    min-width: 0;
    gap: 3px;
    overflow: hidden;
  }

  .ai-modal-action-row .duration-group {
    flex: 1 1 0;
    min-width: 0;
    gap: 2px;
  }

  .ai-modal-action-row .duration-label {
    display: none;
  }

  .ai-modal-action-row .cselect-trigger {
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 5px 6px;
    font-size: 11px;
    gap: 3px;
  }

  .ai-modal-action-row .video-generate-btn {
    flex: 0 0 auto;
    min-width: 0;
    padding: 5px 8px;
    font-size: 11px;
  }
  .ai-modal-action-row .generate-btn-with-price {
    flex: 0 0 auto;
    flex-shrink: 0;
    margin-inline-start: auto;
    justify-content: flex-end;
  }
  .ai-modal-action-row .generate-btn-with-price .video-generate-btn {
    flex: 0 0 auto;
    min-width: 0;
  }

  /* ── AI modal refs: auto height ── */
  .ai-modal-refs {
    height: auto;
  }

  /* ── Lightbox: full-width media ── */
  .lightbox-media {
    max-height: calc(60vh);
  }

  .lightbox-actions {
    justify-content: stretch;
  }

  .lightbox-actions .btn {
    flex: 1;
  }

  /* Lightbox stays centered (not bottom-sheet) on mobile */
  .modal-backdrop:has(.lightbox) {
    align-items: center;
    padding: var(--s-4);
  }

  .modal.modal-lg:has(.lightbox) {
    border-radius: var(--r-xl);
    max-width: calc(100vw - var(--s-6));
    max-height: 90vh;
  }

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

  /* ── Settings: style row stacks ── */
  .style-row {
    flex-direction: column;
    gap: var(--s-3);
  }

  /* ── Settings: element add form stacks ── */
  .elem-add-form {
    flex-wrap: wrap;
  }

  .elem-add-fields {
    flex: 1 1 100%;
  }

  /* ── Settings: API key row — input + actions stay on one line ── */
  .settings-section .api-key-input-row {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
  }

  .settings-section .api-key-input-row .input {
    flex: 1 1 0;
    min-width: 0;
  }

  .settings-section .api-key-input-actions {
    flex-shrink: 0;
    width: auto;
  }

  /* ── Settings: key row stacks ── */
  .settings-key-row {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--s-2);
  }

  /* ── Settings: data actions stay in one row ── */
  .data-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  /* ── Files grid ── */
  .files-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  /* ── Elem tiles ── */
  .card-compact .elem-tiles-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  }

  /* ── Choice pills: 2 columns on mobile ── */
  .choice-pills {
    grid-template-columns: 1fr 1fr;
  }

  /* ── Custom select menu: constrain width ── */
  .cselect-menu {
    max-width: 92vw;
  }

  /* ── Toast: full width with equal side inset ── */
  .toast-container {
    bottom: max(var(--s-4), env(safe-area-inset-bottom, var(--s-4)));
    inset-inline: 0;
    align-items: stretch;
    padding-inline: var(--s-4);
    box-sizing: border-box;
    max-width: 100%;
    overflow: hidden;
  }

  .toast,
  .toast.toast-ai,
  .toast.job-chip,
  .render-progress--in-dock {
    min-width: 0;
    width: 100%;
    max-width: none;
    box-sizing: border-box;
  }

  .toast,
  .toast.toast-ai,
  .toast.job-chip {
    padding: 10px 14px;
  }

  .toast.toast-ai::after {
    inset: -4px;
  }

  /* ── Touch targets: 44px minimum ── */
  .btn:not(.btn-sm):not(.btn-icon):not(.btn-xs) {
    min-height: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .nav-item,
  .sidebar-project {
    min-height: 44px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
    border: none !important;
  }

  .rail-item {
    min-height: 44px;
  }

  .np-pill,
  .style-pill,
  .choice-pill,
  .aspect-pill,
  .usage-tab,
  .wtab {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Inputs: 16px prevents iOS auto-zoom ── */
  .input,
  .textarea,
  .select,
  .input-big {
    font-size: 16px;
  }
}

/* ─── Small phones (≤480px) ─── */
@media (max-width: 480px) {
  .content-area {
    padding: calc(52px + var(--s-2)) var(--s-3) var(--s-6);
  }

  .home-greeting h1 {
    font-size: 20px;
  }

  .projects-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--s-2);
  }

  .modal {
    padding: var(--s-4) var(--s-3)
      max(var(--s-4), env(safe-area-inset-bottom, var(--s-4)));
  }

  .editor-shell {
    grid-template-rows: 1fr minmax(160px, 35%);
  }

  /* Transport: hide timecode on smallest phones to give scrub more room */
  .tr-timecode {
    display: none;
  }

  /* Transport buttons: slightly smaller but still 36px tap zone */
  .tr-btn,
  .tr-fullscreen {
    width: 34px;
    height: 34px;
  }

  /* Tools bar: strip all chrome except icon area */
  .timeline-tools-bar {
    padding: 2px 6px;
    min-height: 40px;
  }

  .tb-btn {
    min-width: 30px;
    padding: 5px;
  }

  .tb-segment .tb-btn {
    min-width: 30px;
  }

  .frame-chooser {
    grid-template-columns: 1fr 16px 1fr;
    gap: var(--s-1);
  }

  /* Stack choice pills to single column */
  .choice-pills {
    grid-template-columns: 1fr;
  }

  /* Style pills: single row, scroll if needed */
  .style-pills-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  /* Compact sidebar when open */
  .side-nav {
    width: min(260px, 90vw);
  }

  /* Usage stats: slightly smaller on small phones */
  .usage-stat-value {
    font-size: 13px;
  }

  .usage-stat-label,
  .usage-stat-sub {
    font-size: 9px;
  }

  /* Files grid: 2 items per row */
  .files-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ─── Touch devices: scrub interaction & larger tap targets ─── */
@media (pointer: coarse) {
  .tr-scrub {
    touch-action: none;
    height: 6px;
  }

  .tr-scrub-handle {
    opacity: 1;
    width: 16px;
    height: 16px;
  }

  .editor-back-btn {
    width: 40px;
    height: 40px;
  }

  /* Reveal controls that are otherwise shown only on hover - on touch there is
     no hover to trigger them, so they'd be unreachable. (Timeline trim handles
     already appear on tap-to-select; rail-insert is hidden on mobile by design.) */
  .panel-video-zoom-btn,
  .panel-video-remove-btn,
  .vplayer-knob,
  .aplayer-knob,
  .project-delete-btn,
  .project-menu-trigger,
  .elem-tile-img-clear {
    opacity: 1;
  }
}

/* ─── Open Editor CTA button ─── */
.btn-open-editor {
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  padding: 7px 16px;
  border-radius: var(--r-sm);
  gap: 6px;
  transition: background 0.15s var(--ease-out);
}
.btn-open-editor:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-open-editor:active:not(:disabled) {
  background: var(--accent-pressed);
}
.btn-open-editor svg {
  flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════════════════
   MOBILE EDITOR - app-grade touch ergonomics. Tool panels slide up as
   bottom sheets (CapCut/InShot style); all controls are finger-sized.
   Loaded last so it wins the cascade and overrides the smaller defaults.
   ════════════════════════════════════════════════════════════════════════ */
@keyframes sheetUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@media (hover: none), (max-width: 768px) {
  /* ── Every editor tool popover → a bottom sheet ──────────────────────── */
  .popover {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
    border-radius: 18px 18px 0 0 !important;
    padding: 22px 16px max(16px, env(safe-area-inset-bottom, 16px)) !important;
    gap: 16px !important;
    box-shadow: 0 -10px 44px rgba(0, 0, 0, 0.3) !important;
    animation: sheetUp 0.24s cubic-bezier(0.32, 0.72, 0, 1) !important;
    z-index: 1000 !important;
  }
  /* Grab handle so it reads as a draggable sheet */
  .popover::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-strong, #c7c7cc);
  }

  /* Finger-sized controls inside the sheets */
  .popover .slider,
  .popover input[type="range"] {
    height: 26px;
  }
  .popover .slider::-webkit-slider-thumb {
    width: 26px;
    height: 26px;
  }
  .popover .slider::-moz-range-thumb {
    width: 26px;
    height: 26px;
  }
  .popover-actions {
    gap: 10px;
  }
  .popover-actions .btn,
  .popover .btn {
    min-height: 46px;
    font-size: 14px;
  }
  .speed-grid button,
  .tx-chip,
  .fit-grid button,
  .fx-grid button {
    min-height: 44px;
  }
  .slider-row {
    gap: 12px;
  }

  /* ── Option pickers (custom-select) → bottom sheets with big rows ──────── */
  .cselect-menu {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    max-height: 72vh !important;
    border-radius: 18px 18px 0 0 !important;
    padding: 20px 10px max(14px, env(safe-area-inset-bottom, 14px)) !important;
    box-shadow: 0 -10px 44px rgba(0, 0, 0, 0.3) !important;
    animation: sheetUp 0.24s cubic-bezier(0.32, 0.72, 0, 1) !important;
    gap: 2px !important;
  }
  .cselect-menu::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-strong, #c7c7cc);
  }
  .cselect-option {
    min-height: 48px;
    font-size: 15px;
    padding: 11px 14px;
  }
  .cselect-option-hint {
    font-size: 12px;
  }

  /* ── Bigger toolbar / transport tap targets (override the 34-38px above) ── */
  .timeline-tools-bar {
    min-height: 54px;
    gap: 6px;
  }
  .tb-btn,
  .tb-segment .tb-btn {
    min-width: 44px;
    min-height: 40px;
    padding: 8px;
  }
  .tb-export,
  .timeline-tools-bar .tb-export {
    height: 40px;
    width: 40px;
  }
  .preview-transport {
    height: 56px;
  }
  .tr-btn,
  .tr-fullscreen {
    width: 42px;
    height: 42px;
  }
  .tr-play {
    width: 58px;
    height: 42px;
  }
  .tr-scrub {
    height: 8px;
  }
  .tr-scrub-handle {
    width: 20px;
    height: 20px;
  }

  /* Slightly tighter shell gap to give the timeline a bit more room */
  .editor-shell {
    gap: 6px;
  }

  /* Native-app feel: kill the grey tap-flash and the long-press text/callout
     on controls and draggable surfaces. */
  button,
  a,
  .cselect-trigger,
  .cselect-option,
  .tb-btn,
  .tr-btn,
  .nav-item,
  .tl-clip,
  .tl-trim,
  .tl-audio-block,
  .wm-box,
  .preview-logo {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }
}

/* ============ Media loading / re-fetch state ============ */
/* Added by attachMediaFallback() on a thumb container while its <img>/<video>
   is being (re)fetched from the server, so a dropped blob URL shows a clear
   "loading" placeholder with a spinner instead of a blank grey box. */
.media-loading {
  position: relative;
}
.media-loading::before {
  content: "טוען מחדש…";
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3, #6e6e73);
  border-radius: inherit;
  pointer-events: none;
  background-color: var(--surface-2, #fafafa);
  background-image: linear-gradient(
    100deg,
    rgba(0, 0, 0, 0) 30%,
    rgba(255, 255, 255, 0.65) 50%,
    rgba(0, 0, 0, 0) 70%
  );
  background-size: 220% 100%;
  background-repeat: no-repeat;
  animation: media-loading-shimmer 1.2s ease-in-out infinite;
}
.media-loading::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -18px 0 0 -11px;
  z-index: 6;
  border: 2.5px solid var(--border-strong, rgba(0, 0, 0, 0.12));
  border-top-color: var(--accent, #0071e3);
  border-radius: 50%;
  pointer-events: none;
  animation: spin 0.7s linear infinite;
}
@keyframes media-loading-shimmer {
  0% {
    background-position: 220% 0;
  }
  100% {
    background-position: -120% 0;
  }
}
