/* sober.guide — chat surface
 * Same room as the rest of the site. Same cream, same teal, same dark.
 * The chat is the centrepiece, not a separate world.
 * Bubbles distinguish speaker by surface tone, not by hue swing.
 */

[data-surface="chat"] {
  /* User bubble — quieter surface, like a card on the page */
  --bubble-user-bg: var(--color-surface);
  --bubble-user-border: var(--color-border);
  --bubble-user-text: var(--color-text);

  /* Bot bubble — the soft teal tint, the page's accent at low volume */
  --bubble-bot-bg: var(--color-primary-soft);
  --bubble-bot-border: var(--color-primary-soft);
  --bubble-bot-text: var(--color-text);
}

/* === Layout ============================================================== */

.chat-page {
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.chat-header {
  border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface);
}
.chat-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  max-width: 880px;
  margin: 0 auto;
  width: 100%;
}
.chat-brand {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  color: var(--color-text);
  text-decoration: none;
}
.chat-actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.chat-actions a,
.chat-actions button {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
  background: none;
  border: none;
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  cursor: pointer;
  transition: color 180ms, background 180ms;
}
.chat-actions a:hover,
.chat-actions button:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.chat-stream {
  flex: 1;
  padding: var(--space-8) 0 var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  min-height: 60vh;
}

.chat-intro {
  text-align: left;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  line-height: 1.65;
  max-width: 56ch;
  padding: var(--space-4) 0 var(--space-2);
}
.chat-intro p { margin-bottom: var(--space-3); }
.chat-intro p:last-child { margin-bottom: 0; }
.chat-intro strong { color: var(--color-text); font-weight: 500; }
.chat-intro-quiet {
  font-family: 'Newsreader', Georgia, serif;
  font-style: italic;
  font-size: 1rem;
  color: var(--color-text);
  opacity: 0.78;
  border-left: 1px solid var(--color-border, rgba(0,0,0,0.12));
  padding-left: var(--space-3);
  margin-left: 0;
}

/* === Bubbles ============================================================= */

.msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  font-size: 1rem;
  line-height: 1.6;
}
.msg p { margin-bottom: 0.6em; }
.msg p:last-child { margin-bottom: 0; }

.msg-user {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  border: 1px solid var(--bubble-user-border);
  color: var(--color-text);
  padding: var(--space-3) var(--space-4);
  border-radius: 14px 14px 4px 14px;
}

.msg-bot {
  align-self: flex-start;
  background: var(--bubble-bot-bg);
  color: var(--bubble-bot-text);
  padding: var(--space-4) var(--space-5);
  border-radius: 14px 14px 14px 4px;
}

.msg-meta {
  font-size: 0.75rem;
  color: var(--color-text-faint);
  margin-top: var(--space-1);
  align-self: inherit;
}

/* Typing indicator — three soft pulses */
.msg-bot.typing {
  padding: var(--space-4) var(--space-5);
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.msg-bot.typing span {
  width: 6px;
  height: 6px;
  background: var(--bubble-bot-text);
  opacity: 0.5;
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
}
.msg-bot.typing span:nth-child(2) { animation-delay: 0.15s; }
.msg-bot.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50%      { opacity: 0.9; transform: translateY(-2px); }
}

/* === Composer ============================================================ */

.chat-composer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, var(--color-bg) 30%);
  padding: var(--space-6) 0 var(--space-5);
}
.chat-composer-inner {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
  box-shadow: 0 4px 16px rgba(42, 31, 51, 0.04);
  transition: border-color 180ms, box-shadow 180ms;
}
.chat-composer-inner:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 4px 20px rgba(91, 61, 122, 0.12);
}
.chat-composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font: inherit;
  color: var(--color-text);
  outline: none;
  min-height: 3em; /* room for the placeholder; JS auto-grow handles real input */
  max-height: 200px;
  line-height: 1.5;
  padding: var(--space-2) 0;
  width: 100%;
}
@media (min-width: 720px) {
  .chat-composer textarea { min-height: 1.6em; } /* desktop placeholder fits one line */
}
.chat-composer textarea::placeholder {
  color: var(--color-text-faint);
}
.chat-send {
  background: var(--color-primary);
  color: #faf6fc;
  border: none;
  border-radius: 10px;
  padding: var(--space-3) var(--space-4);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 180ms;
  white-space: nowrap;
}
.chat-send:hover:not(:disabled) { background: var(--color-primary-hover); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

.chat-meter {
  text-align: center;
  color: var(--color-text-faint);
  font-size: 0.8rem;
  padding: 0 0 var(--space-3);
}
.chat-meter strong { color: var(--color-text-muted); font-weight: 500; }

.chat-disclaimer {
  text-align: center;
  color: var(--color-text-faint);
  font-size: 0.75rem;
  padding-bottom: var(--space-4);
  max-width: 56ch;
  margin: 0 auto;
  line-height: 1.5;
}

/* === Paywall ============================================================= */

.paywall-overlay[hidden] { display: none !important; }
.paywall-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 21, 32, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 100;
  animation: fadeIn 300ms ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.paywall-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  padding: var(--space-10) var(--space-8) var(--space-8);
  max-width: 460px;
  width: 100%;
  text-align: left;
  box-shadow: 0 20px 60px rgba(42, 31, 51, 0.18);
}
.paywall-card h2 {
  font-family: var(--font-display);
  font-size: 1.65rem;
  line-height: 1.2;
  color: var(--color-text);
  margin-bottom: var(--space-4);
  letter-spacing: -0.01em;
}
.paywall-card p {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  line-height: 1.65;
  margin-bottom: var(--space-3);
  max-width: 100%;
}
.paywall-card p strong { color: var(--color-text); font-weight: 500; }
.paywall-price {
  font-family: var(--font-display);
  font-size: 2.5rem;
  color: var(--color-text);
  margin: var(--space-5) 0 var(--space-2);
  letter-spacing: -0.02em;
}
.paywall-price small {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: var(--space-2);
}
.paywall-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-6);
}
.paywall-pay {
  background: var(--color-primary);
  color: #faf6fc;
  border: none;
  border-radius: 12px;
  padding: var(--space-4) var(--space-5);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 180ms;
}
.paywall-pay:hover { background: var(--color-primary-hover); }
.paywall-secondary {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.paywall-secondary:hover { color: var(--color-text); }

.paywall-foot {
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-divider);
  font-size: 0.8rem;
  color: var(--color-text-faint);
  line-height: 1.6;
}

@media (max-width: 540px) {
  .chat-stream { padding: var(--space-5) 0 var(--space-4); }
  .msg { max-width: 95%; font-size: 0.95rem; }
  .paywall-card { padding: var(--space-8) var(--space-5) var(--space-6); }
  .paywall-card h2 { font-size: 1.45rem; }
  .paywall-price { font-size: 2.1rem; }
}
