/* MAGE — Mometrix Asset Generation Engine */
/* Stage 1: Static App Shell */

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

:root {
  --bg-app: #0f1117;
  --bg-panel: #1a1d27;
  --bg-panel-alt: #20232f;
  --bg-input: #12141c;
  --bg-preview: #14161e;
  --border: #2a2d3a;
  --border-light: #33364a;
  --text-primary: #e8eaf0;
  --text-secondary: #8a8fa8;
  --text-muted: #555870;
  --accent: #4f6ef7;
  --accent-hover: #6b84ff;
  --accent-dim: #1e2a5a;
  --brand-orange: #f97316;
  --brand-orange-dim: #3a1a06;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --disabled: #2e3144;
  --disabled-text: #444760;
  --panel-width-left: 300px;
  --panel-width-right: 280px;
  --header-height: 52px;
  --radius: 6px;
  --radius-lg: 10px;
  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App layout ───────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top bar ──────────────────────────────────────── */

#topbar {
  height: var(--header-height);
  min-height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
}

#topbar .logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-primary);
}

#topbar .logo span {
  color: var(--brand-orange);
}

#topbar .tagline {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

#topbar .stage-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--brand-orange-dim);
  color: var(--brand-orange);
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid #6b2d0a;
}

/* ── Main workspace ───────────────────────────────── */

#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Panels ───────────────────────────────────────── */

.panel {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.panel:last-child {
  border-right: none;
  border-left: 1px solid var(--border);
}

#panel-left {
  width: var(--panel-width-left);
}

#panel-center {
  flex: 1;
  background: var(--bg-preview);
  border: none;
  overflow-y: auto;
}

#panel-right {
  width: var(--panel-width-right);
}

/* ── Panel inner ──────────────────────────────────── */

.panel-inner {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Section headers ──────────────────────────────── */

.section-header {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

/* ── Field groups ─────────────────────────────────── */

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

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

.field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.field input[type="text"],
.field select,
.field textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  transition: border-color 0.15s;
  outline: none;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
}

.field input[type="text"]:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 110, 247, 0.15);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-muted);
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a8fa8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}

.field select option {
  background: var(--bg-panel-alt);
}

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

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  padding: 8px 14px;
  transition: background 0.15s, opacity 0.15s;
  width: 100%;
  text-align: center;
  letter-spacing: 0.01em;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-panel-alt);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-secondary:hover {
  background: #282b3e;
  border-color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-panel-alt);
  color: var(--text-primary);
}

.btn:disabled,
.btn[disabled] {
  background: var(--disabled) !important;
  color: var(--disabled-text) !important;
  border-color: transparent !important;
  cursor: not-allowed;
  opacity: 1;
}

.btn-generate {
  background: var(--brand-orange);
  color: #fff;
  font-size: 14px;
  padding: 10px 14px;
}

.btn-generate:hover {
  background: #fb923c;
}

/* ── Button row ───────────────────────────────────── */

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

/* ── Divider ──────────────────────────────────────── */

.divider {
  height: 1px;
  background: var(--border);
}

/* ── Center panel ─────────────────────────────────── */

#panel-center-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
  gap: 16px;
}

.center-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.center-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.version-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Preview box ──────────────────────────────────── */

.preview-box {
  flex: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 300px;
  position: relative;
  overflow: hidden;
}

.preview-box .empty-icon {
  font-size: 48px;
  opacity: 0.15;
  user-select: none;
}

.preview-box .empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

.preview-box .empty-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  max-width: 300px;
  line-height: 1.6;
}

/* ── Center actions ───────────────────────────────── */

.center-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.center-actions .btn {
  flex: 1;
  width: auto;
}

/* ── Selection summary ────────────────────────────── */

.selection-summary {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.selection-summary .summary-row {
  display: flex;
  gap: 6px;
}

.selection-summary .summary-label {
  color: var(--text-muted);
  min-width: 48px;
}

.selection-summary .summary-value {
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Config error banner ──────────────────────────── */

#config-error-banner {
  background: #3a0f0f;
  border-bottom: 1px solid var(--danger);
  color: #fca5a5;
  font-size: 12px;
  padding: 8px 20px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Summary description text ─────────────────────── */

.summary-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  font-style: italic;
}

/* ── Empty state for panels ───────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 12px;
  text-align: center;
}

.empty-state .empty-icon-sm {
  font-size: 28px;
  opacity: 0.2;
}

.empty-state p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Toast / notification ─────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: var(--bg-panel-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  animation: toast-in 0.2s ease;
  pointer-events: auto;
  max-width: 420px;
  text-align: center;
}

.toast.toast-warn {
  border-color: var(--warning);
  color: var(--warning);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #444760;
}

/* ── Preview box states ───────────────────────────── */

#preview-empty,
#preview-loading,
#preview-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
}

/* Generated image fills the box */
#preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius-lg);
}

/* Loading */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

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

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

/* Error state inside preview box */
.error-icon {
  font-size: 36px;
  color: var(--danger);
  opacity: 0.8;
}

.error-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--danger);
}

.error-message {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 320px;
  line-height: 1.6;
}

/* ── Prompt Preview Modal ─────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.15s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-meta {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  flex-shrink: 0;
}

.modal-meta-item {
  font-size: 11px;
  color: var(--text-muted);
}

.modal-meta-item strong {
  color: var(--text-secondary);
  font-weight: 600;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.modal-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.prompt-output {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: 'Menlo', 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.prompt-output .prompt-section-head {
  color: var(--accent);
  font-weight: 700;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-footer .btn {
  width: auto;
  min-width: 120px;
}

.btn-copy-success {
  background: var(--success) !important;
  color: #fff !important;
}

/* ── Version history cards ────────────────────────── */

#version-card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.version-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}

.version-card:hover {
  border-color: var(--border-light);
  background: var(--bg-panel-alt);
}

.version-card.active {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.version-card-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--bg-panel);
}

.version-card-body {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.version-card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.version-card-active-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 1px 6px;
}

.version-card-revision-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 6px;
}

.version-card-revision-of {
  font-weight: 600;
  color: var(--accent);
}

.version-card-meta {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.5;
}

.version-card-meta span {
  display: block;
}

/* ── Reference asset cards ────────────────────────── */

#reference-card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.ref-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  overflow: hidden;
}

.ref-card-thumb-wrap {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  background: var(--bg-panel);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ref-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ref-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ref-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ref-card-purpose {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.4;
}

.ref-card-input-tag {
  margin-top: 2px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--accent);
}

/* Stage 8: reference image input toggle */
.ref-toggle-row {
  margin-top: 10px;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ref-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.ref-toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.ref-toggle-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.ref-toggle-hint {
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.5;
}

.version-card-refinput {
  color: var(--accent);
  font-weight: 600;
}

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

@media (max-width: 900px) {
  #workspace {
    flex-direction: column;
  }

  .panel {
    width: 100% !important;
    border-right: none;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }

  #panel-center {
    min-height: 400px;
  }
}
