:root {
  --bg: #f3efe6;
  --panel: rgba(255, 252, 244, 0.86);
  --panel-solid: #fffaf0;
  --ink: #17231d;
  --muted: #6f776f;
  --line: rgba(23, 35, 29, 0.14);
  --green: #244536;
  --green-2: #3f6b55;
  --gold: #c4852b;
  --teal: #3b8a88;
  --user: #244536;
  --assistant: #fffaf0;
  --shadow: 0 24px 80px rgba(32, 39, 32, 0.16);
  font-family: "Georgia", "Songti SC", "SimSun", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 8%, rgba(196, 133, 43, 0.22), transparent 26%),
    radial-gradient(circle at 92% 12%, rgba(59, 138, 136, 0.2), transparent 28%),
    linear-gradient(135deg, #f8f2e6, #e8ddca 52%, #dce5d8);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(23, 35, 29, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 35, 29, 0.08) 1px, transparent 1px);
  background-size: 42px 42px;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 16px clamp(16px, 4vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(243, 239, 230, 0.74);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 18px;
  color: #fff9ec;
  background: linear-gradient(145deg, var(--green), var(--teal));
  font-weight: 900;
  letter-spacing: 0;
}

.brand p,
.dialog-head p,
.hint,
.chat-meta p,
.role {
  margin: 0;
  color: var(--muted);
}

.brand p,
.dialog-head p {
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: 22px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.ghost,
.primary,
#askButton,
.tool-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.45);
}

.primary,
#askButton {
  border-color: transparent;
  color: #fffaf0;
  background: linear-gradient(135deg, var(--green), var(--green-2));
  box-shadow: 0 16px 36px rgba(36, 69, 54, 0.24);
}

#askButton:disabled {
  opacity: 0.62;
  cursor: wait;
}

.chat-shell {
  overflow-y: auto;
  padding: 22px clamp(12px, 4vw, 42px) 120px;
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  max-width: 980px;
  margin: 0 auto 18px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 252, 244, 0.72);
}

.chat-meta div {
  display: flex;
  gap: 9px;
  align-items: center;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #70b66c;
  box-shadow: 0 0 0 7px rgba(112, 182, 108, 0.16);
}

.messages {
  display: grid;
  gap: 18px;
  max-width: 980px;
  margin: 0 auto;
}

.message {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  animation: rise 260ms ease both;
}

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

.message.user .avatar {
  order: 2;
  background: var(--gold);
}

.message.user .bubble {
  justify-self: end;
  max-width: 78%;
  color: #fffaf0;
  background: var(--user);
}

.avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 15px;
  color: #fffaf0;
  background: var(--teal);
  font-weight: 900;
}

.bubble {
  max-width: 88%;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--assistant);
  box-shadow: 0 12px 38px rgba(32, 39, 32, 0.1);
}

.content {
  line-height: 1.78;
  white-space: pre-wrap;
}

.sources-toggle {
  margin-top: 14px;
  border: 0;
  padding: 0;
  color: var(--teal);
  background: transparent;
  font-weight: 800;
}

.sources-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.source-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.45);
}

.source-item strong {
  display: block;
  margin-bottom: 5px;
}

.source-item p,
.source-item a {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
}

.composer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 14px clamp(12px, 4vw, 42px) 18px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(243, 239, 230, 0.72), rgba(243, 239, 230, 0.96));
  backdrop-filter: blur(20px);
}

.composer-inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  max-width: 980px;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

textarea {
  width: 100%;
  max-height: 170px;
  resize: none;
  border: 0;
  outline: none;
  padding: 12px 6px;
  color: var(--ink);
  background: transparent;
  line-height: 1.6;
}

.tool-button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-weight: 900;
}

#askButton {
  min-width: 84px;
  height: 44px;
}

.hint {
  max-width: 960px;
  margin: 8px auto 0;
  font-size: 13px;
}

.quick-dialog {
  width: min(920px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 30px;
  padding: 0;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.96);
  box-shadow: var(--shadow);
}

.quick-dialog::backdrop {
  background: rgba(20, 28, 24, 0.34);
  backdrop-filter: blur(5px);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px 24px 12px;
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 24px;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 12px 24px 18px;
}

.quick-grid section {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.48);
}

.quick-grid button {
  border: 1px solid rgba(36, 69, 54, 0.16);
  border-radius: 16px;
  padding: 10px 12px;
  text-align: left;
  color: var(--green);
  background: rgba(255, 255, 255, 0.62);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 24px 24px;
}

.tag-row span {
  border-radius: 999px;
  padding: 8px 11px;
  color: var(--green);
  background: rgba(63, 107, 85, 0.1);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.topbar { flex-wrap: wrap; }
.brand { min-width: 0; max-width: 100%; }
.brand > div:last-child { min-width: 0; }
.brand h1 { max-width: 400px; overflow-wrap: anywhere; }
.top-actions { flex-wrap: wrap; align-items: center; min-width: 0; }
.top-actions > button { min-height: 42px; white-space: nowrap; }
.language-control {
  display: inline-grid;
  grid-template-columns: repeat(3, 44px);
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}
.language-control button {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  height: 40px;
  padding: 0;
  color: var(--green);
  background: rgba(255,255,255,.6);
  font-size: 14px;
}
.language-control button:last-child { border-right: 0; }
.language-control button[aria-pressed="true"] { color: white; background: var(--green); }
.language-control button:disabled { opacity: .55; cursor: wait; }
.language-control button:focus-visible { outline: 2px solid var(--gold); outline-offset: -3px; }
.chat-shell { min-height: 0; padding-bottom: calc(var(--composer-height, 180px) + 24px); }
.chat-meta > div, .chat-meta p, .bubble { min-width: 0; }
.chat-meta strong, .content, .source-item strong { overflow-wrap: anywhere; }
.status-dot { flex-shrink: 0; }
.sources-list[hidden] { display: none; }
.quick-dialog { max-height: calc(100dvh - 28px); overflow-y: auto; }

@media (max-width: 820px) {
  .topbar,
  .chat-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    overflow-x: visible;
  }

  .quick-grid {
    grid-template-columns: 1fr;
  }

  .message.user .bubble,
  .bubble {
    max-width: 100%;
  }
}
