/* RESTROY AI Support Chatbot — Premium UI */

:root {
  --rai-red: #ef4444;
  --rai-red-600: #dc2626;
  --rai-red-700: #b91c1c;
  --rai-red-50: #fef2f2;
  --rai-red-100: #fee2e2;
  --rai-ink: #0f172a;
  --rai-ink-soft: #1e293b;
  --rai-muted: #64748b;
  --rai-muted-2: #94a3b8;
  --rai-line: #e2e8f0;
  --rai-line-soft: #f1f5f9;
  --rai-bg: #ffffff;
  --rai-bg-soft: #f8fafc;
  --rai-bg-ai: #f1f5f9;
  --rai-ok: #22c55e;
  --rai-err: #dc2626;
  --rai-radius-lg: 24px;
  --rai-radius-md: 16px;
  --rai-radius-sm: 12px;
  --rai-shadow:
    0 24px 60px -12px rgba(15, 23, 42, 0.18),
    0 8px 24px -8px rgba(15, 23, 42, 0.08);
  --rai-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --rai-dur: 320ms;
  --rai-font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#restroy-ai-chat,
#restroy-ai-chat * {
  box-sizing: border-box;
}

#restroy-ai-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 150;
  font-family: var(--rai-font);
  color: var(--rai-ink);
  line-height: 1.45;
  pointer-events: none;
}

#restroy-ai-chat > * {
  pointer-events: auto;
}

/* ========== Launcher ========== */
.rai-launcher {
  position: relative;
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 999px;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--rai-red) 0%, var(--rai-red-700) 100%);
  color: #fff;
  box-shadow:
    0 12px 28px -8px rgba(239, 68, 68, 0.45),
    0 4px 12px rgba(185, 28, 28, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transform: translateY(0) scale(1);
  transition: transform var(--rai-dur) var(--rai-ease),
    box-shadow var(--rai-dur) var(--rai-ease),
    background 200ms ease;
  animation: raiFloat 4.5s ease-in-out infinite;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.rai-launcher:hover {
  transform: translateY(-2px) scale(1.06);
  box-shadow:
    0 18px 36px -8px rgba(239, 68, 68, 0.5),
    0 8px 18px rgba(185, 28, 28, 0.28);
}

.rai-launcher:active {
  transform: scale(0.96);
}

.rai-launcher:focus-visible {
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 6px rgba(239, 68, 68, 0.55),
    0 12px 28px -8px rgba(239, 68, 68, 0.45);
}

.rai-launcher__glow {
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  background: conic-gradient(
    from 0deg,
    transparent 0%,
    rgba(239, 68, 68, 0.45) 35%,
    transparent 60%,
    transparent 100%
  );
  animation: raiSpin 3.8s linear infinite;
  opacity: 0.55;
  z-index: -1;
  filter: blur(0.5px);
}

.rai-launcher__ring {
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  border: 1.5px solid rgba(239, 68, 68, 0.35);
  animation: raiPulseRing 2.8s ease-in-out infinite;
  pointer-events: none;
}

.rai-launcher__icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  transition: transform 250ms var(--rai-ease), opacity 200ms ease;
}

.rai-launcher__icon svg {
  width: 30px;
  height: 30px;
  display: block;
}

.rai-launcher__close {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
  transition: opacity 220ms var(--rai-ease), transform 280ms var(--rai-ease);
  pointer-events: none;
}

.rai-launcher__close svg {
  width: 22px;
  height: 22px;
}

.rai[data-open="true"] .rai-launcher {
  animation: none;
  background: linear-gradient(145deg, var(--rai-ink-soft), var(--rai-ink));
  box-shadow: 0 10px 24px -8px rgba(15, 23, 42, 0.35);
}

.rai[data-open="true"] .rai-launcher__icon {
  opacity: 0;
  transform: scale(0.5) rotate(45deg);
}

.rai[data-open="true"] .rai-launcher__close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  pointer-events: auto;
}

.rai-launcher__badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--rai-ok);
  border: 2px solid #fff;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
  animation: raiBadgePulse 2.2s ease-out infinite;
}

.rai-launcher__tooltip {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  background: var(--rai-ink);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 8px 12px;
  border-radius: 10px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 250ms var(--rai-ease);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
}

