:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #202522;
  background: #f2f4f1;
  font-synthesis: none;
  --ink: #202522;
  --muted: #6b746f;
  --line: #dde2de;
  --surface: #ffffff;
  --subtle: #f5f7f5;
  --green: #176b4d;
  --green-dark: #10543c;
  --green-soft: #e5f2eb;
  --amber: #b56a16;
  --red: #b33a3a;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(23, 107, 77, 0.2);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  min-width: 0;
  flex-direction: column;
  background: #f8f9f7;
  border-right: 1px solid var(--line);
}

.brand-bar {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 72px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  color: #fff;
  background: var(--green);
  border-radius: 7px;
}

.brand-mark svg {
  width: 19px;
}

.brand-bar strong,
.brand-bar span {
  display: block;
}

.brand-bar strong {
  font-family: Georgia, "Songti SC", serif;
  font-size: 18px;
}

.brand-bar span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--ink);
  background: #edf0ed;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.sidebar-close,
.menu-button {
  display: none;
}

.section-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.workspace-title h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.conversation-history {
  min-height: 0;
  flex: 1;
  padding: 20px 12px 12px;
}

.sidebar-tools {
  display: grid;
  gap: 3px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.tool-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.tool-button:hover { color: var(--ink); background: #ecefec; }
.tool-button.is-active { color: var(--green-dark); background: var(--green-soft); }
.tool-button svg { width: 17px; height: 17px; }

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 7px 12px;
}

.history-heading .section-label {
  margin: 0;
}

.history-heading .icon-button {
  width: 30px;
  height: 30px;
}

.history-list {
  display: grid;
  max-height: calc(100% - 37px);
  gap: 2px;
  overflow-y: auto;
}

.history-item {
  display: grid;
  width: 100%;
  min-width: 0;
  height: 36px;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.history-item:hover {
  color: var(--ink);
  background: #ecefec;
}

.history-item.is-active {
  color: var(--green-dark);
  background: var(--green-soft);
}

.history-item svg {
  width: 16px;
  height: 16px;
}

.history-item span {
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-history {
  padding: 8px 12px 12px;
  color: var(--muted);
  font-size: 11px;
}

.workspace {
  display: grid;
  height: 100%;
  min-height: 0;
  min-width: 0;
  grid-template-rows: 72px minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--surface);
}

.workspace-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
}

.workspace-title {
  min-width: 0;
  flex: 1;
}

.workspace-title .section-label {
  margin: 0 0 2px;
  font-size: 9px;
}

.workspace-title h2 {
  font-size: 16px;
}

.conversation {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.documents-view {
  min-height: 0;
  overflow-y: auto;
  padding: 42px clamp(20px, 5vw, 72px) 56px;
  background: #fbfcfb;
}

.documents-toolbar,
.document-filters,
.document-table-wrap,
.document-pagination {
  width: min(980px, 100%);
  margin: 0 auto;
}

.documents-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.documents-toolbar h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 29px; font-weight: 600; }
.upload-button { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px; border-radius: 6px; color: #fff; background: var(--green); cursor: pointer; font-size: 12px; font-weight: 700; }
.upload-button:hover { background: var(--green-dark); }
.upload-button svg { width: 16px; }
.upload-button input { display: none; }
.document-filters { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.search-field { display: flex; flex: 1; align-items: center; gap: 8px; height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.search-field:focus-within { border-color: var(--green); }
.search-field svg { width: 16px; color: var(--muted); }
.search-field input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 12px; }
.document-filters select { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: #fff; font-size: 12px; }
.document-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.document-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.document-table th { padding: 12px 15px; color: var(--muted); background: #f6f8f6; font-size: 10px; font-weight: 800; text-align: left; text-transform: uppercase; }
.document-table td { padding: 13px 15px; border-top: 1px solid #edf0ed; vertical-align: middle; }
.document-table tr:hover td { background: #fcfdfc; }
.document-name { max-width: 340px; overflow: hidden; padding: 0; border: 0; color: var(--ink); background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.document-name:hover { color: var(--green); }
.muted-cell { color: var(--muted); white-space: nowrap; }
.state-badge { display: inline-flex; min-height: 23px; align-items: center; padding: 0 8px; border-radius: 4px; font-size: 10px; font-weight: 800; }
.state-badge.ready { color: #176b4d; background: var(--green-soft); }
.state-badge.pending { color: #8e5b16; background: #fff1d9; }
.state-badge.failed { color: #a33737; background: #fbe7e7; }
.state-badge.neutral { color: var(--muted); background: #edf0ed; }
.document-actions { display: flex; justify-content: flex-end; gap: 2px; white-space: nowrap; }
.document-actions .icon-button { width: 30px; height: 30px; }
.table-empty { padding: 30px !important; color: var(--muted); text-align: center; }
.document-pagination { padding-top: 16px; text-align: center; }
.text-button { padding: 7px 12px; border: 1px solid var(--line); border-radius: 5px; color: var(--green-dark); background: #fff; cursor: pointer; font-size: 11px; font-weight: 700; }
.text-button:hover { background: var(--green-soft); }
.document-dialog { width: min(720px, calc(100% - 32px)); max-height: min(760px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 8px; color: var(--ink); background: transparent; box-shadow: 0 18px 60px rgba(32, 37, 34, 0.25); }
.document-dialog::backdrop { background: rgba(20, 25, 22, 0.42); }
.dialog-card { position: relative; padding: 28px; background: #fff; }
.dialog-card h2 { margin: 0 0 18px; font-family: Georgia, "Songti SC", serif; font-size: 24px; font-weight: 600; overflow-wrap: anywhere; }
.dialog-close { position: absolute; top: 18px; right: 18px; }
.document-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; color: var(--muted); font-size: 11px; }
.chunks-heading { display: flex; justify-content: space-between; padding-bottom: 9px; border-bottom: 1px solid var(--line); font-size: 12px; }
.chunks-heading span { color: var(--muted); font-size: 10px; }
.chunk-list { max-height: 430px; overflow-y: auto; }
.chunk-item { padding: 14px 0; border-bottom: 1px solid #edf0ed; }
.chunk-item > div { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; }
.chunk-item > div span { color: var(--green); font-size: 10px; }
.chunk-item p { margin: 8px 0 0; color: #5e6761; font-size: 11px; line-height: 1.7; white-space: pre-wrap; }

.welcome-state {
  display: flex;
  min-height: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 9vh 32px 48px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.welcome-icon {
  display: grid;
  width: 52px;
  height: 52px;
  margin-bottom: 20px;
  place-items: center;
  border: 1px solid #bdd5c8;
  border-radius: 8px;
  color: var(--green);
  background: var(--green-soft);
}

.welcome-icon svg {
  width: 25px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
}

.welcome-state h2 {
  margin: 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(26px, 3vw, 36px);
  font-weight: 600;
  line-height: 1.25;
}

.welcome-state > p:not(.eyebrow) {
  margin: 12px 0 28px;
  color: var(--muted);
  font-size: 13px;
}

.message-stream {
  width: min(780px, calc(100% - 48px));
  min-height: 100%;
  margin: 0 auto;
  padding: 40px 0 32px;
}

.message {
  margin-bottom: 34px;
}

.message-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.message-label span:first-child {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 5px;
  color: #fff;
  background: #3d4540;
}

.message.assistant .message-label span:first-child {
  background: var(--green);
}

.message-label svg {
  width: 13px;
}

.message-body {
  margin-left: 32px;
  color: #303632;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.message.user .message-body {
  display: inline-block;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 7px;
  background: #f0f2f0;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
}

.thinking span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7b857f;
  animation: pulse 1.1s infinite ease-in-out;
}

.thinking span:nth-child(2) { animation-delay: 120ms; }
.thinking span:nth-child(3) { animation-delay: 240ms; }

@keyframes pulse {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.sources {
  margin: 18px 0 0 32px;
  border-top: 1px solid var(--line);
}

.sources-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 14px 0 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.sources-heading svg {
  width: 14px;
}

.source-item {
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
}

.source-item summary {
  display: flex;
  min-height: 42px;
  padding: 0 12px;
  align-items: center;
  gap: 10px;
  list-style: none;
  cursor: pointer;
}

.source-item summary::-webkit-details-marker {
  display: none;
}

.source-index {
  display: grid;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 4px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 10px;
  font-weight: 800;
}

.source-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-item summary > svg {
  width: 14px;
  color: var(--muted);
  transition: transform 150ms ease;
}

.source-item[open] summary > svg {
  transform: rotate(180deg);
}

.source-item p {
  margin: 0;
  padding: 0 12px 13px 44px;
  color: #5e6761;
  font-size: 11px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.composer-wrap {
  padding: 15px 32px 18px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
}

.composer {
  display: grid;
  width: min(780px, 100%);
  min-height: 52px;
  margin: 0 auto;
  padding: 6px 7px 6px 16px;
  grid-template-columns: minmax(0, 1fr) 40px;
  align-items: end;
  border: 1px solid #cbd2cd;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(32, 37, 34, 0.06);
}

.composer:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 77, 0.09);
}

.composer textarea {
  width: 100%;
  max-height: 140px;
  padding: 10px 12px 9px 0;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 13px;
  line-height: 1.5;
}

.composer textarea::placeholder {
  color: #959d98;
}

.send-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--green);
  cursor: pointer;
}

.send-button:hover:not(:disabled) {
  background: var(--green-dark);
}

.send-button:disabled {
  color: #9da49f;
  background: #e8ebe9;
  cursor: not-allowed;
}

.send-button svg {
  width: 18px;
}

.composer-note {
  width: min(780px, 100%);
  margin: 7px auto 0;
  color: #909792;
  font-size: 9px;
  text-align: center;
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  display: grid;
  width: min(340px, calc(100vw - 40px));
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid #cbd4ce;
  border-radius: 7px;
  color: #fff;
  background: #29312c;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  font-size: 12px;
}

.toast.error {
  background: #7d2929;
}

.toast svg {
  width: 17px;
  flex: 0 0 auto;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 820px) {
  .app-shell {
    width: 100vw;
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
  }

  .workspace {
    width: 100vw;
    max-width: 100vw;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(360px, calc(100vw - 36px));
    transform: translateX(-100%);
    transition: transform 180ms ease;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    z-index: 15;
    inset: 0;
    display: block;
    visibility: hidden;
    opacity: 0;
    background: rgba(20, 25, 22, 0.35);
    transition: opacity 180ms ease, visibility 180ms ease;
  }

  body.sidebar-open .sidebar-backdrop {
    visibility: visible;
    opacity: 1;
  }

  .sidebar-close {
    display: inline-grid;
    margin-left: auto;
  }

  .menu-button {
    display: inline-grid;
  }

  .workspace-header {
    padding: 0 18px;
    overflow: hidden;
  }

  .welcome-state {
    padding: 48px 20px 36px;
  }

  .message-stream {
    width: calc(100% - 32px);
    padding-top: 28px;
  }

  .composer-wrap {
    padding: 12px 16px 14px;
  }
}

@media (max-width: 560px) {
  .workspace {
    grid-template-rows: 64px minmax(0, 1fr) auto;
  }

  .workspace-header {
    gap: 8px;
  }

  .welcome-state {
    justify-content: flex-start;
  }

  .welcome-state h2 {
    font-size: 27px;
  }

  .message-body,
  .sources {
    margin-left: 0;
  }

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

  .source-item p {
    padding-left: 12px;
  }

  .documents-view { padding: 28px 16px 40px; }
  .documents-toolbar { align-items: flex-start; flex-direction: column; }
  .documents-toolbar h1 { font-size: 26px; }
  .document-filters { flex-wrap: wrap; }
  .search-field { flex-basis: calc(100% - 46px); }
  .document-filters select { flex: 1; }
  .document-table th:nth-child(3), .document-table td:nth-child(3) { display: none; }
  .dialog-card { padding: 22px 18px; }
}

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