:root {
  color-scheme: light;
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17251d;
  background: #f5f7f2;
  --green: #215c40;
  --ink-muted: #536258;
  --line: #dce2d8;
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 3px solid #358366; outline-offset: 3px; }

.site-header {
  border-bottom: 1px solid var(--line);
  background: #fafbf8;
}
.site-header-inner {
  width: min(1100px, 100% - 40px);
  min-height: 66px;
  margin-inline: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.brand {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: inherit;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.05em;
  text-decoration: none;
}
.brand span { font: 37px/1 Georgia, serif; color: var(--green); }
nav { display: flex; align-items: center; gap: clamp(10px, 3vw, 24px); }
nav a, nav button, .text-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--green);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}
nav a:hover, nav button:hover, .text-button { text-decoration: underline; text-underline-offset: 3px; }

main { width: min(850px, 100% - 40px); margin: 28px auto; }
.auth-card, .chat-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 36px #1e39250b;
}
.auth-card {
  width: min(100%, 408px);
  margin: clamp(42px, 9vh, 96px) auto;
  padding: clamp(22px, 5vw, 36px);
}
h1 { margin: 0; font-weight: 700; letter-spacing: -.035em; line-height: 1.2; }
.auth-card h1 { font-size: 28px; margin-top: 18px; }
.auth-card p { color: var(--ink-muted); margin: 10px 0 22px; }
.auth-card form { display: grid; }
.auth-card label { font-weight: 650; font-size: 14px; margin-bottom: 6px; }
.auth-card input {
  width: 100%;
  border: 1px solid #aebbb0;
  border-radius: 9px;
  padding: 11px 12px;
  margin-bottom: 16px;
}
.auth-card .text-button { margin-top: 7px; }
.primary {
  min-height: 44px;
  padding: 8px 17px;
  border: 0;
  border-radius: 9px;
  background: var(--green);
  color: #fff;
  font-weight: 650;
}
.primary:hover:not(:disabled) { background: #174c33; }

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: min(56rem, calc(100dvh - 123px));
  min-height: 20rem;
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
}
.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: #e1efe3;
  color: var(--green);
  font: 33px/1 Georgia, serif;
}
.chat-header h1 { font-size: 19px; }
.history {
  display: flex;
  flex-direction: column;
  padding: 18px clamp(14px, 4vw, 30px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  background: #fbfcf9;
}
.history:focus-visible { outline-offset: -3px; }
.empty {
  margin: auto;
  padding: 16px;
  color: var(--ink-muted);
  text-align: center;
  font-size: 15px;
}
#messages { display: grid; gap: 17px; padding: 0; margin: 0; list-style: none; }
.message {
  display: grid;
  gap: 5px;
  justify-self: start;
  min-width: 0;
  max-width: min(85%, 38rem);
}
.message[data-role="user"] { justify-self: end; }
.message-author { color: var(--ink-muted); font-size: 12px; font-weight: 650; }
.message[data-role="user"] .message-author { text-align: right; }
.bubble {
  padding: 11px 14px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 5px 15px 15px 15px;
  background: #fff;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message[data-role="user"] .bubble {
  background: #e1efe3;
  border-color: #d6e8d9;
  border-radius: 15px 5px 15px 15px;
}
.message-status {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  color: var(--ink-muted);
  font-size: 12px;
}
.message-status .text-button { font-size: inherit; }
.composer {
  padding: 12px clamp(14px, 4vw, 22px) max(13px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.compose-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px;
  border: 1px solid #bbc7ba;
  border-radius: 13px;
}
.compose-box:focus-within { border-color: #358366; }
.compose-box textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  padding: 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 16px;
  line-height: 1.4;
}
.compose-box textarea::placeholder { color: var(--ink-muted); }
.compose-box textarea:focus-visible { outline-offset: 0; }
.feedback { margin: 0 0 8px; color: var(--ink-muted); font-size: 14px; }
.auth-card .error, .error { color: #8c3329; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 600px) {
  .site-header-inner { width: calc(100% - 28px); min-height: 58px; }
  .brand { font-size: 17px; gap: 5px; }
  .brand span { font-size: 31px; }
  main { width: 100%; margin: 0 auto; }
  .auth-card { width: calc(100% - 32px); }
  .chat-panel { height: calc(100dvh - 59px); border: 0; border-radius: 0; box-shadow: none; }
  .chat-header { padding: 10px 14px; }
  .message { max-width: 92%; }
}