.rai-launcher__tooltip::after {
  content: '';
  position: absolute;
  left: -5px;
  top: 50%;
  width: 10px;
  height: 10px;
  background: var(--rai-ink);
  transform: translateY(-50%) rotate(45deg);
  border-radius: 2px;
}

.rai-launcher:hover .rai-launcher__tooltip,
.rai-launcher:focus-visible .rai-launcher__tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.rai[data-open="true"] .rai-launcher__tooltip,
.rai[data-open="true"] .rai-launcher__badge,
.rai[data-open="true"] .rai-launcher__glow,
.rai[data-open="true"] .rai-launcher__ring {
  opacity: 0;
  visibility: hidden;
  animation: none;
}

/* ========== Window ========== */
.rai-window {
  position: absolute;
  right: 0;
  bottom: 84px;
  width: min(420px, calc(100vw - 32px));
  height: min(700px, calc(100dvh - 140px));
  max-height: calc(100dvh - 140px);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: var(--rai-radius-lg);
  box-shadow: var(--rai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform-origin: bottom right;
  transform: translateY(16px) scale(0.92);
  transition:
    opacity 280ms var(--rai-ease),
    transform 360ms var(--rai-ease),
    visibility 0s linear 360ms;
  will-change: transform, opacity;
}

.rai[data-open="true"] .rai-window {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition:
    opacity 320ms var(--rai-ease),
    transform 420ms var(--rai-ease),
    visibility 0s linear 0s;
}

.rai-window::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 88px;
  background: linear-gradient(
    180deg,
    rgba(254, 242, 242, 0.95) 0%,
    rgba(255, 255, 255, 0) 100%
  );
  pointer-events: none;
  z-index: 0;
}

/* ========== Header ========== */
.rai-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px 16px;
  border-bottom: 1px solid rgba(241, 245, 249, 0.95);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 320ms var(--rai-ease) 80ms, transform 360ms var(--rai-ease) 80ms;
}

.rai[data-open="true"] .rai-header {
  opacity: 1;
  transform: translateY(0);
}

.rai-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--rai-red), var(--rai-red-700));
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 6px 16px -6px rgba(239, 68, 68, 0.55);
}

.rai-avatar::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 17px;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.35), transparent 60%);
  z-index: -1;
  animation: raiAvatarGlow 3s ease-in-out infinite;
}

.rai-avatar svg {
  width: 26px;
  height: 26px;
}

.rai-header__meta {
  min-width: 0;
  flex: 1;
}

.rai-header__title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--rai-ink);
  line-height: 1.2;
}

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

.rai-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 500;
  color: #16a34a;
}

.rai-status__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--rai-ok);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
  animation: raiStatusPulse 2s ease-out infinite;
}

.rai-status.is-busy {
  color: var(--rai-red-600);
}

.rai-status.is-busy .rai-status__dot {
  background: var(--rai-red);
  animation-duration: 1s;
}

.rai-status.is-error {
  color: var(--rai-err);
}

.rai-status.is-error .rai-status__dot {
  background: var(--rai-err);
  animation: none;
}

.rai-header__actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.rai-icon-btn {
  position: relative;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--rai-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
  outline: none;
}

.rai-icon-btn:hover {
  background: var(--rai-red-50);
  color: var(--rai-red-600);
}

.rai-icon-btn:active {
  transform: scale(0.94);
}

.rai-icon-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.35);
}

.rai-icon-btn svg {
  width: 16px;
  height: 16px;
}

.rai-icon-btn[aria-expanded="true"] {
  background: var(--rai-red-50);
  color: var(--rai-red-600);
}

/* Dropdown */
.rai-menu-wrap {
  position: relative;
}

.rai-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 196px;
  background: #fff;
  border: 1px solid var(--rai-line);
  border-radius: 14px;
  box-shadow: 0 16px 40px -12px rgba(15, 23, 42, 0.18);
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.97);
  transform-origin: top right;
  transition: opacity 180ms var(--rai-ease), transform 200ms var(--rai-ease), visibility 0s linear 200ms;
  z-index: 20;
}

.rai-menu.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition: opacity 200ms var(--rai-ease), transform 220ms var(--rai-ease), visibility 0s;
}

.rai-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--rai-ink-soft);
  cursor: pointer;
  text-align: left;
  transition: background 140ms ease, color 140ms ease;
}

.rai-menu button:hover {
  background: var(--rai-red-50);
  color: var(--rai-red-700);
}

.rai-menu button:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.45);
  outline-offset: -2px;
}

