/* Xing Cheng Trading System -- internal operations UI.
   Dense, table-first, bilingual. Light and dark both first-class. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #dfe3e8;
  --border-strong: #c4cad2;
  --text: #1c2430;
  --text-dim: #5c6b7a;
  --text-faint: #8b98a5;
  --brand: #0f4c81;
  --brand-soft: #e8f0f8;
  --accent: #1f7a8c;
  --good: #1f7a4d;
  --good-soft: #e6f4ec;
  --warn: #9a6700;
  --warn-soft: #fdf3d8;
  --danger: #a8322d;
  --danger-soft: #fbeae9;
  --info: #2a5db0;
  --info-soft: #e9f0fb;
  --muted-soft: #eceff2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --radius: 6px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
          "PingFang SC", "Hiragino Sans GB", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d;
    --surface: #1b2027;
    --surface-2: #21272f;
    --border: #2e3641;
    --border-strong: #414c5a;
    --text: #e4e9ef;
    --text-dim: #9aa7b5;
    --text-faint: #6f7c8a;
    --brand: #6ba6dd;
    --brand-soft: #1e2b38;
    --accent: #4fb3c4;
    --good: #5cbf8a;
    --good-soft: #16281f;
    --warn: #d9a83a;
    --warn-soft: #2a2416;
    --danger: #e07b74;
    --danger-soft: #2c1a19;
    --info: #7aa5e8;
    --info-soft: #1a2233;
    --muted-soft: #262d36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- layout */

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

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.brand strong { display: block; font-size: 14px; letter-spacing: .01em; }
.brand span { display: block; font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.nav { padding: 8px 6px; overflow-y: auto; flex: 1; }
.nav a {
  display: block;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 1px;
}
.nav a .en { display: block; font-size: 10.5px; color: var(--text-faint); }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav a.active .en { color: var(--brand); opacity: .75; }
.nav .group {
  padding: 12px 10px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-faint);
}

.userbox {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-dim);
}
.userbox .name { color: var(--text); font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; }
.topbar .sub { color: var(--text-faint); font-size: 12px; }
.topbar .spacer { flex: 1; }

.content { padding: 20px 24px 48px; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.card > header {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
}
.card > header h2 { margin: 0; font-size: 13px; font-weight: 650; }
.card > header .en { font-size: 11px; color: var(--text-faint); font-weight: 400; }
.card > header .spacer { flex: 1; }
.card .body { padding: 14px; }
.card .body.tight { padding: 0; }

.grid { display: grid; gap: 18px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ---------------------------------------------------------------- stats */

.stat { padding: 14px; }
.stat .label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.stat .label .en { text-transform: none; letter-spacing: 0; }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .value.sm { font-size: 17px; }
.stat .foot { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }

/* ---------------------------------------------------------------- tables */

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

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data thead th {
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 650;
  color: var(--text-dim);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.data thead th .en { display: block; font-weight: 400; color: var(--text-faint); font-size: 10px; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Codes read as one token; the table scrolls rather than breaking them up. */
table.data td.mono { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
table.data td.mono .sub { white-space: normal; }
table.data tfoot td {
  background: var(--surface-2);
  font-weight: 650;
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
}
table.data .sub { display: block; font-size: 11px; color: var(--text-faint); }
table.data tr.dim td { color: var(--text-faint); }

/* ---------------------------------------------------------------- pills */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.6;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--brand-soft); color: var(--accent); }
.pill.muted { background: var(--muted-soft); color: var(--text-dim); }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 10.5px;
  color: var(--text-dim);
  font-family: var(--mono);
}

/* ------------------------------------------------------------- progress */

.bar { height: 6px; background: var(--muted-soft); border-radius: 3px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.done > i { background: var(--good); }

/* ----------------------------------------------------------- milestones */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--border);
  align-items: start;
}
.timeline li:last-child { border-bottom: none; }
.timeline .dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  margin-top: 3px;
}
.timeline li.done .dot { background: var(--good); border-color: var(--good); }
.timeline li.next .dot { border-color: var(--accent); box-shadow: 0 0 0 3px var(--brand-soft); }
.timeline .what { font-size: 13px; font-weight: 600; }
.timeline .what .en { font-weight: 400; color: var(--text-faint); font-size: 11px; display: block; }
.timeline .when { font-size: 12px; color: var(--text-dim); text-align: right; font-variant-numeric: tabular-nums; }
.timeline .transfer {
  display: inline-block; margin-top: 3px;
  font-size: 10.5px; color: var(--accent);
  background: var(--brand-soft); padding: 1px 6px; border-radius: 4px;
}

