/* Image Prompt Builder — dark theme */

:root {
  --bg: #0f1419;
  --bg-elevated: #161d27;
  --surface: #1c2533;
  --border: #2a3544;
  --text: #e8edf4;
  --text-muted: #8b9aad;
  --accent: #2dd4bf;
  --accent-dim: rgba(45, 212, 191, 0.14);
  --accent-border: rgba(45, 212, 191, 0.45);
  --indigo: #6366f1;
  --indigo-dim: rgba(99, 102, 241, 0.2);
  --danger: #f87171;
  --radius: 12px;
  --radius-pill: 9999px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(
    ellipse 120% 80% at 50% -20%,
    rgba(99, 102, 241, 0.12),
    transparent 55%
  );
}

.page {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.site-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.site-title {
  margin: 0 0 0.35rem;
  font-size: clamp(1.35rem, 4vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 42em;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  padding: 1.25rem 1.1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-title {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.tag-group + .tag-group {
  margin-top: 1.25rem;
}

.tag-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.category-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.btn-mini {
  padding: 0.25rem 0.5rem;
  font-size: 0.72rem;
  line-height: 1.1;
}

.tag-select {
  width: 100%;
  margin-bottom: 0.5rem;
}

#tags-randomize-btn {
  margin-top: 0.75rem;
  color: #0f1419;
  background: linear-gradient(165deg, #fbbf24, #f59e0b);
  border-color: transparent;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.25);
}

#tags-randomize-btn:hover:not(:disabled) {
  background: linear-gradient(165deg, #facc15, #f59e0b);
  border-color: transparent;
}

.field-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.free-text {
  display: block;
  width: 100%;
  margin: 0 0 1rem;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  min-height: 4.5rem;
}

.free-text::placeholder {
  color: rgba(139, 154, 173, 0.65);
}

.free-text:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
  border-color: rgba(99, 102, 241, 0.5);
}

.aspect-fieldset {
  margin: 0 0 1rem;
  padding: 0;
  border: none;
}

.aspect-fieldset .field-label {
  padding: 0;
}

.aspect-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.aspect-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    color 0.15s ease,
    background 0.15s ease;
}

.aspect-option:has(input:focus-visible) {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

.aspect-option:has(input:checked) {
  color: var(--text);
  border-color: rgba(99, 102, 241, 0.55);
  background: var(--indigo-dim);
}

.aspect-option input {
  position: absolute;
  inset: 0;
  z-index: 1;
  margin: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.aspect-option span {
  position: relative;
  z-index: 0;
  user-select: none;
  pointer-events: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.generation-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

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

.generation-status__dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.65);
  animation: thinkingPulse 1.2s ease-out infinite;
}

@keyframes thinkingPulse {
  0% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.65);
  }
  70% {
    transform: scale(1.15);
    box-shadow: 0 0 0 0.5rem rgba(45, 212, 191, 0);
  }
  100% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(45, 212, 191, 0);
  }
}

.model-picker {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 12rem;
}

.model-picker .param-label {
  margin-bottom: 0;
}

.model-status {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.1em;
}

.model-status:empty {
  display: none;
}

.model-status[data-state="warming"] {
  color: var(--accent);
}

.model-status[data-state="warm"] {
  color: var(--text-muted);
}

.model-status[data-state="error"] {
  color: #f87171;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.1s ease;
}

.btn:hover {
  background: #222c3a;
  border-color: rgba(139, 154, 173, 0.35);
}

