:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #eef2f3;
  --text: #182021;
  --muted: #637173;
  --line: #dce3e5;
  --teal: #0a7c7d;
  --green: #2f8a4c;
  --amber: #b97812;
  --red: #bf4a45;
  --blue: #3e6f99;
  --ink: #2a3435;
  --radius: 8px;
  --shadow: 0 12px 30px rgba(37, 48, 50, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 76px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(37, 48, 50, 0.16);
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 2px;
  font-size: 21px;
  font-weight: 760;
  line-height: 26px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.period-pill {
  min-width: 208px;
  height: 34px;
  padding: 7px 12px;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  text-align: center;
}

.period-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 4px 10px;
  color: var(--ink);
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.period-control label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.period-control select {
  max-width: 120px;
  height: 26px;
  padding: 0 8px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  outline: none;
}

.icon-button,
.primary-button,
.segmented button {
  border: 1px solid var(--line);
  cursor: pointer;
}

.icon-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.compact-button {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

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

main {
  padding: 18px 28px 34px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(80px, auto);
  height: 38px;
  padding: 3px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.segmented button.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 3px 12px rgba(37, 48, 50, 0.1);
}

.upload-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.file-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
  height: 34px;
  padding: 0 10px;
  overflow: hidden;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.file-chip-main {
  min-width: 112px;
  font-weight: 650;
}

.mini-chip {
  min-width: 58px;
  height: 30px;
  font-size: 12px;
}

.advanced-upload {
  position: relative;
  color: var(--muted);
  font-size: 12px;
}

.advanced-upload summary {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 8px;
  border-radius: 6px;
  cursor: pointer;
  list-style: none;
}

.advanced-upload summary::-webkit-details-marker {
  display: none;
}

.advanced-upload-panel {
  position: absolute;
  top: 40px;
  right: 0;
  z-index: 20;
  display: flex;
  gap: 6px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.file-chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.status-line {
  width: 148px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.kpi {
  min-height: 108px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.kpi .value {
  margin-top: 12px;
  font-size: 28px;
  font-weight: 780;
  line-height: 34px;
}

.kpi .sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.trend-up {
  color: var(--green);
}

.trend-down {
  color: var(--red);
}

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

.panel {
  min-width: 0;
  min-height: 260px;
  padding: 16px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-span-5 {
  grid-column: span 5;
}

.panel-span-6 {
  grid-column: span 6;
}

.panel-span-7 {
  grid-column: span 7;
}

.panel-span-12 {
  grid-column: span 12;
}

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

.panel-head h2 {
  font-size: 16px;
  font-weight: 760;
  line-height: 22px;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.bu-comparison {
  display: grid;
  gap: 10px;
}

.bu-row {
  display: grid;
  grid-template-columns: 72px minmax(220px, 1fr) 110px 110px 102px;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 10px 12px;
  background: #f9fbfb;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.bu-name {
  font-weight: 800;
}

.scope-note {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.metric-cell {
  text-align: right;
}

.metric-cell strong {
  display: block;
  font-size: 16px;
  line-height: 22px;
}

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

.bar-track {
  position: relative;
  height: 12px;
  overflow: hidden;
  background: #e8eef0;
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: var(--teal);
}

.status-stack {
  width: 100%;
}

.stack-bar {
  display: flex;
  width: 100%;
  height: 34px;
  overflow: hidden;
  background: #eef2f3;
  border-radius: 7px;
}

.stack-segment {
  min-width: 1px;
  height: 100%;
}

.status-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.legend-item {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.legend-item strong {
  color: var(--text);
  font-size: 13px;
}

.age-chart {
  display: grid;
  gap: 14px;
}

.age-row {
  display: grid;
  grid-template-columns: 94px 1fr 84px 84px 84px;
  align-items: center;
  gap: 10px;
}

.age-label {
  font-weight: 700;
  font-size: 13px;
}

.age-bars {
  display: grid;
  gap: 5px;
}

.mini-bar {
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.mini-bar .bar-track {
  height: 9px;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.warning-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 20px;
}

.warning-list li {
  padding: 10px 10px 10px 4px;
  color: var(--ink);
  background: #fff8ed;
  border-bottom: 1px solid #ead6b7;
  font-size: 13px;
  line-height: 20px;
}

.summary-panel {
  min-height: 232px;
}

.summary-text {
  min-height: 158px;
  max-height: 330px;
  padding: 14px 16px;
  overflow: auto;
  color: #263132;
  background: #f9fbfb;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
  line-height: 22px;
  white-space: pre-wrap;
}

.rank-chart {
  display: grid;
  gap: 10px;
}

.rank-row {
  display: grid;
  grid-template-columns: 130px 1fr 72px;
  align-items: center;
  gap: 10px;
  min-height: 27px;
}

.rank-name {
  overflow: hidden;
  font-size: 13px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-row.negative .bar-fill {
  background: var(--red);
}

.owner-table,
.movement-table {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  height: 36px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #f7f9fa;
}

td.amount,
th.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.project-name {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 7px;
  color: var(--muted);
  background: var(--surface-muted);
  border-radius: 999px;
  font-size: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-width: 52px;
  height: 22px;
  padding: 0 7px;
  color: var(--status-color);
  background: color-mix(in srgb, var(--status-color) 10%, white);
  border: 1px solid color-mix(in srgb, var(--status-color) 28%, white);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

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

@media (max-width: 1240px) {
  body {
    min-width: 980px;
  }

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

  .panel-span-5,
  .panel-span-6,
  .panel-span-7 {
    grid-column: span 12;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 700px) {
  body {
    min-width: 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    height: auto;
    padding: 14px 16px;
  }

  .topbar-actions,
  .upload-strip {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .period-pill {
    min-width: 0;
    flex: 1 1 210px;
  }

  main {
    padding: 14px 12px 28px;
  }

  .segmented {
    width: 100%;
    overflow-x: auto;
  }

  .upload-strip {
    width: 100%;
  }

  .status-line {
    width: 100%;
  }

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

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

  .panel-span-5,
  .panel-span-6,
  .panel-span-7,
  .panel-span-12 {
    grid-column: 1;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-head span {
    white-space: normal;
  }
}

@media print {
  body {
    min-width: 0;
    background: #fff;
  }

  .topbar {
    position: static;
  }

  .upload-strip,
  #printButton {
    display: none;
  }

  main {
    padding: 12px;
  }

  .panel,
  .kpi {
    box-shadow: none;
    break-inside: avoid;
  }
}
