:root {
  --bg: #f4efe7;
  --panel: rgba(255, 251, 246, 0.88);
  --panel-strong: rgba(255, 252, 248, 0.94);
  --line: rgba(89, 66, 41, 0.14);
  --line-soft: rgba(89, 66, 41, 0.08);
  --text: #2d241b;
  --muted: #6d5a46;
  --accent: #b65b1e;
  --accent-deep: #7f3612;
  --accent-soft: rgba(182, 91, 30, 0.12);
  --good: #286142;
  --warn: #9b4b20;
  --danger: #a02f25;
  --shadow: 0 24px 56px rgba(89, 58, 28, 0.14);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --font-sans: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-serif: "Songti SC", "STSong", "Source Han Serif SC", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 22%),
    radial-gradient(circle at bottom right, rgba(182, 91, 30, 0.14), transparent 24%),
    linear-gradient(135deg, #fbf6ee 0%, #f0e5d4 46%, #f8f1e7 100%);
}

button,
input,
textarea,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100% - 28px));
  margin: 18px auto 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #d68d58 0%, #9c4516 100%);
  color: #fff8f0;
  font-size: 26px;
  font-weight: 700;
  box-shadow: 0 16px 28px rgba(156, 69, 22, 0.24);
}

.topbar-kicker,
.section-kicker,
.workspace-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 6px 0 0;
  font-family: var(--font-serif);
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.1;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.header-pill {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(182, 91, 30, 0.14);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.workspace {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 18px;
}

.sidebar,
.main-panel {
  display: grid;
  gap: 16px;
}

.hero-card,
.card,
.main-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-card,
.card {
  padding: 20px;
}

.hero-card h2 {
  margin: 14px 0 12px;
  font-family: var(--font-serif);
  font-size: 32px;
  line-height: 1.14;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.hero-copy,
.section-copy,
.workspace-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.76;
  font-size: 14px;
}

.hero-metrics {
  margin: 18px 0 0;
  display: grid;
  gap: 10px;
}

.hero-metrics div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(89, 66, 41, 0.14);
}

.hero-metrics div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.hero-metrics dt {
  color: var(--muted);
  font-size: 13px;
}

.hero-metrics dd {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.section-head h3 {
  margin: 6px 0 0;
  font-size: 18px;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field textarea,
.field select,
.composer textarea {
  width: 100%;
  border: 1px solid rgba(89, 66, 41, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.field select {
  appearance: none;
}

.field input:focus,
.field textarea:focus,
.composer textarea:focus {
  border-color: rgba(182, 91, 30, 0.4);
  box-shadow: 0 0 0 4px rgba(182, 91, 30, 0.1);
}

.primary-button,
.send-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: #fff9f2;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(182, 91, 30, 0.2);
}

.primary-button[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.ghost-button {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(89, 66, 41, 0.14);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  cursor: pointer;
}

.ghost-button-small {
  padding: 8px 12px;
  font-size: 13px;
}

.danger-button {
  color: var(--danger);
}

.action-row {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

.kb-list,
.document-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.empty-state-card {
  padding: 14px;
  border-radius: 16px;
  border: 1px dashed rgba(89, 66, 41, 0.18);
  background: rgba(255, 255, 255, 0.5);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.kb-item,
.document-item {
  border: 1px solid rgba(89, 66, 41, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.84);
  overflow: hidden;
}

.kb-item.is-active {
  border-color: rgba(182, 91, 30, 0.3);
  box-shadow: inset 0 0 0 1px rgba(182, 91, 30, 0.12);
}

.kb-select {
  width: 100%;
  padding: 14px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 8px;
}

.kb-title-row,
.document-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.kb-name,
.document-name {
  font-size: 15px;
  font-weight: 700;
  word-break: break-word;
}

.kb-meta,
.kb-description,
.document-meta,
.document-path,
.document-preview,
.build-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.kb-description,
.document-preview {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.document-item {
  padding: 14px;
  display: grid;
  gap: 8px;
}

.document-path,
.search-result-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  color: #7d654d;
  word-break: break-all;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent-deep);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}

.text-button + .text-button {
  margin-left: 10px;
}

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

.search-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid rgba(89, 66, 41, 0.12);
  border-radius: 22px;
  background: rgba(255, 252, 248, 0.84);
}

.search-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px 140px;
  gap: 12px;
  align-items: end;
}

.search-field,
.search-scope {
  margin: 0;
}

.search-results,
.audit-log-list {
  display: grid;
  gap: 10px;
}

.search-result-item,
.audit-log-item {
  padding: 14px;
  border: 1px solid rgba(89, 66, 41, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.84);
}

.search-result-item {
  display: grid;
  gap: 8px;
}

.search-result-top,
.audit-log-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.search-result-title {
  font-size: 15px;
  font-weight: 700;
  word-break: break-word;
}

.search-result-meta,
.search-result-excerpt,
.audit-log-summary,
.audit-log-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.audit-log-summary {
  color: var(--text);
}

.main-panel {
  padding: 20px;
  align-content: start;
}

.workspace-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  padding: 6px 4px 2px;
}

.workspace-hero h2 {
  margin: 6px 0 8px;
  font-family: var(--font-serif);
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.12;
}

.workspace-meta {
  min-width: 240px;
  padding: 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 248, 239, 0.9) 0%, rgba(255, 255, 255, 0.82) 100%);
  border: 1px solid rgba(182, 91, 30, 0.12);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.prompt-chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(182, 91, 30, 0.14);
  background: rgba(255, 248, 239, 0.92);
  color: var(--accent-deep);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.prompt-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(182, 91, 30, 0.12);
}

