/* Full-height chat layout */
body.chat-page { height: 100dvh; overflow: hidden; }
body.chat-page.has-bottom-nav { padding-bottom: 0; }
.chat-app {
  --bottom: calc(70px + env(safe-area-inset-bottom));
  flex: none;
  height: calc(100dvh - var(--header-h) - var(--bottom));
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr);
  position: relative;
  min-height: 0;
}
@media (min-width: 900px) {
  .chat-app { --bottom: 0px; grid-template-columns: 290px 1fr; }
}

/* Sidebar */
.chat-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--nav-bg);
}
@media (max-width: 899px) {
  .chat-side {
    position: absolute;
    z-index: 30;
    top: 0; bottom: 0; left: 0;
    width: min(320px, 86vw);
    transform: translateX(-102%);
    transition: transform 280ms var(--ease);
    box-shadow: var(--shadow-2);
    background: var(--bg-2);
  }
  .chat-side.is-open { transform: none; }
}
.side-scrim { position: absolute; inset: 0; z-index: 25; background: var(--overlay); }
@media (min-width: 900px) { .side-scrim { display: none; } }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px 12px 18px; min-height: 60px; border-bottom: 1px solid var(--line); }
#new-chat { --btn-h: 34px; padding: 0 14px 0 12px; gap: 6px; font-size: 0.8rem; box-shadow: none; }
#new-chat:hover { box-shadow: 0 6px 14px -8px rgb(var(--teal-rgb) / 0.8); }
#new-chat .icon { width: 16px; height: 16px; }
.side-head h2 { font-family: var(--font-ui); font-size: var(--fs-md); font-weight: 600; }
.side-list { flex: 1; overflow-y: auto; padding: 14px 12px 16px; }
.side-list ul { list-style: none; display: grid; gap: 10px; }
.side-list li { position: relative; }
.chat-item {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 44px 12px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--surface-1), var(--surface-2));
  box-shadow: 0 8px 18px -16px rgb(13 60 52 / 0.5), inset 0 1px 0 rgb(255 255 255 / 0.9);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  overflow: hidden;
  transition: border-color var(--dur), transform 220ms var(--ease), box-shadow 220ms var(--ease), color var(--dur), background var(--dur);
}
/* round icon badge */
.chat-item .icon {
  flex: none;
  box-sizing: content-box;
  width: 16px; height: 16px;
  padding: 8px;
  border-radius: 12px;
  background: rgb(var(--teal-rgb) / 0.1);
  color: var(--teal);
  transition: background var(--dur), color var(--dur);
}
.chat-item span {
  flex: 1; min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: anywhere;
}
.chat-item:hover {
  border-color: rgb(var(--teal-rgb) / 0.55);
  color: var(--teal);
  transform: translateY(-2px);
  box-shadow: 0 14px 24px -16px rgb(var(--teal-rgb) / 0.55), inset 0 1px 0 rgb(255 255 255 / 0.9);
}
.chat-item:hover .icon { background: var(--grad); color: #fff; }
.chat-item:active { transform: translateY(0) scale(0.99); }
.chat-item:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.chat-item[aria-current='true'] {
  border-color: rgb(var(--teal-rgb) / 0.6);
  background: linear-gradient(180deg, rgb(var(--teal-rgb) / 0.09), rgb(var(--teal-rgb) / 0.04));
  color: var(--teal);
}
.chat-item[aria-current='true'] .icon { background: var(--grad); color: #fff; }
.side-empty { display: grid; justify-items: center; gap: 10px; padding: 32px 16px; text-align: center; color: var(--muted); font-size: var(--fs-sm); }
.side-skel { height: 40px; margin: 6px 4px; }

/* Main column */
.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}
.side-toggle { flex: none; }
@media (min-width: 900px) { .side-toggle { display: none; } .chat-top { display: none; } }
.chat-title { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; font-weight: 600; }
.chat-title img { width: 26px; height: 26px; }
.chat-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thread { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-padding-bottom: 24px; }
.thread-inner { width: 100%; max-width: 860px; margin: 0 auto; padding: 28px 16px 36px; display: grid; gap: 26px; }

/* Welcome */
.welcome {
  max-width: 820px;
  margin: 0 auto;
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 16px 16px 20px;
  text-align: center;
}
.welcome h1 { font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.5rem); max-width: 26ch; }
html[lang='hi'] .welcome h1 { font-size: clamp(1.5rem, 1.1rem + 1.5vw, 2.2rem); max-width: 30ch; line-height: 1.35; }
.welcome h1 em { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome p { color: var(--text-2); max-width: 52ch; font-size: var(--fs-sm); }
.welcome p .icon { color: var(--green); }
/* Six ready-made questions as small tiles: 3 across on a computer, 2 across on a phone */
.quick-grid { display: grid; gap: 10px; width: 100%; margin-top: 8px; grid-template-columns: 1fr 1fr; }
@media (min-width: 720px) { .quick-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; } }
.chip.quick {
  position: relative;
  justify-content: center;
  align-items: center;
  padding: 18px 22px;
  min-height: 92px;
  border-radius: 20px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, var(--surface-1), var(--surface-2));
  box-shadow: 0 10px 24px -18px rgb(13 60 52 / 0.45), inset 0 1px 0 rgb(255 255 255 / 0.9);
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: -0.005em;
  text-align: center;
  color: var(--text);
  white-space: normal;
  overflow: hidden;
  animation: fade-up 520ms var(--ease) both;
  transition: border-color var(--dur), transform 240ms var(--ease), box-shadow 240ms var(--ease), color var(--dur), background var(--dur);
}
.chip.quick:nth-child(1) { animation-delay: 60ms; }
.chip.quick:nth-child(2) { animation-delay: 120ms; }
.chip.quick:nth-child(3) { animation-delay: 180ms; }
.chip.quick:nth-child(4) { animation-delay: 240ms; }
.chip.quick:nth-child(5) { animation-delay: 300ms; }
.chip.quick:nth-child(6) { animation-delay: 360ms; }
/* a thin gradient line that grows along the bottom edge when you point at a card */
.chip.quick::after {
  content: '';
  position: absolute;
  left: 22px; right: 22px; bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--grad);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 320ms var(--ease);
}
.chip.quick:hover {
  border-color: rgb(var(--teal-rgb) / 0.55);
  background: var(--surface-1);
  color: var(--teal);
  transform: translateY(-4px);
  box-shadow: 0 18px 30px -18px rgb(var(--teal-rgb) / 0.55), inset 0 1px 0 rgb(255 255 255 / 0.9);
}
.chip.quick:hover::after { transform: scaleX(1); }
.chip.quick:active { transform: translateY(-1px) scale(0.99); }
.chip.quick:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
.chip.quick:disabled { opacity: 0.6; transform: none; }
@media (max-width: 719px) { .chip.quick { min-height: 76px; padding: 14px 16px; font-size: var(--fs-sm); } }

