:root {
  --paper: #f6f7f5;
  --surface: #ffffff;
  --ink: #17201b;
  --muted: #667169;
  --line: #d7ddd9;
  --green: #1f7a4d;
  --green-soft: #e6f2eb;
  --coral: #c54b38;
  --coral-soft: #f8e9e6;
  --steel: #3a6073;
  --steel-soft: #e7eef2;
  --amber: #9a650f;
  --amber-soft: #f7eed9;
  --shadow: 0 10px 28px rgba(23, 32, 27, 0.07);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--paper);
}

button, a { font: inherit; }
button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(58, 96, 115, 0.32);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr auto;
  align-items: center;
  gap: 22px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 245, 0.96);
  backdrop-filter: blur(10px);
}

.brand-block { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--ink);
  border-radius: 4px;
  font: 700 19px/1 Georgia, serif;
}
.brand-block strong, .brand-block span { display: block; }
.brand-block strong { font-size: 15px; }
.brand-block span { margin-top: 2px; color: var(--muted); font-size: 11px; }

.integration-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.integration-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.integration-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa39d;
}
.integration-pill.connected::before, .integration-pill.configured::before { background: var(--green); }
.integration-pill.pending::before { background: var(--amber); }
.integration-pill.error::before { background: var(--coral); }

.workspace {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  min-height: calc(100vh - 68px);
}

.queue {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: #eef1ef;
}
.queue-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 24px 18px 16px;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  display: block;
  color: var(--steel);
  font: 700 10px/1.3 ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 20px; line-height: 1.25; }
.queue-count {
  min-width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--steel);
  font: 700 12px/1 ui-monospace, monospace;
}
.queue-list { flex: 1; padding: 10px; }
.queue-item {
  width: 100%;
  display: block;
  padding: 14px 12px;
  border: 1px solid transparent;
  border-radius: 5px;
  text-align: left;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
}
.queue-item:hover { background: rgba(255, 255, 255, 0.65); }
.queue-item.active { border-color: #c6d2cb; background: var(--surface); box-shadow: var(--shadow); }
.queue-item strong, .queue-item span { display: block; }
.queue-item strong { margin: 5px 0 4px; font-size: 13px; line-height: 1.4; }
.queue-item .queue-meta { color: var(--muted); font-size: 11px; line-height: 1.45; }
.queue-status { color: var(--green) !important; font-weight: 700; }
.queue-foot { padding: 14px 18px 20px; border-top: 1px solid var(--line); }
.queue-link { display: block; padding: 7px 0; color: var(--steel); font-size: 12px; text-decoration: none; }
.queue-link:hover { text-decoration: underline; }

.main { min-width: 0; background: var(--surface); }
.case-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 30px 22px;
  border-bottom: 1px solid var(--line);
}
.case-identity { min-width: 0; }
.case-identity h2 { margin: 5px 0 7px; font-size: clamp(22px, 3vw, 32px); line-height: 1.2; }
.case-identity p { margin-bottom: 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.case-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }

.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 4px;
  text-decoration: none;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
  font-size: 12px;
  font-weight: 700;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: 0.55; transform: none; }
