:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --surface: #ffffff;
  --surface-muted: #f7f7f5;
  --text: #17201b;
  --muted: #67716c;
  --line: #d8ddd7;
  --accent: #1f7a58;
  --accent-strong: #176343;
  --user: #1f7a58;
  --assistant: #f1f3f1;
  --shadow: 0 24px 70px rgba(30, 42, 36, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 22% 10%, rgba(31, 122, 88, 0.13), transparent 28rem),
    linear-gradient(135deg, #f4f2ed 0%, #e9eeea 48%, #eef0f5 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

.chat-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.chat-window {
  width: min(920px, 100%);
  height: min(820px, calc(100vh - 56px));
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

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

.brand-mark,
.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, #1f7a58, #28a071);
  font-size: 13px;
  font-weight: 700;
}

.brand-mark svg,
.icon-button svg,
.send-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button,
.send-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, opacity 0.18s ease;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--muted);
  background: var(--surface-muted);
}

.icon-button:hover,
.send-button:hover {
  transform: translateY(-1px);
}

.settings-panel {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfbfa;
}

.settings-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.settings-row input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.settings-row input:focus,
.composer textarea:focus {
  border-color: rgba(31, 122, 88, 0.65);
  box-shadow: 0 0 0 4px rgba(31, 122, 88, 0.12);
}

.settings-row button {
  height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

.messages {
  overflow-y: auto;
  padding: 26px 20px 18px;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  max-width: 780px;
  margin: 0 auto 18px;
}

.message.user {
  grid-template-columns: minmax(0, 1fr) 40px;
}

.message.user .avatar {
  grid-column: 2;
  grid-row: 1;
  background: #202b25;
}

.message.user .bubble {
  justify-self: end;
  color: #fff;
  background: var(--user);
}

.message.assistant .bubble {
  background: var(--assistant);
}

.bubble {
  width: fit-content;
  max-width: min(650px, 100%);
  padding: 13px 15px;
  border-radius: 18px;
  line-height: 1.55;
  box-shadow: 0 1px 0 rgba(23, 32, 27, 0.04);
  overflow-wrap: anywhere;
}

.bubble p {
  margin: 0;
}

.bubble h3,
.bubble h4,
.bubble h5 {
  margin: 0 0 9px;
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: 0;
}

.bubble h4,
.bubble h5 {
  margin-top: 14px;
}

.bubble p + p,
.bubble p + ul,
.bubble p + ol,
.bubble ul + p,
.bubble ol + p,
.bubble pre + p {
  margin-top: 10px;
}

.bubble ul,
.bubble ol {
  margin: 8px 0 0;
  padding-left: 22px;
}

.bubble li + li {
  margin-top: 5px;
}

.bubble strong {
  font-weight: 700;
}

.bubble code {
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(23, 32, 27, 0.08);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.bubble pre {
  max-width: 100%;
  overflow-x: auto;
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 12px;
  color: #f4f7f5;
  background: #18221d;
}

.bubble pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  white-space: pre;
}

.typing {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 70px;
  margin: 0 0 10px 72px;
  padding: 13px 15px;
  border-radius: 18px;
  background: var(--assistant);
}

.typing[hidden] {
  display: none;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #9aa39e;
  animation: pulse 1.1s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.14s;
}

.typing span:nth-child(3) {
  animation-delay: 0.28s;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 12px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
}

.composer textarea {
  width: 100%;
  height: 48px;
  max-height: 180px;
  min-height: 48px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 15px;
  color: var(--text);
  background: #fff;
  outline: none;
}

.send-button {
  width: 48px;
  height: 48px;
  align-self: end;
  border-radius: 16px;
  color: #fff;
  background: var(--accent);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

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

@keyframes pulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

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

  .chat-window {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    border-radius: 0;
    border: 0;
  }

  .chat-header {
    padding: 14px;
  }

  .messages {
    padding: 18px 14px 12px;
  }

  .message,
  .message.user {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
  }

  .message.user {
    grid-template-columns: minmax(0, 1fr) 32px;
  }

  .brand-mark,
  .avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    font-size: 11px;
  }

  .brand p {
    max-width: 220px;
  }

  .composer {
    grid-template-columns: 1fr 46px;
    padding: 12px 14px 14px;
  }

  .settings-row {
    grid-template-columns: 1fr;
  }
}