/* --------------------------------------------------------------- chain */

.chain { display: flex; align-items: stretch; gap: 0; flex-wrap: wrap; }
.chain .node {
  flex: 1 1 150px;
  padding: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  position: relative;
}
.chain .node + .node { border-left: none; }
.chain .node .who { font-size: 12px; font-weight: 650; }
.chain .node .who .en { font-weight: 400; color: var(--text-faint); font-size: 10.5px; }
.chain .node .amt { font-size: 16px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.chain .node .meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.chain .node.holds { background: var(--brand-soft); border-color: var(--brand); }
.chain .node.holds .who { color: var(--brand); }

/* --------------------------------------------------------------- forms */

form.stack { display: grid; gap: 14px; }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* align-content: start 是关键。
   一行里有的字段带说明文字、有的不带，网格行会被最高的那个撑高；不写这句的话，
   多出来的高度会平摊到「标签／输入框／说明」三行上，于是同一行的输入框一个高
   一个低 —— 运输信息那种四列表单最明显。多出来的高度应该落到底部。 */
.field { display: grid; gap: 4px; align-content: start; }

/* 更进一步：用 subgrid 让三行各自跨行对齐，这样连标签折行都不会把输入框推歪。
   不支持 subgrid 的浏览器退回上面的 align-content，仍然是整齐的。 */
@supports (grid-template-rows: subgrid) {
  .fields > .field {
    grid-row: span 3;
    grid-template-rows: subgrid;
    row-gap: 4px;
  }
}
.field > label { font-size: 11.5px; font-weight: 600; color: var(--text-dim); }
.field > label .en { font-weight: 400; color: var(--text-faint); }
.field .hint { font-size: 11px; color: var(--text-faint); }
.field.wide { grid-column: 1 / -1; }

input[type=text], input[type=date], input[type=number], input[type=email],
input[type=password], select, textarea {
  width: 100%;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
textarea { min-height: 68px; resize: vertical; }
input[readonly], input:disabled, select:disabled {
  background: var(--muted-soft);
  color: var(--text-dim);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters .field { min-width: 130px; }

/* --------------------------------------------------------------- notes */

.flash {
  padding: 9px 13px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.flash.good { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.flash.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.flash.info { background: var(--info-soft); color: var(--info); border-color: var(--info); }

.note {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
  padding: 8px 11px;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.note.warn { border-left-color: var(--warn); background: var(--warn-soft); color: var(--warn); }

.empty { padding: 34px 14px; text-align: center; color: var(--text-faint); font-size: 13px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-faint); font-size: 11.5px; white-space: nowrap; }
.kv dd { margin: 0; }

/* --------------------------------------------------------------- login */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 17px; }
.login-card .sub { color: var(--text-faint); font-size: 12px; margin-bottom: 20px; }

/* --------------------------------------------------------------- misc */

.right { text-align: right; }
.nowrap { white-space: nowrap; }
.dim { color: var(--text-faint); }
.small { font-size: 11.5px; }
.mono { font-family: var(--mono); }
.sep { color: var(--border-strong); }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav .group { display: none; }
  .nav a .en { display: none; }
  .content { padding: 16px; }
}

/* ------------------------------------------------------- SPA additions */

.hidden { display: none !important; }

.view { display: none; }
.view.active { display: block; }

/* Toasts: brief confirmation or error, top-right, never blocking. */
#toasts {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 100;
  display: grid;
  gap: 8px;
  max-width: min(420px, calc(100vw - 28px));
}
.toast {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid;
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(16, 24, 40, .16);
  animation: toast-in .16s ease-out;
}
.toast.good { border-color: var(--good); color: var(--good); background: var(--good-soft); }
.toast.danger { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.toast.info { border-color: var(--info); color: var(--info); background: var(--info-soft); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Modal used for every create/edit form. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .5);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 90;
}
.modal {
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  width: 100%;
  max-width: 780px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(16, 24, 40, .28);
}
.modal > header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal > header h2 { margin: 0; font-size: 15px; }
.modal > header .en { font-size: 11.5px; color: var(--text-faint); }
.modal .modal-body { padding: 16px; overflow-y: auto; }
.modal > footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: var(--surface-2);
}
.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.icon-btn:hover { background: var(--muted-soft); color: var(--text); }

.lang-pick {
  width: auto;
  padding: 4px 8px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
}

.spinner { padding: 30px; text-align: center; color: var(--text-faint); font-size: 13px; }

.breadcrumb { font-size: 12px; color: var(--text-faint); margin-bottom: 10px; }
.breadcrumb a { color: var(--brand); }

/* Clickable table rows in list views. */
table.data tr.clickable { cursor: pointer; }

/* Inline editable cells in the line-item table. */
table.data input.cell {
  width: 100%;
  min-width: 62px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------ order leg sections */

/* Each leg gets a coloured left edge so the three sections read as a
   sequence down the page rather than three identical cards. */
.leg-card { border-left: 3px solid var(--border-strong); }
.leg-card.leg-supplier_xct { border-left-color: var(--info); }
.leg-card.leg-xct_sgss { border-left-color: var(--accent); }
.leg-card.leg-sgss_sgbo { border-left-color: var(--good); }

.leg-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(200px, 1fr) minmax(220px, 1fr) minmax(260px, 1.3fr);
}

.leg-head {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-faint);
  margin-bottom: 7px;
}
.leg-head .en { text-transform: none; letter-spacing: 0; font-weight: 400; }

