/* —— Image generation view ——
   Visual phase: same token system as Home/Chat (dark surfaces, teal accent,
   thin borders, consistent radii, spacing scale). No handler, model,
   capability, aspect-ratio or API change — presentation only. */

.image-nav.active {
  color: var(--color-accent);
  border-color: var(--color-accent-line);
  background: var(--color-accent-soft);
}
.image-nav.active .sidebar-item-icon { color: var(--color-accent); }

/* The view is a centered single-column grid so the "Back to Chat" control and
   the content card share the same left edge, instead of the button hugging the
   viewport padding while the card is centered. */
.image-view { display: none; flex: 1; overflow-y: auto; }
.image-view.active {
  display: grid;
  grid-template-columns: min(100%, 70rem);
  justify-content: center;
  align-content: start;
  padding: clamp(var(--space-4), 3.2vh, var(--space-8)) clamp(var(--space-4), 3vw, var(--space-10)) var(--space-10);
}

/* —— Back to Chat —— */
.image-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.image-back:hover { color: var(--color-text); border-color: var(--color-accent-line); background: var(--color-accent-soft); }

.image-card { width: 100%; margin-top: var(--space-5); }

/* —— Header —— */
.image-heading { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-5); }
.image-heading-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
  background: var(--color-accent-softer);
  color: var(--color-accent);
}
.image-heading-icon svg { width: 20px; height: 20px; }
.image-heading h1 {
  font-size: clamp(1.3rem, 2.4vw, 1.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.image-heading p { margin-top: 2px; color: var(--color-text-secondary); font-size: 0.875rem; line-height: 1.45; }

/* —— Prompt ——
   Composer-like surface: one visible field (the panel) instead of a panel that
   contains a second bordered box, which is what made it feel too tall. */
.image-prompt-panel {
  padding: var(--space-3) var(--space-4) 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-large);
  background: var(--color-surface-raised);
  box-shadow: var(--elevation-2);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.image-prompt-panel:hover { border-color: rgba(230, 247, 243, 0.26); }
.image-prompt-panel:focus-within {
  border-color: rgba(46, 224, 184, 0.45);
  box-shadow: 0 0 0 3px rgba(46, 224, 184, 0.07), var(--elevation-2);
}

.image-prompt-panel label, .image-controls label {
  display: block;
  margin-bottom: 6px;
  color: var(--color-text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

#image-prompt {
  width: 100%;
  min-height: 72px;
  max-height: 240px;
  resize: vertical;
  border: 0;
  border-radius: 0;
  padding: 2px var(--space-1) var(--space-1);
  background: transparent;
  color: var(--color-text);
  caret-color: var(--color-accent);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.55;
  outline: none;
}
#image-prompt::placeholder { color: var(--color-text-faint); }
#image-prompt:focus { outline: none; }
.image-counter {
  margin-top: 2px;
  text-align: right;
  color: var(--color-text-muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}

/* —— Prompt head: label + Improve prompt / Surprise me —— */
.image-prompt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.image-prompt-head label { margin-bottom: 0; }
.image-prompt-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.image-surprise, .image-improve {
  flex: 0 0 auto;
  min-height: 22px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.image-surprise:hover, .image-improve:hover { color: var(--color-text); border-color: var(--color-accent-line); background: var(--color-accent-soft); }
.image-improve { display: inline-flex; align-items: center; gap: 6px; }
.image-improve:disabled { color: var(--color-text-faint); border-color: var(--color-border); background: transparent; cursor: not-allowed; }

/* Loading: discreet inline spinner next to the label (no layout jump). */
.image-improve[aria-busy="true"]::before {
  content: "";
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: image-improve-spin 0.7s linear infinite;
}
@keyframes image-improve-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .image-improve[aria-busy="true"]::before { animation: none; }
}

/* —— Improve prompt feedback: result/undo or a friendly error —— */
.image-prompt-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: 4px;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  line-height: 1.4;
}
.image-prompt-status:not(:has(.image-prompt-status-text:not(:empty))) { display: none; }
.image-prompt-status.is-error .image-prompt-status-text { color: var(--color-danger); }
.image-prompt-status-text { min-width: 0; overflow-wrap: anywhere; }
.image-prompt-undo {
  flex: 0 0 auto;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.image-prompt-undo:hover { color: var(--color-text); border-color: var(--color-accent-line); background: var(--color-accent-soft); }
.image-prompt-undo[hidden] { display: none; }
/* "Prompt improved · Undo" separator, only while the undo action is available. */
.image-prompt-status-text:not(:empty) + .image-prompt-undo:not([hidden])::before {
  content: "\00b7";
  margin-right: var(--space-1);
  color: var(--color-text-faint);
}

/* —— Quick style ——
   Secondary to the prompt and far below Generate in visual weight: small pills,
   single-select, removable by clicking again. Modifiers are appended to the
   prompt in image.js — no new API, no new request shape. */
.image-styles {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.image-styles-label {
  flex: 0 0 auto;
  color: var(--color-text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.image-style-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.image-style-chip {
  min-height: 24px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.image-style-chip:hover { color: var(--color-text); border-color: var(--color-accent-line); background: var(--color-accent-soft); }
/* Selected: same tinted surface + 1px teal inset used by the model menus. */
.image-style-chip[aria-pressed="true"] {
  color: var(--color-text);
  border-color: transparent;
  background: var(--color-accent-soft);
  box-shadow: inset 0 0 0 1px rgba(46, 224, 184, 0.26);
}

/* —— Advanced settings (collapsed by default) ——
   Only parameters the gateway actually accepts end up here (see the report).
   The panel stays visually secondary: a quiet row, no card until opened. */
.image-advanced { margin-top: var(--space-4); }
.image-advanced-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 2px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s;
}
.image-advanced-toggle:hover { color: var(--color-text); }
.image-advanced-chevron { font-size: 0.7rem; line-height: 1; transition: transform 0.15s; }
.image-advanced-toggle[aria-expanded="true"] .image-advanced-chevron { transform: rotate(180deg); }

.image-advanced-panel {
  margin-top: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-large);
  background: var(--color-surface-translucent);
}
.image-advanced-panel[hidden] { display: none; }
.image-count-wrap { display: flex; align-items: center; gap: var(--space-3); }
.image-count-wrap label {
  color: var(--color-text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

/* Number of images: compact segmented control (1-4, gateway max). */
.image-count-picker {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-medium);
  overflow: hidden;
}
.image-count-option {
  min-width: 32px;
  min-height: 28px;
  padding: 0 var(--space-2);
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, box-shadow 0.15s;
}
.image-count-option + .image-count-option { box-shadow: inset 1px 0 0 var(--color-border); }
.image-count-option:hover { color: var(--color-text); background: var(--color-surface-hover); }
.image-count-option[aria-pressed="true"] {
  color: var(--color-text);
  background: var(--color-accent-soft);
  box-shadow: inset 0 0 0 1px rgba(46, 224, 184, 0.26);
}
.image-count-option + .image-count-option[aria-pressed="true"] { box-shadow: inset 1px 0 0 rgba(46, 224, 184, 0.26); }

/* —— Controls —— */
.image-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: var(--space-3);
  align-items: end;
  margin: var(--space-4) 0 var(--space-5);
  padding-bottom: 0;
}
/* The picker anchors its menu. */
.image-aspect-picker { position: relative; }
.image-aspect-wrap { position: relative; display: flex; flex-direction: column; min-width: 0; }

/* —— Selector (same visual system as the composer Model Selector) —— */
.image-aspect-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-medium);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.image-aspect-trigger:hover { border-color: rgba(230, 247, 243, 0.26); }
.image-aspect-picker.open .image-aspect-trigger {
  border-color: rgba(46, 224, 184, 0.5);
  background: var(--color-surface-hover);
  box-shadow: 0 0 0 3px rgba(46, 224, 184, 0.07);
}
.image-aspect-trigger-name {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.image-aspect-chevron {
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--color-text-faint);
  font-size: 0.75rem;
  line-height: 1;
  transition: transform 0.15s;
}
.image-aspect-picker.open .image-aspect-chevron { transform: rotate(180deg); }

/* Same surface, radius and shadow as the composer .model-menu. */
.image-aspect-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + var(--space-2));
  left: 0;
  width: 100%;
  min-width: min(248px, calc(100vw - 2rem));
  max-width: calc(100vw - 2rem);
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-large);
  background: var(--color-overlay);
  box-shadow: var(--elevation-3);
}
.image-aspect-menu[hidden] { display: none; }

.image-aspect-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 4px 10px;
  border-radius: var(--radius-small);
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
}
.image-aspect-option:hover, .image-aspect-option.active { background: var(--color-surface-hover); }
/* Selection mirrors .model-option.active: tinted surface + 1px teal inset, no glow. */
.image-aspect-option[aria-selected="true"] {
  background: var(--color-accent-soft);
  box-shadow: inset 0 0 0 1px rgba(46, 224, 184, 0.26);
}
.image-aspect-option[aria-selected="true"]:hover, .image-aspect-option[aria-selected="true"].active { background: rgba(46, 224, 184, 0.14); }
.image-aspect-option-text { display: block; min-width: 0; }
.image-aspect-option-name { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--color-text); }
.image-aspect-option[aria-selected="true"] .image-aspect-option-name { color: var(--color-text); }

