:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #f9fbfb;
  --text: #172026;
  --muted: #66747f;
  --line: #dce4e6;
  --line-strong: #c9d5d8;
  --brand: #13715f;
  --brand-dark: #0d5548;
  --blue: #245e9f;
  --amber: #b56b10;
  --red: #b83232;
  --green: #16835d;
  --ink: #22313a;
  --shadow: 0 8px 24px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  padding: 2px 8px 18px;
  border-bottom: 1px solid var(--line);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 760;
  color: var(--ink);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #13715f, #245e9f);
}

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

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

.nav-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-radius: 8px;
  text-align: left;
}

.nav-button svg,
.icon-button svg,
.button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.nav-button:hover {
  color: var(--brand-dark);
  background: #eef7f4;
}

.nav-button.active {
  color: var(--brand-dark);
  background: #e4f3ef;
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 22px 28px 32px;
}

.topbar {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.page-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 780;
}

.page-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.button,
.icon-button,
.segmented button {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 36px;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  font-weight: 700;
}

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

.button.danger {
  background: #fff6f6;
  border-color: #e7b7b7;
  color: var(--red);
}

.button:hover,
.icon-button:hover,
.segmented button:hover {
  border-color: var(--brand);
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  border: 0;
  border-radius: 0;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: #fff;
  background: var(--brand);
}

.view {
  display: grid;
  gap: 16px;
}

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

.kpi-grid.compact {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin-bottom: 14px;
}

.kpi-card,
.surface,
.metric-card,
.risk-card,
.contract-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi-card {
  padding: 14px;
  min-height: 112px;
  display: grid;
  gap: 8px;
}

.kpi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.kpi-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #edf6f3;
  color: var(--brand);
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.kpi-note {
  color: var(--muted);
  font-size: 12px;
}

.organizer-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.organizer-step {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  padding: 10px;
}

.organizer-step.pending {
  border-left: 3px solid var(--amber);
}

.organizer-step.done {
  border-left: 3px solid var(--green);
}

.organizer-step.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(19, 113, 95, 0.12);
  background: #f3fbf8;
}

.organizer-step-index {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #edf6f3;
  color: var(--brand-dark);
  font-weight: 800;
}

.organizer-step-title {
  font-weight: 780;
  color: var(--ink);
}

.organizer-step-note {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.organizer-current-step {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: #f3fbf8;
  padding: 12px;
  margin-bottom: 12px;
}

.organizer-current-step.ready {
  border-color: var(--green);
  background: #f2fbf5;
}

.organizer-current-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.organizer-current-step.ready .organizer-current-badge {
  background: var(--green);
}

.organizer-current-title {
  color: var(--ink);
  font-weight: 800;
}

.organizer-current-note {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.organizer-active-section {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(19, 113, 95, 0.1), var(--shadow);
}

.organizer-list {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.organizer-row {
  display: grid;
  grid-template-columns: minmax(280px, 1.4fr) minmax(300px, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  padding: 12px;
}

.organizer-row.high {
  border-left-color: var(--red);
}

.organizer-row.medium {
  border-left-color: var(--amber);
}

.organizer-row.done {
  border-left-color: var(--green);
}

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

.organizer-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.organizer-contract-link {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  font-weight: 800;
  text-align: left;
  overflow-wrap: anywhere;
}

.organizer-contract-link:hover {
  color: var(--brand);
  text-decoration: underline;
}

.organizer-subtitle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

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

.organizer-tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef1f2;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.organizer-tag.high {
  background: #fff0f0;
  color: var(--red);
}

.organizer-tag.medium {
  background: #fff6e8;
  color: var(--amber);
}

.organizer-tag.done {
  background: #e8f5ed;
  color: var(--green);
}

.organizer-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(68px, 1fr));
  gap: 8px;
  min-width: 0;
}

.organizer-facts div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 8px;
  min-width: 0;
}

.organizer-facts span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.organizer-facts strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
  font-size: 12px;
  overflow-wrap: anywhere;
}

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

.organizer-more {
  margin-top: 8px;
}

.layout-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.layout-3 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(300px, 0.8fr);
  gap: 16px;
}

.surface {
  padding: 16px;
  min-width: 0;
}

