* {
  box-sizing: border-box;
}

:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #20232a;
  --muted: #697180;
  --line: #dfe3ea;
  --accent: #2f6fed;
  --accent-strong: #1f54bf;
  --soft: #eef3ff;
  --danger: #b3261e;
  --shadow: 0 18px 60px rgba(29, 35, 49, 0.11);
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  position: relative;
  isolation: isolate;
}

body.access-open {
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 12%, rgba(47, 111, 237, 0.10), transparent 24rem),
    radial-gradient(circle at 82% 8%, rgba(26, 152, 117, 0.08), transparent 26rem),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 54%, #eef1f6 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

button:disabled,
textarea:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  width: min(100%, 1040px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 20px 16px;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-areas:
    "topbar"
    "main"
    "footer";
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 20px;
}

.app-shell > * {
  min-width: 0;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

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

.brand > div {
  min-width: 0;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.76);
  font-weight: 760;
  letter-spacing: 0;
}

.brand-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 680;
  overflow-wrap: anywhere;
}

.brand-subtitle {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.topbar-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-chat-button,
.pro-button {
  flex: 0 0 auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  color: #344054;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 22px rgba(29, 35, 49, 0.06);
  font-size: 13px;
  font-weight: 680;
  white-space: nowrap;
  text-decoration: none;
}

.new-chat-button:hover:not(:disabled),
.pro-button:hover {
  border-color: rgba(47, 111, 237, 0.28);
  color: var(--accent);
  background: #ffffff;
}

.new-chat-button:disabled {
  box-shadow: none;
}

.pro-button {
  border-color: rgba(119, 91, 224, 0.24);
  color: #6941c6;
  background: rgba(255, 255, 255, 0.86);
}

.pro-symbol {
  color: #7f56d9;
  font-size: 15px;
  line-height: 1;
}

.hero {
  grid-area: main;
  align-self: center;
  display: grid;
  place-items: center;
  min-height: 0;
  transform: translateY(-138px);
  text-align: center;
  transition: transform 180ms ease;
}

.hero h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.12;
  letter-spacing: 0;
  font-weight: 720;
}

.chat-active .hero {
  display: none;
  transform: none;
}

.chat-active .hero h1 {
  display: none;
}

.messages {
  grid-area: main;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app-shell:not(.chat-active) .messages {
  display: none;
}

.chat-active .messages {
  grid-area: messages;
}

.chat-active {
  grid-template-areas:
    "topbar"
    "messages"
    "composer"
    "footer";
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.message {
  display: flex;
}

.message--user {
  justify-content: flex-end;
}

.message--assistant {
  justify-content: flex-start;
}

.message--loading .message-bubble {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.78);
}

.message-bubble {
  max-width: min(760px, 88%);
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 22px rgba(29, 35, 49, 0.06);
}

.message--user .message-bubble {
  color: #ffffff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.48;
}

.thinking-text {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 86px;
  white-space: normal;
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transform: translateY(1px);
}

.thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.34;
  animation: thinking-dot 1.15s infinite ease-in-out;
}

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

.thinking-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes thinking-dot {
  0%,
  80%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }

  40% {
    opacity: 0.9;
    transform: translateY(-3px);
  }
}

.message-text--markdown {
  white-space: normal;
}

.message-text--markdown > :first-child {
  margin-top: 0;
}

.message-text--markdown > :last-child {
  margin-bottom: 0;
}

.message-text--markdown p {
  margin: 0 0 10px;
}

.message-text--markdown h1,
.message-text--markdown h2,
.message-text--markdown h3,
.message-text--markdown h4 {
  margin: 14px 0 8px;
  font-size: 1em;
  line-height: 1.32;
}

.message-text--markdown h1,
.message-text--markdown h2 {
  font-size: 1.08em;
}

.message-text--markdown ul,
.message-text--markdown ol {
  margin: 8px 0 10px;
  padding-left: 1.35em;
}

.message-text--markdown li {
  margin: 4px 0;
}

.message-text--markdown blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid rgba(47, 111, 237, 0.35);
  color: var(--muted);
  background: rgba(47, 111, 237, 0.06);
  border-radius: 6px;
}

