:root {
  font-family: "Manrope", sans-serif;
  line-height: 1.5;
  font-weight: 500;
  color: #2a1742;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  --panel: rgba(255, 250, 255, 0.94);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --panel-border: rgba(175, 113, 255, 0.22);
  --panel-shadow: rgba(110, 67, 170, 0.22);
  --text-main: #5e22b5;
  --text-strong: #341559;
  --text-soft: #7e55bf;
  --text-muted: #9d86bf;
  --accent-purple: #a03bff;
  --accent-purple-soft: #c27bff;
  --accent-lilac: #efe0ff;
  --accent-yellow: #ffe922;
  --accent-yellow-soft: #fff6a8;
  --accent-pink: #ff7bc4;
  --theme-bg: rgba(255, 255, 255, 0.92);
  --theme-panel-border: rgba(255, 255, 255, 0.7);
  --theme-window-shadow-strong: rgba(94, 34, 181, 0.18);
  --theme-window-shadow-soft: rgba(81, 24, 149, 0.08);
  --theme-frame-top: rgba(255, 235, 124, 0.18);
  --theme-frame-right: rgba(203, 148, 255, 0.16);
  --theme-frame-bottom: rgba(160, 59, 255, 0.14);
  --theme-frame-base-top: rgba(255, 255, 255, 0.96);
  --theme-frame-base-bottom: rgba(251, 244, 255, 0.9);
  --theme-header-border: rgba(160, 59, 255, 0.12);
  --theme-badge-bg: rgba(255, 233, 34, 0.14);
  --theme-badge-border: rgba(255, 233, 34, 0.38);
  --theme-badge-text: #936000;
  --theme-avatar-shadow: rgba(113, 68, 202, 0.16);
  --theme-close-shadow: rgba(74, 29, 126, 0.12);
  --theme-close-shadow-hover: rgba(74, 29, 126, 0.18);
  --theme-scroll-thumb: rgba(160, 59, 255, 0.18);
  --theme-bot-bubble-top: rgba(245, 239, 255, 0.98);
  --theme-bot-bubble-bottom: rgba(255, 250, 255, 0.95);
  --theme-bot-border: rgba(160, 59, 255, 0.14);
  --theme-bot-shadow: rgba(111, 68, 178, 0.08);
  --theme-user-bubble-start: #a934ff;
  --theme-user-bubble-mid: #8d42ff;
  --theme-user-bubble-end: #7358ff;
  --theme-user-shadow: rgba(108, 64, 215, 0.2);
  --theme-typing-bg: rgba(239, 224, 255, 0.88);
  --theme-typing-border: rgba(160, 59, 255, 0.1);
  --theme-chip-border: rgba(160, 59, 255, 0.18);
  --theme-chip-hover-border: rgba(160, 59, 255, 0.32);
  --theme-chip-hover-bg: rgba(255, 242, 166, 0.94);
  --theme-chip-hover-text: #6a33b4;
  --theme-chip-hover-shadow: rgba(178, 125, 255, 0.16);
  --theme-chip-row-border: rgba(160, 59, 255, 0.08);
  --theme-chip-row-bottom: rgba(249, 243, 255, 0.8);
  --theme-input-bg-top: rgba(249, 243, 255, 0.3);
  --theme-input-bg-bottom: rgba(249, 243, 255, 0.92);
  --theme-icon-border: rgba(160, 59, 255, 0.18);
  --theme-icon-hover-shadow: rgba(160, 59, 255, 0.18);
  --theme-icon-hover-bg: rgba(160, 59, 255, 0.12);
  --theme-input-border: rgba(160, 59, 255, 0.12);
  --theme-input-shadow: rgba(161, 111, 216, 0.08);
  --theme-input-focus-border: rgba(160, 59, 255, 0.32);
  --theme-input-focus-ring: rgba(160, 59, 255, 0.08);
  --theme-send-start: #ffe922;
  --theme-send-end: #ffc52e;
  --theme-send-text: #4e2c00;
  --theme-send-shadow: rgba(255, 213, 61, 0.28);
  --theme-send-shadow-hover: rgba(255, 213, 61, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  min-height: 100%;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 999999;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border: none;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.14);
  transition: transform 180ms ease, box-shadow 180ms ease;
  padding: 0;
}

