:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-muted: #eef2f6;
  --text: #111827;
  --muted: #667085;
  --subtle: #98a2b3;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --brand: #155eef;
  --brand-strong: #0f49c8;
  --brand-soft: #eef4ff;
  --success: #067647;
  --success-soft: #ecfdf3;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 12px 24px rgba(16, 24, 40, 0.06);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(21, 94, 239, 0.18);
  outline-offset: 1px;
}

.icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.app-shell.has-right-panel {
  grid-template-columns: 244px minmax(0, 1fr) 376px;
}

.app-shell.wide-workspace .workspace {
  max-width: 1440px;
  width: 100%;
}

.sidebar {
  min-height: 0;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fbfcfe;
  border-right: 1px solid var(--line);
}

.brand {
  min-height: 80px;
  padding: 20px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #101828;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand-title {
  font-size: 15px;
  font-weight: 760;
  letter-spacing: 0;
}

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

.nav {
  padding: 16px 12px;
  display: grid;
  gap: 6px;
}

.nav-label {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 800;
  padding: 0 10px 6px;
}

.nav-item {
  height: 40px;
  border-radius: 8px;
  background: transparent;
  color: #475467;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-weight: 650;
}

.nav-item:hover {
  background: #f1f5f9;
  color: #1f2937;
}

.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.account-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 11px 12px;
}

.account-label {
  font-size: 11px;
  color: var(--subtle);
  font-weight: 800;
}

.account-name {
  margin-top: 5px;
  color: #344054;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-all;
}