.message-text--markdown code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef1f6;
  color: #1d2738;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.message-text--markdown pre {
  margin: 10px 0;
  overflow-x: auto;
  border-radius: 8px;
  background: #1f2633;
}

.message-text--markdown pre code {
  display: block;
  padding: 12px;
  color: #f5f7fb;
  background: transparent;
  white-space: pre;
}

.message-text--markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-text--markdown hr {
  height: 1px;
  margin: 12px 0;
  border: 0;
  background: var(--line);
}

.markdown-table-wrap {
  max-width: 100%;
  margin: 10px 0;
  overflow-x: auto;
}

.message-text--markdown table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.94em;
}

.message-text--markdown th,
.message-text--markdown td {
  padding: 7px 9px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.message-text--markdown th {
  background: #f4f6fa;
  font-weight: 700;
}

.message-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.message-images img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.42);
}

.access-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 31, 43, 0.24);
  backdrop-filter: blur(8px);
}

.access-card {
  width: min(100%, 440px);
  position: relative;
  border: 1px solid rgba(223, 227, 234, 0.92);
  border-radius: 12px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 70px rgba(29, 35, 49, 0.18);
}

.access-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  color: #667085;
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.access-close:hover:not(:disabled) {
  background: #f0f2f6;
  color: var(--text);
}

.access-kicker {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.access-card h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.access-description {
  margin: 10px 0 18px;
  color: var(--muted);
  line-height: 1.48;
}

.access-question {
  margin-bottom: 12px;
  font-weight: 700;
}

.captcha-form {
  display: flex;
  gap: 8px;
}

.captcha-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
}

.captcha-form button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #ffffff;
  background: var(--accent);
}

.captcha-form button:hover {
  background: var(--accent-strong);
}

.access-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.form-error {
  margin-top: 10px;
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.confirm-card {
  width: min(100%, 420px);
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.confirm-button {
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 680;
}

.confirm-button--secondary {
  border: 1px solid var(--line);
  color: #475467;
  background: #ffffff;
}

.confirm-button--secondary:hover:not(:disabled) {
  background: #f6f7fa;
}

.confirm-button--primary {
  border: 0;
  color: #ffffff;
  background: var(--accent);
}

.confirm-button--primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.composer-zone {
  grid-area: main;
  align-self: center;
  width: min(100%, 760px);
  min-width: 0;
  margin: 116px auto 0;
}

.chat-active .composer-zone {
  grid-area: composer;
  align-self: auto;
  margin-top: 0;
}

.composer {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.composer--locked {
  background: rgba(255, 255, 255, 0.66);
}

.composer-row {
  min-height: 70px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 10px;
  align-items: end;
  padding: 10px 12px;
}

.icon-button,
.send-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  font-size: 25px;
  line-height: 1;
}

.icon-button {
  color: var(--text);
  background: transparent;
}

.icon-button:hover:not(:disabled) {
  background: #f0f2f6;
}

.send-button {
  color: #ffffff;
  background: #aeb4c1;
  font-weight: 700;
}

.send-button:hover:not(:disabled) {
  background: var(--accent);
}

#user-input {
  width: 100%;
  min-height: 44px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: none;
  padding: 11px 0 9px;
  color: var(--text);
  background: transparent;
  font-size: 16px;
  line-height: 1.45;
}

#user-input::placeholder {
  color: #87909f;
}

.attachment-preview {
  display: flex;
  gap: 8px;
  padding: 12px 14px 0;
  overflow-x: auto;
}

.attachment-item {
  position: relative;
  flex: 0 0 74px;
  width: 74px;
  height: 74px;
}

.attachment-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.attachment-item button {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: #ffffff;
  line-height: 1;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.quick-actions button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 0 14px;
  color: #4c5563;
  background: rgba(255, 255, 255, 0.78);
  white-space: nowrap;
}

.quick-actions button[data-quick="extra"] {
  display: none;
}

.quick-actions--expanded button[data-quick="extra"] {
  display: inline-flex;
}

.quick-icon {
  width: 17px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 17px;
  color: #5d6673;
  font-size: 16px;
  line-height: 1;
}