.chat-launcher[data-theme="adult"],
.chat-window[data-theme="adult"] {
  --panel: rgba(250, 247, 241, 0.96);
  --panel-strong: rgba(255, 252, 246, 0.98);
  --text-main: #1f5360;
  --text-strong: #19343b;
  --text-soft: #527580;
  --text-muted: #7d959d;
  --accent-purple: #2d7a78;
  --accent-purple-soft: #5f9f9d;
  --accent-lilac: #dff0ea;
  --accent-yellow: #d6a74f;
  --accent-yellow-soft: #f0ddb3;
  --theme-bg: rgba(255, 251, 245, 0.94);
  --theme-panel-border: rgba(216, 196, 168, 0.48);
  --theme-window-shadow-strong: rgba(34, 62, 68, 0.18);
  --theme-window-shadow-soft: rgba(73, 106, 103, 0.1);
  --theme-frame-top: rgba(214, 167, 79, 0.16);
  --theme-frame-right: rgba(119, 176, 171, 0.16);
  --theme-frame-bottom: rgba(45, 122, 120, 0.12);
  --theme-frame-base-top: rgba(255, 252, 246, 0.97);
  --theme-frame-base-bottom: rgba(244, 237, 226, 0.94);
  --theme-header-border: rgba(118, 150, 146, 0.18);
  --theme-badge-bg: rgba(214, 167, 79, 0.14);
  --theme-badge-border: rgba(214, 167, 79, 0.28);
  --theme-badge-text: #8f6316;
  --theme-avatar-shadow: rgba(76, 111, 108, 0.16);
  --theme-close-shadow: rgba(66, 93, 91, 0.14);
  --theme-close-shadow-hover: rgba(66, 93, 91, 0.2);
  --theme-scroll-thumb: rgba(45, 122, 120, 0.22);
  --theme-bot-bubble-top: rgba(239, 246, 243, 0.98);
  --theme-bot-bubble-bottom: rgba(255, 252, 247, 0.95);
  --theme-bot-border: rgba(103, 154, 151, 0.2);
  --theme-bot-shadow: rgba(81, 111, 108, 0.1);
  --theme-user-bubble-start: #2d7a78;
  --theme-user-bubble-mid: #366f7c;
  --theme-user-bubble-end: #5b6f96;
  --theme-user-shadow: rgba(62, 97, 110, 0.22);
  --theme-typing-bg: rgba(223, 240, 234, 0.88);
  --theme-typing-border: rgba(103, 154, 151, 0.16);
  --theme-chip-border: rgba(103, 154, 151, 0.24);
  --theme-chip-hover-border: rgba(103, 154, 151, 0.36);
  --theme-chip-hover-bg: rgba(240, 221, 179, 0.82);
  --theme-chip-hover-text: #315762;
  --theme-chip-hover-shadow: rgba(140, 117, 76, 0.16);
  --theme-chip-row-border: rgba(103, 154, 151, 0.12);
  --theme-chip-row-bottom: rgba(243, 236, 226, 0.85);
  --theme-input-bg-top: rgba(244, 237, 226, 0.38);
  --theme-input-bg-bottom: rgba(244, 237, 226, 0.95);
  --theme-icon-border: rgba(103, 154, 151, 0.22);
  --theme-icon-hover-shadow: rgba(71, 120, 115, 0.2);
  --theme-icon-hover-bg: rgba(45, 122, 120, 0.1);
  --theme-input-border: rgba(103, 154, 151, 0.16);
  --theme-input-shadow: rgba(91, 124, 121, 0.12);
  --theme-input-focus-border: rgba(45, 122, 120, 0.36);
  --theme-input-focus-ring: rgba(45, 122, 120, 0.1);
  --theme-send-start: #d6a74f;
  --theme-send-end: #bc8450;
  --theme-send-text: #fffdf8;
  --theme-send-shadow: rgba(188, 132, 80, 0.28);
  --theme-send-shadow-hover: rgba(188, 132, 80, 0.34);
}

.chat-launcher:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 22px 44px rgba(0, 0, 0, 0.18);
}

.chat-launcher.active {
  transform: translateY(-1px) scale(1);
}

.launcher-halo {
  display: none;
}

.launcher-icon {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  background: transparent;
}

.launcher-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-window {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: min(430px, calc(100vw - 28px));
  height: min(780px, calc(100vh - 48px));
  padding: 2px;
  border-radius: 38px;
  background: var(--theme-bg);
  border: 1px solid var(--theme-panel-border);
  box-shadow:
    0 48px 120px var(--theme-window-shadow-strong),
    0 8px 32px var(--theme-window-shadow-soft);
  backdrop-filter: blur(24px);
  opacity: 0;
  transform: translateY(20px) scale(0.98);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

.chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-window__frame {
  position: absolute;
  inset: 0;
  border-radius: 38px;
  background:
    radial-gradient(circle at 18% 14%, var(--theme-frame-top), transparent 22%),
    radial-gradient(circle at 82% 10%, var(--theme-frame-right), transparent 20%),
    radial-gradient(circle at 50% 100%, var(--theme-frame-bottom), transparent 38%),
    linear-gradient(180deg, var(--theme-frame-base-top), var(--theme-frame-base-bottom));
  backdrop-filter: blur(18px);
}

.chat-header,
.chat-messages,
.chip-row,
.chat-input {
  position: relative;
  z-index: 1;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--theme-header-border);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(16px);
}

.chat-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  overflow: hidden;
  box-shadow: 0 12px 28px var(--theme-avatar-shadow);
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-header__body {
  min-width: 0;
}

.chat-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: var(--theme-badge-bg);
  border: 1px solid var(--theme-badge-border);
  color: var(--theme-badge-text);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.chat-header h2 {
  margin: 0;
  color: var(--text-strong);
  font-size: 1.38rem;
  font-weight: 800;
  line-height: 1.08;
}

