:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3348;
  --text: #e8eaf0;
  --text-muted: #8b92a8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-dim: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app { max-width: 820px; margin: 0 auto; padding: 0 1.25rem 3rem; flex: 1; min-width: 0; }

/* Layout */
.layout {
  display: flex;
  gap: 0;
  min-height: 100vh;
}

.ai-panel {
  width: 380px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 1.5rem;
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.layout.ai-collapsed .ai-panel {
  display: none;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

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

.api-status {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 99px;
}

.api-status.connected { color: var(--success); background: rgba(34, 197, 94, 0.1); }
.api-status.disconnected { color: var(--text-muted); background: var(--surface-2); }

.ai-toggle-mobile { display: none; }

@media (max-width: 1024px) {
  .layout { flex-direction: column; }
  .ai-panel {
    width: 100%;
    height: auto;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    max-height: 70vh;
    z-index: 50;
    border-left: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  }
  .layout.ai-collapsed .ai-panel { display: none; }
  .ai-toggle-mobile { display: inline-flex; }
  .layout:not(.ai-collapsed) .app { padding-bottom: 50vh; }
}

/* AI Panel */
.ai-panel-header h2 { font-size: 1.1rem; margin-bottom: 0.2rem; }
.ai-panel-header p { font-size: 0.82rem; color: var(--text-muted); }

.ai-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

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

.ai-textarea {
  width: 100%;
  padding: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  resize: vertical;
  margin-bottom: 0.6rem;
}

.ai-btn-group { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.ai-analysis {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  max-height: 240px;
  overflow-y: auto;
  line-height: 1.6;
}

.ai-analysis.hidden { display: none; }
.ai-analysis h3, .ai-analysis h4 { margin: 0.5rem 0 0.3rem; font-size: 0.9rem; }
.ai-analysis ul { padding-left: 1.2rem; margin: 0.3rem 0; }
.ai-analysis p { margin: 0.3rem 0; }

.ai-chat-section { flex: 1; display: flex; flex-direction: column; min-height: 200px; }

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  max-height: 220px;
  margin-bottom: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ai-msg {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  line-height: 1.5;
}

.ai-msg-user { background: var(--primary-dim); border: 1px solid var(--primary); align-self: flex-end; max-width: 90%; }
.ai-msg-assistant { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; max-width: 95%; }
.ai-msg-system { background: transparent; color: var(--text-muted); font-size: 0.8rem; text-align: center; }

.ai-chat-input { display: flex; gap: 0.4rem; align-items: flex-end; }
.ai-chat-input textarea {
  flex: 1;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
  resize: none;
}

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}

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

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  cursor: pointer;
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow);
}

.modal-content h3 { margin-bottom: 0.4rem; }
.modal-desc { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1.25rem; }


/* Header */
.header {
  padding: 2rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

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

.logo { display: flex; align-items: center; gap: 1rem; }

.logo-icon {
  width: 48px; height: 48px;
  background: var(--primary-dim);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: var(--primary);
}

.logo h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.logo p { font-size: 0.85rem; color: var(--text-muted); }

.progress-bar {
  height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #a78bfa);
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 12.5%;
}

.step-indicators {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.step-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.3s;
  cursor: default;
}

.step-dot.active { border-color: var(--primary); color: var(--primary); background: var(--primary-dim); }
.step-dot.done { border-color: var(--success); color: var(--success); background: rgba(34, 197, 94, 0.1); }

/* Steps */
.step { display: none; animation: fadeIn 0.3s ease; }
.step.active { display: block; }

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

.step h2 { font-size: 1.35rem; margin-bottom: 0.4rem; }
.step-desc { color: var(--text-muted); margin-bottom: 1.75rem; font-size: 0.92rem; }

/* Fields */
.field { margin-bottom: 1.25rem; }

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.req { color: var(--danger); }

.hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.3rem; display: block; }

.hint-inline { font-weight: 400; color: var(--text-muted); font-size: 0.78rem; }

input[type="text"],
input[type="email"],
textarea,
select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  resize: vertical;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

select { cursor: pointer; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

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

/* Dynamic list items */
.dynamic-list { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1rem; }

.dynamic-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
}

.dynamic-item .remove-btn {
  position: absolute;
  top: 0.75rem; right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.dynamic-item .remove-btn:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }

.dynamic-item h4 {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-ghost { background: transparent; color: var(--text-muted); border: 1px dashed var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.btn-lg { padding: 0.85rem 1.75rem; font-size: 1rem; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

.nav-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* Review */
.review-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.review-box h3 { font-size: 1rem; margin-bottom: 1rem; color: var(--primary); }
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem 1.5rem; }
.review-item label { font-size: 0.75rem; color: var(--text-muted); display: block; }
.review-item span { font-size: 0.9rem; }

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

/* Generate section */
.generate-section h3 { font-size: 1rem; margin-bottom: 0.75rem; }

.file-list {
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}

.file-list li {
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.3rem 0;
  color: var(--text-muted);
}

.file-list li::before { content: "📄 "; }

.generate-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.export-json-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin-bottom: 0.5rem;
}

.export-json-box p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* Preview panel */
.preview-panel {
  margin-top: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-panel.hidden { display: none; }

.preview-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.preview-header select { flex: 1; max-width: 320px; }

#previewContent {
  padding: 1.25rem;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.7;
  overflow: auto;
  max-height: 480px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c9d1d9;
}

/* Footer */
.footer {
  text-align: center;
  padding: 2rem 0 1rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.footer code {
  background: var(--surface);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  z-index: 100;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { display: none; }

/* Field error */
.field.error input,
.field.error textarea,
.field.error select {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.field-error-msg {
  color: var(--danger);
  font-size: 0.78rem;
  margin-top: 0.3rem;
}