.btn:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn-primary {
  color: #0f1419;
  background: linear-gradient(165deg, #5eead4, #2dd4bf);
  border-color: transparent;
  box-shadow: 0 2px 12px rgba(45, 212, 191, 0.25);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(165deg, #6ee7d8, #34d399);
  border-color: transparent;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
  font-weight: 500;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: rgba(139, 154, 173, 0.4);
  background: rgba(255, 255, 255, 0.04);
}

.output-panel .aspect-ref {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.output-panel .aspect-ref span {
  color: var(--accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.output-generated-title {
  margin: -0.35rem 0 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-muted);
}

.output {
  display: block;
  width: 100%;
  margin: 0 0 0.85rem;
  padding: 0.75rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.55;
  color: #d1e0f0;
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  min-height: 12rem;
}

.output::placeholder {
  color: rgba(139, 154, 173, 0.45);
}

.output:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

.output-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.output-inline-actions {
  display: flex;
  justify-content: flex-start;
  gap: 0.5rem;
  margin: -0.25rem 0 0.75rem;
}

@media (max-width: 520px) {
  .page {
    padding: 1rem 0.75rem 2rem;
  }

  .panel {
    padding: 1rem 0.85rem;
  }

  .actions .btn-primary {
    width: 100%;
  }

  .model-picker {
    width: 100%;
    min-width: 0;
  }

  .output-actions {
    flex-direction: column;
  }

  .output-actions .btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }

  .generation-status__dot {
    animation: none;
  }
}

/* --- Additions (custom tag row, mode toggle, param panels, negative output) --- */

.custom-tag-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.template-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.template-row .category-template-select {
  flex: 1;
  min-width: 10rem;
}

.template-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.template-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.2rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  color: var(--text);
  background: var(--indigo-dim);
  border: 1px solid rgba(99, 102, 241, 0.45);
  border-radius: var(--radius-pill);
}

.template-chip__remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
  line-height: 1;
}

.template-chip__remove:hover {
  color: var(--text);
}

.template-add-btn.btn,
.template-create-open-btn.btn {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.custom-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.custom-tag-input {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0.3rem 0.6rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: none;
}

.custom-tag-input::placeholder {
  color: rgba(139, 154, 173, 0.65);
}

.custom-tag-input:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
  border-color: rgba(99, 102, 241, 0.5);
}

.custom-tag-add.btn {
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.tag-btn-custom {
  appearance: none;
  margin-top: 0.45rem;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.tag-btn-custom.is-selected {
  box-shadow: 0 0 0 1px rgba(45, 212, 191, 0.25);
}

.mode-toggle,
.output-mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: 1rem;
}

.mode-option,
.output-mode-option {
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.mode-option.is-active,
.output-mode-option.is-active {
  background: var(--indigo);
  color: #fff;
}

.mode-option:focus-visible,
.output-mode-option:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
  z-index: 1;
}

.params-panel,
.param-panel {
  padding: 0.75rem;
  background: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.param-fieldset {
  flex: 1 1 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  width: 100%;
}

.param-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1 1 auto;
  min-width: 8rem;
}

.param-help {
  margin: -0.25rem 0 0.1rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.param-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.param-select,
.param-input {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
}

.param-select:focus-visible,
.param-input:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
  border-color: rgba(99, 102, 241, 0.5);
}

label[for="output-negative"],
.output-negative-wrap > .field-label {
  color: var(--danger);
}

#output-negative {
  border-left: 2px solid var(--danger);
  min-height: 14rem;
  max-height: 28rem;
  overflow-y: auto;
}

#output-settings {
  min-height: 8rem;
}

.tag-remove {
  margin-left: 0.35rem;
  font-size: 0.7rem;
  opacity: 0.6;
  cursor: pointer;
}

.tag-remove:hover {
  opacity: 1;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.6);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(480px, 100%);
  max-width: 480px;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-card .panel-title {
  margin: 0 0 0.25rem;
}

.modal-card .field-label {
  margin-bottom: 0.25rem;
}

.modal-card input,
.modal-card textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.modal-card input:focus-visible,
.modal-card textarea:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
  border-color: rgba(99, 102, 241, 0.5);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.modal-actions-right {
  display: flex;
  gap: 0.5rem;
}

/* --- Refine button --- */

.btn-refine {
  color: var(--text);
  background: linear-gradient(165deg, #7c7fff, var(--indigo));
  border-color: transparent;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}

.btn-refine:hover:not(:disabled) {
  background: linear-gradient(165deg, #8a8dff, #6f72f5);
  border-color: transparent;
}

.btn-refine:disabled {
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: none;
  border-color: var(--border);
}

.btn-refine__icon {
  margin-right: 0.35rem;
  font-size: 0.95em;
}

/* --- Save as favorite button --- */

.btn-favorite {
  color: var(--text);
  background: rgba(45, 212, 191, 0.08);
  border-color: var(--accent-border);
}

.btn-favorite[hidden] {
  display: none;
}

.btn-favorite:hover:not(:disabled) {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.btn-favorite__icon {
  margin-right: 0.35rem;
  color: var(--accent);
  font-size: 0.95em;
}

/* --- Favorites panel + cards --- */

.favorites-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.favorites-empty {
  margin: 0;
  padding: 0.9rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
}

.favorites-empty[hidden] {
  display: none;
}

.favorites-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.favorites-list:empty {
  display: none;
}

.favorite-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition:
    border-color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease;
}

.favorite-card:hover {
  border-color: rgba(99, 102, 241, 0.45);
  background: #1f2836;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.favorite-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
}

.favorite-name {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

.favorite-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.favorite-mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  background: var(--indigo-dim);
  border: 1px solid rgba(99, 102, 241, 0.45);
  border-radius: var(--radius-pill);
}

.favorite-mode-badge[data-mode="sdxl"] {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--text);
}

.favorite-preview {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.45;
  color: #c3cfdd;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.favorite-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.1rem;
}

.favorite-card-actions .btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}

.favorite-card-actions .btn-delete {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.35);
  background: transparent;
  margin-left: auto;
}

.favorite-card-actions .btn-delete:hover {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.6);
  color: var(--danger);
}

.field-help {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: var(--danger);
}

.field-help[hidden] {
  display: none;
}

@media (max-width: 520px) {
  .favorite-card-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .favorite-card-actions .btn {
    width: 100%;
  }

  .favorite-card-actions .btn-delete {
    margin-left: 0;
  }

  .output-inline-actions {
    flex-wrap: wrap;
  }
}