.notice-bar {
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(40, 97, 66, 0.14);
  background: rgba(40, 97, 66, 0.08);
  color: var(--good);
  line-height: 1.7;
}

.product-footer {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 252, 248, 0.82);
}

.product-footer strong {
  display: block;
  margin: 6px 0 8px;
  font-size: 16px;
}

.product-footer p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 13px;
}

.footer-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-log {
  min-height: 420px;
  max-height: 58vh;
  overflow-y: auto;
  display: grid;
  gap: 14px;
  padding-right: 4px;
}

.empty-chat-state {
  min-height: 320px;
  display: grid;
  place-items: center;
  padding: 28px;
  border-radius: 24px;
  border: 1px dashed rgba(89, 66, 41, 0.14);
  background: rgba(255, 255, 255, 0.48);
  color: var(--muted);
  line-height: 1.9;
  text-align: center;
}

.message {
  max-width: 84%;
  padding: 16px 18px;
  border-radius: 24px;
  border: 1px solid rgba(89, 66, 41, 0.12);
  background: rgba(255, 255, 255, 0.92);
  display: grid;
  gap: 12px;
}

.message-user {
  justify-self: end;
  background: linear-gradient(180deg, rgba(255, 240, 221, 0.96) 0%, rgba(255, 247, 237, 0.96) 100%);
}

.message-assistant,
.message-error {
  justify-self: start;
}

.message-error {
  border-color: rgba(160, 47, 37, 0.16);
  background: rgba(160, 47, 37, 0.06);
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.message-body {
  line-height: 1.8;
  word-break: break-word;
}

.message-body p {
  margin: 0 0 12px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-source-list {
  padding-top: 12px;
  border-top: 1px dashed rgba(89, 66, 41, 0.16);
  display: grid;
  gap: 10px;
}

.message-source-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.message-source-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 248, 239, 0.88);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.composer {
  display: grid;
  gap: 10px;
}

.composer-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.composer-box {
  padding: 14px;
  border-radius: 24px;
  border: 1px solid rgba(89, 66, 41, 0.12);
  background: rgba(255, 255, 255, 0.84);
}

.composer textarea {
  min-height: 110px;
  resize: vertical;
  border: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.composer-actions {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.typing-status {
  color: var(--muted);
  font-size: 13px;
}

.feature-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.8;
}

.feature-list li + li {
  margin-top: 6px;
}

.checkbox-list {
  display: grid;
  gap: 8px;
  margin: 6px 0 12px;
}

.checkbox-item {
  display: flex;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(89, 66, 41, 0.12);
  background: rgba(255, 255, 255, 0.62);
}

.checkbox-item input {
  margin-top: 3px;
}

.checkbox-copy {
  display: grid;
  gap: 2px;
}

.checkbox-copy strong {
  font-size: 14px;
}

.checkbox-copy span {
  color: var(--muted);
  font-size: 12px;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

@media (max-width: 1080px) {
  .topbar,
  .workspace,
  .workspace-hero {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .workspace {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .workspace-meta {
    min-width: 0;
    width: 100%;
  }

  .message {
    max-width: 100%;
  }

  .product-footer {
    grid-template-columns: 1fr;
  }

  .search-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100%, calc(100% - 20px));
    margin: 10px auto 18px;
  }

  .topbar,
  .hero-card,
  .card,
  .main-panel {
    padding: 16px;
  }

  .brand-lockup {
    align-items: start;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 15px;
  }

  .hero-card h2,
  .workspace-hero h2 {
    font-size: 28px;
  }

  .action-row,
  .upload-actions,
  .topbar-actions,
  .composer-actions,
  .search-result-top,
  .audit-log-top {
    flex-direction: column;
    align-items: stretch;
  }
}
