:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-blue: #f0f7ff;
  --text: #172033;
  --text-soft: #526173;
  --muted: #7a8798;
  --border: #d9e2ee;
  --border-strong: #c5d2e3;
  --primary: #1264d8;
  --primary-hover: #0d55ba;
  --primary-soft: #e8f1ff;
  --success: #0f8a61;
  --success-soft: #e8f7ef;
  --warning: #b8750d;
  --warning-soft: #fff6df;
  --danger: #c5374a;
  --danger-soft: #fff0f3;
  --shadow: 0 12px 32px rgba(20, 38, 68, .10);
  --shadow-soft: 0 6px 18px rgba(20, 38, 68, .07);
  --radius: 10px;
  --radius-sm: 8px;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  width: 100%;
  min-width: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
}

body {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 3px;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 800;
}

h2 {
  margin-top: 4px;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 800;
}

p {
  margin-top: 6px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.65;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  width: min(1680px, calc(100vw - 28px));
  height: 100vh;
  margin: 0 auto;
  padding: 14px 0 18px;
}

.auth-gate {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(248, 250, 252, .94), rgba(238, 243, 248, .96)),
    radial-gradient(circle at top left, rgba(18, 100, 216, .10), transparent 32%);
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  width: min(900px, 100%);
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 20px 50px rgba(15, 23, 42, .10);
}

.auth-intro {
  display: grid;
  align-content: center;
  min-height: 330px;
  padding: 28px;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid #edf2f7;
}

.auth-intro h1 {
  max-width: 520px;
  margin-top: 8px;
  color: #0f172a;
  font-size: 28px;
  letter-spacing: 0;
}

.auth-intro p {
  max-width: 560px;
  font-size: 14px;
  line-height: 1.7;
}

.auth-assurance {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.auth-assurance span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  color: #334155;
  border: 1px solid #dbe6f4;
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
}

.auth-system-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.auth-panel {
  align-self: center;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.auth-panel-head {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
}

.auth-panel-head span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.auth-panel-head strong {
  color: #0f172a;
  font-size: 18px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 18px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.auth-tab {
  min-height: 44px;
  color: var(--text-soft);
  border-radius: 6px;
  background: transparent;
  font-weight: 800;
}

.auth-tab.is-active {
  color: var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.form-note {
  margin: -2px 0 2px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.6;
}

.auth-form .primary-action {
  width: 100%;
  min-height: 46px;
  margin-top: 2px;
}

.auth-message {
  min-height: 24px;
  margin-top: 14px;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.55;
}

.permission-note {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  margin-top: 10px;
  padding: 5px 10px;
  color: #8a4b16;
  border: 1px solid #fed7aa;
  border-radius: var(--radius-sm);
  background: #fff7ed;
  font-size: 13px;
  font-weight: 700;
}

.permission-note.is-ready {
  color: var(--success);
  border-color: #b7e4cc;
  background: var(--success-soft);
}

.permission-note:empty {
  display: none;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
  min-height: 86px;
}

.scope-rule-bar {
  flex: none;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px 6px 12px;
  border: 1px solid #cfe0f5;
  border-radius: var(--radius-sm);
  background: #f8fbff;
}

.scope-rule-bar > div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.scope-rule-bar strong {
  flex: none;
  color: #12345a;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 900;
}

.scope-rule-bar span {
  min-width: 0;
  overflow: hidden;
  color: #5e6f85;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scope-rule-bar button {
  flex: none;
  min-height: 28px;
  padding: 0 10px;
  color: var(--primary);
  border: 1px solid #bfd6fb;
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.scope-rule-bar button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.title-block,
.masthead-stats,
.top-actions,
.process-rail,
.flow-section,
.context-card,
.knowledge-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.title-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 14px 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 14px;
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(18, 100, 216, .16);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.contact-admin-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 14px;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.session-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.ai-status-badge,
.ocr-status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  min-width: 144px;
  padding: 0 14px;
  border: 1px solid #dbe6f4;
  border-radius: 999px;
  background: #f8fafc;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.ai-status-badge {
  min-width: 168px;
}

.ocr-status-badge {
  min-width: 146px;
}

.ai-status-badge::before,
.ocr-status-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, .16);
}

.ai-status-badge.is-connected,
.ocr-status-badge.is-connected {
  color: #075f43;
  border-color: #bfe8d1;
  background: #f0fbf5;
}

.ai-status-badge.is-connected::before,
.ocr-status-badge.is-connected::before {
  background: #0f8a61;
  box-shadow: 0 0 0 3px rgba(15, 138, 97, .16);
}

.ai-status-badge.is-disconnected,
.ocr-status-badge.is-disconnected {
  color: #7c2d12;
  border-color: #fed7aa;
  background: #fffaf4;
}

.ai-status-badge.is-disconnected::before,
.ocr-status-badge.is-disconnected::before {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .18);
}

