/* Prompt Builder — AF99 Design System
   Hierarchy: page (#f7f8fb) > white card (shadow-lifted) > brand-tinted sections > white inputs
   Principle: alternating light/dark at every nesting level. No neutral gray; tint with brand.
   Teal = primary zones (form, output, examples). Purple = secondary zones (guidance).
   Reference: design-md/af99/DESIGN.md, depth levels, shadow philosophy. */

/* ── Main card ── */
.prompt-builder {
  margin-top: 18px;
  border-radius: 18px;
  background: var(--bg-elevated);
  border: 1px solid rgba(15, 23, 42, 0.10);
  box-shadow:
    0 2px 8px color-mix(in srgb, var(--brand-primary) 6%, rgba(0, 0, 0, 0.06)),
    0 12px 36px color-mix(in srgb, var(--brand-primary) 4%, rgba(0, 0, 0, 0.04));
  padding: 24px;
  display: grid;
  gap: 20px;
}

/* ── Track pills ── */
.prompt-builder__tracks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.prompt-builder__track {
  border-radius: 9999px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.prompt-builder__track:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--brand-primary) 6%, var(--bg-elevated));
}

.prompt-builder__track.is-active {
  border-color: transparent;
  background: var(--accent);
  color: #0f172a;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--brand-primary) 25%, transparent);
}

.prompt-builder__track:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── Template selector ── */
.prompt-builder__template {
  padding: 0;
  border: none;
  background: none;
}

.prompt-builder__template label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.prompt-builder__template-select {
  width: 100%;
  border-radius: 12px;
  border: 1.5px solid rgba(15, 23, 42, 0.18);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color-scheme: light dark;
  transition: border-color 0.15s ease;
}

.prompt-builder__template-select:hover {
  border-color: rgba(15, 23, 42, 0.25);
}

.prompt-builder__template-select:focus {
  border-color: var(--accent);
  outline: 2px solid var(--focus-ring);
  outline-offset: -1px;
}

.prompt-builder__template-select option {
  background-color: var(--bg-elevated);
  color: var(--text);
}

.prompt-builder__template-desc {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-faint);
}