.quick-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.quick-actions button:hover {
  border-color: #c8d4ee;
  color: var(--accent-strong);
  background: var(--soft);
}

.quick-actions button:hover .quick-icon {
  color: var(--accent-strong);
}

.site-footer {
  grid-area: footer;
  width: 100%;
  margin: -6px 0 0;
  padding-top: 0;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  color: #8d96a5;
  font-size: 12px;
  line-height: 1.3;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
  font-size: inherit;
  font-weight: inherit;
}

.site-footer a:hover {
  text-decoration: underline;
}

.pro-page {
  grid-template-rows: auto minmax(0, 1fr);
}

.pro-hero {
  grid-area: main;
  align-self: center;
  width: min(100%, 920px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 28px;
  align-items: center;
}

.pro-hero-copy h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.03;
  letter-spacing: 0;
}

.pro-hero-copy p {
  max-width: 620px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.52;
}

.pro-cta {
  min-height: 46px;
  margin-top: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0 20px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 720;
  text-decoration: none;
  box-shadow: 0 12px 28px rgba(47, 111, 237, 0.22);
}

.pro-cta:hover {
  background: var(--accent-strong);
}

.pro-panel {
  border: 1px solid rgba(223, 227, 234, 0.92);
  border-radius: 12px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.pro-feature {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.pro-feature:last-child {
  border-bottom: 0;
}

.pro-feature > span {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #6941c6;
  background: rgba(127, 86, 217, 0.1);
  font-weight: 760;
}

.pro-feature strong {
  display: block;
  color: var(--text);
}

.pro-feature p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

.is-busy .send-button {
  background: #8e97a6;
}

@media (max-width: 720px) {
  .app-shell {
    padding: 18px 12px 10px;
    gap: 10px;
  }

  .topbar {
    padding: 0 2px;
    gap: 8px;
  }

  .brand {
    gap: 8px;
  }

  .topbar-actions {
    gap: 6px;
  }

  .new-chat-button {
    width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    border-radius: 50%;
    font-size: 21px;
  }

  .new-chat-label {
    display: none;
  }

  .pro-button {
    min-height: 40px;
    padding: 0 12px;
    gap: 6px;
  }

  .hero {
    transform: translateY(-116px);
  }

  .message-bubble {
    max-width: 94%;
  }

  .captcha-form {
    width: 100%;
  }

  .captcha-form input {
    flex: 1;
    min-width: 0;
  }

  .access-card {
    padding: 22px 18px 18px;
  }

  .composer {
    border-radius: 24px;
  }

  .composer-row {
    grid-template-columns: 42px 1fr 42px;
    min-height: 62px;
    gap: 6px;
    padding: 9px;
  }

  .icon-button,
  .send-button {
    width: 40px;
    height: 40px;
  }

  .quick-actions {
    justify-content: center;
    overflow-x: visible;
    flex-wrap: nowrap;
    gap: 4px;
    padding-bottom: 0;
  }

  .quick-actions button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 32px;
    justify-content: center;
    gap: 3px;
    white-space: nowrap;
    text-align: center;
    padding: 4px 3px;
    border-radius: 16px;
    font-size: 10.5px;
  }

  .quick-actions button > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .quick-actions--expanded {
    flex-wrap: wrap;
  }

  .quick-actions--expanded button {
    flex: 1 1 calc(50% - 4px);
    padding-inline: 8px;
    font-size: 11px;
  }

  .quick-icon {
    width: 14px;
    height: 14px;
    flex-basis: 14px;
    font-size: 13px;
  }

  .site-footer {
    flex-wrap: wrap;
    justify-content: flex-end;
    text-align: right;
    line-height: 1.2;
    margin-top: -6px;
    font-size: 11px;
  }

  .pro-hero {
    align-self: start;
    grid-template-columns: 1fr;
    gap: 18px;
    padding-top: 26px;
  }

  .pro-hero-copy h1 {
    font-size: 36px;
  }

  .pro-hero-copy p {
    font-size: 16px;
  }

  .pro-panel {
    padding: 14px;
  }
}
