/* Fonts: Cormorant Garamond (scripture-like headings) + Inter (body) */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500;600;700&family=Inter:wght@400;500;600&display=swap');

:root {
  --night: #0a0d1a;        /* midnight sky */
  --nave: #111629;         /* panels */
  --pew: #1a2040;          /* bot bubbles, raised surfaces */
  --glass: #2b3166;        /* stained-glass indigo, borders */
  --gold: #d9b26a;         /* candle gold, primary accent */
  --gold-deep: #b98f45;
  --ivory: #eee8d8;        /* body text */
  --muted: #9a9cb8;
  --ember: #ff6b6b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Inter", system-ui, sans-serif;
}

html { height: 100%; }

body {
  min-height: 100%;
  height: 100dvh;
  overflow: hidden;
  color: var(--ivory);
  color-scheme: dark;
  background:
    radial-gradient(60rem 36rem at 50% -8%, rgba(217, 178, 106, 0.16), transparent 70%),
    radial-gradient(40rem 30rem at 100% 100%, rgba(75, 70, 190, 0.28), transparent 70%),
    radial-gradient(40rem 30rem at 0% 100%, rgba(40, 60, 150, 0.22), transparent 70%),
    var(--night);
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ---------- Chat shell ---------- */
.chatbot {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--nave);
  overflow: hidden;
  padding-top: var(--safe-top);
}

/* ---------- Header ---------- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  background: linear-gradient(180deg, #161c3a, var(--nave));
  border-bottom: 1px solid rgba(217, 178, 106, 0.35);
  position: relative;
}

/* thin gold light along the header edge */
.chat-header::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.header-info {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.header-info .chatbot-logo {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 50%;
  background: var(--pew);
  border: 2px solid var(--gold);
  box-shadow: 0 0 14px rgba(217, 178, 106, 0.35);
}

.header-text { min-width: 0; }

.header-info .logo-text {
  font-family: "Cormorant Garamond", Georgia, serif;
  color: var(--ivory);
  font-weight: 700;
  font-size: clamp(1.25rem, 1rem + 1vw, 1.7rem);
  letter-spacing: 0.01em;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-info .logo-tagline {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--gold);
  line-height: 1.2;
}

.ministry-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
}

.ministry-link .material-symbols-rounded { font-size: 1.2rem; }

.ministry-link:hover,
.ministry-link:focus-visible {
  background: var(--gold);
  color: var(--night);
  outline: none;
}

/* ---------- Messages ---------- */
.chat-body {
  flex: 1;
  padding: 26px 22px;
  gap: 20px;
  display: flex;
  overflow-y: auto;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--glass) transparent;
}

.chat-body .message {
  display: flex;
  gap: 11px;
  align-items: center;
}

.chat-body .message .bot-avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  margin-bottom: 2px;
  align-self: flex-end;
  object-fit: cover;
  border-radius: 50%;
  background: var(--pew);
  border: 1.5px solid var(--gold);
}

.chat-body .message .message-text {
  padding: 12px 16px;
  max-width: min(75%, 640px);
  font-size: 0.96rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.chat-body .bot-message.thinking .message-text { padding: 2px 16px; }

.chat-body .bot-message .message-text {
  color: var(--ivory);
  background: var(--pew);
  border: 1px solid var(--glass);
  border-radius: 14px 14px 14px 3px;
}

.chat-body .user-message {
  flex-direction: column;
  align-items: flex-end;
}

.chat-body .user-message .message-text {
  color: #1a1305;
  font-weight: 500;
  background: linear-gradient(135deg, #e6c685, var(--gold-deep));
  border-radius: 14px 14px 3px 14px;
}

.chat-body .user-message .attachment {
  width: min(50%, 320px);
  margin-top: -7px;
  border-radius: 14px 3px 14px 14px;
  border: 1px solid var(--glass);
}

/* Thinking dots */
.chat-body .bot-message .thinking-indicator {
  display: flex;
  gap: 5px;
  padding-block: 15px;
}

.chat-body .bot-message .thinking-indicator .dot {
  height: 7px;
  width: 7px;
  opacity: 0.7;
  border-radius: 50%;
  background: var(--gold);
  animation: dotPulse 1.8s ease-in-out infinite;
}

.chat-body .bot-message .thinking-indicator .dot:nth-child(1) { animation-delay: 0.2s; }
.chat-body .bot-message .thinking-indicator .dot:nth-child(2) { animation-delay: 0.3s; }
.chat-body .bot-message .thinking-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 44% { transform: translateY(0); }
  28% { opacity: 0.4; transform: translateY(-4px); }
  44% { opacity: 0.2; }
}

/* ---------- Footer / input ---------- */
.chat-footer {
  width: 100%;
  background: var(--nave);
  padding: 14px 22px calc(14px + var(--safe-bottom));
  border-top: 1px solid rgba(43, 49, 102, 0.8);
}

.chat-footer .chat-form {
  display: flex;
  align-items: center;
  position: relative;
  background: var(--night);
  border-radius: 28px;
  outline: 1px solid var(--glass);
  transition: outline-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-form:focus-within {
  outline: 2px solid var(--gold);
  box-shadow: 0 0 18px rgba(217, 178, 106, 0.18);
}

.chat-form .message-input {
  width: 100%;
  height: 47px;
  outline: none;
  resize: none;
  border: none;
  max-height: 180px;
  scrollbar-width: thin;
  border-radius: inherit;
  font-size: 1rem; /* 16px+ stops iOS zooming on focus */
  padding: 14px 0 12px 18px;
  color: var(--ivory);
  caret-color: var(--gold);
  background: transparent;
  scrollbar-color: transparent transparent;
}

.chat-form .message-input::placeholder { color: var(--muted); }

.chat-form .chat-controls {
  gap: 3px;
  height: 47px;
  display: flex;
  padding-right: 6px;
  align-items: center;
  align-self: flex-end;
}

.chat-form .chat-controls button {
  height: 36px;
  width: 36px;
  border: none;
  cursor: pointer;
  color: var(--muted);
  border-radius: 50%;
  font-size: 1.2rem;
  background: none;
  transition: 0.2s ease;
}

.chat-form .chat-controls button:hover,
body.show-emoji-picker .chat-controls #emoji-picker {
  color: var(--gold);
  background: var(--pew);
}

.chat-form .chat-controls #send-message {
  color: #1a1305;
  display: none;
  background: var(--gold);
}

