:root {
  --bg: #eef1f4;
  --bg-warm: #f7f5f1;
  --surface: #ffffff;
  --ink: #17202a;
  --ink-soft: #3d4a57;
  --muted: #6d7a88;
  --line: #e3e8ee;
  --line-strong: #cfd7e1;
  --accent: #0f6e76;
  --accent-deep: #0b4f55;
  --accent-soft: #e6f3f4;
  --copper: #a65b2b;
  --copper-soft: #f6eee7;
  --navy: #1c3d5a;
  --good: #1f7a4d;
  --good-bg: #e8f6ee;
  --bad: #c0392b;
  --bad-bg: #fdecea;
  --warn: #b7791f;
  --warn-bg: #fbf3e4;
  --header-h: 118px;
  --radius: 10px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  --mono: "Cambria Math", "Segoe UI", ui-sans-serif, sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 13px;
  line-height: 1.5;
  min-width: 1100px;
}

button, select, input { font-family: inherit; }

.app { min-height: 100vh; }

/* ===== Header ===== */
.top {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #10232b;
  color: #e8eef0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06);
}

.top-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px 8px;
  min-height: 52px;
}

.filter-row {
  display: flex;
  align-items: center;
  padding: 0 20px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 196px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #1a8a94;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: 13px;
}

.brand h1 {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: #fff;
}

.brand small {
  display: block;
  font-size: 11px;
  color: #93a8ad;
  font-weight: 400;
  margin-top: 1px;
}

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

.grain {
  display: inline-flex;
  background: #1a3840;
  border-radius: 7px;
  padding: 2px;
  border: 1px solid #2a4e57;
}

.grain button {
  border: 0;
  background: transparent;
  color: #b7c9cd;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 5px;
  cursor: pointer;
}

.grain button.active {
  background: #1a8a94;
  color: #fff;
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1a3840;
  border: 1px solid #2a4e57;
  border-radius: 7px;
  padding: 4px 8px;
  min-height: 32px;
  position: relative;
}

.field label {
  font-size: 11px;
  color: #8aa0a6;
  white-space: nowrap;
}

.field select,
.field input {
  background: transparent;
  border: 0;
  color: #e8eef0;
  font-size: 12px;
  outline: none;
  min-width: 92px;
}

.field input[type="month"],
.field input[type="date"] {
  color-scheme: dark;
  max-width: 132px;
}

.field.dates { gap: 4px; }
.field.dates span { color: #6d868c; font-size: 11px; }

.drop-btn {
  background: transparent;
  border: 0;
  color: #e8eef0;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 148px;
}

.drop-btn .val {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.caret { font-size: 9px; opacity: 0.7; }

.menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 35, 43, 0.12);
  padding: 6px;
  z-index: 50;
  max-height: 280px;
  overflow: auto;
}

.menu.open { display: block; }

.menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
}

.menu label:hover { background: #f3f6f7; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 0; }

.top-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-left: auto;
}

.update {
  font-size: 11px;
  color: #93a8ad;
  text-align: right;
  line-height: 1.35;
}

.role {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1a3840;
  border: 1px solid #2a4e57;
  border-radius: 8px;
  padding: 4px 8px 4px 4px;
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #c9a56b;
  color: #2b2114;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
}

.role select {
  background: transparent;
  border: 0;
  color: #e8eef0;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 20px;
  background: #0c1c22;
  border-top: 1px solid #1c3942;
}

.tabs button {
  border: 0;
  background: transparent;
  color: #9bb0b5;
  padding: 10px 16px 9px;
  font-size: 13px;
  cursor: pointer;
  position: relative;
}

.tabs button.active {
  color: #fff;
  font-weight: 600;
}

.tabs button.active::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 2px;
  background: #2bb3bc;
}

/* ===== Main ===== */
.main {
  padding: 16px 20px 28px;
  max-width: 1480px;
  margin: 0 auto;
}

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

.row {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.row-6 { grid-template-columns: repeat(6, 1fr); }
.row-5 { grid-template-columns: repeat(5, 1fr); }
.row-4 { grid-template-columns: repeat(4, 1fr); }
.row-3 { grid-template-columns: repeat(3, 1fr); }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-2-1 { grid-template-columns: 2fr 1fr; }
.row-3-2 { grid-template-columns: 1.6fr 1fr; }

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px 11px;
  position: relative;
  overflow: visible;
  min-height: 96px;
}

.kpi::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
}

.kpi.copper::before { background: var(--copper); }
.kpi.navy::before { background: var(--navy); }
.kpi.warn::before { background: var(--warn); }

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.kpi-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 6px 0 8px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.kpi-value em {
  font-style: normal;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin-left: 4px;
}

.kpi-deltas {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 11px;
}

.delta { color: var(--muted); }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.alert { font-weight: 650; }

.kpi-sub {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.kpi.dual .kpi-value { font-size: 20px; margin-bottom: 2px; }
.kpi.dual .kpi-money {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
}

.card-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px 0;
}

.card-hd h3 {
  font-size: 13px;
  font-weight: 650;
}