/* Messages */
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.me { justify-content: flex-end; }
.msg .bubble { max-width: min(640px, 88%); border-radius: 22px; padding: 12px 18px; }
.msg.me .bubble {
  background: var(--grad);
  color: var(--on-brand);
  border-bottom-right-radius: 6px;
  font-weight: 500;
  display: grid;
  gap: 4px;
  box-shadow: 0 12px 24px -16px rgb(var(--teal-rgb) / 0.8);
}
.voice-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.75; }
.msg.me .thinking i { background: var(--on-brand); }
.msg.ai .avatar { width: 32px; height: 32px; flex: none; margin-top: 2px; filter: drop-shadow(0 4px 14px rgb(var(--teal-rgb) / 0.4)); }
.msg.ai .bubble {
  flex: 1;
  max-width: 100%;
  padding: 16px 20px 12px;
  border-radius: 20px;
  border-top-left-radius: 6px;
  border: 1px solid var(--line-strong);
  background: var(--surface-1);
  box-shadow: 0 12px 26px -20px rgb(13 60 52 / 0.4);
}
.answer { display: grid; gap: 10px; color: var(--text); font-size: 1.02rem; line-height: 1.65; }
.answer ul { display: grid; gap: 8px; padding: 0; list-style: none; }
.answer li { position: relative; padding-left: 22px; }
.answer li::before {
  content: '';
  position: absolute;
  left: 4px; top: 0.62em;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--grad);
}
.answer strong { color: var(--strong); font-weight: 650; }
.answer a { color: var(--teal); word-break: break-all; }
.answer.is-typing > :last-child::after {
  content: '';
  display: inline-block;
  width: 8px; height: 1.05em;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 2px;
  background: var(--teal);
  animation: blink-cursor 0.9s steps(1) infinite;
}
.msg-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
}
.act:hover { background: var(--surface-2); color: var(--text); }
.act.is-playing { color: var(--on-brand); background: var(--grad); border-color: transparent; }
.act.is-loading-inline { color: var(--teal); }
.act[aria-pressed='true'] { color: var(--green); }
.act:disabled { opacity: 1; }
.feedback-form { display: grid; gap: 8px; margin-top: 10px; max-width: 460px; }
.feedback-form .textarea { min-height: 70px; font-size: var(--fs-sm); }
.feedback-form .row { justify-content: flex-end; }
.bubble.is-error { display: grid; gap: 10px; justify-items: start; padding: 12px 14px !important; border-radius: 14px !important; background: rgb(240 98 90 / 0.08) !important; border: 1px solid rgb(240 98 90 / 0.3); color: var(--text-2); }
.bubble.is-error .icon { color: var(--excess); }