.chat-header p {
  margin: 6px 0 0;
  color: var(--text-soft);
  font-size: 0.93rem;
  line-height: 1.4;
}

.close-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  margin-left: auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 20px var(--theme-close-shadow);
  transition: transform 200ms ease, box-shadow 200ms ease, background 200ms ease;
}

.close-button:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 24px var(--theme-close-shadow-hover);
  background: rgba(255, 255, 255, 1);
}

.close-icon {
  position: relative;
  width: 16px;
  height: 16px;
}

.close-icon::before,
.close-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 2px;
  background: var(--text-strong);
  border-radius: 999px;
  transform-origin: center;
  transition: transform 180ms ease;
}

.close-icon::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.close-icon::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.close-button:hover .close-icon::before {
  transform: translate(-50%, -50%) rotate(45deg) scaleX(1.1);
}

.close-button:hover .close-icon::after {
  transform: translate(-50%, -50%) rotate(-45deg) scaleX(1.1);
}

.chat-messages {
  flex: 1;
  min-height: 0;
  /* reserve extra bottom padding so typing indicator and last messages don't overlap the input */
  padding: 18px 18px 110px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--theme-scroll-thumb);
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 87%;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.bot {
  align-self: flex-start;
}

.message-bubble {
  padding: 16px 18px;
  border-radius: 30px;
  font-size: 0.98rem;
  line-height: 1.65;
  letter-spacing: -0.01em;
}

.message-time {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.message-status {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: capitalize;
}

.message-bubble a {
  color: inherit;
  text-decoration: underline;
}

.message-bubble a:hover {
  text-decoration: none;
}

.message.bot .message-bubble {
  background:
    linear-gradient(180deg, var(--theme-bot-bubble-top), var(--theme-bot-bubble-bottom));
  color: var(--text-strong);
  border: 1px solid var(--theme-bot-border);
  border-bottom-left-radius: 18px;
  box-shadow: 0 18px 40px var(--theme-bot-shadow);
}

.message.user .message-bubble {
  background:
    linear-gradient(145deg, var(--theme-user-bubble-start) 0%, var(--theme-user-bubble-mid) 45%, var(--theme-user-bubble-end) 100%);
  color: #ffffff;
  border-bottom-right-radius: 18px;
}

.chip-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 18px;
  background: var(--theme-chip-row-bottom);
}

.chip {
  align-self: flex-start;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--theme-bg);
  border: 1px solid var(--theme-chip-border);
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 200ms ease;
}

.chip:hover {
  background: var(--theme-chip-hover-bg);
  color: var(--theme-chip-hover-text);
  border-color: var(--theme-chip-hover-border);
  box-shadow: 0 4px 12px var(--theme-chip-hover-shadow);
}

.chat-input {
  position: relative;
  display: flex;
  align-items: center;
  padding: 12px 18px;
  background: var(--theme-input-bg-bottom);
  gap: 12px;
}

.chat-input input[name="message"] {
  flex: 1;
  padding: 14px 20px;
  border-radius: 999px;
  border: 2px solid var(--theme-input-border);
  background: var(--theme-bg);
  color: var(--text-strong);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.chat-input input[name="message"]:focus {
  border-color: var(--theme-input-focus-border);
  box-shadow: 0 0 0 4px var(--theme-input-focus-ring);
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-main);
  transition: all 200ms ease;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--theme-icon-hover-bg);
  border-color: var(--theme-icon-border);
  box-shadow: 0 4px 12px var(--theme-icon-hover-shadow);
}

button[type="submit"].icon-button {
  background: linear-gradient(135deg, var(--theme-send-start), var(--theme-send-end));
  color: var(--theme-send-text);
  box-shadow: 0 6px 16px var(--theme-send-shadow);
}

button[type="submit"].icon-button svg {
  color: #fff;
  width: 20px;
  height: 20px;
}

button[type="submit"].icon-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px var(--theme-send-shadow-hover);
}

button[type="submit"].icon-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#chat-file-upload {
  display: none;
}

/* ── Typing indicator (three bouncing dots) ─────────────────────────── */

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

@keyframes bubble-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

/* Make the typing bubble itself compact */
.typing-indicator-wrapper .message-bubble {
  padding: 10px 14px;
  display: inline-flex;
  align-items: center;
}

.typing-indicator-wrapper {
  align-self: flex-start;
  margin-bottom: 6px;
}

.typing-indicator-wrapper .message-time {
  display: none;
}

.typing-indicator span {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-purple);
  animation: typing-bounce 1.2s ease-in-out infinite;
  flex-shrink: 0;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ── Smooth fade-in for newly rendered bot messages ─────────────────── */
.smooth-loading .message-bubble {
  animation: bubble-fade-in 220ms ease;
}

/* Hide empty bot message bubbles (avoids ghost blank bubble during stream delay) */
.message.bot .message-bubble:empty {
  display: none;
}

/* Also hide the article wrapper if the bot bubble is empty */
.message.bot:has(.message-bubble:empty) {
  display: none;
}