.ai-status-badge.is-checking,
.ocr-status-badge.is-checking {
  color: #334155;
  border-color: #cbd5e1;
  background: #f8fafc;
}

.ai-status-badge.is-checking::before,
.ocr-status-badge.is-checking::before {
  background: #64748b;
  box-shadow: 0 0 0 3px rgba(100, 116, 139, .14);
}

.session-user {
  max-width: 180px;
  padding: 8px 10px;
  overflow: hidden;
  color: var(--text-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-action {
  min-height: 42px;
  padding: 0 14px;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(18, 100, 216, .28);
  outline-offset: 2px;
}

.settings-button:hover {
  border-color: var(--primary-hover);
  background: var(--primary-hover);
}

.settings-button.is-connected {
  color: #06734f;
  border-color: #a7dfc2;
  background: #e8f7ef;
  box-shadow: none;
}

.settings-button.is-connected:hover {
  color: #075f43;
  border-color: #7fcca4;
  background: #dcf3e8;
}

.contact-admin-button:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.brand-avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  overflow: hidden;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  background: #eff6ff;
}

.brand-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.masthead-stats {
  display: grid;
  grid-template-columns: repeat(3, 84px);
  gap: 8px;
  padding: 9px;
}

.masthead-stat {
  display: grid;
  place-items: center;
  min-height: 64px;
  padding: 7px 8px;
  border: 1px solid #e3ebf5;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.masthead-stat strong {
  color: var(--primary);
  font-size: 20px;
  line-height: 1;
  font-weight: 900;
}

.masthead-stat span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.top-actions,
.button-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.top-actions {
  padding: 12px;
}

.workbench-grid {
  display: grid;
  grid-template-columns: 220px 242px minmax(0, 1fr) 320px;
  gap: 14px;
  min-height: 0;
}

.history-panel,
.process-rail,
.stage,
.context-panel {
  min-width: 0;
  min-height: 0;
}

.process-rail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow: auto;
}

.history-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 9px;
  padding: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fbfdff 0%, #f6f9fd 100%);
  box-shadow: var(--shadow-soft);
}

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

.history-head > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.history-head strong {
  color: #0f2747;
  font-size: 14px;
  line-height: 1.25;
  font-weight: 900;
}

.history-head span {
  color: #6b7b8f;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 700;
}

.history-new,
.history-delete {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #bfd6fb;
  border-radius: var(--radius-sm);
  color: var(--primary);
  background: #eef6ff;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.history-actions {
  display: grid;
  gap: 8px;
}

.history-new {
  width: 100%;
  color: #ffffff;
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: 0 10px 20px rgba(21, 104, 218, .16);
}

.history-new:hover {
  border-color: #0f58c4;
  background: #0f58c4;
}

.history-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.history-empty {
  min-height: 62px;
  display: grid;
  place-items: center;
  padding: 10px;
  color: #748297;
  text-align: center;
  border: 1px dashed #cbd8e8;
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 12px;
  line-height: 1.5;
  font-weight: 700;
}

.history-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 9px;
  color: var(--text);
  text-align: left;
  border: 1px solid #e0e8f2;
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.history-item:hover {
  border-color: #bdd4f5;
  background: #f8fbff;
}

