@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --bg-0: #f6fbfa;
  --bg-1: #dfefeb;
  --ink: #173031;
  --muted: #5f7678;
  --stroke: #d3e3df;
  --header-a: #0d8a7a;
  --header-b: #0f6074;
  --bot: #ffffff;
  --user: #d8f8df;
  --danger: #b23b3b;
  --action: #0c7f72;
  --action-ink: #ffffff;
  --card-shadow: 0 16px 40px rgba(8, 39, 44, 0.2);
  --radius: 18px;
  --vh: 1vh;
  --kb: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Manrope', 'Segoe UI', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at -10% -20%, rgba(34, 173, 155, 0.22), transparent 60%),
    radial-gradient(900px 540px at 110% -30%, rgba(23, 129, 172, 0.2), transparent 65%),
    linear-gradient(160deg, var(--bg-0) 0%, var(--bg-1) 100%);
  overscroll-behavior-y: contain;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

.chat-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

.ambient {
  position: absolute;
  border-radius: 999px;
  filter: blur(34px);
  opacity: 0.4;
  pointer-events: none;
}

.ambient-a {
  width: 360px;
  height: 360px;
  top: -120px;
  left: -140px;
  background: rgba(19, 145, 117, 0.42);
}

.ambient-b {
  width: 320px;
  height: 320px;
  bottom: -120px;
  right: -90px;
  background: rgba(13, 122, 172, 0.36);
}

.app {
  position: relative;
  width: min(100%, 980px);
  height: calc((var(--vh) * 100) - 24px);
  max-height: 960px;
  background:
    radial-gradient(500px 220px at 15% -30%, rgba(30, 156, 130, 0.08), transparent 70%),
    linear-gradient(180deg, #f9fcfc 0%, #f4f8f7 100%);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 24px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: app-in 280ms ease-out;
}

.chat-header {
  background: linear-gradient(110deg, var(--header-a), var(--header-b));
  color: #e7fbf8;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 18px rgba(10, 70, 74, 0.26);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(6, 52, 58, 0.36);
  font-family: 'Space Grotesk', 'Manrope', sans-serif;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.h-meta {
  display: flex;
  flex-direction: column;
}

.h-name {
  font-family: 'Space Grotesk', 'Manrope', sans-serif;
  font-size: 1.02rem;
  line-height: 1.1;
  font-weight: 600;
}

.h-status {
  margin-top: 2px;
  font-size: 0.82rem;
  opacity: 0.92;
  display: flex;
  align-items: center;
  gap: 6px;
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64efb0;
  box-shadow: 0 0 0 6px rgba(100, 239, 176, 0.2);
}

.chat-body {
  flex: 1;
  overflow: auto;
  padding: 16px 16px 8px;
  padding-bottom: calc(90px + env(safe-area-inset-bottom) + var(--kb));
  scroll-behavior: smooth;
}

.date-pill {
  width: fit-content;
  margin: 0 auto 12px;
  font-size: 0.74rem;
  color: #5f7477;
  border: 1px solid #d7e6e2;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  padding: 6px 10px;
}

.msgs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: min(82%, 760px);
  border-radius: var(--radius);
  padding: 10px 12px;
  word-break: break-word;
  box-shadow: 0 4px 14px rgba(14, 36, 38, 0.08);
  border: 1px solid transparent;
  animation: msg-in 180ms ease-out both;
}

.msg.bot {
  align-self: flex-start;
  background: var(--bot);
  border-color: #dce9e6;
}

.msg.user {
  align-self: flex-end;
  background: var(--user);
  border-color: #bbecce;
}

.msg.system {
  background: #fff4f4;
  border: 1px dashed #e7bcbc;
}

.msg-text {
  white-space: pre-wrap;
  line-height: 1.46;
  font-size: 0.97rem;
}

.msg-text a {
  color: #0d6ea8;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

.ticks {
  color: #67a6d6;
}

.ticks.read {
  color: #1b9de0;
}

.typing {
  width: fit-content;
}

.dots {
  display: inline-flex;
  width: 34px;
}

.dots span {
  width: 6px;
  height: 6px;
  margin-right: 4px;
  border-radius: 50%;
  background: #a8b8b9;
  animation: dot-bounce 1.15s infinite ease-in-out;
}

.dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.dots span:nth-child(3) {
  animation-delay: 0.4s;
  margin-right: 0;
}

.chat-input {
  display: grid;
  grid-template-columns: 42px 42px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border-top: 1px solid #deebe8;
  background: rgba(249, 252, 251, 0.94);
  backdrop-filter: blur(6px);
  transform: translateY(calc(-1 * var(--kb)));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

.chat-input.busy {
  opacity: 0.96;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 1px solid #d4e3e0;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  font-size: 1.03rem;
  transition: transform 120ms ease, background-color 120ms ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  background: #f3fbf8;
}

#msg {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  border: 1px solid #d3e1df;
  border-radius: 14px;
  padding: 11px 13px;
  font-family: inherit;
  font-size: 0.98rem;
  line-height: 1.35;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

#msg:disabled {
  background: #edf4f2;
  color: #4f6466;
}

.send {
  height: 44px;
  border: 0;
  border-radius: 14px;
  padding: 0 16px;
  background: linear-gradient(120deg, #0d8b7b, #0f6f84);
  color: var(--action-ink);
  font-family: 'Space Grotesk', 'Manrope', sans-serif;
  font-size: 0.96rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  min-width: 112px;
}

.send:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}

.send-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  display: none;
  animation: spin 0.9s linear infinite;
}

.chat-input.busy .send-spinner {
  display: inline-block;
}

.retry-btn {
  margin-top: 10px;
  border: 1px solid #e1a6a6;
  color: var(--danger);
  border-radius: 10px;
  background: #fff;
  font-weight: 600;
  padding: 7px 10px;
  cursor: pointer;
}

.retry-btn:hover {
  background: #fff7f7;
}

.chat-input.locked {
  opacity: 0.88;
}

.chat-input.locked #msg,
.chat-input.locked .icon-btn,
.chat-input.locked .send {
  cursor: not-allowed;
}

.toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  bottom: calc(74px + env(safe-area-inset-bottom));
  background: rgba(19, 46, 48, 0.92);
  color: #eef9f8;
  padding: 9px 13px;
  border-radius: 999px;
  font-size: 0.82rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.terms-open {
  overflow: hidden;
}

.terms-modal {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
}

.terms-modal[hidden] {
  display: none !important;
}

.terms-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 26, 30, 0.58);
  backdrop-filter: blur(4px);
}