/* ── Guidance panel — purple-tinted (dark on white card) ── */
.prompt-builder__guidance {
  border-radius: 12px;
  border: none;
  border-left: 3px solid var(--brand-accent, #663399);
  background: color-mix(in srgb, var(--brand-accent) 8%, #e2e8f0);
  padding: 14px 16px;
}

.prompt-builder__guidance-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.prompt-builder__guidance-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: rgba(15, 23, 42, 0.95);
}

.prompt-builder__guidance-list {
  margin: 0;
  padding-left: 18px;
  color: rgba(15, 23, 42, 0.85);
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.prompt-builder__guidance.is-collapsed .prompt-builder__guidance-list {
  display: none;
}

.prompt-builder__guidance.is-collapsed .prompt-builder__guidance-header {
  margin-bottom: 0;
}

/* ── Form wrapper — teal-tinted (dark on white card) ── */
.prompt-builder__form {
  background: color-mix(in srgb, var(--brand-primary) 8%, #e2e8f0);
  border-radius: 12px;
  padding: 16px;
}

/* ── Form fields — white inputs (light on tinted form) ── */
.prompt-builder__field {
  display: grid;
  gap: 6px;
}

.prompt-builder__field + .prompt-builder__field {
  margin-top: 4px;
}

.prompt-builder__field label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.prompt-builder__field textarea {
  border-radius: 12px;
  border: 1.5px solid rgba(15, 23, 42, 0.18);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.prompt-builder__field textarea:hover {
  border-color: rgba(15, 23, 42, 0.25);
}

.prompt-builder__field textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--focus-ring);
  outline-offset: -1px;
}

.prompt-builder__field textarea::placeholder {
  color: var(--placeholder);
}

/* ── Output wrapper — teal-tinted (dark on white card) ── */
.prompt-builder__output {
  background: color-mix(in srgb, var(--brand-primary) 8%, #e2e8f0);
  border-radius: 12px;
  padding: 16px;
}

/* ── Output text — white (light on tinted wrapper) ── */
.prompt-builder__output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.prompt-builder__output-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.prompt-builder__text {
  margin: 0;
  padding: 14px 16px;
  border-radius: 12px;
  border: none;
  border-left: 4px solid var(--accent);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.prompt-builder__text.is-empty {
  color: var(--text-faint);
  font-style: italic;
}

.prompt-builder__status {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 13px;
  min-height: 18px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.prompt-builder__status.is-visible {
  opacity: 1;
}

/* ── Saved prompts ── */
.prompt-builder__saved {
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: transparent;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.prompt-builder__saved-header h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.prompt-builder__saved-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-faint);
}

.prompt-builder__saved-list {
  display: grid;
  gap: 12px;
}

.prompt-builder__saved-item {
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: color-mix(in srgb, var(--brand-primary) 6%, #e2e8f0);
  padding: 12px 14px;
}

.prompt-builder__saved-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.prompt-builder__saved-meta {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.prompt-builder__saved-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-builder__saved-empty {
  color: var(--text-faint);
  margin: 0;
}

.prompt-builder__saved-clear {
  width: fit-content;
}

/* ── Example prompts ── */
.pb-examples {
  margin: 14px 0 4px;
  border-radius: 18px;
  background: var(--bg-elevated);
  border: 1px solid rgba(15, 23, 42, 0.10);
  box-shadow:
    0 1px 4px color-mix(in srgb, var(--brand-primary) 4%, rgba(0, 0, 0, 0.05)),
    0 4px 12px color-mix(in srgb, var(--brand-primary) 3%, rgba(0, 0, 0, 0.03));
  padding: 0;
}

.pb-examples summary {
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
}

.pb-examples summary::-webkit-details-marker {
  display: none;
}

.pb-examples summary::before {
  content: "\25B6\FE0E";
  display: inline-block;
  margin-right: 8px;
  font-size: 11px;
  transition: transform 0.2s ease;
}

.pb-examples[open] summary::before {
  transform: rotate(90deg);
}

.pb-examples__list {
  display: grid;
  gap: 14px;
  padding: 0 18px 18px;
}

/* Example items — teal-tinted (dark on white examples card) */
.pb-examples__item {
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.18);
  background: color-mix(in srgb, var(--brand-primary) 6%, #e2e8f0);
  padding: 14px;
}

.pb-examples__meta {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.pb-examples__track {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #0f172a;
  background: var(--accent);
  border-radius: 9999px;
  padding: 3px 10px;
}

.pb-examples__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* Prompt blocks — white (light on tinted item) */
.pb-examples__prompt {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* ── Dark mode adjustments ── */
:root.theme-dark .prompt-builder {
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.3),
    0 12px 36px rgba(0, 0, 0, 0.2);
}

:root.theme-dark .prompt-builder__track {
  border-color: rgba(255, 255, 255, 0.10);
  background: var(--bg);
}

:root.theme-dark .prompt-builder__track.is-active {
  color: #0f172a;
}

:root.theme-dark .prompt-builder__guidance {
  background: color-mix(in srgb, var(--brand-accent) 8%, rgba(255, 255, 255, 0.04));
  border-left-color: var(--brand-accent, #663399);
}

:root.theme-dark .prompt-builder__form,
:root.theme-dark .prompt-builder__output {
  background: color-mix(in srgb, var(--brand-primary) 6%, rgba(255, 255, 255, 0.04));
}

:root.theme-dark .prompt-builder__template-select,
:root.theme-dark .prompt-builder__field textarea {
  background: var(--bg);
  border-color: rgba(255, 255, 255, 0.10);
}

:root.theme-dark .prompt-builder__template-select:hover,
:root.theme-dark .prompt-builder__field textarea:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

:root.theme-dark .prompt-builder__text {
  background: var(--bg);
}

:root.theme-dark .prompt-builder__saved,
:root.theme-dark .prompt-builder__saved-item {
  border-color: rgba(255, 255, 255, 0.08);
}

:root.theme-dark .prompt-builder__saved-item {
  background: color-mix(in srgb, var(--brand-primary) 6%, rgba(255, 255, 255, 0.04));
}

:root.theme-dark .pb-examples {
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow:
    0 1px 4px rgba(0, 0, 0, 0.2),
    0 4px 12px rgba(0, 0, 0, 0.15);
}

:root.theme-dark .pb-examples__item {
  border-color: rgba(255, 255, 255, 0.06);
  background: color-mix(in srgb, var(--brand-primary) 6%, rgba(255, 255, 255, 0.04));
}

:root.theme-dark .pb-examples__prompt {
  background: var(--bg);
}

:root.theme-dark .pb-examples__track {
  color: #0f172a;
}

/* ── Responsive ── */
@media (max-width: 720px) {
  .prompt-builder {
    padding: 16px;
    border-radius: 14px;
  }

  .prompt-builder__form,
  .prompt-builder__output {
    padding: 12px;
  }

  .prompt-builder__guidance-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