.rai-menu button svg {
  width: 15px;
  height: 15px;
  opacity: 0.75;
  flex-shrink: 0;
}

.rai-menu__divider {
  height: 1px;
  background: var(--rai-line-soft);
  margin: 5px 6px;
}

/* Context hint */
.rai-context {
  position: relative;
  z-index: 1;
  display: none;
  margin: 10px 14px 0;
  padding: 9px 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--rai-red-50), #fff7ed);
  border: 1px solid rgba(254, 226, 226, 0.9);
  font-size: 12px;
  color: var(--rai-red-700);
  font-weight: 500;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 280ms var(--rai-ease) 140ms, transform 300ms var(--rai-ease) 140ms;
}

.rai-context.is-visible {
  display: flex;
}

.rai[data-open="true"] .rai-context.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.rai-context svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ========== Messages area ========== */
.rai-main {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.rai-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.rai-messages::-webkit-scrollbar {
  width: 6px;
}

.rai-messages::-webkit-scrollbar-track {
  background: transparent;
}

.rai-messages::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 999px;
}

.rai-messages::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

.rai-messages {
  scrollbar-width: thin;
  scrollbar-color: #e2e8f0 transparent;
}

/* Welcome */
.rai-welcome {
  animation: raiFadeUp 420ms var(--rai-ease) both;
  padding-bottom: 4px;
}

.rai-welcome__greet {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.rai-welcome__orb {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: linear-gradient(145deg, #fff, var(--rai-red-50));
  border: 1px solid rgba(254, 226, 226, 0.95);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 8px 20px -10px rgba(239, 68, 68, 0.35);
  animation: raiFloatSoft 3.5s ease-in-out infinite;
}

.rai-welcome__orb svg {
  width: 28px;
  height: 28px;
}

.rai-welcome__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--rai-ink);
}

.rai-welcome__role {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--rai-red-600);
  font-weight: 600;
}

.rai-welcome__desc {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--rai-muted);
  line-height: 1.55;
  max-width: 34em;
}

.rai-welcome__label {
  margin: 18px 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--rai-muted-2);
}

/* Quick actions */
.rai-quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  animation: raiFadeUp 420ms var(--rai-ease) 80ms both;
}

.rai-quick__card {
  border: 1px solid var(--rai-line);
  background: var(--rai-bg-soft);
  border-radius: 14px;
  padding: 11px 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  transition:
    transform 200ms var(--rai-ease),
    box-shadow 200ms var(--rai-ease),
    border-color 180ms ease,
    background 180ms ease;
  outline: none;
  min-height: 64px;
}

.rai-quick__card:hover {
  transform: translateY(-2px);
  border-color: rgba(239, 68, 68, 0.35);
  background: #fff;
  box-shadow: 0 10px 22px -12px rgba(15, 23, 42, 0.18);
}

.rai-quick__card:focus-visible {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
}

.rai-quick__icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--rai-red-50);
  color: var(--rai-red-600);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}

.rai-quick__card:hover .rai-quick__icon {
  background: var(--rai-red);
  color: #fff;
  transform: scale(1.05);
}

.rai-quick__icon svg {
  width: 15px;
  height: 15px;
}

.rai-quick__text {
  min-width: 0;
}

.rai-quick__title {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--rai-ink);
  line-height: 1.25;
}

.rai-quick__desc {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--rai-muted);
  line-height: 1.35;
}

/* Chips */
.rai-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 2px 4px;
  margin: 0 -2px;
  scrollbar-width: none;
  animation: raiFadeUp 420ms var(--rai-ease) 140ms both;
}

.rai-chips::-webkit-scrollbar {
  display: none;
}

.rai-chip {
  flex: 0 0 auto;
  border: 1px solid var(--rai-line);
  background: #fff;
  color: var(--rai-ink-soft);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

.rai-chip:hover {
  border-color: rgba(239, 68, 68, 0.45);
  color: var(--rai-red-700);
  background: var(--rai-red-50);
  transform: translateY(-1px);
}

.rai-chip:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.45);
  outline-offset: 2px;
}

/* Messages */
.rai-msg {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  animation: raiMsgIn 320ms var(--rai-ease) both;
  align-items: flex-start;
}

.rai-msg--user {
  flex-direction: row-reverse;
}

