/* ==========================================================
   Health1st — AI chat assistant
   Uses the design tokens from style.css (--cyan, --violet, --surface, --line, ...).
   Sits above the nav (z 50) and below the custom cursor (z 9999).
   ========================================================== */
#algo-chat {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  font-family: var(--font-body); font-size: 15px; line-height: 1.5; color: var(--text);
}
#algo-chat [hidden] { display: none !important; }
#algo-chat svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
html:not(.has-cursor) #algo-chat button { cursor: pointer; }

/* Launcher */
.algo-chat-launcher {
  display: flex; align-items: center; justify-content: center; width: 58px; height: 58px; margin-left: auto;
  border: 0; border-radius: 50%; background: var(--cyan); color: var(--ink);
  box-shadow: 0 0 0 0 rgba(79,243,210,0), 0 10px 30px -8px rgba(79,243,210,.6);
  transition: transform .5s var(--ease), box-shadow .4s;
}
.algo-chat-launcher:hover { transform: translateY(-2px); box-shadow: 0 0 0 6px rgba(79,243,210,.12), 0 14px 40px -8px rgba(79,243,210,.75); }
.algo-chat-launcher svg { width: 26px; height: 26px; }

/* Panel */
.algo-chat-panel {
  position: relative; display: flex; flex-direction: column; width: 380px; max-width: calc(100vw - 44px);
  height: 580px; max-height: calc(100vh - 124px); max-height: calc(100dvh - 124px); margin-bottom: 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden;
  background: rgba(8, 11, 20, .9); backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 30px 80px -30px rgba(79,243,210,.35), 0 20px 50px -20px rgba(0,0,0,.8);
  animation: algoChatIn .45s var(--ease);
}
@keyframes algoChatIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.algo-chat-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 14px 14px 20px; border-bottom: 1px solid var(--line); }
.algo-chat-title { display: flex; align-items: center; gap: 9px; font: 600 1.1rem/1.2 var(--font-display); letter-spacing: -.03em; }
.algo-chat-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.algo-chat-subtitle { margin-top: 3px; padding-left: 17px; font: 500 .68rem/1 var(--font-display); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.algo-chat-close {
  display: flex; align-items: center; justify-content: center; flex: none; width: 34px; height: 34px;
  border: 1px solid var(--line); border-radius: 50%; background: none; color: var(--text); transition: border-color .3s, color .3s;
}
.algo-chat-close:hover { border-color: var(--cyan); color: var(--cyan); }
.algo-chat-close svg { width: 16px; height: 16px; }

/* Messages */
.algo-chat-log { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.algo-chat-log:focus-visible { outline-offset: -2px; }
.algo-chat-row { display: flex; }
.algo-chat-row-user { justify-content: flex-end; }
.algo-chat-bubble { max-width: 86%; padding: 11px 14px; border-radius: 16px; font-size: .93rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; animation: panelIn .5s var(--ease); }
.algo-chat-row-bot .algo-chat-bubble { background: rgba(255,255,255,.045); border: 1px solid var(--line); color: #D5DCE8; border-bottom-left-radius: 5px; }
.algo-chat-row-user .algo-chat-bubble { background: var(--cyan); color: var(--ink); font-weight: 500; border-bottom-right-radius: 5px; }
.algo-chat-bubble a { color: var(--cyan); text-decoration: underline; text-underline-offset: 2px; }
.algo-chat-row-user .algo-chat-bubble a { color: var(--ink); }

.algo-chat-typing { display: inline-flex; align-items: center; gap: 5px; padding: 15px 15px; }
.algo-chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); animation: algoChatDot 1.2s infinite ease-in-out; }
.algo-chat-typing span:nth-child(2) { animation-delay: .15s; }
.algo-chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes algoChatDot { 0%, 60%, 100% { opacity: .25; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* Quick replies */
.algo-chat-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px; }
.algo-chat-chip {
  padding: 8px 13px; border-radius: 999px; border: 1px solid rgba(79,243,210,.28); background: rgba(79,243,210,.07);
  color: var(--cyan); font: 500 .8rem/1.2 var(--font-display); transition: background-color .3s, border-color .3s;
}
.algo-chat-chip:hover { background: rgba(79,243,210,.16); border-color: var(--cyan); }

/* Input */
.algo-chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
.algo-chat-input {
  flex: 1 1 auto; min-width: 0; height: 44px; min-height: 44px; max-height: 120px; padding: 11px 14px; resize: none;
  border-radius: 12px; border: 1px solid var(--line-strong); background: rgba(5,7,13,.6); color: var(--text);
  font-size: 16px; line-height: 1.35; /* 16px stops iOS zooming on focus */
  transition: border-color .25s, box-shadow .25s;
}
.algo-chat-input::placeholder { color: var(--muted); opacity: 1; }
.algo-chat-input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(79,243,210,.12); }
.algo-chat-send {
  display: flex; align-items: center; justify-content: center; flex: none; width: 44px; height: 44px;
  border: 0; border-radius: 12px; background: var(--cyan); color: var(--ink); transition: box-shadow .3s, opacity .3s;
}
.algo-chat-send:hover { box-shadow: 0 0 0 5px rgba(79,243,210,.14); }
.algo-chat-send[disabled] { opacity: .45; }
.algo-chat-send svg { width: 20px; height: 20px; }

/* Footer */
.algo-chat-footer { padding: 0 14px 13px; }
.algo-chat-actions { display: flex; gap: 8px; }
.algo-chat-action {
  flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; padding: 10px 8px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--text); font: 600 .82rem/1.2 var(--font-display); white-space: nowrap; transition: border-color .3s, color .3s, background-color .3s;
}
.algo-chat-action:hover { border-color: var(--cyan); color: var(--cyan); }
.algo-chat-action-primary { border-color: rgba(79,243,210,.45); color: var(--cyan); background: rgba(79,243,210,.06); }
.algo-chat-action-primary:hover { background: rgba(79,243,210,.14); }
.algo-chat-note { margin-top: 9px; font-size: .7rem; line-height: 1.4; color: #6B7488; text-align: center; }

/* Phones: the open chat fills the screen */
@media (max-width: 480px) {
  #algo-chat { right: 14px; bottom: 14px; }
  #algo-chat.algo-chat-open { inset: 0; }
  #algo-chat.algo-chat-open .algo-chat-panel { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; border: 0; border-radius: 0; background: var(--bg); }
  #algo-chat.algo-chat-open .algo-chat-launcher { display: none; }
}