.card-hd p {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.card-tools {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.seg {
  display: inline-flex;
  background: #f3f5f7;
  border-radius: 6px;
  padding: 2px;
}

.seg button {
  border: 0;
  background: transparent;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
}

.seg button.active {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}

.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.chk {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.chk input { accent-color: var(--accent); }

.collapse-body[hidden] { display: none !important; }
.collapse-body { padding-bottom: 4px; }

.card.collapsible.expanded .card-hd {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 0;
}

.chart {
  height: 280px;
  padding: 4px 8px 10px;
}

.chart.tall { height: 340px; }
.chart.short { height: 220px; }

.chart-split {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  min-height: 340px;
}

.map-host { height: 340px; padding: 4px 8px 12px; }
.rank-host { height: 340px; padding: 4px 8px 12px; border-left: 1px solid var(--line); }

.ratios {
  display: flex;
  gap: 16px;
  padding: 0 14px 12px;
  font-size: 12px;
  color: var(--ink-soft);
}

.ratios b { color: var(--accent-deep); font-variant-numeric: tabular-nums; }

.ratio-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 14px 18px;
  min-height: 220px;
  align-content: center;
}

.ratio-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 16px;
  cursor: pointer;
  background: #fbfcfd;
  transition: border-color .15s, background .15s;
}

.ratio-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ratio-card .lab {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.ratio-card .val {
  font-size: 28px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.ratio-card .go {
  margin-top: 10px;
  font-size: 11px;
  color: var(--accent);
}

.table-wrap { padding: 8px 12px 12px; overflow: auto; }

.cell-groups {
  display: inline-block;
  max-width: 280px;
  color: var(--ink);
  line-height: 1.45;
  white-space: normal;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

table.data th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 8px 8px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  background: #fff;
}

table.data td {
  padding: 8px 8px;
  border-bottom: 1px solid #f0f3f6;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

table.data tbody tr:hover { background: #f7fbfb; }
table.data tbody tr.clickable { cursor: pointer; }
table.data .num { text-align: right; font-family: var(--mono); }
table.data th.num { text-align: right; }
table.data .link { color: var(--accent); cursor: pointer; }
table.data .link:hover { text-decoration: underline; }

.sat-row { align-items: stretch; }

.sat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.sat-card.alert { border-color: #f0b8b2; background: #fffafa; }

.sat-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.sat-score {
  font-size: 26px;
  font-weight: 650;
  margin: 8px 0;
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 6px;
  background: #edf1f4;
  border-radius: 99px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
}

.sat-card.alert .bar > span { background: var(--bad); }
.sat-note { margin-top: 8px; font-size: 11px; color: var(--muted); }

.empty {
  display: grid;
  place-items: center;
  height: 220px;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #10232b;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 12px;
  display: none;
  z-index: 80;
}

.modal-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 35, 43, 0.45);
  z-index: 70;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-mask.open { display: flex; }

.modal {
  background: #fff;
  border-radius: 12px;
  width: min(860px, 96vw);
  max-height: 86vh;
  overflow: auto;
  padding: 18px 20px 16px;
}

.modal h3 { font-size: 16px; margin-bottom: 4px; }
.modal .sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.modal-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.modal-grid div {
  background: #f6f8fa;
  border-radius: 8px;
  padding: 10px;
}
.modal-grid span { display: block; color: var(--muted); font-size: 11px; }
.modal-grid b { font-size: 15px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  border-radius: 99px;
  padding: 2px 8px;
  font-size: 11px;
}

.chip button {
  border: 0;
  background: none;
  cursor: pointer;
  color: inherit;
}

.drop-btn.ink { color: var(--ink); }

.light-field {
  background: #f3f5f7;
  border-color: var(--line);
  min-height: 28px;
}

.light-field label { color: var(--muted); }
.light-field select { color: var(--ink); min-width: 108px; }

.kpi .drop-btn {
  color: var(--ink);
  max-width: 120px;
  font-size: 11px;
}

.kpi .field {
  background: #f3f5f7;
  border-color: var(--line);
  padding: 2px 6px;
  min-height: 24px;
}

.kpi.has-pop:hover,
.kpi:focus-within { z-index: 6; }

.kpi-pop {
  display: none;
  position: absolute;
  top: calc(100% - 8px);
  left: 12px;
  right: 12px;
  z-index: 8;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 35, 43, 0.12);
  padding: 8px 10px;
  font-size: 11px;
  color: var(--ink-soft);
  max-height: 180px;
  overflow: auto;
}

.kpi:hover .kpi-pop { display: block; }

.kpi-pop b { color: var(--ink); }

tr.prod-row { cursor: pointer; background: #f8fbfb; }
tr.prod-row:hover { background: #eef6f6; }
tr.prod-row td { font-weight: 600; }
tr.sup-row td:first-child { padding-left: 28px; color: var(--muted); font-weight: 400; }
.exp-caret { display: inline-block; width: 14px; color: var(--accent); }

.view-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #1a3840;
  border: 1px solid #2a4e57;
  color: #c9dce0;
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 11px;
  margin-left: 8px;
}

.expand {
  padding: 0 12px 12px;
}

.expand table { margin-top: 8px; }

.hint {
  font-size: 11px;
  color: var(--muted);
  padding: 0 14px 10px;
}

@media (max-width: 1200px) {
  .row-6 { grid-template-columns: repeat(3, 1fr); }
  .row-5 { grid-template-columns: repeat(3, 1fr); }
  .row-4 { grid-template-columns: repeat(2, 1fr); }
  .row-2, .row-2-1, .row-3-2 { grid-template-columns: 1fr; }
  .chart-split { grid-template-columns: 1fr; }
  .rank-host { border-left: 0; border-top: 1px solid var(--line); }
  .supplier-cols { grid-template-columns: 1fr; }
  body { min-width: 0; }
}
