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

:root {
  --red-600: #e33f37;
  --red-700: #cb332d;
  --red-100: #fff0ef;
  --ink: #171717;
  --ink-soft: #363636;
  --gray-600: #6f6f6f;
  --gray-400: #cfcfcf;
  --gray-300: #dddddd;
  --gray-200: #ececec;
  --gray-100: #f5f5f5;
  --paper: #fcfcfc;
  --white: #ffffff;
  --line: rgba(23, 23, 23, 0.1);
  --shadow: 0 26px 72px rgba(0, 0, 0, 0.1);
  --panel-radius: 34px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  font-family: "Manrope", "Avenir Next", sans-serif;
  background:
    radial-gradient(circle at 100% 0%, rgba(227, 63, 55, 0.1), transparent 24%),
    linear-gradient(180deg, #ffffff 0%, #f4f4f4 100%);
}

.page-shell {
  --shell-pad: clamp(12px, 1.8vw, 20px);
  position: relative;
  min-height: 100svh;
  min-height: 100dvh;
  padding: var(--shell-pad);
  overflow: hidden;
  isolation: isolate;
}

.ambient {
  position: absolute;
  pointer-events: none;
  opacity: 1;
}

.ambient-one {
  width: 40rem;
  height: 40rem;
  left: -12rem;
  bottom: -18rem;
  border-radius: 32% 68% 0 0 / 38% 62% 0 0;
  background: linear-gradient(135deg, rgba(227, 63, 55, 0.96), rgba(227, 63, 55, 0.88));
  transform: rotate(-7deg);
}

.ambient-two {
  width: 22rem;
  height: 22rem;
  left: 13rem;
  top: 7rem;
  border-radius: 43% 57% 55% 45%;
  background: rgba(227, 63, 55, 0.1);
  filter: blur(4px);
}

.ambient-three {
  width: 28rem;
  height: 28rem;
  right: -12rem;
  top: -14rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.025);
  filter: blur(8px);
}

.chat-app {
  position: relative;
  z-index: 1;
  width: min(100%, 1360px);
  height: calc(100svh - (var(--shell-pad) * 2));
  height: calc(100dvh - (var(--shell-pad) * 2));
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(23, 23, 23, 0.08);
  border-radius: var(--panel-radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  animation: panel-rise 340ms ease both;
}

.chat-topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: clamp(18px, 2vw, 24px) clamp(18px, 2.5vw, 30px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
}

.chat-topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--red-600), transparent 24%);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.eyebrow,
.message-meta,
.typing-label,
.sources-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow {
  color: var(--gray-600);
}

.wordmark {
  margin: 0;
  font-size: clamp(2rem, 2.8vw, 3rem);
  line-height: 0.94;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.wordmark-core {
  color: #6a6a6a;
}

.wordmark-accent {
  color: var(--red-600);
}

.brand-submark {
  margin: 0;
  max-width: 42rem;
  color: var(--ink-soft);
  font-size: 0.96rem;
  line-height: 1.45;
}

.header-actions,
.source-meta,
.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.ghost-button,
#send-button {
  border-radius: 999px;
  font: inherit;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.58rem 0.94rem;
  border: 1px solid var(--gray-300);
  background: var(--white);
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 700;
  transition:
    background 180ms ease,
    color 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

.status-pill.ready {
  background: var(--white);
  color: var(--ink);
}

.status-pill.thinking {
  background: var(--red-100);
  border-color: rgba(227, 63, 55, 0.26);
  color: var(--red-700);
  animation: soft-pulse 1.8s ease infinite;
}

.status-pill.warning {
  background: #fff4e6;
  border-color: rgba(207, 131, 46, 0.24);
  color: #9a5f18;
}

.status-pill.error {
  background: #ffeaea;
  border-color: rgba(203, 51, 45, 0.24);
  color: var(--red-700);
}

.ghost-button {
  border: 1px solid var(--gray-300);
  background: var(--white);
  color: var(--ink);
  padding: 0.6rem 0.98rem;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.ghost-button:hover,
.ghost-button:focus-visible {
  background: #fafafa;
  border-color: var(--ink);
  transform: translateY(-1px);
  outline: none;
}

.chat-history {
  min-height: 0;
  overflow: auto;
  padding: clamp(18px, 2vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 15% 88%, rgba(227, 63, 55, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(248, 248, 248, 0.9));
}

.chat-history::-webkit-scrollbar {
  width: 10px;
}

.chat-history::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  background-clip: padding-box;
}

.chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.message-card,
.typing-card {
  max-width: min(76%, 48rem);
  padding: 1rem 1.06rem;
  border-radius: 26px;
  border: 1px solid var(--gray-200);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.05);
}

.message-card.assistant,
.typing-card {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.98);
}

.message-card.user {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(255, 240, 239, 0.95), rgba(255, 247, 246, 0.95));
  border-color: rgba(227, 63, 55, 0.2);
  color: var(--ink);
}

.intro-card {
  position: relative;
  overflow: hidden;
  border-color: rgba(227, 63, 55, 0.22);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(249, 249, 249, 0.98));
}

.intro-card::before {
  content: "";
  position: absolute;
  width: 14rem;
  height: 14rem;
  right: -5rem;
  bottom: -6rem;
  border-radius: 38% 62% 0 0 / 42% 58% 0 0;
  background: rgba(227, 63, 55, 0.12);
  transform: rotate(-16deg);
}

.intro-card .message-meta,
.sources-title {
  color: var(--red-700);
}

