/* ──────────────────────────────────────
   Design Tokens
   Dark theme, cool slate foundation
   Accent: violet (creative energy)
   ────────────────────────────────────── */

:root {
  /* Surfaces */
  --bg-base: #0e1117;
  --bg-raised: #161b22;
  --bg-overlay: #1c2129;
  --bg-input: #0d1117;

  /* Borders */
  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-focus: rgba(139, 92, 246, 0.5);

  /* Text */
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --text-faint: #484f58;

  /* Accent — violet */
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-subtle: rgba(139, 92, 246, 0.12);

  /* Status */
  --success: #3fb950;
  --error: #f85149;
  --warning: #d29922;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Transitions */
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
  --duration: 150ms;
}

/* ──────────────────────────────────────
   Reset & Base
   ────────────────────────────────────── */

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ──────────────────────────────────────
   Typography
   ────────────────────────────────────── */

h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }
h3 { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; color: var(--text-secondary); text-transform: uppercase; }

/* ──────────────────────────────────────
   Modal
   ────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal {
  width: 100%;
  max-width: 400px;
  background: var(--bg-raised);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.modal-wide { max-width: 520px; }

.modal-header {
  padding: 24px 24px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.modal-header h2 { margin-bottom: 4px; }
.modal-subtitle { font-size: 13px; color: var(--text-muted); }

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ──────────────────────────────────────
   Form Fields
   ────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.required {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.optional {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  background: var(--bg-input);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--duration) var(--ease);
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--border-focus);
}

input::placeholder, textarea::placeholder {
  color: var(--text-faint);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%236e7681' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}

textarea { resize: vertical; min-height: 80px; }

.field-error {
  font-size: 12px;
  color: var(--error);
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.field-inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field-inline label { white-space: nowrap; }
.field-inline input, .field-inline select { width: auto; min-width: 80px; }

/* ──────────────────────────────────────
   Buttons
   ────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 0.5px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--accent-subtle);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-full { width: 100%; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}
.btn-icon:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }

/* ──────────────────────────────────────
   Radio Cards
   ────────────────────────────────────── */

.radio-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.radio-group-vertical {
  grid-template-columns: 1fr;
}

.radio-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
}

.radio-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.radio-card input { display: none; }

.radio-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.radio-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-feature-settings: 'tnum';
}

.radio-meta.cost { color: var(--text-secondary); }

/* ──────────────────────────────────────
   Custom Dimensions
   ────────────────────────────────────── */

.custom-dims { margin-top: 12px; }

.dims-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dims-x {
  color: var(--text-muted);
  font-size: 14px;
  padding-top: 20px;
}

/* ──────────────────────────────────────
   Settings Sections
   ────────────────────────────────────── */

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-section + .settings-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 0.5px solid var(--border);
}

/* ──────────────────────────────────────
   Header
   ────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 0.5px solid var(--border);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.header-title { color: var(--text-primary); }

/* ──────────────────────────────────────
   Product Input Section
   ────────────────────────────────────── */

.product-input {
  padding: 32px 0;
  border-bottom: 0.5px solid var(--border);
}

.input-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}

/* Upload Zone */
.upload-zone {
  position: relative;
  aspect-ratio: 1;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  overflow: hidden;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.upload-zone.has-image {
  border-style: solid;
  border-color: var(--border);
  cursor: default;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 16px;
}

.upload-hint { font-size: 12px; color: var(--text-faint); }

.upload-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-input);
}

.upload-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-overlay);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
}

/* Product Details */
.product-details {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.prompt-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
}

/* ──────────────────────────────────────
   Prompt Cards
   ────────────────────────────────────── */

.prompts-section { padding: 32px 0; }

#prompts-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.prompt-card {
  background: var(--bg-raised);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.prompt-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px;
  gap: 12px;
}

.prompt-card-number {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}

.prompt-text {
  flex: 1;
  background: transparent;
  border: 0.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  resize: none;
  outline: none;
  overflow: hidden;
  min-height: 40px;
  transition: border-color var(--duration) var(--ease), background var(--duration) var(--ease);
}

.prompt-text.editing,
.prompt-text:not([readonly]) {
  border-color: var(--border-focus);
  background: var(--bg-input);
}

.prompt-text:not([readonly]):focus {
  border-color: var(--accent);
}

.prompt-card-actions {
  padding: 0 16px 16px;
}

.prompt-card-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 16px 16px;
}

.prompt-card-images.single-model {
  grid-template-columns: 1fr;
  max-width: 50%;
}

.variation {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.variation-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.variation-img-wrap {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 0.5px solid var(--border);
  background: var(--bg-input);
  aspect-ratio: var(--aspect-ratio, 1);
}

.variation-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.variation-actions {
  display: flex;
  gap: 8px;
}

/* Loading spinner for image generation */
.variation-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: var(--aspect-ratio, 1);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border);
  background: var(--bg-input);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Generation loading bar on prompt card */
.prompt-card.generating .prompt-card-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  animation: loading-bar 2s var(--ease) infinite;
}

.prompt-card-header { position: relative; }

@keyframes loading-bar {
  0% { transform: scaleX(0); transform-origin: left; }
  50% { transform: scaleX(1); transform-origin: left; }
  50.01% { transform-origin: right; }
  100% { transform: scaleX(0); transform-origin: right; }
}

/* ──────────────────────────────────────
   Responsive
   ────────────────────────────────────── */

@media (max-width: 720px) {
  .input-grid {
    grid-template-columns: 1fr;
  }

  .upload-zone {
    max-width: 280px;
    margin: 0 auto;
  }

  .prompt-card-images {
    grid-template-columns: 1fr;
  }

  .prompt-card-images.single-model {
    max-width: 100%;
  }

  .radio-group {
    grid-template-columns: 1fr 1fr;
  }
}
