/* Chat widget + floating chat panel.
   Variables (--navy, --cyan, --bg, --text, --text-muted, --border) are inherited
   from the page. */

.chat-widget {
  background: var(--white, #fff);
  border: 1px solid var(--border, rgba(0, 61, 106, 0.12));
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0, 61, 106, 0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Fixed height so the body can scroll instead of pushing the page down. */
  height: 580px;
  max-height: calc(100vh - 120px);
}

/* When the widget is rendered inside a flex container with sized children
   (e.g. floating panel), let it fill that height. */
.float-chat-body .chat-widget,
.chat-fullscreen .chat-widget {
  height: 100%;
  max-height: none;
}

.chat-body {
  flex: 1 1 0;
  min-height: 0;          /* critical for flex-children to actually scroll */
  padding: 20px 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, #f8faf5 0%, #ffffff 100%);
}

.chat-suggests {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.chat-suggest {
  background: rgba(0, 161, 202, 0.08);
  color: var(--navy, #003D6A);
  border: 1px solid rgba(0, 161, 202, 0.25);
  border-radius: 100px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}
.chat-suggest:hover { background: rgba(0, 161, 202, 0.18); }

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

.msg-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.msg-bubble p { margin: 0 0 8px 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0 4px 22px; padding: 0; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble strong { color: var(--navy, #003D6A); }
.msg-bubble code { background: rgba(0, 61, 106, 0.08); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg-bubble a { color: var(--cyan, #00A1CA); text-decoration: underline; word-break: break-word; }
.msg-bubble .md-h { display: block; margin: 8px 0 4px; font-size: 14.5px; }

.msg-user .msg-bubble {
  background: var(--cyan, #00A1CA);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-user .msg-bubble strong { color: #fff; }
.msg-user .msg-bubble a { color: #fff; }
.msg-bot .msg-bubble {
  background: #fff;
  color: var(--text, #1B2A4A);
  border: 1px solid var(--border, rgba(0, 61, 106, 0.12));
  border-bottom-left-radius: 4px;
}

.msg-tools {
  margin-top: 6px;
}
.msg-tool {
  background: transparent;
  border: 1px solid var(--border, rgba(0, 61, 106, 0.18));
  color: var(--text-muted, #5A6E8A);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 100px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, color .15s, border-color .15s;
}
.msg-tool:hover { background: rgba(0,161,202,0.08); color: var(--navy, #003D6A); border-color: var(--cyan, #00A1CA); }
.msg-tool:disabled { opacity: 0.6; cursor: default; }

.chat-cursor {
  display: inline-block;
  width: 2px;
  background: var(--cyan, #00A1CA);
  animation: chat-blink 1s infinite;
}
@keyframes chat-blink { 50% { opacity: 0.2; } }

.chat-typing {
  display: inline-flex; gap: 4px; padding: 4px 0;
}
.chat-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--cyan, #00A1CA);
  opacity: 0.5;
  animation: chat-bounce 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.chat-error { color: #c2410c; font-weight: 500; }

.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border, rgba(0, 61, 106, 0.12));
  background: #fff;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border, rgba(0, 61, 106, 0.18));
  border-radius: 14px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text, #1B2A4A);
  resize: none;
  max-height: 160px;
  /* Hide scrollbar until the user types enough to hit max-height; the JS
     auto-grow handler flips this to 'auto' once the threshold is reached. */
  overflow-y: hidden;
  outline: none;
  background: #fafbf8;
  transition: border-color .15s;
}
.chat-input:focus { border-color: var(--cyan, #00A1CA); background: #fff; }
.chat-input:disabled { background: #f3f5ef; opacity: 0.7; }

.chat-send {
  flex: 0 0 auto;
  border: none;
  background: var(--cyan, #00A1CA);
  color: #fff;
  border-radius: 12px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .15s;
}
.chat-send:hover:not(:disabled) {
  background: var(--navy, #003D6A);
  transform: translateY(-1px);
}
.chat-send:disabled { background: #b0c8d4; cursor: default; }

.chat-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 12px;
  font-size: 12px;
  color: var(--text-muted, #5A6E8A);
  background: #fff;
  flex-wrap: wrap;
}
.chat-foot-left {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.chat-foot-btn {
  background: transparent;
  border: none;
  color: var(--text-muted, #5A6E8A);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.chat-foot-btn:hover { background: rgba(0,0,0,0.05); color: var(--navy, #003D6A); }
.chat-foot-hint { white-space: nowrap; }
@media (max-width: 480px) {
  .chat-foot-hint { display: none; }
}

/* ──────── Floating chat ──────── */

.float-chat-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 90;
  background: var(--cyan, #00A1CA);
  color: #fff;
  border: none;
  border-radius: 100px;
  padding: 14px 22px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 161, 202, 0.4);
  transition: transform .15s, box-shadow .15s;
}
.float-chat-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(0, 161, 202, 0.5); }

.float-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  width: min(420px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 120px));
  z-index: 95;
  display: none;
  flex-direction: column;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 16px 60px rgba(0, 61, 106, 0.25);
  overflow: hidden;
}
.float-chat-panel.open { display: flex; }

.float-chat-head {
  padding: 14px 18px;
  background: var(--navy, #003D6A);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-family: 'Unbounded', sans-serif;
  font-size: 14px;
}
.float-chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.float-chat-body { flex: 1; min-height: 0; }
.float-chat-body .chat-widget {
  border: none;
  border-radius: 0;
  box-shadow: none;
  height: 100%;
  min-height: 0;
}

@media (max-width: 640px) {
  .float-chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
  .float-chat-btn { right: 16px; bottom: 16px; padding: 12px 18px; }
  .chat-widget { height: 520px; }
}

/* ──────── Chat header (with fullscreen toggle) ──────── */

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, rgba(0, 61, 106, 0.10));
  background: #fff;
  flex-shrink: 0;
}
.chat-head-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'Unbounded', sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy, #003D6A);
}
.chat-head-title::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
}
.chat-head-tools { display: flex; gap: 4px; }
.chat-head-tool {
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-muted, #5A6E8A);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.chat-head-tool:hover { background: rgba(0, 161, 202, 0.08); color: var(--navy, #003D6A); }

/* ──────── Fullscreen mode ──────── */

.chat-fullscreen-overlay {
  position: fixed;
  inset: 90px 0 0 0;          /* leave the page header visible */
  z-index: 80;
  background: rgba(243, 245, 239, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 16px 16px 16px;
}
.chat-fullscreen {
  width: min(960px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
}
body.chat-fs-open { overflow: hidden; }
@media (max-width: 640px) {
  .chat-fullscreen-overlay { inset: 70px 0 0 0; padding: 0; }
}
