:root {
  --bg-1: #1a0b2e;
  --bg-2: #2d1b4e;
  --bg-3: #4a1b5c;
  --cyan: #00f5ff;
  --magenta: #ff00ff;
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.75);
  --text-dimmer: rgba(255, 255, 255, 0.55);
  --card-bg: rgba(255, 255, 255, 0.05);
  --card-border: rgba(0, 245, 255, 0.3);
  --danger: #ff5252;
  --bubble-user: linear-gradient(135deg, rgba(0, 245, 255, 0.28), rgba(120, 60, 220, 0.28));
  --bubble-bot: rgba(255, 255, 255, 0.07);
  --radius: 18px;
}

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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-3) 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--cyan); }

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
}
.view.active { display: flex; }

/* ---------- Shared widgets ---------- */

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 20px 8px;
}
.brand img { width: 44px; height: 44px; filter: drop-shadow(0 0 12px rgba(0, 245, 255, 0.5)); }
.brand span {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(90deg, #00f5ff, #ff00ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.centered-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px 60px;
}

.card {
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 24px;
  backdrop-filter: blur(10px);
  padding: 32px;
  width: 100%;
  max-width: 440px;
}

.card h1, .card h2 { margin-bottom: 8px; }
.card p.subtitle { color: var(--text-dim); margin-bottom: 24px; line-height: 1.5; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 24px;
  border-radius: 50px;
  border: none;
  font-size: 16px;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  color: white;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary {
  background: linear-gradient(135deg, #00f5ff 0%, #ff00ff 100%);
  box-shadow: 0 8px 24px rgba(255, 0, 255, 0.35);
}
.btn-primary:not(:disabled):hover { transform: translateY(-2px); }
.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.btn-danger {
  background: rgba(255, 82, 82, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
}
.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-dim);
}
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 12px; margin-top: 8px; }
.btn-row .btn { flex: 1; }

.field {
  margin-bottom: 18px;
}
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 15px;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--cyan);
}
.field .hint { font-size: 12px; color: var(--text-dimmer); margin-top: 6px; }
.field .error-text { font-size: 12px; color: var(--danger); margin-top: 6px; display: none; }
.field.has-error input { border-color: var(--danger); }
.field.has-error .error-text { display: block; }

.link-button {
  background: none;
  border: none;
  color: var(--cyan);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 0;
}

.divider-label {
  text-align: center;
  color: var(--text-dimmer);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 20px 0;
  position: relative;
}

.error-banner {
  background: rgba(255, 82, 82, 0.12);
  border: 1px solid var(--danger);
  color: #ffb3b3;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
}
.error-banner.show { display: block; }

.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Get Started ---------- */

.choice-cards {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 460px;
}
.choice-card {
  background: var(--card-bg);
  border: 2px solid rgba(0, 245, 255, 0.25);
  border-radius: 20px;
  padding: 24px;
  text-align: left;
  color: white;
  transition: all 0.2s ease;
}
.choice-card:hover {
  border-color: var(--cyan);
  transform: translateY(-3px);
  box-shadow: 0 15px 40px rgba(0, 245, 255, 0.2);
}
.choice-card .icon { font-size: 32px; margin-bottom: 10px; }
.choice-card h3 { font-size: 19px; margin-bottom: 6px; }
.choice-card p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.choice-card .badge-new {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  background: linear-gradient(135deg, #ff00ff, #00f5ff);
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
}

/* ---------- Setup / provisioning ---------- */

.steps-list { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 14px; margin: 20px 0; }
.step-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  opacity: 0.6;
  transition: opacity 0.3s ease;
}
.step-row.active { opacity: 1; }
.step-row .step-icon { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.step-row .step-icon .spinner { display: none; }
.step-row.active .step-icon .spinner { display: block; }
.step-row .step-icon .check { display: none; color: var(--cyan); font-size: 18px; }
.step-row.done .step-icon .check { display: block; }
.step-row.done .step-icon .spinner { display: none; }

.final-details { width: 100%; max-width: 460px; }
.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.detail-row .val { word-break: break-all; font-size: 14px; }
.detail-row .lbl { font-size: 11px; text-transform: uppercase; color: var(--text-dimmer); letter-spacing: 0.5px; display: block; margin-bottom: 3px; }
.detail-row .copy-icon { flex-shrink: 0; font-size: 16px; opacity: 0.7; }
.detail-row:hover .copy-icon { opacity: 1; }

/* ---------- Chat screen ---------- */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.chat-header .webhook-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: white;
  max-width: 60vw;
}
.chat-header .webhook-selector .title { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header .webhook-selector .caret { color: var(--text-dimmer); font-size: 12px; }
.chat-header .header-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  color: white;
  font-size: 19px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn.n8n-info { color: var(--cyan); }
.icon-btn[hidden] { display: none; }

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-banner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dimmer);
  gap: 10px;
  padding: 20px;
}
.empty-banner .mic-big { font-size: 44px; }
.empty-banner .examples { font-size: 13px; max-width: 300px; line-height: 1.6; }