/* —— Primary action —— */
.image-generate {
  min-height: 36px;
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-medium);
  background: var(--color-accent);
  color: var(--color-on-accent);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, color 0.15s, transform 0.12s;
}
.image-generate:hover:not(:disabled) { background: var(--color-accent-hover); box-shadow: 0 0 18px rgba(46, 224, 184, 0.26); }
.image-generate:active:not(:disabled) { transform: scale(0.99); }
/* Disabled state copied from the composer send button (#btn-send). */
.image-generate:disabled {
  border-color: var(--color-border);
  background: var(--color-surface-translucent);
  color: var(--color-text-faint);
  cursor: not-allowed;
  box-shadow: none;
}

/* —— Result / preview ——
   Solid, quieter surface instead of a dashed empty box; the empty state keeps
   the same copy, with a lighter icon and a clearer message hierarchy. */
.image-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: clamp(230px, 32vh, 320px);
  padding: clamp(var(--space-8), 5vh, var(--space-10)) var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-large);
  background:
    radial-gradient(70% 110% at 50% -10%, rgba(46, 224, 184, 0.05), transparent 62%),
    var(--color-surface-translucent);
  color: var(--color-text-secondary);
  text-align: center;
  overflow: hidden;
}
.image-generation-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(100%, 420px);
  animation: image-state-in .24s ease both;
}
.image-generation-preview {
  position: relative;
  width: min(100%, 320px);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-large);
  background: linear-gradient(135deg, rgba(46,224,184,.08), rgba(46,224,184,.025) 45%, rgba(255,255,255,.035));
}
.image-generation-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(105deg, transparent 28%, rgba(125,255,225,.15) 48%, transparent 68%);
  animation: image-preview-shimmer 1.8s ease-in-out infinite;
}
.image-generation-preview::after {
  content: "✦";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(125,255,225,.82);
  font-size: 1.8rem;
  text-shadow: 0 0 24px rgba(46,224,184,.45);
  animation: image-preview-sparkle 2s ease-in-out infinite;
}
.image-generation-state strong { color: var(--color-text); font-size: .92rem; }
.image-generation-state > span:not(.image-generation-dots) {
  max-width: 28rem;
  color: var(--color-text-faint);
  font-size: .78rem;
  line-height: 1.5;
}
.image-generation-dots { display: inline-flex; align-items: center; gap: 4px; height: 10px; }
.image-generation-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: image-generation-dot 1.05s ease-in-out infinite;
}
.image-generation-dots i:nth-child(2) { animation-delay: .14s; }
.image-generation-dots i:nth-child(3) { animation-delay: .28s; }
@keyframes image-preview-shimmer { to { transform: translateX(100%); } }
@keyframes image-preview-sparkle {
  0%, 100% { opacity: .55; transform: scale(.94); }
  50% { opacity: 1; transform: scale(1.08); }
}
@keyframes image-generation-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30% { transform: translateY(-3px); opacity: 1; }
}
@keyframes image-state-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .image-generation-state,
  .image-generation-preview::before,
  .image-generation-preview::after,
  .image-generation-dots i { animation: none !important; }
}
.image-placeholder-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
  background: var(--color-surface-translucent);
  color: var(--color-text-muted);
}
.image-placeholder-icon svg { width: 21px; height: 21px; }
.image-result strong { color: var(--color-text); font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; }
.image-result > span:not(.image-placeholder-icon) { max-width: 28rem; color: var(--color-text-faint); font-size: 0.8125rem; line-height: 1.55; }

