/*
  Under the Firmament - chatbot widget styling.
  Reuses the site's own design tokens (navy borders, hard-offset
  shadows, gold accents, cream panels, Baloo 2 / Source Serif 4)
  so the widget reads as part of the site rather than a bolted-on
  generic chat plugin.
*/

#utf-chat-root {
  --utf-bg: #ffffff;
  --utf-bg-panel: #fdf3d7;
  --utf-bg-callout: #fff6d9;
  --utf-bg-soft: #eaf4fc;
  --utf-text: #0d2438;
  --utf-text-dim: #4a6274;
  --utf-navy: #0b3d68;
  --utf-navy-deep: #082a49;
  --utf-sky: #2e9ee0;
  --utf-gold: #f7c331;
  --utf-gold-deep: #e0a615;
  --utf-orange: #f0891e;
  --utf-red: #e2453c;
  --utf-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --utf-display: 'Baloo 2', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --utf-serif: 'Source Serif 4', Georgia, serif;
  position: fixed;
  z-index: 2147483000;
  font-family: var(--utf-sans);
}

/* ---------- Top-right toggle button ("Ask Rex!") ---------- */
#utf-chat-toggle {
  position: fixed;
  right: 20px;
  top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--utf-gold);
  border: 3px solid var(--utf-navy);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--utf-navy);
  cursor: pointer;
  padding: 6px 18px 6px 8px;
  transition: transform 0.15s ease;
}
#utf-chat-toggle:hover { transform: translateY(-2px); background: var(--utf-gold-deep); }
#utf-chat-toggle:focus-visible {
  outline: 3px solid var(--utf-navy);
  outline-offset: 3px;
}
#utf-chat-toggle img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  object-position: center 30%;
  pointer-events: none;
  border-radius: 50%;
}
#utf-chat-toggle .utf-toggle-label {
  font-family: var(--utf-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--utf-navy);
  white-space: nowrap;
}

/* ---------- Chat panel ---------- */
#utf-chat-panel {
  position: fixed;
  right: 20px;
  top: 76px;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 100px);
  background: var(--utf-bg);
  border: 3px solid var(--utf-navy);
  border-radius: 14px;
  box-shadow: 0 6px 0 var(--utf-navy), 0 10px 24px rgba(8,42,73,0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#utf-chat-panel[hidden] { display: none; }

#utf-chat-header {
  background: var(--utf-navy);
  color: #fff;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#utf-chat-header img { width: 30px; height: 33px; object-fit: contain; flex-shrink: 0; }
#utf-chat-header-text { flex: 1; min-width: 0; }
#utf-chat-header-text .utf-title {
  font-family: var(--utf-display);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}
#utf-chat-header-text .utf-subtitle {
  font-size: 11px;
  color: #cfe3f2;
  margin-top: 1px;
}
.utf-icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.utf-icon-btn:hover { background: rgba(255,255,255,0.15); }
.utf-icon-btn:focus-visible { outline: 2px solid var(--utf-gold); outline-offset: 1px; }
.utf-icon-btn svg { width: 18px; height: 18px; }

#utf-chat-disclaimer {
  background: var(--utf-bg-callout);
  border-bottom: 2px solid var(--utf-gold);
  color: var(--utf-text-dim);
  font-size: 11.5px;
  line-height: 1.4;
  padding: 8px 14px;
  flex-shrink: 0;
}

#utf-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--utf-bg-soft);
}

.utf-msg { display: flex; flex-direction: column; max-width: 92%; }
.utf-msg.user { align-self: flex-end; align-items: flex-end; }
.utf-msg.bot { align-self: flex-start; align-items: flex-start; }

.utf-bubble {
  border: 2px solid var(--utf-navy);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.5;
}
.utf-msg.user .utf-bubble {
  background: var(--utf-navy);
  color: #fff;
  border-color: var(--utf-navy-deep);
}
.utf-msg.bot .utf-bubble {
  background: #fff;
  color: var(--utf-text);
}
.utf-msg.bot .utf-bubble.utf-notfound {
  background: var(--utf-bg-panel);
  border-color: var(--utf-orange);
}

.utf-passage {
  font-family: var(--utf-serif);
  font-style: italic;
  color: var(--utf-text);
}
.utf-passage-label {
  font-family: var(--utf-sans);
  font-style: normal;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--utf-text-dim);
  margin-bottom: 4px;
}