.po-no {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 650;
  color: var(--brand);
}

.amt-big { font-size: 15px; font-variant-numeric: tabular-nums; }

/* Milestone rows inside a leg section: dot, label, date box, buttons. */
.ms-list { display: grid; gap: 2px; }

.ms-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 6px;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px dashed var(--border);
}
.ms-row:last-child { border-bottom: none; }

.ms-what { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; font-weight: 600; }
.ms-what .en { display: block; font-weight: 400; font-size: 10.5px; color: var(--text-faint); }
.ms-what .dot {
  width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; flex: none;
  border: 2px solid var(--border-strong); background: var(--surface);
}
.ms-row.done .ms-what .dot { background: var(--good); border-color: var(--good); }

.ms-row .ms-date { width: 128px; padding: 4px 6px; font-size: 12px; }
.ms-row .ms-when { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ms-row .transfer {
  display: inline-block; margin-top: 2px;
  font-size: 10px; color: var(--accent);
  background: var(--brand-soft); padding: 0 5px; border-radius: 3px;
}

@media (max-width: 1100px) {
  .leg-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .ms-row { grid-template-columns: 1fr; gap: 4px; }
  .ms-row .ms-date { width: 100%; }
}

/* A checkbox's own text is the label; the field heading must not be one too,
   or clicking the heading silently toggles the box. */
.field .field-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.field .field-title .en { font-weight: 400; color: var(--text-faint); }

/* 复选框只有 14px 高，跟 35px 的文本框顶端对不齐。给它一条等高的行，
   方框在行内垂直居中，同一行里就齐了。 */
.field .check-row {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 35px;              /* = input 的 7px 内边距 ×2 + 行高 + 1px 边框 ×2 */
  font-size: 13px;
  cursor: pointer;
}
.field .check-row input[type=checkbox] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex: none;
  accent-color: var(--brand);
  cursor: pointer;
}

