/* ---------------------------------------------------------------
   Message area — centered column like ChatGPT
--------------------------------------------------------------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 8px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }

/* Inner column — constrained + centered */
.messages-inner {
  max-width: var(--content-max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------------------------------------------------------------
   Message rows
--------------------------------------------------------------- */
.message {
  display: flex;
  flex-direction: column;
}

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

.message.assistant {
  align-items: flex-start;
}

/* ---------------------------------------------------------------
   Bubbles
--------------------------------------------------------------- */
.bubble {
  padding: 10px 15px;
  border-radius: var(--radius);
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 85%;
}

/* User: small pill bubble, right-aligned */
.message.user .bubble {
  background: var(--color-user-bubble);
  color: var(--color-user-bubble-text);
  border-bottom-right-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

/* Assistant: no bubble background — full-width text like ChatGPT */
.message.assistant .bubble {
  background: transparent;
  color: var(--color-text);
  max-width: 100%;
  padding: 12px 0;
  white-space: normal;
}

/* Spacing between messages */
.message.user + .message.assistant,
.message.assistant + .message.user {
  margin-top: 10px;
}

/* ---------------------------------------------------------------
   Streaming cursor
--------------------------------------------------------------- */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--color-accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ---------------------------------------------------------------
   Markdown inside assistant bubbles
--------------------------------------------------------------- */
.message.assistant .bubble strong {
  color: var(--color-accent);
  font-weight: 600;
}

.message.assistant .bubble em {
  color: var(--color-accent);
  font-style: italic;
}

.message.assistant .bubble code {
  background: var(--color-surface);
  color: var(--color-accent);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

.message.assistant .bubble .code-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 10px 0;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.6;
}

.message.assistant .bubble .code-block code {
  background: transparent;
  padding: 0;
  color: #c9d1d9;
  font-size: 12.5px;
}

.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3 {
  color: var(--color-text);
  margin: 12px 0 6px;
  line-height: 1.3;
}
.message.assistant .bubble h1 { font-size: 1.3em; }
.message.assistant .bubble h2 { font-size: 1.15em; }
.message.assistant .bubble h3 { font-size: 1.05em; }

.message.assistant .bubble ul,
.message.assistant .bubble ol {
  padding-left: 22px;
  margin: 6px 0;
}

.message.assistant .bubble li {
  margin: 3px 0;
  line-height: 1.6;
}

.message.assistant .bubble a {
  color: var(--color-accent);
  text-decoration: none;
}

.message.assistant .bubble a:hover {
  text-decoration: underline;
}

.message.assistant .bubble del {
  color: var(--color-text-muted);
}

.message.assistant .bubble table {
  border-collapse: collapse;
  margin: 10px 0;
  width: 100%;
  font-size: 0.92em;
}

.message.assistant .bubble th,
.message.assistant .bubble td {
  border: 1px solid var(--color-border);
  padding: 6px 12px;
  text-align: left;
}

.message.assistant .bubble th {
  background: var(--color-surface);
  color: var(--color-accent);
  font-weight: 600;
}

.message.assistant .bubble td {
  background: transparent;
}

/* ---------------------------------------------------------------
   Config result card
--------------------------------------------------------------- */
.config-result {
  border: 1px solid var(--color-border);
  border-radius: var(--radius) !important;
  padding: 14px 18px !important;
  background: var(--color-surface) !important;
}

.config-link {
  color: var(--color-accent);
  text-decoration: none;
  font-weight: 500;
}

.config-link:hover {
  text-decoration: underline;
  color: #3EEBD4;
}

.config-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: "JetBrains Mono", monospace;
}

/* ---------------------------------------------------------------
   Generate progress indicator
--------------------------------------------------------------- */
.generate-progress {
  border: 1px solid var(--color-border);
  border-radius: var(--radius) !important;
  padding: 14px 18px !important;
  background: var(--color-surface) !important;
}

.progress-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ---------------------------------------------------------------
   Thinking block (Reason mode)
--------------------------------------------------------------- */

.thinking-block {
  margin: 6px 16px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.thinking-block details {
  border-left: 2px solid var(--color-primary-light);
  padding-left: 12px;
}

.thinking-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  padding: 4px 0;
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

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

.thinking-block--active .thinking-summary::after {
  content: "";
}

.thinking-block:not(.thinking-block--active) .thinking-summary::after {
  content: " ▸";
  font-size: 10px;
}

.thinking-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--color-border);
  border-top-color: var(--color-primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.thinking-content {
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.6;
  max-height: 220px;
  overflow-y: auto;
  padding: 6px 0 4px;
  color: var(--color-text-muted);
}

/* ---------------------------------------------------------------
   Publish as App button
--------------------------------------------------------------- */
.publish-btn {
  margin-top: 10px;
  padding: 6px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.publish-btn:hover { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.publish-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------------
   Rollback (delete after) button
--------------------------------------------------------------- */
.rollback-btn {
  align-self: center;
  margin-top: 2px;
  padding: 2px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.message:hover .rollback-btn { opacity: 1; }
.rollback-btn:hover { background: var(--color-danger, #e53935); color: #fff; opacity: 1; }
.rollback-btn.rollback-hidden { visibility: hidden; }

/* Toast notice */
.chat-notice {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  padding: 20px 36px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
}
.chat-notice.visible { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------------------------------------------------------------
   Inline QR display (shared by chat messages and app cards)
--------------------------------------------------------------- */
.qr-inline {
  margin: 10px 0 4px;
}
.qr-inline .qr-img {
  width: 180px;
  height: 180px;
  border-radius: var(--radius-sm);
  display: block;
}

/* ---------------------------------------------------------------
   Flow Preview
--------------------------------------------------------------- */
.preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 0;
  align-items: flex-start;
}

.preview-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 288px; /* 360 * 0.8 */
}

.preview-card .preview-scale-box {
  flex-shrink: 0;
  width: 288px;  /* 360 * 0.8 */
  height: 611px; /* 764 * 0.8  (720 phone + 44 nav bar) */
  overflow: hidden;
}

.preview-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preview-scale-box {
  overflow: hidden;
  border-radius: 19px; /* 24 * 0.8 */
  border: 1px solid var(--color-border);
}

.preview-frame {
  width: 360px;
  height: 764px; /* 720 phone + 44 nav bar */
  border: none;
  zoom: 0.8;
  display: block;
}

/* ── Shared preview controls ── */
.preview-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.preview-theme-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.preview-theme-btn:hover { border-color: var(--color-primary); }

/* ── Per-flow step nav ── */
.preview-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.preview-nav-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: var(--color-primary);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}
.preview-nav-btn:hover { opacity: 0.85; }
.preview-nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.preview-step-label {
  font-size: 11px;
  color: var(--color-text-muted);
  min-width: 40px;
  text-align: center;
}

.preview-error {
  padding: 10px 14px;
  border: 1px solid var(--color-danger);
  border-radius: 8px;
  background: color-mix(in srgb, var(--color-danger) 10%, transparent);
  color: var(--color-danger);
  font-size: 13px;
}
