/* RCCG Tower of Refuge — Church AI Assistant */
.tor-ai-root {
  --tor-teal: #087f98;
  --tor-teal-dark: #05627a;
  --tor-teal-deep: #04495b;
  --tor-teal-soft: #e3f3f6;
  --tor-gold: #f0a51a;
  --tor-gold-soft: #fef7e6;
  --tor-coral: #d62f24;
  --tor-ink: #14181f;
  --tor-muted: #545b66;
  --tor-line: #dce3e8;
  --tor-mist: #f4f7f8;
  --tor-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: var(--tor-sans);
  color: var(--tor-ink);
}

.tor-ai-root *,
.tor-ai-root *::before,
.tor-ai-root *::after {
  box-sizing: border-box;
}

.tor-ai-root :focus-visible {
  outline: 3px solid var(--tor-gold);
  outline-offset: 2px;
}

/* Floating Launcher Button */
.tor-ai-launcher {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-height: 54px;
  padding: 7px 18px 7px 8px;
  border-radius: 999px;
  border: 2px solid rgba(240, 165, 26, 0.85);
  background: linear-gradient(135deg, var(--tor-teal-deep) 0%, var(--tor-teal-dark) 55%, var(--tor-teal) 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(4, 73, 91, 0.34), 0 2px 8px rgba(0, 0, 0, 0.14);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  font-family: inherit;
  text-align: left;
}

.tor-ai-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(4, 73, 91, 0.42), 0 4px 12px rgba(0, 0, 0, 0.18);
}

.tor-ai-launcher[hidden] {
  display: none;
}

.tor-ai-launcher-badge {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(240, 165, 26, 0.45);
}

.tor-ai-launcher-badge img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.tor-ai-launcher-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.tor-ai-launcher-text strong {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.tor-ai-launcher-text span {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.88);
  margin-top: 2px;
}

.tor-ai-launcher-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tor-gold);
  box-shadow: 0 0 0 3px rgba(240, 165, 26, 0.25);
  margin-left: 2px;
  flex-shrink: 0;
}

/* Chat Panel */
.tor-ai-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 400px;
  max-width: calc(100vw - 28px);
  height: min(610px, calc(100vh - 40px));
  height: min(610px, calc(100dvh - 40px));
  background: var(--tor-mist);
  border: 1px solid rgba(5, 98, 122, 0.2);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(10, 28, 38, 0.28), 0 4px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: torAiSlideUp 0.2s ease-out;
}

.tor-ai-panel[hidden] {
  display: none;
}

@keyframes torAiSlideUp {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */
.tor-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 13px 16px;
  background: linear-gradient(135deg, var(--tor-teal-deep) 0%, var(--tor-teal-dark) 62%, var(--tor-teal) 100%);
  color: #fff;
  border-bottom: 3px solid var(--tor-gold);
  flex-shrink: 0;
}

.tor-ai-header-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.tor-ai-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.tor-ai-avatar img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.tor-ai-header-meta {
  min-width: 0;
}

.tor-ai-header-meta h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
}

.tor-ai-header-meta p {
  margin: 2px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tor-ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6bf09c;
  flex-shrink: 0;
}

.tor-ai-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.tor-ai-icon-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease;
}

.tor-ai-icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Message Feed */
.tor-ai-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.tor-ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
}

.tor-ai-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.tor-ai-msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.tor-ai-bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.tor-ai-msg.user .tor-ai-bubble {
  background: linear-gradient(135deg, var(--tor-teal-dark), var(--tor-teal-deep));
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(4, 73, 91, 0.18);
}

.tor-ai-msg.assistant .tor-ai-bubble {
  background: #fff;
  color: var(--tor-ink);
  border: 1px solid var(--tor-line);
  border-bottom-left-radius: 4px;
  box-shadow: 0 3px 10px rgba(16, 40, 50, 0.05);
}

.tor-ai-msg.error .tor-ai-bubble {
  background: var(--tor-gold-soft);
  border-color: rgba(240, 165, 26, 0.5);
}