/* A leg whose title has transferred goes light green — the page then reads at a
   glance as "how far along the chain are we". The tint is a token, so it stays
   legible in dark mode instead of turning into a bright slab. */
.leg-card.done { background: var(--good-soft); }
/* Nested surfaces would otherwise sit as grey patches on the green. */
.leg-card.done table.data thead th,
.leg-card.done table.data tfoot td { background: transparent; }
.leg-card.done table.data th,
.leg-card.done table.data td { border-bottom-color: rgba(31, 122, 77, .18); }
.leg-card.done table.data tbody tr:hover { background: rgba(31, 122, 77, .07); }
.leg-card.done .ms-row { border-bottom-color: rgba(31, 122, 77, .22); }
.leg-card.done .note { background: transparent; }

/* --------------------------------------------- collapsible leg sections */

/* Native <details>, so keyboard and screen readers work without any JS. */
.leg-card > summary {
  padding: 11px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  cursor: pointer;
  list-style: none;                 /* Firefox */
  user-select: none;
}
.leg-card > summary::-webkit-details-marker { display: none; }  /* Safari/Chrome */
.leg-card > summary:hover { background: var(--muted-soft); }
.leg-card > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

/* Collapsed cards have no visible body, so the summary should not look like
   it is sitting on top of something. */
.leg-card:not([open]) > summary { border-bottom-color: transparent; }

.leg-card .chev {
  width: 0; height: 0; flex: none;
  border-left: 5px solid var(--text-faint);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .12s ease;
}
.leg-card[open] .chev { transform: rotate(90deg); }

.leg-card .leg-name { font-size: 13px; font-weight: 650; }
.leg-card .leg-name .en { font-size: 11px; color: var(--text-faint); font-weight: 400; margin-left: 6px; }

/* The summary line is the whole section when collapsed: PO, amount, profit. */
.leg-card .leg-sum {
  display: flex;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.leg-card .leg-sum .mono { font-family: var(--mono); font-size: 11.5px; color: var(--brand); }
.leg-card .leg-sum > span:not(.mono):first-of-type { color: var(--text); font-weight: 650; font-size: 13px; }

.leg-card.done > summary { background: transparent; }
.leg-card.done > summary:hover { background: rgba(31, 122, 77, .08); }
.leg-card[open].done > summary { border-bottom-color: var(--good); }

@media (max-width: 700px) {
  .leg-card .leg-sum { width: 100%; gap: 10px; }
}

/* 金额标题后面那个 ≈：提示这个数按未舍入金额算，跟上面几行相加会差一分。
   做得很轻 —— 它是解释，不是警告。 */
.hint-mark {
  color: var(--muted);
  font-weight: 400;
  cursor: help;
}

/* 登录报错里的英文那一行 —— 登录之前不知道人用哪种语言，中英都显示 */
#loginError .en {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  opacity: 0.75;
}

/* ---------------------------------------------- 第一段的三个分部 / leg parts */

/* 第一段（供应商→星辰）拆成 PO／发票／付款安排三块。每块之间用一条线隔开，
   不用卡片套卡片 —— 外层已经是一张 leg-card，再套一层边框会显得很吵。 */
.leg-part + .leg-part {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.part-head {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}
.part-head .en {
  font-weight: 400;
  font-size: 11px;
  opacity: 0.6;
  margin-left: 6px;
}

.part-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) {
  .part-grid { grid-template-columns: 1fr; gap: 12px; }
}

/* ------------------------------------------------------ 附件 / attachments */

.attach { margin-top: 12px; }

