:root {
  color-scheme: light;
  --ink: #24262d;
  --muted: #72747d;
  --paper: #f4f1eb;
  --card: #fffdf9;
  --line: #ded9cf;
  --accent: #c74b32;
  --accent-dark: #963622;
  --soft: #ece6dc;
  --shadow: 0 18px 55px rgba(49, 43, 35, .09);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 12% 0%, rgba(199, 75, 50, .09), transparent 28rem),
    linear-gradient(90deg, rgba(36, 38, 45, .025) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 42px 42px, auto;
}

button, textarea { font: inherit; }

.shell {
  width: min(940px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 15px;
  padding: 28px 2px 22px;
  border-bottom: 1px solid var(--line);
}

.brand-mark, .avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: white;
  background: var(--ink);
  font-family: Georgia, serif;
  font-weight: 800;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px 2px 12px 2px;
  font-size: 27px;
  box-shadow: 5px 5px 0 var(--accent);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .19em;
}

h1 { margin: 0; font-size: clamp(19px, 3vw, 25px); letter-spacing: .02em; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 253, 249, .72);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #c7a544; }
.status.ready .status-dot { background: #3f9c63; box-shadow: 0 0 0 3px rgba(63, 156, 99, .13); }
.status.preview .status-dot { background: #c7792f; }
.status.error .status-dot { background: #bf3f3f; }

.scenario-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px 2px;
  border-bottom: 1px solid var(--line);
}

.scenario-title { margin: 0 0 3px; font-size: 13px; font-weight: 800; }
.scenario-hint { margin: 0; color: var(--muted); font-size: 11px; }
.scenario-options { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.scenario-option {
  display: grid;
  gap: 2px;
  min-width: 124px;
  padding: 8px 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  text-align: left;
}
.scenario-option span { font-size: 13px; font-weight: 800; }
.scenario-option small { color: var(--muted); font-size: 10px; }
.scenario-option:hover { border-color: #d19a8d; }
.scenario-option.selected {
  color: var(--accent-dark);
  border-color: var(--accent);
  background: #fff5f1;
  box-shadow: 0 0 0 2px rgba(199, 75, 50, .08);
}
.scenario-option.selected small { color: var(--accent); }
.scenario-option:disabled { cursor: wait; opacity: .6; }


.chat { min-width: 0; padding: 34px 0 150px; }

.message {
  display: flex;
  min-width: 0;
  max-width: 100%;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 28px;
  animation: rise .28s ease-out both;
}

.message.user { justify-content: flex-end; }
.avatar { width: 34px; height: 34px; border-radius: 9px 2px 9px 2px; font-size: 15px; }
.message.user .avatar { background: var(--accent); font-family: inherit; font-size: 12px; }

.bubble {
  max-width: min(760px, calc(100% - 46px));
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 4px 18px 18px 18px;
  background: var(--card);
  box-shadow: 0 8px 26px rgba(49, 43, 35, .05);
}

.user .bubble {
  padding: 13px 17px;
  color: white;
  border-color: var(--accent);
  border-radius: 18px 4px 18px 18px;
  background: var(--accent);
  box-shadow: none;
}

.message-label { margin: 0 0 9px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.answer { min-width: 0; max-width: 100%; font-size: 15px; line-height: 1.8; overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: .65em 0; }
.answer h2, .answer h3 { margin: 1em 0 .35em; line-height: 1.4; }
.answer h2 { font-size: 17px; }
.answer h3 { font-size: 15px; }
.answer ul, .answer ol { margin: .5em 0; padding-left: 1.4em; }
.answer code { padding: 1px 5px; border-radius: 4px; background: var(--soft); font-family: Consolas, monospace; font-size: .9em; }

.table-wrap {
  width: 100%;
  max-width: 100%;
  margin: 14px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}

.answer table {
  width: 100%;
  min-width: 440px;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.55;
}

.answer th,
.answer td {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.answer th:last-child,
.answer td:last-child { border-right: 0; }
.answer tbody tr:last-child td { border-bottom: 0; }
.answer th { color: var(--ink); background: var(--soft); font-weight: 800; white-space: nowrap; }
.answer tbody tr:nth-child(even) { background: #faf8f3; }
.answer .align-left { text-align: left; }
.answer .align-center { text-align: center; }
.answer .align-right { text-align: right; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.suggestions button {
  padding: 7px 10px;
  color: var(--accent-dark);
  border: 1px solid #e0b4a9;
  border-radius: 999px;
  background: #fff8f5;
  cursor: pointer;
  font-size: 12px;
}
.suggestions button:hover { border-color: var(--accent); background: #fff2ed; }

.sources { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); }
.sources summary { color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 700; }
.source-list { display: grid; gap: 9px; margin-top: 11px; }
.source-card { padding: 11px 12px; border-left: 3px solid var(--accent); background: #f6f2eb; }
.source-card a { color: var(--ink); font-size: 13px; font-weight: 750; text-decoration: none; }
.source-card a:hover { color: var(--accent-dark); text-decoration: underline; }
.source-meta { margin-left: 5px; color: var(--muted); font-size: 11px; }
.source-card p { margin: 6px 0 0; color: #55565d; font-size: 12px; line-height: 1.55; }

.composer {
  position: sticky;
  bottom: 18px;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid #d2ccc1;
  border-radius: 18px;
  background: rgba(255, 253, 249, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

textarea {
  width: 100%;
  max-height: 150px;
  resize: none;
  padding: 10px 8px;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
  line-height: 1.5;
}

textarea::placeholder { color: #9b998f; }

#send {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 15px;
  color: white;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

#send:hover { background: var(--accent-dark); }
#send:disabled { cursor: wait; opacity: .55; }
#send svg { width: 17px; fill: currentColor; }

.footnote { margin: 6px 0 18px; color: var(--muted); font-size: 11px; text-align: center; }
.typing { display: inline-flex; gap: 5px; align-items: center; min-height: 28px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

.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 rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-4px); opacity: 1; } }

@media (max-width: 640px) {
  .shell { width: min(100% - 22px, 940px); }
  .topbar { padding-top: 18px; gap: 12px; }
  .brand-mark { width: 41px; height: 41px; font-size: 22px; }
  .status { grid-column: 1 / -1; justify-self: start; }
  .scenario-picker { align-items: flex-start; flex-direction: column; gap: 10px; }
  .scenario-options { width: 100%; justify-content: flex-start; }
  .scenario-option { flex: 1; }
  .chat { padding-top: 24px; }
  .bubble { padding: 15px 16px; }
  #send span { display: none; }
  #send { width: 42px; justify-content: center; padding: 0; }
}

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