:root {
  --paper: #f8f5ee;
  --cream: #efe7d7;
  --ink: #292b29;
  --muted: #686b65;
  --sage: #6e7f6b;
  --sage-dark: #455744;
  --gold: #ad8741;
  --rose: #b98b83;
  --line: #d8d0c1;
  --white: #ffffff;
  --shadow: 0 16px 45px rgba(50, 45, 35, 0.12);
}

* { box-sizing: border-box; }

html { background: var(--cream); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(185, 139, 131, 0.16), transparent 34rem),
    radial-gradient(circle at bottom right, rgba(110, 127, 107, 0.18), transparent 36rem),
    var(--cream);
}

button, textarea { font: inherit; }

button { cursor: pointer; }

.shell {
  width: min(880px, calc(100% - 24px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto auto minmax(320px, 1fr) auto auto auto;
  background: var(--paper);
  border: 1px solid rgba(173, 135, 65, 0.28);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
}

.brand-logo-frame {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
}

.brand-logo {
  width: 58px;
  height: 58px;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 3px 5px rgba(41, 43, 41, 0.22));
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.45rem, 3vw, 2rem);
  font-weight: 600;
}

.app-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--sage-dark);
  padding: 8px;
  font-weight: 650;
}

.text-button:hover, .text-button:focus-visible { text-decoration: underline; }

.notice {
  padding: 10px 22px;
  background: #fbf1df;
  border-bottom: 1px solid #e6d6b9;
  color: #5a482a;
  font-size: 0.88rem;
  line-height: 1.45;
}

.chat {
  padding: 22px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message {
  max-width: 82%;
  margin: 0 0 18px;
  padding: 14px 16px;
  border-radius: 16px;
  line-height: 1.58;
  overflow-wrap: anywhere;
}

.assistant-message {
  margin-right: auto;
  background: var(--white);
  border: 1px solid var(--line);
  border-top-left-radius: 5px;
}

.user-message {
  margin-left: auto;
  color: var(--white);
  background: var(--sage-dark);
  border-top-right-radius: 5px;
}

.message-label {
  margin-bottom: 6px;
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.035em;
  text-transform: uppercase;
  opacity: 0.72;
}

.message-body a {
  color: var(--sage-dark);
  font-weight: 650;
}

.user-message .message-body a { color: var(--white); }

.sources {
  margin-top: 12px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.82rem;
}

.sources summary { cursor: pointer; font-weight: 650; }
.sources ul { margin: 7px 0 0; padding-left: 20px; }

.suggestions {
  display: flex;
  gap: 8px;
  padding: 0 22px 13px;
  overflow-x: auto;
}

.suggestions button {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--sage-dark);
  background: var(--white);
}

.suggestions button:hover, .suggestions button:focus-visible {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(173, 135, 65, 0.12);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

textarea {
  width: 100%;
  resize: none;
  min-height: 52px;
  max-height: 180px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--white);
  outline: none;
}

textarea:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(110, 127, 107, 0.14);
}

#send-button {
  min-width: 82px;
  border: 0;
  border-radius: 14px;
  color: var(--white);
  background: var(--sage-dark);
  font-weight: 750;
}

#send-button:hover, #send-button:focus-visible { background: #344633; }
#send-button:disabled { opacity: 0.58; cursor: wait; }

.app-footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 12px 22px 16px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

.app-footer p { margin: 0; max-width: 640px; }
.app-footer a { color: var(--sage-dark); white-space: nowrap; }

.typing-dots::after {
  content: "";
  display: inline-block;
  width: 1.4em;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75%, 100% { content: "..."; }
}

.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;
}

@media (max-width: 640px) {
  .shell { width: 100%; min-height: 100vh; margin: 0; border: 0; border-radius: 0; }
  .app-header { padding: 15px; }
  .app-header p { display: none; }
  .brand-logo { width: 48px; height: 48px; }
  .notice, .chat { padding-left: 15px; padding-right: 15px; }
  .message { max-width: 92%; }
  .suggestions { padding-left: 15px; padding-right: 15px; }
  .composer { padding: 12px 15px 14px; }
  .app-footer { display: block; padding: 10px 15px 14px; }
  .app-footer a { display: inline-block; margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; }
}