.history-item.is-active {
  border-color: #e0b760;
  background: #fff8e8;
  box-shadow: inset 3px 0 0 var(--warning);
}

.history-item.is-progress {
  border-color: #efd59a;
  background: #fffaf0;
}

.history-item.is-progress.is-active {
  border-color: #d8a938;
  box-shadow: inset 3px 0 0 var(--warning);
}

.history-item.is-complete {
  border-color: #b8e1ce;
  background: #f2fbf6;
}

.history-item.is-complete.is-active {
  border-color: #73c69d;
  box-shadow: inset 3px 0 0 var(--success);
}

.history-item.is-return {
  border-color: #f4bdc6;
  background: #fff4f6;
}

.history-item.is-return.is-active {
  border-color: #e18291;
  box-shadow: inset 3px 0 0 var(--danger);
}

.history-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 3px var(--warning-soft);
}

.history-dot.is-complete {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-soft);
}

.history-dot.is-return {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.history-dot.is-warning {
  background: #d97706;
  box-shadow: 0 0 0 3px #fff7ed;
}

.history-main {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.history-main strong,
.history-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-main strong {
  color: #12233d;
  font-size: 13px;
  line-height: 1.25;
  font-weight: 900;
}

.history-main small {
  color: #66778c;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 700;
}

.history-delete {
  width: 100%;
  color: var(--danger);
  border-color: #f2c6ce;
  background: #fff5f7;
}

.history-delete:hover:not(:disabled) {
  border-color: #e895a3;
  background: #fff0f3;
}

.history-delete:disabled {
  color: #9aa6b5;
  border-color: #dfe6ef;
  background: #f6f8fb;
  cursor: not-allowed;
}

.rail-head,
.rail-foot {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid #dbeafe;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
}

.rail-head strong,
.rail-foot strong {
  font-size: 15px;
  font-weight: 800;
}

.rail-head span,
.rail-foot span {
  color: #5b6b80;
  font-size: 12px;
  font-weight: 700;
}

.rail-foot {
  margin-top: auto;
  background: var(--surface-soft);
  border-color: #e3ebf5;
}

.rail-step {
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  grid-template-areas:
    "num label"
    "num hint";
  align-items: center;
  column-gap: 10px;
  width: 100%;
  min-height: 66px;
  padding: 10px 11px;
  color: var(--text-soft);
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, box-shadow .16s ease, color .16s ease;
}

.rail-step:hover {
  color: var(--text);
  border-color: #dbeafe;
  background: #f7fbff;
}

.rail-step.is-active {
  color: var(--text);
  border-color: #b9d3ff;
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.rail-step.is-done {
  border-color: #cdebdc;
  background: #f2fbf6;
}

.rail-step.is-locked {
  opacity: .55;
  cursor: not-allowed;
}

.rail-step.is-return-skip {
  opacity: 1;
  color: #991b1b;
  border-color: #fecaca;
  background: #fff1f2;
  box-shadow: inset 3px 0 0 #ef4444;
}

.rail-step.is-return-skip b {
  color: #fff;
  background: #ef4444;
}

.rail-step.is-return-skip small {
  color: #b91c1c;
  font-weight: 800;
}

.rail-step b {
  grid-area: num;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #64748b;
  border-radius: 50%;
  background: #edf2f7;
  font-size: 13px;
  font-weight: 900;
}

.rail-step.is-active b {
  color: #fff;
  background: var(--primary);
}

.rail-step.is-done b {
  color: #fff;
  background: var(--success);
}

.rail-step span {
  grid-area: label;
  font-size: 14px;
  font-weight: 800;
}

.rail-step small {
  grid-area: hint;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.stage {
  overflow: hidden;
}

.flow-section {
  display: none;
  height: 100%;
  padding: 18px;
  overflow: auto;
  box-shadow: var(--shadow);
}

.flow-section.is-active {
  display: block;
}

#step-3.flow-section.is-active {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 0;
  overflow: hidden;
}

.flow-section::-webkit-scrollbar,
.process-rail::-webkit-scrollbar,
.history-list::-webkit-scrollbar,
.context-panel::-webkit-scrollbar {
  width: 8px;
}

.flow-section::-webkit-scrollbar-thumb,
.process-rail::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb,
.context-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #bfccdc;
}

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

.flow-section .section-head {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.section-head > div {
  min-width: 0;
}

.section-head span,
.block-title span,
.context-head span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.context-head b {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  color: var(--primary);
  border-radius: 999px;
  background: var(--primary-soft);
  font-size: 11px;
  font-weight: 800;
}

.intake-grid {
  display: grid;
  grid-template-columns: minmax(210px, .38fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.image-upload,
.image-preview {
  min-height: 142px;
  border-radius: var(--radius-sm);
}

.image-upload {
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 18px;
  color: var(--primary);
  text-align: center;
  border: 1px dashed #9ec5ff;
  background: linear-gradient(180deg, #f8fbff 0%, #f4f8ff 100%);
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, box-shadow .16s ease;
}

.image-upload:hover,
.image-upload.is-dragging {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(18, 100, 216, .10);
}

.image-upload input {
  display: none;
}

.image-upload span {
  font-size: 16px;
  font-weight: 900;
}

.image-upload small {
  max-width: 250px;
  color: #475569;
  font-size: 12px;
  line-height: 1.7;
}

.image-preview {
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 13px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  max-height: 220px;
  object-fit: contain;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.field span {
  color: #334155;
  font-size: 13px;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  background: #fff;
  transition: border-color .16s ease, box-shadow .16s ease;
}

input {
  min-height: 42px;
  padding: 0 11px;
  font-size: 14px;
}

textarea {
  min-height: 92px;
  padding: 10px 11px;
  font-size: 14px;
  line-height: 1.65;
  resize: vertical;
}

.large-input {
  min-height: 350px;
}

input:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(18, 100, 216, .14);
}

.raw-text-field {
  position: relative;
}

.raw-text-field.is-recognizing textarea {
  opacity: .5;
}

.ocr-progress {
  position: absolute;
  inset: 31px 10px 10px;
  z-index: 2;
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 18px;
  border: 1px solid #b9d3ff;
  border-radius: var(--radius-sm);
  background: rgba(247, 251, 255, .94);
}

.ocr-progress[hidden] {
  display: none;
}

.ocr-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--primary);
  font-size: 14px;
}

.ocr-progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbeafe;
}

.ocr-progress-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width .16s ease;
}

.primary-action,
.secondary-action,
.ghost-action,
.copy-button {
  min-height: 42px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease, opacity .16s ease;
}

.primary-action {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(18, 100, 216, .18);
}

.primary-action:hover {
  background: var(--primary-hover);
}

.secondary-action {
  color: var(--primary);
  border: 1px solid #b9d3ff;
  background: var(--primary-soft);
}

.secondary-action:hover {
  border-color: var(--primary);
  background: #dcedff;
}

.ghost-action,
.copy-button {
  color: var(--text-soft);
  border: 1px solid var(--border);
  background: #fff;
}

.ghost-action:hover,
.copy-button:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-soft);
}

