/* Chat page — extends the Health Compass design system from styles.css */

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: min(860px, calc(100% - 24px));
  margin: 0 auto;
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  flex-shrink: 0;
  /* Break out of the centered chat-shell so the logo can sit at the
     viewport's left edge rather than the 860px content column. */
  width: 100vw;
  margin-left: calc(50% - 50vw);
}

.chat-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
}

.chat-brand img {
  width: 77px;
  height: 77px;
  object-fit: contain;
}

.chat-brand-text {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.05;
}

.chat-brand-tagline {
  font-family: "Avenir Next", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.chat-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-nav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.92rem;
}

/* Model picker — pill-styled inline select sitting in the topbar */
.chat-model-pick {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

.chat-model-pick-label {
  font-family: "Avenir Next", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.chat-model-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  padding-right: 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%2384909c' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right center;
}

.chat-model-select:focus {
  outline: none;
}

/* Message area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  /* Horizontal padding leaves room for the speech-bubble tails that
     extend ~10px past each bubble's edge — without it, the auto
     overflow-y silently clips the tails on the outside of the column. */
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(21, 48, 76, 0.14);
  border-radius: 3px;
}

.chat-welcome {
  text-align: center;
  padding: 28px 24px;
  color: var(--ink-soft);
}

.chat-welcome h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.6rem;
  color: var(--ink);
  margin: 0 0 6px;
}

.chat-welcome p {
  max-width: 32rem;
  margin: 0 auto 2px;
  font-size: 0.96rem;
  line-height: 1.45;
}

/* Suggestion chips, sitting just below the input row. */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding: 0 4px;
}

.chat-suggestion {
  position: relative;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink-soft);
  font-size: 0.84rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.chat-suggestion:hover {
  background: rgba(17, 146, 208, 0.1);
  border-color: rgba(17, 146, 208, 0.28);
  color: var(--ink);
}

/* Tail under each suggestion chip — same path as the bubble tail,
   mirrored to point down-left so the chip reads as a tiny speech bubble.
   Path uses fill="currentColor" so this `color` drives the fill. */
.chat-suggestion-tail {
  position: absolute;
  bottom: -7px;
  left: 12px;
  width: 11px;
  height: 11px;
  color: rgba(255, 255, 255, 0.9);
  pointer-events: none;
  transform: scaleX(-1);
  filter: drop-shadow(0 1px 0 var(--line));
  transition: color 150ms ease;
}

.chat-suggestion:hover .chat-suggestion-tail {
  color: rgba(225, 240, 250, 0.95);
}

/* Message blocks: bubble + name label, aligned to a side of the column */
.msg-block {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: msg-in 250ms ease;
}

