:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --panel-soft: #fbfcfd;
  --ink: #16212b;
  --muted: #60717f;
  --line: #d9e1e8;
  --line-strong: #bdc9d4;
  --accent: #0f766e;
  --accent-soft: #e8f4f2;
  --blue: #2859a8;
  --blue-soft: #edf4ff;
  --warn: #9a5b05;
  --warn-soft: #fff6e8;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --ok: #157347;
  --ok-soft: #eaf7ef;
  --code: #111a20;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", Inter, ui-sans-serif, system-ui, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand {
  min-width: 0;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 4px;
  font-size: 26px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
}

h3 {
  margin-bottom: 6px;
  font-size: 15px;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.mode-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fafb;
  padding: 0 7px 0 9px;
}

.actions .mode-control > label {
  display: inline-flex;
  align-items: center;
  align-self: center;
  height: 30px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  line-height: 30px;
  white-space: nowrap;
}

.mode-control select {
  width: auto;
  min-width: 72px;
  height: 30px;
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  line-height: 30px;
  padding: 0 18px 0 2px;
}

.mode-control select:focus {
  outline: none;
}

.help-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  min-width: 22px;
  height: 22px;
  min-height: 22px;
  border-color: #c7d8e0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  padding: 0;
}

.help-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  display: none;
  width: min(340px, 78vw);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(21, 35, 45, 0.16);
  padding: 10px 12px;
  text-align: left;
}

.help-popover strong,
.help-popover span {
  display: block;
}

.help-popover strong {
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 12px;
}

.help-popover span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: normal;
}

.mode-control:hover .help-popover,
.mode-control:focus-within .help-popover {
  display: block;
}

.mode-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  max-width: 132px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 12px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #eef3f6;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.button-link.primary-link {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

button:hover {
  filter: brightness(0.97);
}

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

button.ghost {
  border-color: var(--line);
  background: #eef3f6;
  color: var(--ink);
}

button.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

button.danger-action {
  color: var(--danger);
}

.page-shell {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(110px, 1fr));
  gap: 10px;
}

