:root {
  --blue: #204a80;
  --blue-weak: #eaf3ff;
  --blue-soft: #f4f9ff;
  --ink: #17233d;
  --muted: #60719b;
  --line: #e6ebf5;
  --surface: #ffffff;
  --surface-soft: #f7f9fe;
  --green: #17a35c;
  --green-bg: #e6f7ee;
  --red: #e5484d;
  --red-bg: #fdecec;
  --gray-bg: #f2f4f8;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #fff;
}

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

button,
label {
  user-select: none;
}

svg {
  display: block;
}

.app-shell {
  display: grid;
  grid-template-columns: 288px 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.18s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 84px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  min-width: 0;
}

.brand {
  position: relative;
  display: grid;
  grid-template-columns: 52px 1fr 34px;
  gap: 14px;
  align-items: center;
  height: 104px;
  padding: 22px 20px;
}

.brand-mark {
  display: block;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(155, 34, 38, 0.22);
}

.brand-text {
  min-width: 0;
}

.brand-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #5c6b8a;
  cursor: pointer;
}

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

.nav {
  display: grid;
  gap: 10px;
  padding: 14px 14px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.nav-item.active {
  color: var(--blue);
  background: var(--blue-weak);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: currentColor;
  flex: 0 0 auto;
}

.nav-icon svg {
  width: 21px;
  height: 21px;
}

.app-shell.sidebar-collapsed .brand {
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 12px;
  height: auto;
  padding: 18px 12px;
}

.app-shell.sidebar-collapsed .brand-text,
.app-shell.sidebar-collapsed .nav-item span:last-child,
.app-shell.sidebar-collapsed .sidebar-footer {
  display: none;
}

.app-shell.sidebar-collapsed .brand-mark {
  width: 44px;
  height: 44px;
}

.app-shell.sidebar-collapsed .collapse-button {
  order: -1;
}

.app-shell.sidebar-collapsed .nav {
  padding: 18px 12px;
}

.app-shell.sidebar-collapsed .nav-item {
  justify-content: center;
  width: 60px;
  height: 52px;
  padding: 0;
}

.sidebar-footer {
  margin: auto 22px 26px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  color: #7d8bab;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}

.main {
  min-width: 0;
}

.view {
  display: none;
  min-height: 100vh;
}

.view.active {
  display: block;
}

.chat-view.active {
  display: grid;
  grid-template-columns: 356px 1fr;
}

.conversation-panel {
  border-right: 1px solid var(--line);
  background: #fff;
}

.panel-header {
  padding: 28px 28px 14px;
}

.panel-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
}

.docs-header h1 {
  position: relative;
  margin: 0;
  padding-left: 18px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 1px;
}

.docs-header h1::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 30px;
  border-radius: 2px;
  background: var(--blue);
}

.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 48px;
  margin-top: 22px;
  border: 0;
  border-radius: 8px;
  color: var(--blue);
  background: var(--blue-weak);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.new-chat-button svg {
  width: 17px;
  height: 17px;
}

.timeline-label {
  padding: 16px 28px 10px;
  color: #6378a5;
  font-size: 14px;
  font-weight: 700;
}

.timeline-label.earlier {
  padding-top: 30px;
}

.conversation-list {
  display: grid;
  gap: 6px;
  padding: 0 14px;
}

.conversation-row {
  position: relative;
  min-width: 0;
}

.conversation-item {
  position: relative;
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 66px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.conversation-avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: #33415e;
}

.conversation-avatar svg {
  width: 22px;
  height: 22px;
}

.conversation-more-button {
  position: absolute;
  z-index: 2;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
}

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

.conversation-row.active .conversation-more-button {
  display: flex;
}

.conversation-more-button:hover,
.conversation-more-button:focus-visible {
  background: #dceaff;
}

.conversation-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% - 6px);
  right: 8px;
  min-width: 130px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(23, 35, 61, 0.16);
}

.conversation-menu[hidden] {
  display: none;
}

