/* ============================================================
   Mizu Chat Widget — self-contained, config-driven
   Drop-in for IMC prelanders. Matches the restrained clinical
   aesthetic of the advertorial (accent #1e3a5f, Inter headline,
   Georgia body, #e2e8f0 borders). Mobile-first slide-up panel.
   All selectors namespaced .mizu-* to avoid colliding with the
   host page styles.
   ============================================================ */

.mizu-root {
  /* Local design tokens (mirror the prelander, but self-contained
     so this file works on any prelander without depending on the
     page :root vars). */
  --mz-accent: #1e3a5f;
  --mz-accent-dark: #0f2440;
  --mz-bg: #ffffff;
  --mz-surface: #f8fafc;
  --mz-text: #0f172a;
  --mz-text-muted: #475569;
  --mz-border: #e2e8f0;
  --mz-bubble-mizu: #f1f5f9;
  --mz-bubble-user: #1e3a5f;
  --mz-font-head: -apple-system, BlinkMacSystemFont, 'Inter', 'Helvetica Neue', sans-serif;
  --mz-font-body: Georgia, 'Times New Roman', serif;
  --mz-radius: 14px;
  --mz-shadow: 0 -10px 40px rgba(15, 23, 42, 0.18);

  font-family: var(--mz-font-head);
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
}
.mizu-root *,
.mizu-root *::before,
.mizu-root *::after { box-sizing: border-box; }

/* ---------- Backdrop (dim the page behind the panel) ---------- */
.mizu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
  z-index: 2147483000; /* above the page's sticky CTA (z-index:100) */
}
.mizu-root.mizu-open .mizu-backdrop {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s ease;
}

/* ---------- Panel ---------- */
.mizu-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 480px;
  height: min(85vh, 720px);
  background: var(--mz-bg);
  border-radius: var(--mz-radius) var(--mz-radius) 0 0;
  box-shadow: var(--mz-shadow);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 2147483001;
  overflow: hidden;
}
.mizu-root.mizu-open .mizu-panel { transform: translateY(0); }
/* The panel is a tabindex=-1 scroll container we focus programmatically on
   open (for screen-reader context + scroll management); it is not a user-
   operable control, so suppress its focus ring. Real controls (close, send,
   input, textarea) keep their :focus / :focus-visible rings below. */
.mizu-panel:focus { outline: none; }

@media (min-width: 600px) {
  .mizu-panel {
    right: 24px;
    left: auto;
    bottom: 24px;
    margin: 0;
    height: min(78vh, 680px);
    border-radius: var(--mz-radius);
  }
}

/* ---------- Header ---------- */
.mizu-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--mz-accent);
  color: #fff;
}
.mizu-avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2c5282, #1e3a5f);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 17px;
  color: #fff;
  position: relative;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
}
.mizu-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.mizu-avatar::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #34d399;
  border: 2px solid var(--mz-accent);
}
.mizu-id { flex: 1 1 auto; min-width: 0; line-height: 1.25; }
.mizu-id .mizu-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.mizu-id .mizu-role {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
}
.mizu-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.mizu-close:hover { background: rgba(255, 255, 255, 0.24); }
.mizu-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ---------- Message list ---------- */
.mizu-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  background: var(--mz-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mizu-messages::-webkit-scrollbar { width: 8px; }
.mizu-messages::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 4px;
}

.mizu-day {
  align-self: center;
  font-size: 11px;
  color: var(--mz-text-muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--mz-border);
  border-radius: 999px;
  padding: 3px 12px;
  margin: 4px 0 6px;
}

/* Message rows + bubbles */
.mizu-row { display: flex; width: 100%; }
.mizu-row.mizu-in { justify-content: flex-start; }
.mizu-row.mizu-out { justify-content: flex-end; }

.mizu-bubble {
  max-width: 82%;
  padding: 11px 14px;
  font-family: var(--mz-font-body);
  font-size: 15.5px;
  line-height: 1.5;
  border-radius: 16px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: mizu-pop 0.22s ease both;
}
.mizu-row.mizu-in .mizu-bubble {
  background: var(--mz-bubble-mizu);
  color: var(--mz-text);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--mz-border);
}
.mizu-row.mizu-out .mizu-bubble {
  background: var(--mz-bubble-user);
  color: #fff;
  border-bottom-right-radius: 5px;
}
/* Links inside bubbles: clearly a link + safely wrap long URLs so they
   never overflow the bubble (the affiliate/booster URLs can be long). */