.stat {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.stat span,
.stat em {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.stat strong {
  display: block;
  margin: 5px 0 4px;
  font-size: 25px;
  line-height: 1;
}

.stat.danger {
  border-color: #efb5ad;
  background: var(--danger-soft);
}

.stat.warning {
  border-color: #f0c986;
  background: var(--warn-soft);
}

.workbench {
  display: grid;
  grid-template-columns: 320px minmax(420px, 1fr) 420px;
  gap: 14px;
}

.sidebar,
.timeline-column {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
}

.filters,
.detail {
  align-self: start;
  position: sticky;
  top: 14px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}

.detail-title {
  align-items: flex-start;
}

.detail-title span {
  display: block;
  margin-top: 4px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.pill.loading {
  background: var(--blue-soft);
  color: var(--blue);
}

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

label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.filter-block {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f6;
  padding: 4px;
}

.segment {
  min-height: 30px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 6px;
  font-size: 12px;
}

.segment:hover,
.segment.active {
  background: var(--panel);
  color: var(--accent);
  filter: none;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  outline-offset: 2px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 10px;
}

.hint {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-word;
}

.hint strong {
  color: var(--ink);
  font-weight: 700;
}

.session-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 430px);
  min-height: 220px;
  overflow: auto;
  padding-right: 4px;
}

.session-item {
  display: grid;
  justify-items: start;
  gap: 4px;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  color: var(--ink);
  text-align: left;
}

.session-item:hover,
.session-item.active {
  border-color: #aebdca;
  border-left-color: var(--accent);
  background: var(--accent-soft);
  filter: none;
}

.session-main {
  max-width: 100%;
  overflow: hidden;
  font-size: 13px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.risk-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.risk {
  min-height: 20px;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

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

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

.session-summary {
  padding: 16px;
}

.session-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.session-head p {
  margin-bottom: 0;
  color: var(--muted);
  word-break: break-word;
}

.session-facts {
  display: grid;
  grid-template-columns: repeat(3, 82px);
  gap: 8px;
}

.fact {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 9px;
}

.fact span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.fact strong {
  display: block;
  margin-top: 3px;
  font-size: 19px;
  line-height: 1;
}

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

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

.insight-card {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.insight-card strong {
  font-size: 14px;
}

.insight-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.insight-card.danger {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.insight-card.warning {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.insight-card.success {
  border-left-color: var(--ok);
  background: var(--ok-soft);
}

.stage-rail {
  display: grid;
  grid-template-columns: repeat(6, minmax(70px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 8px;
}

.stage.active {
  border-color: #bddfc8;
  background: var(--ok-soft);
}

.stage span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.stage strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  line-height: 1;
}

.issue-digest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.issue-digest span {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.issue-digest .danger {
  border-color: #efb5ad;
  background: var(--danger-soft);
  color: var(--danger);
}

.issue-digest .warning {
  border-color: #f0c986;
  background: var(--warn-soft);
  color: var(--warn);
}

.timeline {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 300px);
  min-height: 420px;
  overflow: auto;
  padding-right: 4px;
}

.event {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
  cursor: pointer;
}

.event:hover,
.event.active {
  border-color: #aebdca;
  box-shadow: 0 1px 0 rgba(22, 33, 43, 0.04);
}

.event.danger {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.event.warning {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.event.success {
  border-left-color: var(--ok);
  background: var(--ok-soft);
}

.event-pin {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.event-main {
  min-width: 0;
}

.event-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.event-title-row strong {
  min-width: 0;
  word-break: break-word;
}

.event-title-row span {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.event-summary {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.chip.danger {
  border-color: #efb5ad;
  background: var(--danger-soft);
  color: var(--danger);
}

.chip.warning {
  border-color: #f0c986;
  background: var(--warn-soft);
  color: var(--warn);
}

.chip.success {
  border-color: #bddfc8;
  background: var(--ok-soft);
  color: var(--ok);
}

.chip.layer {
  border-color: #c2d7f4;
  background: var(--blue-soft);
  color: var(--blue);
}

.chip.session {
  overflow: hidden;
  max-width: 220px;
  text-overflow: ellipsis;
}

.detail {
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.detail-summary {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.detail-summary p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.detail-summary.danger {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.detail-summary.warning {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.detail-summary.success {
  border-left-color: var(--ok);
  background: var(--ok-soft);
}

.fact-table,
.decision-summary {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.path-list {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.path-list p {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.path-list ul {
  display: grid;
  gap: 5px;
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.fact-table div,
.decision-summary div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 8px;
  font-size: 12px;
}

.fact-table span,
.decision-summary span {
  color: var(--muted);
  font-weight: 900;
}

.fact-table strong,
.decision-summary strong {
  min-width: 0;
  color: var(--ink);
  font-weight: 800;
  word-break: break-word;
}

.detail pre {
  max-height: calc(100vh - 520px);
  min-height: 220px;
  overflow: auto;
  margin: 10px 0 0;
  border-radius: 8px;
  background: var(--code);
  color: #d5ece7;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.5;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 8px;
}

.pagination span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.pagination button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

@media (max-width: 1380px) {
  .stats-grid {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .workbench {
    grid-template-columns: 300px minmax(420px, 1fr);
  }

  .detail {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }

  .detail pre {
    max-height: 420px;
  }
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

  .stats-grid,
  .workbench,
  .field-grid,
  .session-head {
    grid-template-columns: 1fr;
  }

  .filters {
    position: static;
  }

  .session-list,
  .timeline {
    max-height: none;
    min-height: 0;
  }

  .session-facts {
    grid-template-columns: repeat(2, minmax(100px, 1fr));
  }

  .stage-rail {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .event {
    grid-template-columns: 1fr;
  }

  .event-title-row {
    display: grid;
  }
}