.thinking-msg .bubble { display: flex; flex: none; align-items: center; gap: 12px; color: var(--text-2); font-size: var(--fs-sm); padding: 10px 18px; }
.avatar-orb { position: relative; width: 32px; height: 32px; flex: none; display: grid; place-items: center; }
.avatar-orb img { width: 24px; height: 24px; }
.avatar-orb .ring {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 55%, var(--blue) 72%, var(--green) 90%, transparent);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1.5px));
  animation: spin 1.2s linear infinite;
}
.loading-chat { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 40px; color: var(--muted); }

/* Composer */
.composer { padding: 12px 16px 12px; border-top: 1px solid var(--line); background: linear-gradient(180deg, transparent, rgb(var(--teal-rgb) / 0.04)); }
.composer-box, .recording {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  border-radius: 26px;
  border: 1px solid var(--line-strong);
  background: var(--surface-1);
  box-shadow: 0 14px 30px -22px rgb(13 60 52 / 0.5);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.composer-box:focus-within { border-color: var(--teal); box-shadow: 0 0 0 4px rgb(var(--teal-rgb) / 0.14); }
.composer-box, .recording, .composer-hint { max-width: 860px; }
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: 11px 10px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.4;
}
.composer textarea { overflow-y: hidden; }
.composer textarea::placeholder { color: var(--placeholder); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mic-btn { --btn-h: 44px; border-radius: 50%; color: var(--green); background: rgb(var(--green-rgb) / 0.12); border-color: rgb(var(--green-rgb) / 0.3); }
.mic-btn:hover { background: rgb(var(--green-rgb) / 0.2); }
.send-btn { --btn-h: 44px; border-radius: 50%; }
.composer.is-busy .composer-box { opacity: 0.85; }
.composer-hint { max-width: 820px; margin: 6px auto 0; text-align: center; font-size: 0.72rem; color: var(--muted); }
@media (max-width: 520px) { .composer-hint { display: none; } }

/* Recording state */
.recording { align-items: center; border-color: rgb(240 98 90 / 0.5); box-shadow: 0 0 0 4px rgb(240 98 90 / 0.1); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--excess); box-shadow: 0 0 12px var(--excess); animation: pulse-glow 1s ease-in-out infinite; flex: none; }
.rec-time { font-size: var(--fs-sm); color: var(--text); min-width: 3.2ch; }
.rec-bars { flex: 1; height: 36px; display: flex; align-items: center; gap: 3px; overflow: hidden; }
.rec-bars i { flex: 1; min-width: 2px; max-width: 6px; height: 12%; border-radius: 3px; background: var(--grad-v); transition: height 80ms linear; }
.rec-send { --btn-h: 44px; }

@keyframes blink-cursor { 50% { opacity: 0; } }

/* Spoken reply chip (questions asked by voice) */
.voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 7px 14px;
  border-radius: var(--r-pill);
  border: 1px solid rgb(var(--teal-rgb) / 0.45);
  background: rgb(var(--teal-rgb) / 0.08);
  color: var(--teal);
  font-size: var(--fs-xs);
  font-weight: 700;
}
.voice-chip.is-playing { border-color: transparent; background: var(--grad); color: var(--on-brand); }
.voice-chip:hover { filter: brightness(1.05); }