.message-enter {
  animation: message-rise 240ms ease both;
}

.message-meta {
  margin-bottom: 0.45rem;
  color: var(--gray-600);
}

.message-body {
  position: relative;
  z-index: 1;
  color: var(--ink);
  font-size: 0.97rem;
  line-height: 1.62;
}

.message-body p {
  margin: 0.3rem 0 0.75rem;
}

.message-body p:last-child,
.message-body ul:last-child,
.message-body ol:last-child {
  margin-bottom: 0;
}

.message-body ul,
.message-body ol {
  margin: 0.2rem 0 0.75rem;
  padding-left: 1.15rem;
}

.message-body li + li {
  margin-top: 0.36rem;
}

.message-body a,
.message-card.user .message-body a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
}

.message-body code {
  padding: 0.1rem 0.32rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.06);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
}

.best-step {
  padding-top: 0.54rem;
  border-top: 1px solid rgba(23, 23, 23, 0.1);
  color: var(--ink);
}

.sources-block {
  display: grid;
  gap: 8px;
  margin-top: 1rem;
}

.source-card {
  display: grid;
  gap: 0.35rem;
  padding: 0.9rem 0.95rem;
  border-radius: 18px;
  background: #fafafa;
  border: 1px solid var(--gray-200);
  color: inherit;
  text-decoration: none;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.source-card:hover,
.source-card:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(227, 63, 55, 0.26);
  background: var(--white);
  outline: none;
}

.source-card strong {
  font-size: 0.95rem;
  line-height: 1.28;
}

.source-card p {
  margin: 0;
  color: var(--gray-600);
  font-size: 0.88rem;
  line-height: 1.45;
}

.source-meta {
  gap: 12px;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.54rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.source-badge.hcs {
  background: var(--red-100);
  color: var(--red-700);
}

.source-badge.tpgateway {
  background: #f1f1f1;
  color: var(--ink);
}

.source-url {
  color: var(--gray-600);
  font-size: 0.71rem;
}

.typing-card {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
}

.typing-label {
  color: var(--red-700);
}

.typing-dots {
  display: inline-flex;
  gap: 0.35rem;
}

.typing-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--red-600);
  animation: bounce 1s ease infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.12s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.24s;
}

.chat-form {
  display: grid;
  gap: 10px;
  padding:
    clamp(14px, 2vw, 18px)
    clamp(16px, 2.5vw, 30px)
    calc(clamp(14px, 2vw, 18px) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
}

.composer-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

#message-input {
  width: 100%;
  min-height: 58px;
  max-height: 136px;
  resize: none;
  padding: 1rem 1.05rem;
  border: 1px solid var(--gray-300);
  border-radius: 24px;
  background: var(--white);
  color: var(--ink);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
  font: inherit;
  line-height: 1.45;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

#message-input::placeholder {
  color: var(--gray-600);
}

#message-input:focus {
  outline: none;
  border-color: rgba(227, 63, 55, 0.42);
  box-shadow: 0 0 0 4px rgba(227, 63, 55, 0.1);
}

#send-button {
  min-width: 132px;
  height: 58px;
  border: 0;
  background: linear-gradient(135deg, var(--red-600), var(--red-700));
  color: var(--white);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 16px 32px rgba(227, 63, 55, 0.22);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    opacity 160ms ease;
}

#send-button:hover,
#send-button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 18px 36px rgba(227, 63, 55, 0.28);
  outline: none;
}

#send-button:disabled {
  opacity: 0.78;
  cursor: wait;
}

.composer-hint {
  margin: 0;
  color: var(--gray-600);
  font-size: 0.78rem;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@keyframes panel-rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes message-rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes soft-pulse {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-1px);
  }
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@media (max-width: 980px) {
  .chat-topbar {
    align-items: flex-start;
  }

  .header-actions {
    justify-content: flex-start;
  }

  .message-card,
  .typing-card {
    max-width: 88%;
  }
}

@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  .page-shell {
    --shell-pad: 0px;
    padding: 0;
  }

  .ambient-one {
    width: 28rem;
    height: 28rem;
    left: -10rem;
    bottom: -14rem;
  }

  .ambient-two {
    width: 16rem;
    height: 16rem;
    left: 8rem;
    top: 6rem;
  }

  .ambient-three {
    width: 18rem;
    height: 18rem;
    right: -8rem;
    top: -10rem;
  }

  .chat-app {
    height: 100svh;
    height: 100dvh;
    border-radius: 0;
    border: 0;
  }

  .chat-topbar {
    padding:
      max(16px, env(safe-area-inset-top))
      16px
      14px;
    flex-direction: column;
    gap: 14px;
  }

  .wordmark {
    font-size: clamp(1.9rem, 8vw, 2.6rem);
  }

  .brand-submark {
    font-size: 0.88rem;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-history {
    padding: 14px 12px;
    gap: 10px;
  }

  .message-card,
  .typing-card {
    max-width: 100%;
    padding: 0.95rem 0.9rem;
    border-radius: 22px;
  }

  .source-meta,
  .composer-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .composer-shell {
    grid-template-columns: 1fr;
  }

  #message-input {
    min-height: 54px;
    border-radius: 22px;
  }

  #send-button {
    width: 100%;
    min-width: 0;
    height: 52px;
  }
}

@media (max-height: 760px) {
  .chat-topbar {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .brand-submark {
    font-size: 0.88rem;
  }

  .chat-history {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  #message-input,
  #send-button {
    min-height: 52px;
    height: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