.bubble-row { display: flex; max-width: 100%; }
.bubble-row.user { justify-content: flex-end; }
.bubble-row.bot, .bubble-row.error, .bubble-row.progress { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  animation: bubbleIn 0.22s ease;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble.user { background: var(--bubble-user); border: 1px solid rgba(0, 245, 255, 0.35); border-bottom-right-radius: 4px; }
.bubble.bot { background: var(--bubble-bot); border: 1px solid rgba(255, 255, 255, 0.1); border-bottom-left-radius: 4px; }
.bubble.error { background: rgba(255, 82, 82, 0.12); border: 1px solid var(--danger); color: #ffb3b3; border-bottom-left-radius: 4px; }
.bubble.progress { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); display: flex; align-items: center; gap: 10px; color: var(--text-dim); }

.bubble p:not(:last-child) { margin-bottom: 8px; }
.bubble pre.md-code { background: rgba(0, 0, 0, 0.35); padding: 10px; border-radius: 8px; overflow-x: auto; margin: 8px 0; font-size: 13px; }
.bubble code { background: rgba(0, 0, 0, 0.3); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.bubble ul, .bubble ol { margin: 6px 0 6px 20px; }
.bubble blockquote { border-left: 3px solid var(--cyan); padding-left: 10px; color: var(--text-dim); margin: 6px 0; }
.bubble img { max-width: 100%; border-radius: 8px; margin: 6px 0; }
.bubble .tts-row { margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.bubble .tts-row button { background: rgba(0, 245, 255, 0.15); border: 1px solid var(--cyan); color: var(--cyan); border-radius: 20px; padding: 4px 12px; font-size: 12px; }

.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); animation: blink 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: white;
  padding: 11px 16px;
  font-size: 15px;
  line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--cyan); }
.composer .round-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
  flex-shrink: 0;
}
.composer .send-btn { background: linear-gradient(135deg, #00f5ff, #ff00ff); }
.composer .send-btn:disabled { opacity: 0.4; }
.composer .mic-btn { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.2); }
.composer .mic-btn.listening { background: var(--danger); animation: pulseMic 1s infinite; }
@keyframes pulseMic { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.5); } 50% { box-shadow: 0 0 0 10px rgba(255, 82, 82, 0); } }
.composer .mic-btn:disabled { opacity: 0.3; }

/* ---------- Modal system ---------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}
.modal-box {
  background: #241236;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px 22px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px 22px 26px;
  transform: translateY(20px);
  transition: transform 0.15s ease;
}
.modal-backdrop.show .modal-box { transform: translateY(0); }
@media (min-width: 640px) {
  .modal-box { border-radius: 22px; }
}
.modal-box h3 { margin-bottom: 4px; font-size: 19px; }
.modal-box .modal-subtitle { color: var(--text-dim); font-size: 13px; margin-bottom: 18px; }

.menu-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 4px;
  border-radius: 12px;
  background: none;
  border: none;
  color: white;
  width: 100%;
  text-align: left;
  font-size: 15px;
}
.menu-row:hover { background: rgba(255, 255, 255, 0.06); }
.menu-row .emoji { font-size: 18px; width: 22px; text-align: center; }
.menu-row.danger { color: var(--danger); }
.menu-divider { height: 1px; background: rgba(255, 255, 255, 0.1); margin: 8px 0; }

.header-row-inline {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.header-row-inline input { flex: 1; }
.header-row-inline button { background: none; border: none; color: var(--danger); font-size: 18px; }

.radio-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.03);
}
.radio-option.selected { border-color: var(--cyan); background: rgba(0, 245, 255, 0.08); }
.radio-option input { width: auto; }
.radio-option label { flex: 1; }

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 0 16px;
}
.toast {
  background: rgba(20, 10, 35, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: white;
  padding: 11px 18px;
  border-radius: 30px;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  max-width: 420px;
  text-align: center;
  animation: toastIn 0.2s ease;
}
.toast.error { border-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.top-bar {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px 0;
}

.back-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 0;
}
.back-row button { background: none; border: none; color: white; font-size: 20px; }

@media (max-width: 480px) {
  .card { padding: 24px 20px; border-radius: 18px; }
}
