:root {
  color: #1f2937;
  background: #f3f5f7;
  font-family:
    "PingFang SC",
    "Microsoft YaHei",
    "Noto Sans CJK SC",
    system-ui,
    -apple-system,
    sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.boot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #6366f1;
}

.boot-screen strong {
  font-size: 28px;
}

.boot-screen span {
  color: #667085;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  background: #eef2f4;
}

.login-card {
  width: min(100%, 460px);
  background: #ffffff;
  border: 1px solid #d9e0e5;
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 12px 30px rgba(31, 41, 55, 0.08);
}

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

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #6366f1;
  color: #ffffff;
  font-weight: 700;
}

.login-card .brand-block {
  margin-bottom: 22px;
}

.login-card h1 {
  margin: 0;
  font-size: 22px;
}

.login-card p {
  margin: 2px 0 0;
  color: #667085;
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #344054;
  font-size: 14px;
}

.login-form input,
.share-cell input {
  height: 40px;
  border: 1px solid #cfd8de;
  border-radius: 6px;
  padding: 0 12px;
  background: #ffffff;
  color: #1f2937;
}

.login-form input:focus,
.share-cell input:focus {
  outline: 2px solid rgba(99, 102, 241, 0.2);
  border-color: #6366f1;
}

.primary-button {
  height: 42px;
  border: 0;
  border-radius: 6px;
  background: #6366f1;
  color: #ffffff;
  font-weight: 600;
}

.form-error,
.inline-error {
  color: #b42318;
}

.demo-accounts {
  margin-top: 22px;
}

.section-title {
  color: #344054;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
}

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

.account-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 58px;
  border: 1px solid #d9e0e5;
  border-radius: 6px;
  padding: 10px 12px;
  background: #f8fafb;
  color: #1f2937;
  text-align: left;
}

.account-chip:hover {
  border-color: #6366f1;
  background: #eef2ff;
}

.account-chip small {
  color: #667085;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 224px;
  flex: 0 0 224px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-right: 1px solid #d9e0e5;
}

.sidebar-brand {
  height: 64px;
  padding: 0 16px;
  border-bottom: 1px solid #e7ecef;
  font-weight: 700;
  color: #1f2937;
}

.side-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px;
}

.side-nav button {
  height: 42px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: transparent;
  color: #475467;
  text-align: left;
}

.side-nav button:hover {
  background: #eef2ff;
  color: #6366f1;
}

.side-nav button.active {
  background: #6366f1;
  color: #ffffff;
  font-weight: 600;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid #e7ecef;
  padding: 14px 16px;
}

.sidebar-user div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-user strong,
.sidebar-user span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user strong {
  font-size: 14px;
}

.sidebar-user span {
  color: #667085;
  font-size: 12px;
}

.text-button {
  border: 0;
  background: transparent;
  color: #475467;
  font-size: 13px;
}

.text-button:hover {
  color: #b42318;
}

.main-panel {
  flex: 1;
  min-width: 0;
  background: #f3f5f7;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: #ffffff;
  border-bottom: 1px solid #d9e0e5;
}

.topbar h2 {
  margin: 0;
  font-size: 18px;
}

.topbar-meta {
  display: flex;
  gap: 8px;
  color: #667085;
  font-size: 13px;
}

.topbar-meta span + span::before {
  content: "·";
  margin-right: 8px;
  color: #98a2b3;
}

.page-content {
  padding: 24px;
}

.page-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1180px;
  margin: 0 auto;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-heading h3 {
  margin: 0;
  font-size: 20px;
}

.page-heading p {
  margin: 4px 0 0;
  color: #667085;
  font-size: 13px;
}

.heading-extra {
  flex: 0 0 auto;
}

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

.metric-cell {
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
  background: #ffffff;
  border: 1px solid #d9e0e5;
  border-radius: 8px;
}

.metric-cell span {
  color: #667085;
  font-size: 13px;
}

.metric-cell strong {
  color: #6366f1;
  font-size: 24px;
}

.panel {
  background: #ffffff;
  border: 1px solid #d9e0e5;
  border-radius: 8px;
  padding: 16px;
}

.empty-panel {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #667085;
}

