/* Crystallization Wizard v3 — Dark Theme */

:root {
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --accent: #58a6ff;
  --accent-dim: #1f6feb;
  --user-bubble: #1f6feb;
  --ai-bubble: #21262d;
  --danger: #f85149;
  --success: #3fb950;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Landing Page ── */

.landing {
  max-width: 640px;
  margin: 0 auto;
  padding: 80px 24px;
  text-align: center;
}

.landing-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), #a371f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 48px;
}

.mode-grid {
  display: grid;
  gap: 16px;
}

.mode-card {
  display: block;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: left;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, transform 0.2s;
}

.mode-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.mode-card h2 {
  font-size: 1.25rem;
  margin-bottom: 6px;
}

.mode-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.mode-meta {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.badge {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
}

.landing-footer {
  margin-top: 48px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Chat Page ── */

.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header h1 {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1.2rem;
  padding: 4px 8px;
}

.back-link:hover { color: var(--accent); }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

/* ── Split Pane ── */

.split-pane {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Messages ── */

.message {
  display: flex;
  max-width: 85%;
}

.message-user {
  align-self: flex-end;
}

.message-ai {
  align-self: flex-start;
}

.message-system {
  align-self: center;
  max-width: 90%;
}

.message-error {
  align-self: center;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.message-user .message-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-ai .message-bubble {
  background: var(--ai-bubble);
  border-bottom-left-radius: 4px;
}

.message-system .message-bubble {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

.message-error .message-bubble {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 0.85rem;
}

/* Typing indicator */
.typing-indicator .message-bubble {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ── Chat Input ── */

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

#chat-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
  max-height: 120px;
}

#chat-input:focus {
  outline: none;
  border-color: var(--accent);
}

#chat-input::placeholder {
  color: var(--text-muted);
}

#chat-input:disabled {
  opacity: 0.5;
}

.btn-send {
  background: var(--accent-dim);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  transition: background 0.2s;
}

.btn-send:hover { background: var(--accent); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Preview Pane ── */

.preview-pane {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg-surface);
}

.preview-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.preview-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.preview-section {
  margin-bottom: 16px;
}

.preview-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.preview-section.populated h3 {
  color: var(--accent);
}

.preview-section.empty h3 {
  color: var(--text-muted);
}

.preview-section ul {
  list-style: none;
  padding: 0;
}

.preview-section li {
  font-size: 0.85rem;
  padding: 4px 0;
  padding-left: 12px;
  border-left: 2px solid var(--accent-dim);
  margin-bottom: 4px;
  color: var(--text);
}

.muted {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* ── Editable Preview Items (v3.1) ── */

.preview-item {
  cursor: default;
  transition: background 0.15s;
  border-radius: 4px;
  padding: 4px 8px !important;
  padding-left: 12px !important;
}

.preview-item:hover {
  background: rgba(88, 166, 255, 0.08);
}

.preview-edit-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  padding: 4px 8px;
  outline: none;
}

/* ── Progress Bar ── */

.preview-progress {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.progress-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.progress-bar {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ── Preview Actions ── */

.preview-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.btn-action {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: border-color 0.2s;
}

.btn-action:hover { border-color: var(--accent); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }

/* ── Error Page ── */

.error-page {
  text-align: center;
  padding: 80px 24px;
}

.error-page h1 { margin-bottom: 8px; }
.error-page a { color: var(--accent); }

/* ── Mobile ── */

@media (max-width: 768px) {
  .preview-pane {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 100;
    border-left: none;
  }

  .preview-pane.mobile-visible {
    display: flex;
  }

  .btn-ghost {
    display: block;
  }

  .chat-messages {
    padding: 12px;
  }

  .message {
    max-width: 92%;
  }
}

@media (min-width: 769px) {
  #toggle-preview {
    display: none;
  }
}

/* ── Scrollbar ── */

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

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