.tor-ai-bubble p {
  margin: 0 0 8px;
}

.tor-ai-bubble p:last-child {
  margin-bottom: 0;
}

.tor-ai-bubble ul {
  margin: 6px 0;
  padding-left: 18px;
}

.tor-ai-bubble li {
  margin-bottom: 4px;
}

.tor-ai-bubble a {
  color: var(--tor-teal-dark);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tor-ai-bubble a:hover {
  color: var(--tor-teal-deep);
}

/* Action CTA buttons under assistant reply */
.tor-ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.tor-ai-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.12s ease;
}

.tor-ai-action-btn:hover {
  transform: translateY(-1px);
}

.tor-ai-action-btn.primary {
  background: var(--tor-teal-dark);
  color: #fff;
}

.tor-ai-action-btn.primary:hover {
  background: var(--tor-teal-deep);
  color: #fff;
}

.tor-ai-action-btn.secondary {
  background: var(--tor-teal-soft);
  color: var(--tor-teal-deep);
  border: 1px solid rgba(8, 127, 152, 0.25);
}

.tor-ai-action-btn.secondary:hover {
  background: #d1ebf0;
  color: var(--tor-teal-deep);
}

/* Typing indicator */
.tor-ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 15px;
}

.tor-ai-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tor-teal);
  opacity: 0.45;
  animation: torAiDot 1.1s infinite ease-in-out;
}

.tor-ai-typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.tor-ai-typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes torAiDot {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Suggested Quick Questions */
.tor-ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 10px;
  background: var(--tor-mist);
  border-top: 1px solid var(--tor-line);
  flex-shrink: 0;
}

.tor-ai-chips[hidden] {
  display: none;
}

.tor-ai-chip {
  appearance: none;
  border: 1px solid rgba(5, 98, 122, 0.28);
  background: #fff;
  color: var(--tor-teal-deep);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 34px;
  font-size: 12.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.tor-ai-chip:hover {
  background: var(--tor-teal-soft);
  border-color: var(--tor-teal);
  transform: translateY(-1px);
}

/* Composer */
.tor-ai-composer {
  padding: 10px 12px 10px;
  background: #fff;
  border-top: 1px solid var(--tor-line);
  flex-shrink: 0;
}

.tor-ai-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--tor-mist);
  border: 1.5px solid var(--tor-line);
  border-radius: 14px;
  padding: 6px 6px 6px 12px;
  transition: border-color 0.15s ease;
}

.tor-ai-input-wrap:focus-within {
  border-color: var(--tor-teal);
  background: #fff;
}

.tor-ai-input {
  flex: 1 1 auto;
  border: 0;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  color: var(--tor-ink);
  max-height: 104px;
  min-height: 24px;
  padding: 5px 0;
  margin: 0;
}

.tor-ai-input:focus {
  outline: none;
}

.tor-ai-input::placeholder {
  color: var(--tor-muted);
}

.tor-ai-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 11px;
  border: 0;
  background: var(--tor-teal-dark);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
  padding: 0;
}

.tor-ai-send:hover:not(:disabled) {
  background: var(--tor-teal-deep);
}

.tor-ai-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tor-ai-composer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--tor-muted);
  padding-inline: 2px;
}

.tor-ai-count {
  font-weight: 700;
}

.tor-ai-count.over {
  color: var(--tor-coral);
}

/* Mobile Responsive */
@media (max-width: 540px) {
  .tor-ai-root {
    right: 12px;
    bottom: 12px;
  }

  .tor-ai-launcher {
    padding: 6px 14px 6px 7px;
    min-height: 48px;
  }

  .tor-ai-panel {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-width: none;
    height: min(84vh, 650px);
    height: min(84dvh, 650px);
    border-radius: 18px;
  }

  .tor-ai-icon-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .tor-ai-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tor-ai-panel,
  .tor-ai-launcher,
  .tor-ai-chip,
  .tor-ai-action-btn,
  .tor-ai-typing span {
    animation: none !important;
    transition: none !important;
  }
}