.empty-panel h3 {
  margin: 0 0 6px;
  color: #344054;
}

.empty-panel p {
  margin: 0;
}

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

.data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  padding: 10px 12px;
  color: #667085;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid #e7ecef;
}

.data-table td {
  padding: 12px;
  vertical-align: top;
  border-bottom: 1px solid #eef1f3;
}

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

.data-table td:first-child {
  min-width: 180px;
}

.cell-description {
  display: block;
  margin-top: 4px;
  color: #667085;
}

.count-badge,
.scope-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 6px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.count-badge {
  min-width: 32px;
  justify-content: center;
  background: #eef2ff;
  color: #6366f1;
}

.scope-badge {
  background: #eff8ff;
  color: #175cd3;
}

.status-badge {
  background: #f2f4f7;
  color: #475467;
}

.muted-text {
  color: #98a2b3;
}

.share-cell {
  min-width: 180px;
}

.share-cell form {
  display: flex;
  gap: 6px;
}

.share-cell input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  font-size: 13px;
}

.share-cell button {
  height: 34px;
  border: 1px solid #6366f1;
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  color: #6366f1;
  white-space: nowrap;
}

.share-cell button:hover {
  background: #eef2ff;
}

.share-cell .inline-error {
  display: block;
  margin-top: 6px;
  font-size: 12px;
}

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

.tool-tile {
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px;
  background: #ffffff;
  border: 1px solid #d9e0e5;
  border-radius: 8px;
}

.tool-tile strong {
  color: #1f2937;
}

.tool-tile span {
  color: #98a2b3;
  font-size: 13px;
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid #d9e0e5;
  }

  .sidebar-brand {
    height: 56px;
  }

  .side-nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 10px;
  }

  .side-nav button {
    flex: 0 0 auto;
    width: auto;
    padding: 0 12px;
  }

  .sidebar-user {
    border-top: 1px solid #e7ecef;
  }

  .topbar,
  .page-content {
    padding-left: 14px;
    padding-right: 14px;
  }

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