.button-primary { color: white; background: var(--green); }
.button-primary:hover { background: #17633e; }
.button-outline { color: var(--steel); border-color: var(--steel); background: transparent; }
.button-quiet { color: var(--ink); border-color: var(--line); background: var(--surface); }
.is-hidden { display: none !important; }
.risk-badge, .ai-mode {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 4px;
  color: var(--amber);
  background: var(--amber-soft);
  font-size: 11px;
  font-weight: 700;
}
.risk-badge.approved { color: var(--green); background: var(--green-soft); }
.risk-badge.danger { color: var(--coral); background: var(--coral-soft); }

.proof-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.proof-strip > div { min-width: 0; padding: 14px 18px; border-right: 1px solid var(--line); }
.proof-strip > div:last-child { border-right: 0; }
.proof-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.proof-strip strong { display: block; font-size: 12px; overflow-wrap: anywhere; }

.quote-rail-section { padding: 22px 30px; border-bottom: 1px solid var(--line); }
.quote-rail {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}
.quote-rail::before {
  content: "";
  position: absolute;
  top: 11px;
  left: 10%;
  right: 10%;
  height: 2px;
  background: var(--line);
}
.rail-step { position: relative; z-index: 1; text-align: center; color: var(--muted); font-size: 11px; }
.rail-dot {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  margin: 0 auto 8px;
  border: 2px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: var(--surface);
  font: 700 10px/1 ui-monospace, monospace;
}
.rail-step.done .rail-dot { color: white; border-color: var(--green); background: var(--green); }
.rail-step.current .rail-dot { color: var(--steel); border-color: var(--steel); box-shadow: 0 0 0 4px var(--steel-soft); }
.rail-step.done, .rail-step.current { color: var(--ink); font-weight: 700; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(280px, 0.72fr); }
.work-area { min-width: 0; padding: 24px 30px 36px; border-right: 1px solid var(--line); }
.audit-area { min-width: 0; padding: 24px 22px 36px; background: #fafbfa; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.section-heading h3 { margin: 4px 0 0; font-size: 17px; }
.ai-mode { color: var(--steel); background: var(--steel-soft); }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 5px; }
table { width: 100%; min-width: 660px; border-collapse: collapse; font-size: 12px; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: var(--paper); font-size: 10px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
td strong, td span { display: block; }
td span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.empty-row td { padding: 24px; color: var(--muted); text-align: center; }

.totals { width: min(340px, 100%); margin: 18px 0 0 auto; }
.total-row { display: flex; justify-content: space-between; gap: 22px; padding: 5px 0; color: var(--muted); font-size: 12px; }
.total-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.total-row.grand { margin-top: 6px; padding-top: 11px; border-top: 2px solid var(--green); color: var(--ink); font-size: 14px; }

.source-evidence { margin-top: 26px; border-top: 1px solid var(--line); }
.source-evidence summary { padding: 14px 0; color: var(--steel); cursor: pointer; font-size: 12px; font-weight: 700; }
.source-evidence pre {
  max-height: 360px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: #35423a;
  background: var(--paper);
  white-space: pre-wrap;
  font: 11px/1.75 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.timeline { border-top: 1px solid var(--line); }
.event { position: relative; padding: 15px 0 15px 22px; border-bottom: 1px solid var(--line); }
.event::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 20px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--steel);
}
.event.approval::before { background: var(--coral); }
.event.pricing::before { background: var(--amber); }
.event.email::before { background: var(--green); }
.event strong { display: block; margin-bottom: 5px; font-size: 12px; }
.event p { margin: 0 0 6px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.event-meta { color: #879089; font: 10px/1.4 ui-monospace, monospace; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 14px;
  border-radius: 4px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 12px;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .integration-strip { grid-column: 1 / -1; order: 3; }
  .workspace { grid-template-columns: 230px minmax(0, 1fr); }
  .proof-strip { grid-template-columns: repeat(2, 1fr); }
  .proof-strip > div:nth-child(2) { border-right: 0; }
  .proof-strip > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .content-grid { grid-template-columns: 1fr; }
  .work-area { border-right: 0; border-bottom: 1px solid var(--line); }
}

@media (max-width: 720px) {
  .topbar { position: static; padding: 10px 14px; }
  .brand-block span { display: none; }
  .topbar-actions { align-self: stretch; }
  .topbar-actions .button { min-height: 34px; padding-inline: 10px; }
  .integration-strip { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .workspace { display: block; }
  .queue { border-right: 0; border-bottom: 1px solid var(--line); }
  .queue-head { padding: 16px 14px 10px; }
  .queue-list { display: flex; overflow-x: auto; padding: 8px 10px 12px; }
  .queue-item { flex: 0 0 245px; }
  .queue-foot { display: none; }
  .case-head { display: block; padding: 20px 16px; }
  .case-actions { justify-content: flex-start; margin-top: 16px; }
  .proof-strip { grid-template-columns: 1fr; }
  .proof-strip > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .proof-strip > div:last-child { border-bottom: 0; }
  .quote-rail-section { padding: 18px 10px; overflow-x: auto; }
  .quote-rail { min-width: 560px; }
  .work-area, .audit-area { padding: 20px 16px 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
