/* multichar-refs.css — multi-character reference panel for the
   dashboard Video tab. 8 upload slots + live cost preview.
   Uses the same custom properties as the rest of the dashboard
   (--violet, --mute, --text, --line-strong, etc.) so dark and light
   themes both render correctly. */

.multichar-refs {
  margin-top: 14px;
  padding: 14px 16px;
  background: rgba(124, 109, 250, 0.04);
  border: 1px solid rgba(124, 109, 250, 0.18);
  border-radius: 12px;
  font-family: 'Space Grotesk', system-ui, sans-serif;
}

.multichar-refs__header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.multichar-refs__header h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text, #fff);
}

.multichar-refs__header .badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.multichar-refs__toggle {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--mute, #b4b4cc);
  cursor: pointer;
  user-select: none;
}

.multichar-refs__toggle input { cursor: pointer; }

/* Secondary toggle (Smart-expand) lives inside the body, below the
   slot grid — visually subordinate to the primary header toggle. */
.multichar-refs__toggle--secondary {
  display: flex;
  align-items: flex-start;
  margin: 4px 0 6px;
  margin-left: 0;
  font-size: 12px;
  color: var(--text, #fff);
}

.multichar-refs .hint--small {
  margin: 0 0 12px;
  padding-left: 22px;
  font-size: 10.5px;
  font-style: italic;
}

.multichar-cost__row--note {
  font-size: 10.5px;
  font-style: italic;
  padding-top: 0;
  color: var(--mute, #b4b4cc);
}

.multichar-refs__body { margin-top: 12px; }
.multichar-refs__body[hidden] { display: none; }

.multichar-refs .hint {
  margin: 0 0 12px;
  font-size: 11px;
  color: var(--mute, #b4b4cc);
  line-height: 1.5;
}

.multichar-refs .hint code {
  background: rgba(124, 109, 250, 0.15);
  color: #b8b0ff;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
}

.multichar-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

@media (max-width: 760px) {
  .multichar-slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.multichar-slot {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 1.5px dashed rgba(124, 109, 250, 0.4);
  background: rgba(0, 0, 0, 0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-size: 11px;
  color: var(--mute, #b4b4cc);
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
}

.multichar-slot:hover {
  border-color: var(--violet, #7c6dfa);
  background: rgba(124, 109, 250, 0.08);
}

.multichar-slot--filled {
  border: 1.5px solid rgba(124, 109, 250, 0.5);
  cursor: default;
}

.multichar-slot--uploading { opacity: 0.6; pointer-events: none; }

.multichar-slot__plus { font-size: 22px; line-height: 1; margin-bottom: 4px; }
.multichar-slot__label-empty { font-weight: 600; }

.multichar-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.multichar-slot__tag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  padding: 2px 7px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 4px;
  pointer-events: none;
  letter-spacing: 0.03em;
}

.multichar-slot__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.multichar-slot__remove:hover { background: rgba(239, 68, 68, 0.8); }

.multichar-slot__hidden-input { display: none; }

.multichar-slot__caption-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 6px;
  font-size: 9.5px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.92);
  background: linear-gradient(to top, rgba(0,0,0,0.78), rgba(0,0,0,0.45));
  pointer-events: none;
  font-weight: 500;
  letter-spacing: 0.01em;
}

/* === Slot popover (Upload / Pick from Storage) === */
.multichar-slot-menu {
  background: var(--glass-strong, rgba(20, 23, 42, 0.98));
  border: 1px solid var(--line-strong, rgba(124, 109, 250, 0.3));
  border-radius: 8px;
  padding: 4px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-width: 220px;
  font-family: 'Inter', system-ui, sans-serif;
  backdrop-filter: blur(8px);
}
.multichar-slot-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  background: transparent;
  border: none;
  color: var(--text, #fff);
  cursor: pointer;
  font-size: 13px;
}
.multichar-slot-menu button:hover {
  background: rgba(124, 109, 250, 0.18);
}

/* === My Storage picker modal === */
.multichar-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.multichar-picker {
  background: var(--glass-strong, #14172a);
  border: 1px solid var(--line-strong, rgba(124, 109, 250, 0.3));
  border-radius: 12px;
  width: min(900px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  color: var(--text, #fff);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.multichar-picker__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.multichar-picker__head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.multichar-picker__close {
  background: transparent;
  border: none;
  color: var(--text, #fff);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.multichar-picker__search {
  margin: 14px 20px 8px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text, #fff);
  font-size: 13px;
  font-family: inherit;
}
.multichar-picker__grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px 20px 20px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 760px) {
  .multichar-picker__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.multichar-picker__loading,
.multichar-picker__empty,
.multichar-picker__error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--mute, rgba(255, 255, 255, 0.6));
  font-size: 13px;
}
.multichar-picker-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.multichar-picker-card:hover {
  border-color: rgba(124, 109, 250, 0.5);
  transform: translateY(-2px);
}
.multichar-picker-card__thumb {
  aspect-ratio: 1 / 1;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
}
.multichar-picker-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.multichar-picker-card__name {
  padding: 6px 10px 0;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.multichar-picker-card__caption {
  padding: 2px 10px 8px;
  font-size: 11px;
  color: var(--mute, rgba(255, 255, 255, 0.6));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multichar-cost {
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(124, 109, 250, 0.18);
  border-radius: 8px;
  font-size: 12px;
}

.multichar-cost__row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  color: var(--mute, #b4b4cc);
}

.multichar-cost__row--total {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid rgba(124, 109, 250, 0.2);
  color: var(--text, #fff);
  font-weight: 700;
}

.multichar-cost__row strong { font-weight: 700; color: var(--text, #fff); }

.multichar-note {
  margin: 12px 0 0;
  font-size: 11px;
  color: var(--mute, #b4b4cc);
  line-height: 1.5;
  font-style: italic;
}

/* The mirror's wrap-width must equal the textarea's at all times,
   otherwise chips drift off later @image[N] tokens. The mirror has
   overflow:hidden (no scrollbar gutter); reserve the gutter on the
   textarea so its content wrap-width stays constant whether or not
   a scrollbar is currently visible. Fallback to always-on scrollbar
   for browsers that don't support scrollbar-gutter (Chrome <94,
   Firefox <97, Safari <18.2). */
.prompt-area {
  scrollbar-gutter: stable;
}
@supports not (scrollbar-gutter: stable) {
  .prompt-area {
    overflow-y: scroll;
  }
}

/* Token chip overlay used to color @image[N] in the prompt textarea.
   The textarea itself can't be styled per-token, so multichar-tokens.js
   renders an invisible mirror div behind it with these spans. */
.multichar-token-mirror {
  position: absolute;
  inset: 0;
  pointer-events: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: hidden;
  color: transparent;
  font: inherit;
  padding: inherit;
  box-sizing: border-box;
}

.multichar-token--filled {
  background: rgba(34, 197, 94, 0.22);
  border-radius: 3px;
  color: rgba(34, 197, 94, 0.95);
}

.multichar-token--empty {
  background: rgba(239, 68, 68, 0.22);
  border-radius: 3px;
  color: rgba(239, 68, 68, 0.95);
  text-decoration: underline wavy rgba(239, 68, 68, 0.7);
}

/* Dim the existing single-ref / 2×2 grid section when multichar mode
   is on, so the user understands which uploader is active. The
   --dimmed modifier is added by multichar-tokens.js. */
.char-section.multichar-dimmed {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(0.5);
  transition: opacity 0.2s, filter 0.2s;
}
