/* ==========================================================================
   LIFE AI — floating chat assistant
   Matches the site's editorial look: Inter, electric blue, pill controls.
   ========================================================================== */

.lai-root {
  --lai-blue: #0057ff;
  --lai-blue-hover: #0046d1;
  --lai-blue-ink: #001a8c;
  --lai-blue-tint: #eef3ff;
  --lai-ink: #141414;
  --lai-text: #2b2b2b;
  --lai-muted: #6b6b6b;
  --lai-line: rgba(128, 128, 128, 0.2);
  --lai-bg: #f5f5f5;
  --lai-warn-bg: #fff6e5;
  --lai-warn-ink: #7a4b00;
  --lai-red: #e5252a;

  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--lai-ink);
}
.lai-root *, .lai-root *::before, .lai-root *::after { box-sizing: border-box; }
.lai-root button { font-family: inherit; cursor: pointer; }

/* ---------- Launcher ---------- */
.lai-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 500;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 22px 0 8px;
  border: 0;
  border-radius: 999px;
  background: var(--lai-blue);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 12px 32px rgba(0, 40, 160, 0.35);
  transition: transform 0.18s ease, background-color 0.18s ease, opacity 0.18s ease;
}
.lai-launcher:hover { background: var(--lai-blue-hover); transform: translateY(-2px); }
.lai-launcher:focus-visible { outline: 3px solid rgba(0, 87, 255, 0.35); outline-offset: 3px; }
.lai-launcher-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}
.lai-root.open .lai-launcher { opacity: 0; pointer-events: none; transform: scale(0.9); }

/* ---------- Panel ---------- */
.lai-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 510;
  display: flex;
  flex-direction: column;
  width: 400px;
  height: min(640px, calc(100vh - 48px));
  border-radius: 18px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 10, 60, 0.28), 0 0 0 1px rgba(0, 0, 0, 0.04);
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}
.lai-root.open .lai-panel {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  visibility: visible;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.lai-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 16px 18px;
  color: #fff;
  background:
    linear-gradient(100deg, transparent 0 55%, rgba(255, 255, 255, 0.08) 55% 70%, transparent 70%),
    linear-gradient(115deg, #0a1aa8 0%, #0c2fe0 50%, #1b4dff 100%);
}
.lai-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.lai-title { flex: 1; min-width: 0; }
.lai-title strong { display: block; font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.lai-title span { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: 0.85; }
.lai-title span::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
}
.lai-head-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
}
.lai-head-btn:hover { background: rgba(255, 255, 255, 0.16); }

.lai-disclaimer {
  padding: 9px 18px;
  background: var(--lai-warn-bg);
  color: var(--lai-warn-ink);
  font-size: 12px;
  line-height: 1.45;
  border-bottom: 1px solid rgba(122, 75, 0, 0.1);
}
.lai-disclaimer strong { font-weight: 700; }

/* ---------- Messages ---------- */
.lai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  background: var(--lai-bg);
  scroll-behavior: smooth;
}

.lai-msg { display: flex; gap: 8px; margin-bottom: 14px; animation: laiIn 0.2s ease both; }
.lai-msg-user { justify-content: flex-end; }

.lai-bubble {
  max-width: 85%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.lai-msg-user .lai-bubble {
  background: var(--lai-blue);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.lai-msg-ai .lai-bubble {
  background: #fff;
  color: var(--lai-text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.lai-msg-ai .lai-mini-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--lai-blue-ink);
  color: #fff;
}

/* Rendered markdown */
.lai-bubble p { margin: 0 0 10px; }
.lai-bubble p:last-child, .lai-bubble ul:last-child, .lai-bubble ol:last-child { margin-bottom: 0; }
.lai-bubble ul, .lai-bubble ol { margin: 0 0 10px; padding-left: 20px; }
.lai-bubble li { margin-bottom: 4px; }
.lai-bubble strong { font-weight: 700; color: var(--lai-ink); }
.lai-msg-user .lai-bubble strong { color: #fff; }
.lai-bubble a { color: var(--lai-blue); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.lai-bubble a.lai-story-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--lai-blue-tint);
}
.lai-bubble a.lai-story-link:hover { background: #dfe8ff; }
.lai-bubble code { font-size: 0.9em; padding: 1px 5px; border-radius: 4px; background: #f0f0f0; }

.lai-notice {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--lai-muted);
  font-style: italic;
}
.lai-error .lai-bubble { background: #fdeeee; color: #8a1c1f; }

/* Typing indicator */
.lai-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.lai-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b5b5b5;
  animation: laiDot 1.2s infinite ease-in-out;
}
.lai-typing i:nth-child(2) { animation-delay: 0.15s; }
.lai-typing i:nth-child(3) { animation-delay: 0.3s; }

/* Welcome */
.lai-welcome { padding: 6px 4px 4px; }
.lai-welcome h3 { margin: 0 0 6px; font-size: 22px; line-height: 1.2; font-weight: 800; letter-spacing: -0.02em; color: #000; }
.lai-welcome p { margin: 0 0 16px; font-size: 14px; line-height: 1.55; color: var(--lai-muted); }
.lai-suggest-label {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lai-muted);
}
.lai-suggestions { display: flex; flex-direction: column; gap: 8px; }
.lai-suggestion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1.6px solid var(--lai-line);
  border-radius: 12px;
  background: #fff;
  color: var(--lai-text);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.lai-suggestion:hover { border-color: var(--lai-blue); color: var(--lai-blue); }

/* ---------- Composer ---------- */
.lai-composer {
  padding: 12px 14px 10px;
  background: #fff;
  border-top: 1px solid #ececec;
}
.lai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border: 1.6px solid var(--lai-line);
  border-radius: 22px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.lai-input-row:focus-within { border-color: var(--lai-blue); box-shadow: 0 0 0 3px rgba(0, 87, 255, 0.12); }
.lai-input {
  flex: 1;
  min-height: 24px;
  max-height: 120px;
  padding: 6px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  color: var(--lai-ink);
}
.lai-input::placeholder { color: #9a9a9a; }
.lai-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--lai-blue);
  color: #fff;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}
.lai-send:hover { background: var(--lai-blue-hover); }
.lai-send:disabled { opacity: 0.35; cursor: default; }
.lai-send.lai-stop { background: var(--lai-ink); }
.lai-foot {
  margin-top: 7px;
  text-align: center;
  font-size: 11px;
  color: var(--lai-muted);
}

@keyframes laiIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes laiDot { 0%, 80%, 100% { opacity: 0.35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

@media (prefers-reduced-motion: reduce) {
  .lai-root *, .lai-root *::before, .lai-root *::after { animation: none !important; transition: none !important; }
}

/* ---------- Mobile: full screen sheet ---------- */
@media (max-width: 520px) {
  .lai-launcher { right: 16px; bottom: 16px; height: 52px; padding: 0 18px 0 6px; font-size: 14px; }
  .lai-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
  }
  .lai-input { font-size: 16px; } /* prevents iOS zoom on focus */
}