@media (max-width: 560px) {
  .account-list,
  .metric-grid,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .page-heading,
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    height: auto;
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

.table-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.table-actions button,
.download-button {
  min-height: 30px;
  border: 1px solid #6366f1;
  border-radius: 6px;
  padding: 0 9px;
  background: #ffffff;
  color: #6366f1;
  white-space: nowrap;
}

.table-actions button.active,
.table-actions button:hover,
.download-button:hover {
  background: #6366f1;
  color: #ffffff;
}

.guide-list {
  margin: 8px 0 14px;
  padding-left: 20px;
  color: #475467;
  font-size: 13px;
}

.import-form,
.ask-form,
.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.import-form input {
  flex: 1;
  min-width: 0;
}

.import-form button,
.ask-form button,
.chat-form button {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid #6366f1;
  border-radius: 6px;
  padding: 0 14px;
  background: #6366f1;
  color: #ffffff;
  font-weight: 600;
}

.ask-form,
.chat-form {
  align-items: stretch;
}

.ask-form textarea,
.chat-form textarea {
  flex: 1;
  min-height: 64px;
  resize: vertical;
  border: 1px solid #cfd8de;
  border-radius: 6px;
  padding: 10px 12px;
  color: #1f2937;
}

.answer-block {
  margin-top: 16px;
  border-top: 1px solid #e7ecef;
  padding-top: 14px;
}

.answer-text {
  color: #1f2937;
  line-height: 1.7;
  white-space: pre-wrap;
}

.reasoning-details {
  margin-top: 10px;
  color: #667085;
  font-size: 13px;
}

.reasoning-details summary {
  cursor: pointer;
  color: #6366f1;
  font-weight: 600;
}

.reasoning-list {
  margin: 8px 0 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.reasoning-list li strong {
  display: inline-block;
  min-width: 90px;
  color: #344054;
}

.source-list {
  margin-top: 12px;
}

.source-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.source-anchor {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  border: 1px solid #d9e0e5;
  border-radius: 6px;
  padding: 10px 12px;
  background: #f8fafb;
  color: #1f2937;
  text-align: left;
}

.source-anchor:hover {
  border-color: #6366f1;
  background: #eef2ff;
}

.source-anchor > span:first-child {
  flex: 0 0 180px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.source-anchor small {
  display: block;
  margin-top: 4px;
  color: #667085;
}

.source-preview {
  flex: 1;
  min-width: 0;
  color: #475467;
  font-size: 13px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(31, 41, 55, 0.32);
}

.chunk-modal {
  width: min(100%, 760px);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: #ffffff;
  border: 1px solid #d9e0e5;
  border-radius: 8px;
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head button {
  border: 0;
  background: transparent;
  color: #475467;
}

.chunk-content {
  margin: 14px 0;
  padding: 14px;
  background: #f8fafb;
  border: 1px solid #e7ecef;
  border-radius: 6px;
  line-height: 1.8;
  white-space: pre-wrap;
}

.disclaimer {
  margin: 12px 0 0;
  color: #b42318;
  font-size: 12px;
}

.model-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.model-row .muted-text {
  margin: 0;
  white-space: nowrap;
}

.scope-select {
  min-height: 36px;
  border: 1px solid #cfd8de;
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  color: #1f2937;
}

.chat-panel {
  min-height: 560px;
  display: flex;
  flex-direction: column;
}

.chat-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}

.chat-message {
  max-width: 78%;
  border-radius: 8px;
  padding: 12px 14px;
}

.chat-message.user {
  align-self: flex-end;
  background: #6366f1;
  color: #ffffff;
}

.chat-message.assistant {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid #d9e0e5;
  color: #1f2937;
}

.chat-message strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.chat-message p {
  margin: 0;
  line-height: 1.7;
  white-space: pre-wrap;
}

.chat-message .answer-block {
  border-top-color: rgba(99, 102, 241, 0.2);
}

.chat-message.user .answer-block {
  display: none;
}

@media (max-width: 720px) {
  .import-form,
  .ask-form,
  .chat-form {
    flex-direction: column;
    align-items: stretch;
  }

  .source-anchor {
    flex-direction: column;
  }

  .source-anchor > span:first-child {
    flex-basis: auto;
  }

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

/* SOP 逐点自查 */
.sop-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sop-step {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 14px;
  background: #ffffff;
}

.sop-step.found {
  border-left: 3px solid #16a34a;
}

.sop-step.missing {
  border-left: 3px solid #f59e0b;
}

.sop-step-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.sop-step-head span {
  font-size: 0.85em;
  color: #6b7280;
}

.sop-evidence {
  font-size: 0.9em;
  color: #374151;
  background: #f3f4f6;
  border-radius: 6px;
  padding: 6px 10px;
  margin-top: 6px;
  border-left: 2px solid #9ca3af;
}

/* ═══════════ 品牌紫 · 卡片语言(生哥设计语言) ═══════════ */
.login-page {
  background: linear-gradient(135deg, #eef2ff 0%, #f6f7fb 55%, #eef2ff 100%);
}

.brand-mark {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.28);
}

.primary-button {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.primary-button:hover {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

.side-nav button.active {
  background: linear-gradient(135deg, #6366f1 0%, #7c6cf0 100%);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.import-form button,
.ask-form button,
.chat-form button {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.chat-message.user {
  background: linear-gradient(135deg, #6366f1 0%, #7c6cf0 100%);
}

/* 卡片:顶部细条 + hover 上浮紫边 */
.metric-cell,
.tool-tile {
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.metric-cell::before,
.tool-tile::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
}

.metric-cell:hover,
.tool-tile:hover {
  transform: translateY(-2px);
  border-color: #6366f1;
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.12);
}

/* 新建 SOP 表单 */
.sop-create-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sop-create-form input,
.sop-create-form textarea {
  border: 1px solid #cfd8de;
  border-radius: 6px;
  padding: 8px 12px;
  color: #1f2937;
  font: inherit;
}

.sop-create-form textarea {
  resize: vertical;
}

.sop-create-form button {
  align-self: flex-start;
  min-height: 38px;
  border: 1px solid #6366f1;
  border-radius: 6px;
  padding: 0 14px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #ffffff;
  font-weight: 600;
}