.conversation-delete {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #c93d44;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}

.conversation-delete:hover,
.conversation-delete:focus-visible {
  background: #fff0f0;
}

.conversation-item.active .conversation-time {
  visibility: hidden;
}

.conversation-item.active {
  background: var(--blue-weak);
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
}

.conversation-time {
  color: #93a1bd;
  font-size: 13px;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 100vh;
  background: #fff;
}

.chat-header {
  padding: 24px 32px 18px;
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
}

.chat-header p {
  margin: 8px 0 0;
  color: var(--blue);
  font-size: 14px;
}

.model-picker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.model-picker select {
  max-width: 240px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

.messages {
  min-height: 0;
  padding: 32px 32px 24px;
  overflow: auto;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 26px;
}

.message.user {
  justify-content: flex-end;
}

.message-content {
  min-width: 0;
  max-width: min(920px, 80%);
}

.message-bubble {
  border-radius: 10px;
  padding: 18px 22px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(23, 35, 61, 0.06);
  border: 1px solid #edf1f8;
  font-size: 15px;
  line-height: 1.8;
  overflow-wrap: anywhere;
  white-space: normal;
}

.message.user .message-bubble {
  padding: 14px 20px;
  background: var(--blue-weak);
  border-color: transparent;
  box-shadow: none;
  font-size: 15px;
  font-weight: 600;
  white-space: pre-wrap;
}

.sent-files {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.sent-file {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  font-weight: 500;
}

.sent-file svg { width: 15px; height: 15px; flex: 0 0 auto; }
.sent-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.upload-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 18px;
}

.upload-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  animation: upload-dot-pulse 0.9s ease-in-out infinite;
}

.upload-dots i:nth-child(2) { animation-delay: 0.15s; }
.upload-dots i:nth-child(3) { animation-delay: 0.3s; }

.waiting-bubble {
  display: flex;
  align-items: center;
  min-width: 72px;
  min-height: 48px;
  padding: 14px 20px;
}

.answer-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.answer-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--blue);
  animation: upload-dot-pulse 0.9s ease-in-out infinite;
}

.answer-dots i:nth-child(2) { animation-delay: 0.15s; }
.answer-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes upload-dot-pulse {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .upload-dots i,
  .answer-dots i { animation: none; opacity: 0.8; }
}

.uploaded-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.uploaded-file svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.uploaded-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bot-bubble {
  border-color: transparent;
  box-shadow: none;
  padding: 8px 0 6px;
}

.answer-heading {
  margin-bottom: 8px;
  color: var(--ink);
  font-weight: 700;
}

.answer-body {
  color: #26354f;
  line-height: 1.85;
}

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

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

.answer-body h4 {
  margin: 18px 0 8px;
  color: var(--ink);
  font-size: 15px;
}

.answer-body h4:first-child {
  margin-top: 0;
}

.answer-body ul,
.answer-body ol {
  margin: 4px 0 14px;
  padding-left: 24px;
}

.answer-body li {
  margin: 5px 0;
}

.answer-body blockquote {
  margin: 10px 0 14px;
  padding: 8px 14px;
  border-left: 3px solid #a9cbff;
  border-radius: 0 6px 6px 0;
  background: #f6f9ff;
  color: #4d5f7e;
}

.answer-body code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #f2f5fa;
  font-size: 0.92em;
}

.citation-ref {
  color: var(--blue);
  font-weight: 700;
  white-space: nowrap;
}

.sources-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f9fbff;
}

.sources-panel summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  color: #526581;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.sources-panel summary::-webkit-details-marker {
  display: none;
}

.sources-panel summary::before {
  content: "›";
  color: var(--blue);
  font-size: 20px;
  line-height: 1;
  transition: transform 0.15s ease;
}

.sources-panel[open] summary::before {
  transform: rotate(90deg);
}

.sources-panel summary span {
  color: #8393ac;
  font-weight: 500;
}

.sources-content {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.bot-avatar,
.user-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--blue-weak);
  color: var(--blue);
  flex: 0 0 auto;
}

.bot-avatar svg,
.user-avatar svg {
  width: 24px;
  height: 24px;
}

.message.user .user-avatar {
  order: 2;
}

.answer-table {
  width: 100%;
  margin: 14px 0;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.answer-result {
  margin-top: 16px;
}

.answer-result-title {
  font-weight: 700;
}

.answer-source,
.source-cell {
  color: #60749d;
  font-size: 12px;
}

.answer-source {
  margin-top: -4px;
}

.source-cell {
  white-space: nowrap;
}

.send-button:disabled {
  opacity: .6;
  cursor: wait;
}

.notice {
  position: fixed;
  z-index: 20;
  right: 24px;
  bottom: 22px;
  max-width: min(480px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid #b9dfc9;
  border-radius: 6px;
  background: #f0fff5;
  color: #155c37;
  box-shadow: 0 8px 22px rgba(23, 35, 61, .12);
}

.notice.error {
  border-color: #f4b8b8;
  background: #fff4f4;
  color: #a92323;
}

.answer-table th,
.answer-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

.answer-table td {
  border-right: 0;
}

.answer-table th {
  width: 110px;
  background: var(--surface-soft);
  font-weight: 700;
}

.answer-table tr:last-child th,
.answer-table tr:last-child td {
  border-bottom: 0;
}

.message-time {
  color: #93a1bd;
  text-align: right;
  font-size: 13px;
  margin-top: 8px;
}

.composer {
  margin: 0 32px 28px;
  border: 1px solid #e2e8f4;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(23, 35, 61, 0.06);
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 72px;
  padding: 16px 20px 4px;
  border: 0;
  resize: none;
  outline: 0;
  color: var(--ink);
  font-size: 15px;
}

.composer textarea::placeholder,
.search-field input::placeholder {
  color: #9aa8c7;
}

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 8px;
}

.chat-attachments:empty {
  display: none;
}

.chat-upload-attachment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid #d9e5f5;
  border-radius: 8px;
  background: #f5f8fe;
  color: #2c3a55;
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
}