.attach-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}
.attach-head .en { font-weight: 400; opacity: 0.55; }
.attach-head .count {
  font-weight: 400;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

.attach-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.attach-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
/* 文件名可能很长，让它自己截断，别把删除按钮挤出去 */
.attach-list .file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-list .file-meta {
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.attach-empty { font-size: 12px; opacity: 0.45; }

/* 付款表里那一列凭证：表格单元格里的附件区不要再留上边距 */
.voucher-cell .attach { margin-top: 0; min-width: 150px; }
/* 表格那一列窄，藏掉「付款凭证」四个字，但上传按钮和文件列表必须留着 ——
   整个 attach-head 一起藏，按钮就跟着没了，那一列变成只能看不能传。 */
.voucher-cell .attach-label { display: none; }
.voucher-cell .attach-head { margin-bottom: 4px; }
.voucher-cell .attach-empty { display: none; }

/* 两栏变体：发票字段 + 附件并排。发票只有五六行，单独占一整行会在右边
   留下一大片空白，看着像漏了内容。 */
.part-grid.pair { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 900px) {
  .part-grid.pair { grid-template-columns: 1fr; }
}

/* 定金／尾款两个节点放在付款表下面，横排 —— 竖排会把这一块拉得很长，
   而它们本来就是并列的两件事。 */
.ms-list.ms-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}
.ms-list.ms-inline .ms-row { flex: 1 1 240px; min-width: 0; }

/* 四列 dl：标签/值/标签/值。字段少的时候竖着排会把一行撑得很高，旁边的短内容
   就留下一大片空白 —— 折成两组，高度立刻和邻居对齐。 */
.kv.cols2 { grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr); }
@media (max-width: 700px) {
  .kv.cols2 { grid-template-columns: auto minmax(0, 1fr); }
}

/* 紧凑变体：标题、上传按钮、文件列表挤在一行。
   放进窄栏（比如 PO 那块的金额栏下面）时，比默认的三行样式省两行高度。 */
.attach.compact {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 10px;
}
.attach.compact .attach-head { margin-bottom: 0; }
/* 默认样式里那个 flex:1 的 spacer 会把上传按钮推到最右边；一行排布时不需要，
   让它塌成 0 宽，按钮就紧跟在标题后面。 */
.attach.compact .attach-head .spacer { display: none; }
.attach.compact .attach-list { display: flex; flex-wrap: wrap; gap: 4px; }
.attach.compact .attach-list li { padding: 2px 6px; }
.attach.compact .attach-list .file-name { max-width: 220px; }

/* 横跨整行的网格项。附件区用它：文件名很长，挤在单栏里一个就占一行，
   横跨整行才排得开。 */
.part-grid > .span-all { grid-column: 1 / -1; }

/* 分块标题带附件：标题在左，附件区跟在右边。标题行本来只有 20px 高、右边全是空白，
   附件放进去不新增一行，是最省地方的位置。文件多了会折到标题下面。 */
.part-head.with-attach {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
}
.part-head.with-attach .attach { margin-top: 0; }

/* 六列 dl：三组「标签/值」并排。字段少（发票就五个）时铺满整行只要两行高，
   用两列会排成三行，还得再开一栏放按钮，右边又空一片。 */
.kv.cols3 { grid-template-columns: repeat(3, auto minmax(0, 1fr)); }
@media (max-width: 1100px) {
  .kv.cols3 { grid-template-columns: repeat(2, auto minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .kv.cols3 { grid-template-columns: auto minmax(0, 1fr); }
}

/* 一段里并排放几个附件区（星辰→SGSS 有采购订单、发票、报关单三份）。
   横跨整行才排得开：塞进三栏布局里的话，栏宽只有三百来像素，
   一个中文文件名就占满一行。 */
.attach-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px 20px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.attach-row .attach { margin-top: 0; }
/* 并排时各自的文件名给窄一点，免得一个长名把整格撑开 */
.attach-row .attach-list .file-name { max-width: 180px; }