.main {
  min-width: 0;
  min-height: 0;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 88px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.title-group {
  min-width: 0;
}

.eyebrow {
  color: var(--brand);
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
}

h1,
h2,
p {
  margin: 0;
}

.topbar h1 {
  margin-top: 5px;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 820;
  letter-spacing: 0;
}

.topbar p,
.section-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.topbar p {
  margin-top: 4px;
}

.api-control {
  display: grid;
  grid-template-columns: auto 280px auto;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.topbar-api-control {
  display: none;
}

.api-control label {
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

.settings-api-control {
  grid-template-columns: 96px minmax(260px, 420px) auto;
  justify-content: start;
}

.workspace {
  flex: 1;
  min-height: 0;
  padding: 20px 24px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 16px;
  align-content: start;
}

.right-panel {
  min-height: 0;
  max-height: 100vh;
  max-height: 100dvh;
  border-left: 1px solid var(--line);
  background: #fff;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
}

.scope-panel {
  display: grid;
  gap: 16px;
}

.scope-head,
.panel-head,
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-title {
  font-size: 14px;
  font-weight: 780;
  line-height: 1.35;
}

.scope-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.metric {
  padding: 10px;
  display: grid;
  gap: 2px;
  background: #fff;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric strong {
  font-size: 19px;
  line-height: 1.1;
}

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

.scope-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-list {
  display: grid;
  gap: 9px;
}

.doc-item {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 11px;
  display: grid;
  gap: 10px;
}

.doc-main {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.doc-main input,
.doc-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--brand);
}

.doc-main input:disabled,
.doc-table input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.doc-name {
  display: block;
  color: #1f2937;
  font-size: 13px;
  font-weight: 730;
  line-height: 1.45;
  word-break: break-all;
}

.doc-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.doc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.work-panel,
.auth-panel,
.auth-intro,
.chat-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.work-panel {
  overflow: hidden;
}

.panel-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-body {
  padding: 18px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

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

.form-grid {
  display: grid;
  gap: 13px;
}

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

.field label {
  color: #344054;
  font-size: 12px;
  font-weight: 760;
}

.field.compact {
  min-width: 120px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 8px;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 11px;
}

textarea {
  min-height: 84px;
  resize: vertical;
  padding: 11px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.12);
}

.secret-input {
  -webkit-text-security: disc;
}

.secret-input:focus {
  -webkit-text-security: none;
}

.btn,
.icon-btn {
  min-height: 38px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 730;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn {
  padding: 0 13px;
  color: #344054;
  background: #fff;
  border: 1px solid var(--line-strong);
}

.btn:hover {
  background: #f8fafc;
}

.btn.primary {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.btn.primary:hover {
  background: var(--brand-strong);
}

.btn.ghost {
  color: #475467;
  background: #fff;
}

.btn.subtle {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: #d6e4ff;
}

.btn.full {
  width: 100%;
}

.btn.fit {
  justify-self: start;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  color: #475467;
  background: #fff;
  border: 1px solid var(--line);
}

.icon-btn:hover {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: #d6e4ff;
}

.icon-btn.danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #fecdca;
}

.status-line {
  min-height: 22px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.status-line:not(:empty) {
  margin-top: 4px;
}

.status-line.error {
  color: var(--danger);
  padding: 8px 10px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: var(--danger-soft);
}

.status-line.success {
  color: var(--success);
  padding: 8px 10px;
  border: 1px solid #abefc6;
  border-radius: 8px;
  background: #ecfdf3;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: #f2f4f7;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.badge.ok {
  color: var(--success);
  background: var(--success-soft);
}

.badge.warn {
  color: var(--warning);
  background: var(--warning-soft);
}

.badge.bad {
  color: var(--danger);
  background: var(--danger-soft);
}

.auth-page {
  min-height: 100vh;
  padding: clamp(24px, 4vw, 56px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 246, 248, 0.96)),
    var(--bg);
  display: grid;
  align-items: center;
}

.auth-layout {
  min-height: calc(100vh - 132px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  align-items: center;
  gap: 16px;
}

.auth-page .auth-layout {
  min-height: 0;
  width: min(1120px, 100%);
  margin: 0 auto;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  gap: 22px;
}

.auth-intro {
  padding: 32px;
  min-height: 520px;
  display: grid;
  align-content: center;
  gap: 18px;
}

.auth-page .auth-intro {
  min-height: 560px;
  border-color: rgba(21, 94, 239, 0.14);
  background:
    linear-gradient(180deg, #ffffff, #f8fbff);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 20px 52px rgba(16, 24, 40, 0.08);
}

.auth-intro h2 {
  max-width: 620px;
  font-size: 30px;
  line-height: 1.2;
  font-weight: 830;
  letter-spacing: 0;
}

.auth-intro p {
  max-width: 640px;
  color: var(--muted);
  line-height: 1.8;
  font-size: 14px;
}

.intro-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.intro-list span,
.chip {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: #344054;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 700;
}

.intro-list .icon {
  color: var(--success);
}

.auth-panel {
  padding: 22px;
  align-self: center;
  display: grid;
  gap: 14px;
}

.auth-page .auth-panel {
  padding: 26px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 18px 44px rgba(16, 24, 40, 0.09);
}

.split-line {
  height: 1px;
  background: var(--line);
  margin: 2px 0;
}

.chat-shell {
  height: calc(100vh - 132px);
  height: calc(100dvh - 132px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr) auto;
  overflow: hidden;
}

.chat-toolbar {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.messages {
  min-height: 0;
  padding: 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  align-content: start;
  gap: 14px;
  background: var(--surface-soft);
}

.message {
  max-width: 86%;
  display: grid;
  gap: 6px;
}

.message.user {
  justify-self: end;
}

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

.message-label {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 800;
}

.message.user .message-label {
  text-align: right;
}

.message-bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px 13px;
  line-height: 1.7;
  font-size: 14px;
  white-space: pre-wrap;
}

.message.user .message-bubble {
  color: #fff;
  background: #1f2937;
  border-color: #1f2937;
}

.prompt-dock {
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fff;
  display: grid;
  gap: 10px;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 30px;
  cursor: pointer;
}

.chip:hover {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: #d6e4ff;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.send-btn {
  min-width: 92px;
}

.knowledge-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 16px;
}

.upload-zone {
  min-height: 124px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fbfdff;
  padding: 18px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  cursor: pointer;
}

.upload-zone:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.upload-zone.dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.upload-zone input {
  display: none;
}

.upload-zone > .icon {
  width: 34px;
  height: 34px;
  color: var(--brand);
}

.upload-zone strong,
.upload-zone small {
  display: block;
}

.upload-zone strong {
  color: #1f2937;
  font-size: 14px;
}

.upload-zone small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.inline-fields {
  display: grid;
  grid-template-columns: 120px auto;
  align-items: end;
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.doc-table th,
.doc-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  color: #344054;
  font-size: 13px;
}

.doc-table th {
  color: #667085;
  background: #f8fafc;
  font-size: 11px;
  font-weight: 850;
}

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

.table-title {
  color: #1f2937;
  font-weight: 760;
  max-width: 520px;
  word-break: break-all;
}

.table-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.table-subtitle.error {
  color: #b42318;
}

.results {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
}

.result-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  display: grid;
  grid-template-columns: 44px auto minmax(0, 1fr);
  gap: 10px;
  color: #344054;
  font-size: 13px;
  line-height: 1.65;
}

.result-rank {
  color: var(--brand);
  font-weight: 850;
}

.evidence-thumb {
  width: 72px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.evidence-title {
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 6px;
}

.evidence-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.message-evidence {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 8px;
}

.evidence-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 12px;
}

.evidence-chip img {
  width: 28px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
}

.settings-grid {
  display: grid;
  gap: 16px;
  max-width: 1180px;
}

.field-hint {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.connection-panel .panel-body {
  display: grid;
  gap: 8px;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  padding: 18px;
}

.empty-state.small {
  padding: 12px 0;
}

.hidden {
  display: none !important;
}

@media (max-width: 1220px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .app-shell.has-right-panel {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .right-panel {
    grid-column: 1 / -1;
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .main,
  .sidebar {
    max-height: none;
    overflow: visible;
  }

  .chat-shell {
    height: auto;
    min-height: 620px;
  }
}

@media (max-width: 860px) {
  .app-shell,
  .auth-layout,
  .knowledge-grid,
  .grid-2,
  .grid-3,
  .composer,
  .inline-fields {
    grid-template-columns: 1fr;
  }

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

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .api-control {
    grid-template-columns: 1fr;
  }

  .auth-page {
    padding: 18px;
    align-items: start;
  }

  .auth-page .auth-layout {
    grid-template-columns: 1fr;
  }

  .auth-page .auth-intro {
    min-height: auto;
  }

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