/* Result state: the image is the content, so the container steps back. */
.generated-image {
  display: block;
  animation: image-result-reveal .38s cubic-bezier(.2,.75,.25,1) both;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(70vh, 40rem);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-medium);
  background: rgba(0, 0, 0, 0.25);
  object-fit: contain;
}
.image-result:has(.generated-image) {
  gap: var(--space-2);
  min-height: clamp(200px, 28vh, 260px);
  padding: clamp(var(--space-3), 1.5vw, var(--space-4));
  border-color: var(--color-border-strong);
  background: rgba(0, 0, 0, 0.14);
}

/* Several results (n > 1): keep every image within the viewport column. */
.generated-image:not(:only-of-type) { max-height: min(44vh, 26rem); }

/* Clear model attribution for the result (never an ambiguous "AI-made" seal). */
@keyframes image-result-reveal {
  from { opacity: 0; transform: translateY(8px) scale(.985); filter: blur(5px); }
  to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

@media (prefers-reduced-motion: reduce) {
  .generated-image { animation: none !important; }
}

.generated-image-error {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.image-result-caption {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

/* —— Responsive —— */
@media (max-width: 900px) {
  .image-controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .image-view.active { padding: var(--space-4) var(--space-4) var(--space-8); }
  .image-card { margin-top: var(--space-4); }
  .image-heading { gap: var(--space-3); margin-bottom: var(--space-4); }
  .image-heading-icon { width: 38px; height: 38px; border-radius: var(--radius-medium); }
  .image-heading-icon svg { width: 19px; height: 19px; }
  .image-heading h1 { font-size: 1.28rem; }
  .image-heading p { font-size: 0.84375rem; }
  .image-prompt-panel { border-radius: var(--radius-medium); }
  /* Mobile: the two prompt actions may drop to their own line instead of
     squeezing the label — never overflow horizontally. */
  .image-prompt-head { align-items: flex-start; }
  .image-prompt-actions { flex: 1 1 100%; justify-content: flex-start; }
  .image-styles { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
  .image-advanced-panel { padding: var(--space-3); }
  .image-controls { grid-template-columns: minmax(0, 1fr); gap: 10px; margin: var(--space-4) 0 var(--space-5); }
  .image-result { border-radius: var(--radius-medium); min-height: 240px; padding: var(--space-6) var(--space-4); }
  .generated-image { border-radius: var(--radius-small); max-height: 60vh; }
}