.mizu-bubble a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  font-weight: 600;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.mizu-bubble a:hover { text-decoration-thickness: 2px; }
/* Mizu (inbound) bubbles are light → use the accent for contrast. */
.mizu-row.mizu-in .mizu-bubble a { color: var(--mz-accent); }
/* User (outbound) bubbles are dark accent → keep links white/underlined. */
.mizu-row.mizu-out .mizu-bubble a { color: #fff; }

@keyframes mizu-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Typing indicator */
.mizu-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 13px 16px;
}
.mizu-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
  animation: mizu-blink 1.3s infinite ease-in-out both;
}
.mizu-typing span:nth-child(2) { animation-delay: 0.18s; }
.mizu-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes mizu-blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Affiliate CTA card rendered inside the stream */
.mizu-cta-card {
  align-self: stretch;
  background: var(--mz-bg);
  border: 1.5px solid var(--mz-accent);
  border-radius: 12px;
  padding: 16px 16px 18px;
  margin: 4px 0 6px;
  box-shadow: 0 4px 14px rgba(30, 58, 95, 0.1);
}
.mizu-cta-card .mizu-cta-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mz-accent);
  margin-bottom: 8px;
}
.mizu-cta-card .mizu-cta-text {
  font-family: var(--mz-font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--mz-text);
  margin: 0 0 14px;
}
.mizu-cta-btn {
  display: block;
  width: 100%;
  background: var(--mz-accent);
  color: #fff;
  text-decoration: none;
  text-align: center;
  font-family: var(--mz-font-head);
  font-weight: 700;
  font-size: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 50px;
}
.mizu-cta-btn:hover, .mizu-cta-btn:active { background: var(--mz-accent-dark); text-decoration: none; }
.mizu-cta-sub {
  text-align: center;
  font-size: 11.5px;
  color: var(--mz-text-muted);
  margin-top: 8px;
}

/* Inline email-capture form (used for graceful degradation AND
   optional in-chat capture) */
.mizu-email-card {
  align-self: stretch;
  background: var(--mz-bg);
  border: 1px solid var(--mz-border);
  border-radius: 12px;
  padding: 16px;
  margin: 4px 0 6px;
}
.mizu-email-card .mizu-email-title {
  font-family: var(--mz-font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--mz-text);
  margin: 0 0 12px;
}
.mizu-field { margin-bottom: 10px; }
.mizu-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--mz-text-muted);
  margin-bottom: 5px;
}
.mizu-input {
  width: 100%;
  padding: 12px 13px;
  border: 1.5px solid var(--mz-border);
  border-radius: 8px;
  font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  font-family: var(--mz-font-body);
  color: var(--mz-text);
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
}
.mizu-input:focus {
  outline: none;
  border-color: var(--mz-accent);
}
.mizu-input.mizu-invalid { border-color: #c53030; }
.mizu-error {
  font-size: 12px;
  color: #c53030;
  margin: 4px 0 0;
  line-height: 1.4;
}
.mizu-email-card .mizu-cta-btn { margin-top: 4px; }
.mizu-note {
  font-size: 11.5px;
  color: var(--mz-text-muted);
  margin: 10px 0 0;
  line-height: 1.45;
}

/* System / status line (degradation, errors) */
.mizu-system {
  align-self: center;
  text-align: center;
  font-size: 12.5px;
  color: var(--mz-text-muted);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--mz-border);
  border-radius: 10px;
  padding: 8px 14px;
  margin: 4px 0;
  max-width: 92%;
  line-height: 1.45;
}

/* ---------- Composer ---------- */
.mizu-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--mz-bg);
  border-top: 1px solid var(--mz-border);
}
.mizu-textarea {
  flex: 1 1 auto;
  resize: none;
  border: 1.5px solid var(--mz-border);
  border-radius: 22px;
  padding: 11px 15px;
  font-family: var(--mz-font-body);
  font-size: 16px; /* avoids iOS zoom */
  line-height: 1.4;
  color: var(--mz-text);
  background: #fff;
  max-height: 120px;
  min-height: 44px;
  -webkit-appearance: none;
  appearance: none;
}
.mizu-textarea:focus {
  outline: none;
  border-color: var(--mz-accent);
}
.mizu-textarea::placeholder { color: #94a3b8; }
.mizu-send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--mz-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.mizu-send:hover { background: var(--mz-accent-dark); }
.mizu-send:disabled { opacity: 0.45; cursor: not-allowed; }
.mizu-send:focus-visible {
  outline: 2px solid var(--mz-accent);
  outline-offset: 2px;
}
.mizu-send svg { width: 20px; height: 20px; display: block; }

/* Visually-hidden helper (for a11y labels) */
.mizu-sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .mizu-panel,
  .mizu-backdrop,
  .mizu-bubble,
  .mizu-typing span { transition: none !important; animation: none !important; }
}