.chat-upload-content {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.chat-attachment-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.chat-attachment-remove:hover {
  background: #e5edf9;
  color: #cc2a2a;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 8px 14px 12px 18px;
}

.upload-inline,
.primary-upload {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 700;
}

.upload-inline {
  color: #2c3a55;
  font-size: 15px;
}

.upload-inline svg {
  width: 18px;
  height: 18px;
}

.upload-inline input[type="file"],
.primary-upload input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  outline: 0;
}

.send-button,
.action-button,
.primary-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(32, 74, 128, 0.25);
}

.send-button svg,
.primary-upload svg {
  width: 17px;
  height: 17px;
}

.send-button {
  min-width: 102px;
}

.primary-upload {
  min-width: 168px;
  height: 52px;
  border-radius: 6px;
}

.docs-view {
  background: #fff;
}

.docs-inner {
  max-width: 1680px;
  margin: 0 auto;
  padding: 40px 48px;
}

.docs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}

.docs-header p {
  margin: 12px 0 0;
  color: #5a6a8c;
  font-size: 16px;
  font-weight: 500;
}

.filters {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 32px 0 24px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 480px;
  height: 52px;
  padding: 0 16px;
  border: 1px solid #d9e1ef;
  border-radius: 6px;
  color: #93a1bd;
}

.search-field svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.search-field input,
.filters select {
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search-field input {
  width: 100%;
  font-size: 16px;
}

.filters select {
  width: 168px;
  height: 52px;
  padding: 0 18px;
  border: 1px solid #d9e1ef;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-size: 16px;
  font-weight: 600;
}

.action-button,
.ghost-button {
  min-width: 104px;
  height: 52px;
  border-radius: 6px;
  font-size: 16px;
  box-shadow: none;
}

.ghost-button {
  border: 1px solid #d9e1ef;
  color: var(--ink);
  background: #fff;
  font-weight: 600;
  cursor: pointer;
}

.table-wrap {
  border: 1px solid #d9e1ef;
  border-radius: 4px;
  overflow: hidden;
}

.documents-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.documents-table th,
.documents-table td {
  height: 68px;
  padding: 0 32px;
  border-bottom: 1px solid #e3e9f3;
  text-align: left;
  vertical-align: middle;
}

.documents-table th {
  height: 58px;
  color: #3c4a63;
  background: #f3f6fb;
  font-size: 16px;
  font-weight: 700;
  border-bottom: 1px solid #d9e1ef;
}

.documents-table tr:last-child td {
  border-bottom: 0;
}

.doc-name {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background: var(--blue-weak);
  color: var(--blue);
  flex: 0 0 auto;
}

.file-icon svg {
  width: 22px;
  height: 22px;
}

.doc-name span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  height: 34px;
  padding: 0 14px;
  border-radius: 4px;
  font-size: 15px;
  font-weight: 700;
}

.status-pill.done {
  color: var(--green);
  background: var(--green-bg);
}

.status-pill.running {
  color: var(--blue);
  background: var(--blue-weak);
}

.status-pill.waiting {
  color: #6d7485;
  background: var(--gray-bg);
}

.status-pill.failed {
  color: #c92f34;
  background: var(--red-bg);
}

.doc-time {
  color: #3c4a63;
  font-size: 16px;
}

.delete-button {
  border: 0;
  color: var(--red);
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.document-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  white-space: nowrap;
}

.preview-button {
  color: var(--blue);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}

.preview-button:hover {
  text-decoration: underline;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  padding: 24px 0 4px;
}

.page-button {
  display: grid;
  place-items: center;
  min-width: 42px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid #cfe0f7;
  border-radius: 7px;
  color: #3c4a63;
  background: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

.page-button.page-nav {
  min-width: 76px;
  padding: 0 15px;
}

.page-button.active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
  font-weight: 700;
}

.page-button:not(.active):not(:disabled):hover {
  color: var(--blue);
  border-color: var(--blue);
  background: var(--blue-soft);
}

.page-button:disabled {
  color: #9aa9bf;
  background: #fbfcfe;
  cursor: not-allowed;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .chat-view.active {
    grid-template-columns: 1fr;
  }

  .conversation-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .conversation-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .docs-header,
  .filters {
    flex-wrap: wrap;
  }

  .search-field {
    width: 100%;
  }

  .documents-table {
    min-width: 860px;
  }
}
