:root {
  --bg-base: #f0f0f5;
  --bg-card: #ffffff;
  --bg-muted: #f3f4f6;
  --border-subtle: rgba(0, 0, 0, 0.06);
  --border-medium: rgba(0, 0, 0, 0.1);
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent-gradient: linear-gradient(90deg, #60a5fa 0%, #a78bfa 55%, #c084fc 100%);
  --accent-gradient-hover: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 55%, #a855f7 100%);
  --user-bg: linear-gradient(90deg, #4f8ef7 0%, #7c5cfc 50%, #a855f7 100%);
  --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --radius-full: 999px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-smooth: cubic-bezier(0.22, 0.85, 0.25, 1);
  --content-max: 720px;
  --avatar-size: 32px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
  background: var(--bg-base);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Ambient background ── */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.ambient-mesh {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(96, 165, 250, 0.12), transparent 60%),
    radial-gradient(ellipse 50% 40% at 100% 80%, rgba(167, 139, 250, 0.1), transparent 50%),
    radial-gradient(ellipse 40% 35% at 0% 60%, rgba(192, 132, 252, 0.08), transparent 45%),
    var(--bg-base);
}

/* ── App layout ── */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.app-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
}

.reveal {
  opacity: 0;
  transform: translateY(10px);
  animation: reveal 0.55s var(--ease) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes reveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Header ── */
.header {
  flex-shrink: 0;
  padding: 16px 20px 8px;
  max-width: calc(var(--content-max) + 40px);
  margin: 0 auto;
  width: 100%;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 14px rgba(96, 165, 250, 0.35);
}

.header-avatar svg {
  width: 18px;
  height: 18px;
}

.header-text {
  min-width: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.header-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-pill.online .status-dot {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.status-pill.offline .status-dot {
  background: #ef4444;
}

.status-pill.warning .status-dot {
  background: #f59e0b;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.btn-ghost svg {
  width: 14px;
  height: 14px;
}

.btn-ghost:hover {
  color: var(--text);
  box-shadow: var(--shadow-card);
  transform: translateY(-1px);
}

/* ── Chat workspace ── */
.chat-workspace {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  width: 100%;
  padding: 20px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  cursor: grab;
}

.messages::-webkit-scrollbar {
  display: none;
}

.messages.is-dragging {
  cursor: grabbing;
  user-select: none;
  touch-action: none;
}

.messages.is-dragging * {
  user-select: none;
}

/* Empty state removed — suggestions live in the composer */

/* Shared suggestion list */
.suggestion-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.suggestion-item,
.quick-reply-chip {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  font-family: var(--font);
  font-size: 14.5px;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  transition: color 0.25s var(--ease-smooth), background 0.25s var(--ease-smooth),
    box-shadow 0.25s var(--ease-smooth), transform 0.25s var(--ease-smooth);
}

.suggestion-item:hover:not(:disabled):not(.used) {
  color: var(--text);
  background: var(--bg-muted);
}

.suggestion-item.active,
.quick-reply-chip.active {
  color: #fff;
  background: var(--accent-gradient);
  box-shadow: 0 4px 16px rgba(96, 165, 250, 0.35);
}

.suggestion-item.active:focus-visible,
.quick-reply-chip.active:focus-visible,
.quick-reply-chip:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 2px;
}

.suggestion-item.active:hover:not(:disabled),
.quick-reply-chip.active:hover:not(:disabled) {
  background: var(--accent-gradient-hover);
  color: #fff;
}

.suggestion-item:disabled,
.suggestion-item.used,
.quick-reply-chip:disabled,
.quick-reply-chip.used {
  cursor: default;
  color: var(--text-muted);
  background: transparent;
  box-shadow: none;
  opacity: 0.7;
}

/* ── Message rows ── */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 100%;
  animation: msg-in 0.35s var(--ease) both;
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 100%;
  width: 100%;
}

.message-row.assistant {
  align-self: flex-start;
}

.message-row.system {
  align-self: center;
  justify-content: center;
}

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

.message-avatar {
  flex-shrink: 0;
  width: var(--avatar-size);
  height: var(--avatar-size);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 2px 10px rgba(96, 165, 250, 0.3);
}

.message-avatar svg {
  width: 14px;
  height: 14px;
}

.message-avatar--spacer {
  visibility: hidden;
  pointer-events: none;
}

.message {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
}

.message.assistant {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(82%, 520px);
  background: var(--bg-card);
  color: var(--text);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-soft);
}

.message-body {
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 2px;
}

.message.assistant .feedback-comment {
  width: 100%;
}

.message.user {
  max-width: min(94%, 720px);
  background: var(--user-bg);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 16px rgba(79, 142, 247, 0.3);
}

.message.system {
  max-width: 88%;
  padding: 10px 18px;
  background: var(--bg-muted);
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  border-radius: var(--radius-full);
  box-shadow: none;
}

.message-row.system .message.system {
  max-width: 360px;
  padding: 16px 22px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  font-size: 14px;
}

/* ── Typing indicator ── */
.message-row.typing .typing-content {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-soft);
  color: var(--text-secondary);
  font-size: 14px;
}

.typing-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--bg-muted);
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* ── Composer ── */
.composer {
  flex-shrink: 0;
  padding: 8px 0 max(20px, env(safe-area-inset-bottom));
}