.terms-modal__dialog {
  position: relative;
  z-index: 1;
  width: min(100%, 760px);
  max-height: min(88vh, 860px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: #ffffff;
  border: 1px solid #d8e5e2;
  border-radius: 24px;
  box-shadow: 0 30px 80px rgba(7, 26, 30, 0.32);
  overflow: hidden;
}

.terms-modal__header {
  padding: 18px 20px 16px;
  background: linear-gradient(120deg, #0c7f72, #0f6074);
  color: #effcfa;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.terms-modal__eyebrow {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.88;
}

.terms-modal__title {
  margin: 0;
  font-family: 'Space Grotesk', 'Manrope', sans-serif;
  font-size: clamp(1.05rem, 2vw, 1.4rem);
  line-height: 1.2;
}

.terms-modal__link {
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.38);
}

.terms-modal__notice {
  padding: 11px 20px;
  border-bottom: 1px solid #e6eeeb;
  background: #f2f9f7;
  color: #476568;
  font-size: 0.85rem;
  font-weight: 600;
}

.terms-modal__body {
  min-height: 320px;
  max-height: min(56vh, 560px);
  overflow-y: auto;
  padding: 18px 20px;
  background: #ffffff;
  outline: none;
}

.terms-modal__content {
  white-space: pre-wrap;
  color: #183234;
  font-size: 0.94rem;
  line-height: 1.68;
}

.terms-modal__actions {
  padding: 16px 20px 20px;
  border-top: 1px solid #e6eeeb;
  background: #fbfdfd;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.terms-btn {
  min-height: 46px;
  border-radius: 14px;
  padding: 0 18px;
  border: 1px solid transparent;
  font-family: 'Space Grotesk', 'Manrope', sans-serif;
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
}

.terms-btn--ghost {
  border-color: #d3e3df;
  background: #ffffff;
  color: #315255;
}

.terms-btn--primary {
  background: linear-gradient(120deg, #0d8b7b, #0f6f84);
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(12, 96, 116, 0.2);
}

.terms-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

#msg:focus-visible,
.icon-btn:focus-visible,
.send:focus-visible,
.retry-btn:focus-visible,
.terms-btn:focus-visible,
.terms-modal__body:focus-visible,
.terms-modal__link:focus-visible {
  outline: 2px solid #1f7dd2;
  outline-offset: 2px;
}

@keyframes app-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

@keyframes dot-bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 980px) {
  .chat-shell {
    padding: 0;
  }

  .app {
    width: 100%;
    height: calc(var(--vh) * 100);
    border-radius: 0;
    border: 0;
  }
}

@media (max-width: 680px) {
  .msg {
    max-width: 92%;
  }

  .terms-modal {
    padding: 10px;
  }

  .terms-modal__dialog {
    width: 100%;
    max-height: calc(100vh - 20px);
    border-radius: 18px;
  }

  .terms-modal__header,
  .terms-modal__actions {
    padding-left: 16px;
    padding-right: 16px;
  }

  .terms-modal__body {
    padding: 16px;
    max-height: min(62vh, 520px);
  }

  .chat-input {
    grid-template-columns: 38px 38px minmax(0, 1fr) auto;
    gap: 7px;
    padding: 8px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  #msg {
    min-height: 40px;
    border-radius: 12px;
    padding: 9px 12px;
  }

  .send {
    height: 40px;
    min-width: 90px;
    border-radius: 12px;
  }

  .terms-modal__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .terms-modal__link {
    white-space: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