.rai-msg__avatar {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--rai-red), var(--rai-red-700));
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 4px 10px -4px rgba(239, 68, 68, 0.5);
}

.rai-msg__avatar svg {
  width: 15px;
  height: 15px;
}

.rai-msg__body {
  max-width: 78%;
  min-width: 0;
}

.rai-msg__name {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--rai-muted-2);
  margin-bottom: 4px;
}

.rai-msg--user .rai-msg__name {
  text-align: right;
}

.rai-msg__bubble {
  border-radius: 16px;
  padding: 11px 13px;
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.rai-msg__bubble--md {
  white-space: normal;
}

.rai-msg__bubble--md .rai-li {
  display: block;
  margin: 2px 0;
}

.rai-msg__bubble--md strong {
  font-weight: 700;
  color: var(--rai-ink);
}

.rai-msg__bubble--md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  background: rgba(15, 23, 42, 0.06);
  padding: 1px 5px;
  border-radius: 5px;
}

.rai-msg__bubble--md .rai-pre,
.rai-msg__bubble--md pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  margin: 8px 0;
}

.rai-msg--ai .rai-msg__bubble {
  background: var(--rai-bg-ai);
  color: var(--rai-ink-soft);
  border-top-left-radius: 6px;
}

.rai-msg--user .rai-msg__bubble {
  background: linear-gradient(145deg, var(--rai-red), var(--rai-red-600));
  color: #fff;
  border-top-right-radius: 6px;
  box-shadow: 0 8px 18px -10px rgba(239, 68, 68, 0.55);
}

.rai-msg--error .rai-msg__bubble {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.rai-msg__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  font-size: 10.5px;
  color: var(--rai-muted-2);
}

.rai-msg--user .rai-msg__meta {
  justify-content: flex-end;
}

.rai-msg__retry {
  border: 0;
  background: transparent;
  color: var(--rai-red-600);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 2px 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.rai-msg__retry:hover {
  color: var(--rai-red-700);
}

.rai-msg__retry:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.45);
  border-radius: 4px;
}

/* Error card inside chat */
.rai-error-card {
  border: 1px solid #fecaca;
  background: linear-gradient(180deg, #fff7f7, #fef2f2);
  border-radius: 16px;
  padding: 16px;
  margin: 8px 0 14px;
  animation: raiFadeUp 300ms var(--rai-ease) both;
}

.rai-error-card h4 {
  margin: 0 0 4px;
  font-size: 13.5px;
  font-weight: 700;
  color: #991b1b;
}

.rai-error-card p {
  margin: 0;
  font-size: 12.5px;
  color: #7f1d1d;
  line-height: 1.5;
}

.rai-error-card__actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.rai-btn {
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.rai-btn:active {
  transform: scale(0.97);
}

.rai-btn--primary {
  background: linear-gradient(145deg, var(--rai-red), var(--rai-red-600));
  color: #fff;
  box-shadow: 0 6px 14px -6px rgba(239, 68, 68, 0.55);
}

.rai-btn--primary:hover {
  box-shadow: 0 10px 18px -6px rgba(239, 68, 68, 0.5);
}

.rai-btn--ghost {
  background: #fff;
  color: var(--rai-ink-soft);
  border: 1px solid var(--rai-line);
}

.rai-btn--ghost:hover {
  border-color: #cbd5e1;
}

.rai-btn:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.5);
  outline-offset: 2px;
}

/* Typing */
.rai-typing {
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  animation: raiMsgIn 280ms var(--rai-ease) both;
}

.rai-typing.is-visible {
  display: flex;
}

.rai-typing__bubble {
  background: var(--rai-bg-ai);
  border-radius: 16px;
  border-top-left-radius: 6px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rai-typing__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--rai-muted);
}

.rai-typing__dots {
  display: flex;
  gap: 5px;
  align-items: center;
  height: 8px;
}

.rai-typing__dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--rai-red);
  opacity: 0.35;
  animation: raiDot 1.15s ease-in-out infinite;
}

.rai-typing__dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.rai-typing__dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.rai-typing .rai-msg__avatar {
  animation: raiAvatarPulse 1.4s ease-in-out infinite;
}

/* Scroll bottom */
.rai-scroll-bottom {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%) translateY(8px);
  border: 1px solid var(--rai-line);
  background: rgba(255, 255, 255, 0.95);
  color: var(--rai-ink-soft);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: none;
  align-items: center;
  gap: 6px;
  box-shadow: 0 8px 20px -8px rgba(15, 23, 42, 0.2);
  z-index: 5;
  opacity: 0;
  transition: opacity 200ms ease, transform 240ms var(--rai-ease);
  pointer-events: none;
}