button:disabled {
  opacity: .48;
  cursor: not-allowed;
  box-shadow: none;
}

.ai-result-panel {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 128px;
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid #b9d3ff;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface-blue);
}

.ai-orbit {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--primary);
}

.ai-orbit::before,
.ai-orbit::after {
  content: "";
  position: absolute;
  border-radius: 999px;
}

.ai-orbit::before {
  inset: 15px;
  background: #fff;
}

.ai-orbit::after {
  inset: 8px;
  border: 2px solid rgba(255, 255, 255, .72);
  border-top-color: transparent;
}

.ai-result-panel > div:not(.ai-orbit) {
  min-width: 0;
}

.ai-result-panel span {
  display: block;
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.ai-result-panel strong {
  display: block;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 900;
}

.ai-result-panel p {
  max-width: 760px;
}

.ai-result-panel.is-pass {
  border-color: #bee5cf;
  border-left-color: var(--success);
  background: var(--success-soft);
}

.ai-result-panel.is-pass .ai-orbit {
  background: var(--success);
}

.ai-result-panel.is-return {
  border-color: #f2d58f;
  border-left-color: var(--warning);
  background: var(--warning-soft);
}

.ai-result-panel.is-return .ai-orbit {
  background: var(--warning);
}

.ai-result-panel.is-missing {
  border-color: #f3c1cb;
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.ai-result-panel.is-missing .ai-orbit {
  background: var(--danger);
}

.ai-result-panel.is-pass span,
.ai-result-panel.is-pass strong {
  color: var(--success);
}

.ai-result-panel.is-return span,
.ai-result-panel.is-return strong {
  color: var(--warning);
}

.ai-result-panel.is-missing span,
.ai-result-panel.is-missing strong {
  color: var(--danger);
}

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

.decision-card {
  min-height: 126px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  opacity: .72;
  transition: border-color .16s ease, box-shadow .16s ease, opacity .16s ease, background .16s ease;
}

.decision-card.is-selected {
  opacity: 1;
  border-color: #b9d3ff;
  background: var(--surface-blue);
  box-shadow: inset 3px 0 0 var(--primary), var(--shadow-soft);
}

.decision-card b {
  display: block;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 900;
}

.decision-card.is-selected b::after {
  content: "AI结果";
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-left: 8px;
  padding: 0 7px;
  color: #fff;
  border-radius: 999px;
  background: var(--primary);
  font-size: 11px;
  vertical-align: middle;
}

.decision-card span {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.65;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  min-width: 88px;
  padding: 0 12px;
  color: var(--primary);
  border-radius: 999px;
  background: var(--primary-soft);
  font-size: 13px;
  font-weight: 900;
}

.status-pill.is-pass {
  color: var(--success);
  background: var(--success-soft);
}

.status-pill.is-return {
  color: var(--warning);
  background: var(--warning-soft);
}

.status-pill.is-missing {
  color: var(--danger);
  background: var(--danger-soft);
}

.knowledge-panel {
  padding: 14px;
  margin-top: 14px;
}

.knowledge-panel[hidden],
.return-fields[hidden],
.tab-panel[hidden] {
  display: none;
}

.output-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.tab-button {
  width: 100%;
  min-height: 42px;
  min-width: 0;
  padding: 0 12px;
  color: var(--text-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease;
}

.tab-button:hover {
  color: var(--primary);
  border-color: #dbeafe;
  background: #fff;
}

.tab-button.is-active {
  color: var(--text);
  border-color: #b9d3ff;
  background: #fff;
  box-shadow: 0 8px 18px rgba(18, 100, 216, .10);
}

.tab-panel {
  min-height: 0;
  overflow: hidden;
}

.tab-panel.is-active {
  display: flex;
  flex-direction: column;
}

.result-block {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.main-output-textarea {
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  height: 100%;
  resize: vertical;
}

.hidden-source-textarea {
  display: none;
}

.section-note {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.empty-note {
  margin: 0;
  color: var(--muted);
}

.process-card,
.legal-reference-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 0;
  flex: 1 1 auto;
  height: auto;
  overflow: auto;
  padding: 2px;
}

.process-steps {
  counter-reset: process-step;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.process-steps li {
  counter-increment: process-step;
  position: relative;
  min-height: 42px;
  padding: 10px 14px 10px 50px;
  color: #243244;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  line-height: 1.7;
  box-shadow: 0 4px 12px rgba(20, 38, 68, .05);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.process-steps li::before {
  content: counter(process-step);
  position: absolute;
  left: 12px;
  top: 10px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: #fff;
  border-radius: 999px;
  background: #0f8aa6;
  font-size: 14px;
  font-weight: 900;
}

.legal-reference-card {
  padding: 13px 14px;
  border: 1px solid #c9d8ea;
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: 0 5px 14px rgba(20, 38, 68, .05);
}

.legal-reference-card + .legal-reference-card {
  margin-top: 2px;
}

.legal-reference-card header {
  margin-bottom: 8px;
  padding-bottom: 8px;
  color: #0f6178;
  border-bottom: 1px solid #e3ebf5;
  font-size: 15px;
  line-height: 1.45;
  font-weight: 900;
}

.legal-reference-card p {
  margin: 0;
  color: #243244;
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.step3-footer {
  margin: 14px -18px -18px;
  padding: 12px 18px 14px;
  border-top: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 -6px 14px rgba(20, 38, 68, .05);
}

.new-situation-field {
  margin-top: 0;
}

.new-situation-field textarea {
  min-height: 96px;
  resize: vertical;
}

.step3-footer-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.knowledge-refs {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.knowledge-item {
  padding: 11px;
  color: var(--text-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.knowledge-item b {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

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

.result-status-card {
  display: grid;
  gap: 6px;
  min-height: 78px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #fff, #f8fbff);
  color: var(--text);
  text-align: left;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease, background .16s ease;
}

.result-status-card strong {
  font-size: 17px;
  line-height: 1.2;
}

.result-status-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
}

.result-status-card:hover {
  border-color: #91b8ff;
  transform: translateY(-1px);
}

.result-status-card.is-selected {
  border-color: var(--primary);
  background: #eef6ff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, .14);
}

.result-option-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.result-option-panel[hidden] {
  display: none;
}

.result-option-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 13px;
}

.result-option-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.result-option-head strong {
  color: var(--text);
  font-size: 14px;
}

.result-option-head span {
  color: var(--muted);
  font-size: 12px;
}

.option-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-chip {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid #c8d7ec;
  border-radius: 8px;
  background: #f8fbff;
  color: #24364f;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease;
}

.option-chip:hover {
  border-color: #8fb7ff;
  background: #f0f7ff;
}

.option-chip.is-selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .18);
}

.result-draft-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.context-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
}

.context-card {
  padding: 14px;
}

.context-card.compact p {
  margin-top: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: 420px;
  padding: 11px 14px;
  color: #fff;
  border-radius: var(--radius-sm);
  background: #172033;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 24, 39, .36);
}

.settings-modal[hidden] {
  display: none;
}

.settings-dialog {
  width: min(520px, calc(100vw - 32px));
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid #c9d8ea;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
}

.responsibility-dialog {
  width: min(680px, calc(100vw - 32px));
}

.responsibility-dialog textarea {
  min-height: 190px;
  resize: vertical;
}

.settings-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e4ebf5;
}

.settings-dialog-head span {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.settings-dialog-head h2 {
  font-size: 19px;
}

.icon-close {
  width: 36px;
  height: 36px;
  color: #526173;
  border: 1px solid #d9e2ee;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.settings-hint {
  margin: 0;
  color: #64748b;
  font-size: 13px;
  line-height: 1.55;
}

.settings-guide {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #dbe6f4;
  border-radius: var(--radius-sm);
  background: #f8fafc;
}

.settings-guide strong {
  color: #0f172a;
  font-size: 14px;
}

.settings-guide ol {
  margin: 0;
  padding-left: 20px;
  color: #526173;
  font-size: 13px;
  line-height: 1.7;
}

.settings-guide a {
  width: fit-content;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.settings-guide a:hover {
  text-decoration: underline;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

@media (max-width: 1260px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr);
  }

  .masthead-stats {
    display: none;
  }

  .workbench-grid {
    grid-template-columns: 220px 226px minmax(0, 1fr);
  }

  .context-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }
}

@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .auth-card {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .auth-intro {
    min-height: auto;
    padding: 18px;
  }

  .auth-intro h1 {
    font-size: 24px;
  }

  .app-shell {
    width: calc(100vw - 20px);
    height: auto;
    min-height: 100vh;
    padding: 10px 0 16px;
  }

  .topbar,
  .workbench-grid,
  .context-panel,
  .intake-grid,
  .output-tabs,
  .decision-grid,
  .result-status-grid,
  .ai-result-panel {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .section-head,
  .button-row,
  .session-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

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

  .scope-rule-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .scope-rule-bar > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .scope-rule-bar button {
    width: 100%;
  }

  .session-actions > * {
    max-width: none;
  }

  .process-rail,
  .flow-section {
    overflow: visible;
  }

  .flow-section {
    height: auto;
  }
}