.chat-form .chat-controls #send-message:hover {
  color: #1a1305;
  background: #ecc982;
}

.chat-form .message-input:valid ~ .chat-controls #send-message { display: block; }

/* File upload */
.chat-form .file-upload-wrapper {
  position: relative;
  height: 36px;
  width: 36px;
}

.chat-form .file-upload-wrapper :where(button, img) { position: absolute; }

.chat-form .file-upload-wrapper img {
  height: 100%;
  width: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.chat-form .file-upload-wrapper #file-cancel {
  color: var(--ember);
  background: var(--night);
}

.chat-form .file-upload-wrapper :where(img, #file-cancel),
.chat-form .file-upload-wrapper.file-uploaded #file-upload { display: none; }

.chat-form .file-upload-wrapper.file-uploaded img,
.chat-form .file-upload-wrapper.file-uploaded:hover #file-cancel { display: block; }

.footer-note {
  margin-top: 10px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
}

.footer-note a {
  color: var(--gold);
  text-underline-offset: 3px;
}

/* ---------- Emoji picker ---------- */
em-emoji-picker {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  width: 100%;
  max-width: 350px;
  max-height: min(330px, 50dvh);
  visibility: hidden;
  transform: translateX(-50%);
  color-scheme: dark;
}

body.show-emoji-picker em-emoji-picker { visibility: visible; }

/* ---------- Focus + motion ---------- */
:where(button, a, textarea):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

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

/* ---------- Responsive ---------- */

/* Tablets and small laptops: slightly tighter spacing */
@media (max-width: 768px) {
  .chat-header { padding: 12px 16px; }
  .chat-body { padding: 22px 16px; }
  .chat-footer { padding-inline: 16px; }
  .chat-body .message .message-text { max-width: 82%; }
}

/* Phones: ministry link collapses to an icon button */
@media (max-width: 520px) {
  .chat-header { padding: 10px 14px; }
  .header-info .chatbot-logo { width: 38px; height: 38px; }
  .header-info .logo-tagline { display: none; }
  .ministry-link { padding: 9px; }
  .ministry-link-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .chat-body { padding: 18px 12px; gap: 16px; }
  .chat-body .message .message-text { max-width: 86%; padding: 11px 14px; }
  .chat-footer { padding: 10px 12px calc(10px + var(--safe-bottom)); }
  .footer-note { font-size: 0.72rem; }
  .chat-form .file-upload-wrapper.file-uploaded #file-cancel { opacity: 0; }
}

/* Very small phones */
@media (max-width: 340px) {
  .header-info .logo-text { font-size: 1.05rem; }
  .chat-form .chat-controls { gap: 0; }
}

/* Short landscape screens: reclaim vertical space */
@media (max-height: 480px) {
  .chat-header { padding-block: 8px; }
  .header-info .logo-tagline,
  .footer-note { display: none; }
}

/* Desktop: floating chapel-window card */
@media (min-width: 900px) and (min-height: 640px) {
  .chatbot {
    max-width: 880px;
    height: min(94dvh, 960px);
    padding-top: 0;
    border-radius: 24px;
    border: 1px solid rgba(217, 178, 106, 0.35);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 60px rgba(217, 178, 106, 0.08);
  }
  .chat-header { padding: 18px 28px; }
  .chat-body { padding: 30px 34px; }
  .chat-footer { padding: 16px 34px 18px; }
}

/* Large / ultra-wide monitors */
@media (min-width: 1600px) {
  html { font-size: 112.5%; }
  .chatbot { max-width: 1000px; }
}
