/* image-field.css
 * Styles for the shared image-field widget (assets/js/shared/image-field/).
 * Mounted by the Spell Creator, the Campaign Forge entity panel, and the
 * Monster Creator. Colors come from the shared theme tokens defined in
 * assets/css/main_style.css (--primary-color, --card-bg, --text-*, etc.) with
 * fallbacks, so the widget inherits each host's accent without hardcoding.
 */

.image-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 320px;
}

.image-field__label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary, #8a93a6);
}

/* Square preview slot — a small framed "portrait". Fluid: fills its column up
   to a cap, so it adapts from a single field (spell) to a 2-up grid (monster). */
.image-field__preview {
  position: relative;
  width: 100%;
  max-width: 160px;
  aspect-ratio: 1 / 1;
  border: 1px dashed var(--border-color, #ccc);
  border-radius: 10px;
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(var(--primary-color-rgb, 74, 105, 189), 0.10), transparent 62%),
    var(--card-bg, #fff);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

/* Once it holds an image it reads as a framed picture: solid accent border. */
.image-field__preview:has(.image-field__img[src]) {
  border-style: solid;
  border-color: rgba(var(--primary-color-rgb, 74, 105, 189), 0.4);
}

.image-field__preview:hover {
  border-color: var(--primary-color, #4a69bd);
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 6px 16px rgba(0, 0, 0, 0.28);
}

.image-field__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Placeholder shown when there is no value yet. */
.image-field__placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  color: var(--text-secondary, #9aa0a6);
  text-align: center;
  padding: 0.5rem;
}

.image-field__placeholder-text {
  font-size: 0.75rem;
}

.image-field__controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.image-field__btn {
  font: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.45rem 0.75rem;
  border-radius: var(--border-radius, 6px);
  border: 1px solid var(--border-color, #ccc);
  background: var(--card-bg, #fff);
  color: var(--text-primary, var(--text-dark, #34495e));
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.image-field__btn:hover:not(:disabled) {
  border-color: var(--primary-color, #4a69bd);
  background: rgba(var(--primary-color-rgb, 74, 105, 189), 0.08);
}

.image-field__btn:focus-visible {
  outline: 2px solid var(--primary-color, #4a69bd);
  outline-offset: 2px;
}

.image-field__btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Generate gets the accent treatment as the primary affordance. */
.image-field__btn--generate {
  border-color: var(--primary-color, #4a69bd);
  color: var(--primary-color, #4a69bd);
}

.image-field__btn--generate:hover:not(:disabled) {
  background: rgba(var(--primary-color-rgb, 74, 105, 189), 0.12);
}

.image-field__btn--generate.is-busy {
  cursor: progress;
}

/* Remove is quieter and danger-tinted on hover. Hidden until a value exists. */
.image-field__btn--remove {
  color: var(--text-secondary, #7f8c8d);
}

.image-field__btn--remove:hover:not(:disabled) {
  border-color: var(--danger-color, #e74c3c);
  color: var(--danger-color, #e74c3c);
  background: transparent;
}

html.dark .image-field__preview,
html.dark .image-field__btn {
  background: var(--card-bg-dark, #2c2d33);
}

/* ── Generation progress ───────────────────────────────────
   Indeterminate affordance shown while an image is being generated. Spinner +
   honest elapsed seconds (no fake percentage bar) plus a one-line hint, since
   the async providers can poll for many seconds. */
.image-field__generating {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary, #7f8c8d);
}

.image-field__spinner {
  flex: 0 0 auto;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  border: 2px solid rgba(var(--primary-color-rgb, 74, 105, 189), 0.25);
  border-top-color: var(--primary-color, #4a69bd);
  animation: image-field-spin 0.7s linear infinite;
}

.image-field__generating-text {
  font-weight: 600;
  color: var(--text-primary, var(--text-dark, #34495e));
}

/* Hint pushes to its own line on narrow widths via flex-wrap above. */
.image-field__generating-hint {
  font-size: 0.72rem;
  opacity: 0.85;
}

@keyframes image-field-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .image-field__spinner { animation-duration: 1.6s; }
}

/* ── Prompt panel ──────────────────────────────────────── */
.image-field__prompt-panel {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem;
  border: 1px solid var(--border-color, #ccc);
  border-radius: var(--border-radius, 8px);
  background: rgba(var(--primary-color-rgb, 74, 105, 189), 0.05);
}

.image-field__prompt-heading {
  font-size: 0.78rem;
  color: var(--text-secondary, #7f8c8d);
}

.image-field__prompt-input {
  font: inherit;
  font-size: 0.85rem;
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 3.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--border-radius, 6px);
  border: 1px solid var(--border-color, #ccc);
  background: var(--card-bg, #fff);
  color: var(--text-primary, var(--text-dark, #34495e));
}

.image-field__prompt-input:focus-visible {
  outline: 2px solid var(--primary-color, #4a69bd);
  outline-offset: 1px;
}

.image-field__prompt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* Create is the primary action in the panel. */
.image-field__btn--create {
  border-color: var(--primary-color, #4a69bd);
  background: var(--primary-color, #4a69bd);
  color: #fff;
}

.image-field__btn--create:hover:not(:disabled) {
  filter: brightness(1.07);
  background: var(--primary-color, #4a69bd);
}

.image-field__btn--cancel {
  color: var(--text-secondary, #7f8c8d);
}

html.dark .image-field__prompt-input {
  background: var(--card-bg-dark, #2c2d33);
}
