:root {
  --page: #f4f1ea;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: #ffffff;
  --ink: #1d2725;
  --muted: #68736f;
  --line: #d9ddd7;
  --accent: #156f61;
  --accent-dark: #0d5147;
  --accent-soft: #dff2ed;
  --user: #1c665c;
  --danger: #a13b3b;
  --danger-soft: #fae8e6;
  --shadow: 0 20px 55px rgba(31, 49, 44, 0.10);
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 2%, rgba(46, 139, 122, 0.13), transparent 31rem),
    radial-gradient(circle at 90% 88%, rgba(205, 169, 104, 0.15), transparent 30rem),
    var(--page);
}

[hidden] { display: none !important; }
button, input, textarea { font: inherit; }
button { color: inherit; }
:focus-visible { outline: 3px solid #2e8f7e; outline-offset: 3px; }

.shell { min-height: 100vh; }
.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 24px;
  min-height: 82px;
  padding: 14px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid rgba(123, 136, 130, 0.22);
  background: rgba(250, 249, 245, 0.84);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand__mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(145deg, #1b7d6e, #0d5147);
  box-shadow: 0 8px 20px rgba(21, 111, 97, 0.23);
  font-family: Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
}
.brand h1 { margin: 0; font-family: Georgia, serif; font-size: 1.3rem; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }
.brand__model { overflow-wrap: anywhere; }

.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.86rem; }
.status__dot { width: 9px; height: 9px; border-radius: 50%; background: #ad8b48; box-shadow: 0 0 0 4px rgba(173, 139, 72, 0.13); }
.status--online .status__dot { background: #178466; box-shadow: 0 0 0 4px rgba(23, 132, 102, 0.13); }
.status--offline .status__dot { background: #b84b4b; box-shadow: 0 0 0 4px rgba(184, 75, 75, 0.13); }
.status--loading .status__dot { animation: pulse 1.2s ease-in-out infinite; }

.account { display: flex; align-items: center; gap: 10px; }
.account__name { font-size: 0.84rem; font-weight: 750; }
.account__quota { color: var(--muted); font-size: 0.76rem; white-space: nowrap; }

.button {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 650;
}
.button:disabled { cursor: wait; opacity: 0.58; }
.button--secondary { border-color: var(--line); background: var(--surface-strong); }
.button--secondary:hover:not(:disabled) { border-color: #aeb8b2; background: #fafbf9; }
.button--quiet { min-height: 36px; padding: 6px 10px; border-color: var(--line); background: transparent; font-size: 0.8rem; }
.button--primary { width: 100%; color: #fff; background: var(--accent); }
.button--primary:hover:not(:disabled) { background: var(--accent-dark); }

.content { min-height: calc(100vh - 82px); }
.login { display: grid; min-height: calc(100vh - 82px); padding: 36px 18px; place-items: center; }
.login__card {
  display: grid;
  width: min(100%, 430px);
  gap: 10px;
  padding: clamp(28px, 5vw, 44px);
  border: 1px solid rgba(120, 135, 128, 0.30);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.login__mark { margin: 0 auto 8px; }
.login h2 { margin: 0 0 4px; text-align: center; font-family: Georgia, serif; font-size: 2rem; font-weight: 560; }
.login .eyebrow { text-align: center; }
.login__lead { margin: 0 0 15px; color: var(--muted); text-align: center; line-height: 1.5; }
.login label { margin-top: 5px; font-size: 0.8rem; font-weight: 720; }
.login input {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--surface-strong);
}
.login .notice { margin: 4px 0; }

.chat {
  display: flex;
  width: min(100% - 28px, 900px);
  min-height: calc(100vh - 82px);
  margin: 0 auto;
  padding: clamp(30px, 7vh, 72px) 0 154px;
  flex-direction: column;
}
.welcome { max-width: 680px; margin: auto auto 42px; padding: 20px; text-align: center; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 0.78rem; font-weight: 780; letter-spacing: 0.11em; text-transform: uppercase; }
.welcome h2 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 3.35rem); font-weight: 540; letter-spacing: -0.035em; }
.welcome > p:last-of-type { max-width: 620px; margin: 17px auto 0; color: var(--muted); line-height: 1.6; }
.collections { display: flex; justify-content: center; gap: 7px; flex-wrap: wrap; margin-top: 18px; }
.collections span { padding: 5px 10px; border-radius: 999px; color: var(--accent-dark); background: var(--accent-soft); font-size: 0.78rem; font-weight: 700; }

.messages { display: grid; gap: 25px; }
.message { width: min(84%, 720px); animation: appear 180ms ease-out; }
.message--user { justify-self: end; }
.message--assistant { justify-self: start; }
.message__role { margin: 0 0 7px 4px; color: var(--muted); font-size: 0.77rem; font-weight: 750; letter-spacing: 0.03em; text-transform: uppercase; }
.message__content {
  padding: 15px 18px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 6px;
  background: var(--surface-strong);
  box-shadow: 0 8px 25px rgba(31, 49, 44, 0.045);
  line-height: 1.62;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message--user .message__content { border-color: var(--user); border-radius: 18px 18px 6px 18px; color: #fff; background: var(--user); }
.sources { margin: 8px 0 0 4px; color: var(--muted); font-size: 0.83rem; }
.sources summary { cursor: pointer; color: var(--accent-dark); font-weight: 700; }
.sources ul { margin: 8px 0 0; padding-left: 19px; }

.typing { display: flex; width: 70px; gap: 6px; padding: 17px 19px; border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; background: #fff; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #7a8b86; animation: bounce 1.1s infinite; }
.typing span:nth-child(2) { animation-delay: 120ms; }
.typing span:nth-child(3) { animation-delay: 240ms; }

.notice { margin: 24px 0 0; padding: 12px 15px; border: 1px solid #edc6c1; border-radius: 12px; color: var(--danger); background: var(--danger-soft); line-height: 1.45; }
.composer {
  position: fixed;
  z-index: 8;
  right: 50%;
  bottom: 22px;
  display: grid;
  grid-template-columns: 1fr auto;
  width: min(calc(100% - 28px), 900px);
  padding: 8px 8px 6px 17px;
  transform: translateX(50%);
  border: 1px solid rgba(120, 135, 128, 0.38);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}
.composer textarea { min-height: 46px; max-height: 220px; padding: 12px 5px 8px; resize: none; border: 0; outline: 0; color: var(--ink); background: transparent; line-height: 1.45; }
.composer textarea::placeholder { color: #87918e; }
.button--send { align-self: end; width: 44px; min-height: 44px; padding: 0; border-radius: 14px; color: #fff; background: var(--accent); font-size: 1.35rem; }
.button--send:hover:not(:disabled) { background: var(--accent-dark); }
.composer__hint { grid-column: 1 / -1; margin: 0 0 2px; color: #8b9692; font-size: 0.72rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes pulse { 50% { opacity: 0.35; transform: scale(0.8); } }
@keyframes bounce { 0%, 65%, 100% { transform: translateY(0); opacity: 0.45; } 35% { transform: translateY(-5px); opacity: 1; } }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 700px) {
  .topbar { grid-template-columns: 1fr auto; gap: 12px; padding: 12px 14px; }
  .status { grid-row: 2; grid-column: 1; }
  .account { grid-row: 3; grid-column: 1 / -1; justify-content: space-between; }
  .brand__model { max-width: min(62vw, 360px); font-size: 0.72rem !important; line-height: 1.25; }
  .chat { min-height: calc(100vh - 106px); padding-top: 38px; }
  .welcome { margin-top: 5vh; }
  .message { width: 93%; }
  .composer { bottom: 10px; }
}

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

@media (prefers-color-scheme: dark) {
  :root { --page: #111817; --surface-strong: #1b2523; --ink: #edf4f1; --muted: #a4b2ad; --line: #34433f; --accent-soft: #173d36; --accent: #55b6a4; --accent-dark: #76cdbd; --user: #216f63; --danger-soft: #3a2020; --danger: #ffaaa5; }
  body { background: radial-gradient(circle at 12% 2%, rgba(38, 123, 106, 0.20), transparent 31rem), var(--page); }
  .topbar { background: rgba(17, 24, 23, 0.84); }
  .button--secondary, .login input, .typing { background: #1b2523; }
  .composer { background: rgba(27, 37, 35, 0.96); }
  .message__content { box-shadow: none; }
}