.chat-form {
  width: 100%;
}

.composer-card {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  padding: 16px 16px 12px;
}

.composer-quick-replies {
  padding: 2px 4px 12px;
}

.composer-quick-replies .quick-reply-item {
  animation: quick-reply-rise 0.7s var(--ease-smooth) both;
  animation-delay: calc(var(--stagger-index, 0) * 120ms);
}

@keyframes quick-reply-rise {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.97);
  }
  60% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.composer-quick-replies.hidden {
  display: none;
}

.composer-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 14px;
  color: var(--text-secondary);
  font-size: 14px;
}

.composer-loading.hidden {
  display: none;
}

.composer-loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--bg-muted);
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.composer-card--loading .composer-input-row {
  opacity: 0.55;
  pointer-events: none;
}

.composer-card .suggestion-item {
  padding: 11px 14px;
  font-size: 14.5px;
}

.composer-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 16px;
  background: var(--bg-muted);
  border-radius: var(--radius-full);
  transition: box-shadow 0.2s;
}

.composer-input-row:focus-within {
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.25);
}

.composer-globe {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  color: var(--text-muted);
}

.composer-globe svg {
  width: 18px;
  height: 18px;
}

#message-input {
  flex: 1;
  min-width: 0;
  display: block;
  resize: vertical;
  min-height: 24px;
  max-height: 140px;
  padding: 10px 0;
  border: none;
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: transparent;
  overflow-y: auto;
  scrollbar-width: none;
}

#message-input::-webkit-scrollbar {
  display: none;
}

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

#message-input:focus {
  outline: none;
}

.btn-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #111827;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, opacity 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-send svg {
  width: 18px;
  height: 18px;
}

.btn-send:not(:disabled):hover {
  background: #1f2937;
  transform: scale(1.05);
}

.btn-send:not(:disabled):active {
  transform: scale(0.97);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.turnstile-container {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0;
}

.hidden {
  display: none !important;
}

/* ── Feedback (inside assistant bubble) ── */
.message-feedback {
  display: flex;
  gap: 2px;
  align-items: center;
  justify-content: flex-end;
}

.thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  border-radius: var(--radius-full);
  opacity: 0.6;
  transform: scale(1);
  transition: opacity 0.2s, transform 0.2s var(--ease), background 0.2s, font-size 0.2s;
}

.thumb:hover {
  opacity: 0.85;
  transform: scale(1.04);
}

.thumb.active {
  opacity: 1;
  transform: scale(1.1);
  font-size: 18px;
  background: rgba(96, 165, 250, 0.15);
}

.message-feedback:has(.thumb.active) .thumb:not(.active) {
  opacity: 0.35;
  transform: scale(0.88);
  font-size: 12px;
}

.feedback-comment {
  display: flex;
  gap: 8px;
  width: 100%;
  animation: msg-in 0.25s var(--ease) both;
}

.feedback-comment.hidden {
  display: none;
}

.feedback-comment input {
  flex: 1;
  min-width: 0;
  padding: 9px 14px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.feedback-comment input::placeholder {
  color: var(--text-muted);
}

.feedback-comment input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.feedback-comment-send {
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}

.feedback-comment-send:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .header {
    padding: 12px 16px 6px;
  }

  .app-body {
    padding: 0 14px;
  }

  .header h1 {
    font-size: 1rem;
  }

  .header-subtitle {
    font-size: 12px;
  }

  .header-avatar {
    width: 36px;
    height: 36px;
  }

  .btn-ghost .btn-label {
    display: none;
  }

  .btn-ghost {
    padding: 7px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
  }

  .messages {
    padding: 16px 2px 12px;
    gap: 16px;
  }

  .message.assistant {
    max-width: min(90%, 520px);
    font-size: 14px;
    padding: 12px 16px;
  }

  .message.user {
    max-width: min(96%, 720px);
    font-size: 14px;
    padding: 12px 16px;
  }

  .composer-card {
    padding: 14px 14px 10px;
    border-radius: var(--radius-lg);
  }

  .composer-quick-replies {
    padding: 0 2px 10px;
  }

  .composer-card .suggestion-item {
    font-size: 14px;
    padding: 10px 12px;
  }

  .composer-input-row {
    padding: 4px 6px 4px 14px;
  }

  #message-input {
    font-size: 14px;
    padding: 8px 0;
  }

  .btn-send {
    width: 34px;
    height: 34px;
  }

  .message-row.assistant {
    gap: 8px;
  }

  :root {
    --avatar-size: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .reveal,
  .message-row,
  .composer-quick-replies .quick-reply-item {
    opacity: 1;
    transform: none;
  }
}

/* ── Embedded widget mode (widget.html inside the loader iframe) ── */
body.embed {
  --content-max: 100%;
}

body.embed .ambient {
  display: none;
}

body.embed .header {
  padding: 12px 16px 6px;
}

body.embed .header-subtitle {
  display: none;
}

body.embed .header h1 {
  font-size: 15px;
}

body.embed .app-body {
  padding: 0 12px;
}

body.embed .composer {
  padding: 6px 0 max(12px, env(safe-area-inset-bottom));
}