.surface-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.surface-title {
  margin: 0;
  font-size: 16px;
  font-weight: 780;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.inline-select select {
  height: 36px;
  min-width: 170px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.profit-table {
  min-width: 1120px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: #fff;
}

.ledger-table {
  min-width: 1040px;
  table-layout: fixed;
}

.ledger-col-party {
  width: 20%;
}

.ledger-col-project {
  width: 30%;
}

.ledger-col-node {
  width: 14%;
}

.ledger-col-date {
  width: 12%;
}

.ledger-col-amount {
  width: 9%;
}

.ledger-col-status {
  width: 8%;
}

.ledger-col-actions {
  width: 7%;
}

th,
td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 720;
  font-size: 12px;
  background: var(--panel-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr {
  transition: background 0.16s ease;
}

tbody tr:hover {
  background: #f4faf8;
}

tbody tr.selected {
  background: #edf8f4;
}

.project-source-row td {
  background: #fbfdfc;
  padding-top: 8px;
  padding-bottom: 14px;
}

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

.source-section {
  min-width: 0;
}

.source-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  margin-bottom: 6px;
}

.source-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.source-line span:first-child,
.source-link-button {
  min-width: 0;
  overflow-wrap: anywhere;
}

.source-link-button {
  display: inline-flex;
  align-items: flex-start;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  font: inherit;
  font-weight: 700;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.source-link-button svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  margin-top: 1px;
  color: var(--brand);
}

.source-link-button:hover {
  color: var(--brand);
  text-decoration: underline;
}

.health-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-gutter: stable;
}

.health-item {
  border-left: 3px solid var(--line);
  background: #fbfdfc;
  border-radius: 8px;
  padding: 10px 12px;
}

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

.health-text-body,
.health-text-button {
  flex: 1;
  min-width: 0;
}

.health-text-button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.health-text-button:hover .row-title {
  color: var(--brand);
  text-decoration: underline;
}

.health-actions {
  display: inline-flex;
  gap: 8px;
  flex-shrink: 0;
}

.health-item.high {
  border-left-color: var(--red);
}

.health-item.medium {
  border-left-color: var(--amber);
}

.health-item.low {
  border-left-color: var(--blue);
}

@media (max-width: 980px) {
  .project-source-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .project-source-grid {
    grid-template-columns: 1fr;
  }
}

td .row-title {
  font-weight: 720;
  color: var(--ink);
  overflow-wrap: anywhere;
}

td .row-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.warning-text {
  color: var(--amber) !important;
  font-weight: 700;
}

.status-pill,
.type-pill,
.risk-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.status-pill.done {
  background: #e8f5ed;
  color: var(--green);
}

.status-pill.pending {
  background: #fff6e8;
  color: var(--amber);
}

.status-pill.overdue,
.risk-pill.high {
  background: #fff0f0;
  color: var(--red);
}

.status-pill.partial,
.risk-pill.medium {
  background: #edf4fc;
  color: var(--blue);
}

.status-pill.draft,
.risk-pill.low {
  background: #eef1f2;
  color: var(--muted);
}

.type-pill.sales {
  background: #e9f5ff;
  color: var(--blue);
}

.type-pill.purchase {
  background: #f1efe9;
  color: #6c5a33;
}

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.amount.positive {
  color: var(--green);
}

.amount.negative {
  color: var(--red);
}

.upload-zone {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  min-height: 132px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 16px;
  background:
    linear-gradient(90deg, rgba(19, 113, 95, 0.06), rgba(36, 94, 159, 0.05)),
    #fff;
}

.upload-title {
  font-size: 18px;
  font-weight: 780;
  margin: 0 0 6px;
}

.upload-meta {
  color: var(--muted);
  margin: 0;
  line-height: 1.55;
}

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

.detail-item {
  min-height: 58px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.detail-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.detail-value {
  font-weight: 760;
  word-break: break-word;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 92px;
  gap: 10px;
  align-items: center;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #e9eff1;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--blue));
}

.list-stack {
  display: grid;
  gap: 10px;
}

.alert-row,
.cash-row,
.risk-row {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.alert-row:last-child,
.cash-row:last-child,
.risk-row:last-child {
  border-bottom: 0;
}

.alert-title,
.cash-title,
.risk-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  font-weight: 760;
}

.alert-meta,
.cash-meta,
.risk-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
}

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

.span-2 {
  grid-column: span 2;
}

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

.field input,
.field select,
.field textarea,
.readonly-value {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 0 10px;
}

.readonly-value {
  display: flex;
  align-items: center;
  background: #f6faf8;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.35;
}

.field textarea {
  padding: 9px 10px;
  min-height: 74px;
  resize: vertical;
}

.chart-grid {
  display: grid;
  gap: 12px;
}

.dashboard-scroll {
  max-height: 360px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-gutter: stable;
}

.chart-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 96px;
  gap: 10px;
  align-items: center;
}

.chart-label {
  font-weight: 720;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-value {
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  text-align: right;
}

.risk-board {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 0.55fr);
  gap: 16px;
}

.risk-card {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.risk-card.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(19, 113, 95, 0.12), var(--shadow);
}

.risk-card button {
  justify-self: start;
}

.clause-box {
  border-left: 3px solid var(--amber);
  background: #fff9ef;
  border-radius: 0 8px 8px 0;
  padding: 10px 12px;
  color: #65420e;
  line-height: 1.55;
}

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

.metric-card {
  padding: 12px;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 6px;
  font-weight: 800;
  font-size: 18px;
}

.empty {
  min-height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(19, 113, 95, 0.08), rgba(36, 94, 159, 0.08)),
    var(--bg);
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-subtitle {
  margin: 12px 0 18px;
  color: var(--muted);
  line-height: 1.55;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-divider {
  margin: 18px 0 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-help {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1180px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .kpi-grid.compact {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .layout-2,
  .layout-3,
  .risk-board {
    grid-template-columns: 1fr;
  }

  .organizer-flow {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .organizer-row {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

  .main {
    padding: 16px;
  }

  .topbar,
  .upload-zone {
    grid-template-columns: 1fr;
    display: grid;
    align-items: start;
  }

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

  .kpi-grid,
  .metric-strip,
  .form-grid,
  .detail-grid,
  .organizer-flow,
  .organizer-facts {
    grid-template-columns: 1fr;
  }

  .kpi-grid.compact,
  .span-2 {
    grid-template-columns: 1fr;
    grid-column: span 1;
  }

  .timeline-row,
  .chart-row {
    grid-template-columns: 1fr;
  }

  .chart-value {
    text-align: left;
  }
}