.msg-block-user {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-block-assistant {
  align-self: flex-end;
  align-items: flex-end;
}

/* Bubbles — cartoon-ish: chunky radius, asymmetric tail-corner pinch,
   soft shadow, SVG tail. The pinched corner + tail point toward the speaker. */
.msg {
  padding: 10px 14px;
  border-radius: 24px;
  font-size: 1rem;
  line-height: 1.4;
  position: relative;
}

/* Sharp triangular tail — hangs below the bubble's bottom corner.
   Position: bottom is negative so the triangle dangles below; horizontal
   offset places the wide top edge near (but not at) the corner. */
.msg-tail {
  position: absolute;
  bottom: -10px;
  width: 16px;
  height: 12px;
  pointer-events: none;
  /* The path uses fill="currentColor", so this drives the tail fill. */
  color: rgba(255, 255, 255, 0.92);
}

.msg-block-user .msg-tail {
  left: 16px;
  transform: scaleX(-1);
  color: #0e7ab8;
}

.msg-block-assistant .msg-tail {
  right: 16px;
  color: rgba(255, 255, 255, 0.92);
  /* Subtle outline so the tail edges read against the warm-white page */
  filter: drop-shadow(0 1px 0 var(--line))
    drop-shadow(-1px 0 0 var(--line));
}

.msg-user {
  background: linear-gradient(135deg, var(--blue), #0e7ab8);
  color: white;
  border-bottom-left-radius: 6px;
  box-shadow: 0 4px 14px rgba(17, 122, 184, 0.22);
}

.msg-assistant {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 14px rgba(21, 48, 76, 0.08);
}

.msg-assistant strong {
  font-weight: 700;
}

/* Name label under each bubble — leaves room to add other voices later
   (e.g. "Cardiologist", "Care Team", "Pharmacist"). */
.msg-label {
  font-family: "Avenir Next", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 4px;
  padding: 0 12px;
  opacity: 0.72;
}

.msg-label-tag {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  font-size: 0.7rem;
  margin-left: 6px;
  opacity: 0.8;
}

/* Compact lists inside bubbles — meds tight, condition headings get a half-line above */
.msg ul {
  margin: 0;
  padding-left: 1.15em;
}

.msg li {
  margin: 0;
  line-height: 1.35;
}

.msg-h {
  display: block;
  font-family: "Avenir Next", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0.4em 0 0.05em;
}

.msg-h:first-child {
  margin-top: 0;
}

/* "Thinking" status bubble — a thought-cloud shape that reads as
   contemplation: fully rounded body (no pinched corner) plus two
   trailing puff-circles below-right that point toward the speaker.
   On entry it rises from the input area below over 1.5s. */
.msg-status {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-style: italic;
  font-size: 0.94rem;
  padding: 12px 20px;
  border-radius: 28px;
  box-shadow: 0 4px 14px rgba(21, 48, 76, 0.06);
  animation:
    thought-rise 1.5s cubic-bezier(0.16, 1, 0.3, 1) both,
    status-pulse 1.6s ease-in-out infinite 1.5s;
  /* Reserve space below for the trailing puffs */
  margin-bottom: 18px;
  transform-origin: bottom right;
}

/* The block holding the status bubble normally fades in via msg-in;
   suppress that so only the thought-rise animation drives the entry. */
#typing-indicator {
  animation: none;
}

@keyframes thought-rise {
  0% {
    opacity: 0;
    transform: translateY(120px) translateX(8px) scale(0.2) rotate(-6deg);
  }
  60% {
    opacity: 0.85;
    transform: translateY(28px) translateX(-3px) scale(0.78) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) translateX(0) scale(1) rotate(0deg);
  }
}

/* Two trailing thought-puffs, smaller-and-smaller toward the speaker */
.msg-status::before,
.msg-status::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 50%;
}

.msg-status::before {
  bottom: -10px;
  right: 24px;
  width: 10px;
  height: 10px;
}

.msg-status::after {
  bottom: -20px;
  right: 10px;
  width: 6px;
  height: 6px;
}

@keyframes status-pulse {
  0%, 100% { opacity: 0.82; }
  50%      { opacity: 1; }
}

/* Input area */
.chat-input-area {
  flex-shrink: 0;
  padding: 12px 0 16px;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 8px 24px rgba(21, 48, 76, 0.08);
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 4px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  resize: none;
  min-height: 24px;
  max-height: 120px;
  outline: none;
  border-radius: 0;
}

.chat-input::placeholder {
  color: var(--ink-soft);
  opacity: 0.6;
}

.chat-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--red), var(--orange));
  color: white;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 150ms ease, opacity 150ms ease;
}

.chat-send:hover {
  transform: scale(1.06);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.chat-send svg {
  width: 18px;
  height: 18px;
}

.chat-disclaimer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
  opacity: 0.6;
  margin-top: 6px;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typing-dot {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Auth link in nav */
.chat-auth-link {
  font-size: 0.84rem;
}

.chat-auth-connect {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(178, 204, 52, 0.18);
  color: var(--ink);
  text-decoration: none;
}

.chat-auth-connect:hover {
  background: rgba(178, 204, 52, 0.32);
}

@media (max-width: 640px) {
  .chat-shell {
    width: calc(100% - 16px);
  }

  .msg {
    max-width: 90%;
    padding: 12px 14px;
  }

  .chat-brand {
    font-size: 1.15rem;
  }
}