.utf-sources {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.utf-source-link {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--utf-navy);
  background: var(--utf-bg-panel);
  border: 2px solid var(--utf-navy);
  border-radius: 8px;
  padding: 6px 9px;
  text-decoration: none;
  box-shadow: 0 2px 0 var(--utf-navy);
}
.utf-source-link:hover { background: var(--utf-gold); }
.utf-source-link:focus-visible { outline: 2px solid var(--utf-orange); outline-offset: 1px; }
.utf-source-link .utf-source-course { color: var(--utf-orange); }

.utf-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
}
.utf-loading-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--utf-navy);
  animation: utf-bounce 1.1s infinite ease-in-out;
}
.utf-loading-dot:nth-child(2) { animation-delay: 0.15s; }
.utf-loading-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes utf-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

#utf-chat-suggested {
  padding: 8px 14px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  background: var(--utf-bg-soft);
}
.utf-chip {
  font-family: var(--utf-sans);
  font-size: 11.5px;
  font-weight: 600;
  background: #fff;
  border: 2px solid var(--utf-navy);
  color: var(--utf-navy);
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
}
.utf-chip:hover { background: var(--utf-gold); }
.utf-chip:focus-visible { outline: 2px solid var(--utf-orange); outline-offset: 1px; }

#utf-chat-inputrow {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 2px solid var(--utf-navy);
  background: var(--utf-bg-soft);
  flex-shrink: 0;
}
#utf-chat-input {
  flex: 1;
  resize: none;
  border: 2px solid var(--utf-navy);
  border-radius: 10px;
  padding: 9px 11px;
  font-family: var(--utf-sans);
  font-size: 16px;
  color: var(--utf-text);
  max-height: 76px;
  line-height: 1.4;
}
#utf-chat-input:focus-visible { outline: 2px solid var(--utf-gold); outline-offset: 1px; }
#utf-chat-send {
  background: var(--utf-gold);
  border: 2px solid var(--utf-navy);
  box-shadow: 0 2px 0 var(--utf-navy);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#utf-chat-send:hover { background: var(--utf-gold-deep); }
#utf-chat-send:focus-visible { outline: 2px solid var(--utf-orange); outline-offset: 1px; }
#utf-chat-send:disabled { opacity: 0.5; cursor: default; }
#utf-chat-send svg { width: 18px; height: 18px; }

#utf-chat-clear {
  font-size: 11px;
  color: var(--utf-text-dim);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  margin-left: 4px;
}

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

@media (max-width: 460px) {
  #utf-chat-toggle {
    right: 16px;
    top: auto;
    bottom: 16px;
    width: 58px;
    height: 58px;
    padding: 0;
    justify-content: center;
    background: var(--utf-navy);
    border-radius: 50%;
    box-shadow: 0 3px 0 var(--utf-navy-deep), 0 5px 12px rgba(8,42,73,0.3);
  }
  #utf-chat-toggle img {
    box-sizing: border-box;
    width: 50px;
    height: 50px;
    border: 2px solid var(--utf-gold);
  }
  #utf-chat-toggle .utf-toggle-label { display: none; }
  #utf-chat-panel {
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-width: 0;
    border-radius: 0;
    box-shadow: none;
  }
  #utf-chat-toggle[aria-expanded="true"] { display: none; }
  #utf-chat-header { padding: 14px 14px calc(env(safe-area-inset-bottom, 0px) * 0 + 14px); }
  #utf-chat-header-text .utf-title { font-size: 17px; }
  #utf-chat-header-text .utf-subtitle { font-size: 12.5px; }
  #utf-chat-disclaimer { font-size: 12.5px; padding: 10px 14px; }
  .utf-bubble { font-size: 15px; padding: 12px 13px; }
  .utf-passage-label { font-size: 11.5px; }
  .utf-source-link { font-size: 13px; padding: 9px 11px; }
  .utf-chip { font-size: 13px; padding: 7px 13px; }
  #utf-chat-inputrow { padding: 10px 12px calc(env(safe-area-inset-bottom, 10px) + 10px); }
  #utf-chat-send { width: 44px; height: 44px; }
  #utf-chat-send svg { width: 20px; height: 20px; }
  .utf-icon-btn { padding: 10px; }
  .utf-icon-btn svg { width: 20px; height: 20px; }
}