.rai-scroll-bottom.is-visible {
  display: inline-flex;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.rai-scroll-bottom:hover {
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--rai-red-700);
}

.rai-scroll-bottom:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.45);
}

/* ========== Composer ========== */
.rai-composer {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(241, 245, 249, 0.95);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 300ms var(--rai-ease) 160ms, transform 320ms var(--rai-ease) 160ms;
}

.rai[data-open="true"] .rai-composer {
  opacity: 1;
  transform: translateY(0);
}

.rai-composer__row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #fff;
  border: 1.5px solid var(--rai-line);
  border-radius: 18px;
  padding: 8px 8px 8px 14px;
  transition: border-color 180ms ease, box-shadow 200ms ease;
}

.rai-composer__row:focus-within {
  border-color: rgba(239, 68, 68, 0.65);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.12);
}

.rai-composer textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--rai-ink);
  background: transparent;
  max-height: 120px;
  min-height: 22px;
  padding: 8px 0;
  overflow-y: auto;
}

.rai-composer textarea::placeholder {
  color: var(--rai-muted-2);
}

.rai-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(145deg, var(--rai-red), var(--rai-red-600));
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 160ms ease, opacity 160ms ease, box-shadow 160ms ease;
  box-shadow: 0 6px 14px -6px rgba(239, 68, 68, 0.55);
}

.rai-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.rai-send:active:not(:disabled) {
  transform: scale(0.94);
}

.rai-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.rai-send:focus-visible {
  outline: 2px solid rgba(239, 68, 68, 0.5);
  outline-offset: 2px;
}

.rai-send svg {
  width: 16px;
  height: 16px;
}

.rai-send.is-loading svg {
  display: none;
}

.rai-send .rai-send__spin {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 999px;
  animation: raiSpin 0.7s linear infinite;
}

.rai-send.is-loading .rai-send__spin {
  display: block;
}

.rai-composer__hint {
  margin: 6px 4px 0;
  font-size: 10.5px;
  color: var(--rai-muted-2);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.rai-composer__hint kbd {
  font-family: inherit;
  font-size: 10px;
  background: var(--rai-bg-soft);
  border: 1px solid var(--rai-line);
  border-radius: 4px;
  padding: 1px 4px;
}

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

/* ========== Animations ========== */
@keyframes raiFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-5px) scale(1); }
}

@keyframes raiFloatSoft {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

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

@keyframes raiPulseRing {
  0%, 100% { transform: scale(1); opacity: 0.35; }
  50% { transform: scale(1.08); opacity: 0.1; }
}

@keyframes raiBadgePulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

@keyframes raiStatusPulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

@keyframes raiAvatarGlow {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@keyframes raiAvatarPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes raiFadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes raiDot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Stagger welcome children */
.rai-welcome .rai-quick { animation-delay: 60ms; }
.rai-welcome .rai-chips { animation-delay: 120ms; }

/* ========== Responsive ========== */
@media (max-width: 640px) {
  #restroy-ai-chat {
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    pointer-events: none;
  }

  .rai-launcher {
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 2;
  }

  .rai-launcher__tooltip {
    display: none;
  }

  .rai-window {
    position: fixed;
    inset: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
    transform: translateY(24px) scale(0.98);
    transform-origin: bottom center;
  }

  .rai[data-open="true"] .rai-window {
    transform: translateY(0) scale(1);
  }

  .rai[data-open="true"] .rai-launcher {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.8);
  }

  .rai-messages {
    padding-bottom: 16px;
  }

  .rai-composer {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .rai-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    min-height: calc(64px + env(safe-area-inset-top, 0px));
  }

  .rai-quick {
    grid-template-columns: 1fr 1fr;
  }

  .rai-msg__body {
    max-width: 86%;
  }
}

@media (max-width: 360px) {
  .rai-quick {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .rai-window {
    width: min(400px, calc(100vw - 32px));
    height: min(640px, calc(100dvh - 120px));
  }
}

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

  .rai-window {
    transform: none !important;
  }
}

/* Body lock when mobile chat open */
body.rai-mobile-open {
  overflow: hidden !important;
  touch-action: none;
}
