:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #eef4f8;
  --ink: #172033;
  --muted: #657083;
  --line: #dde5ee;
  --blue: #2563eb;
  --teal: #0f9f8e;
  --green: #16a34a;
  --amber: #d97706;
  --red: #e5484d;
  --shadow: 0 12px 30px rgba(26, 38, 64, 0.09);
}

* {
  box-sizing: border-box;
}

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

button {
  font: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px;
  background: #fbfcfe;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 6px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #123c69;
  color: white;
  border-radius: 8px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.nav {
  display: grid;
  gap: 7px;
}

.nav button,
.mobile-nav button,
.ghost,
.primary {
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  min-height: 42px;
}

.nav button {
  justify-content: flex-start;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border-radius: 8px;
}

.nav button.active {
  background: #e8f3f1;
  color: #0b7169;
  font-weight: 700;
}

.nav-section {
  display: grid;
  gap: 5px;
}

.nav-parent {
  width: 100%;
}

.nav-children {
  display: grid;
  gap: 4px;
  padding-left: 31px;
}

.nav-child {
  min-height: 34px !important;
  padding: 0 10px !important;
  font-size: 13px;
}

.nav-child::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}

.icon {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
}

.entry-card {
  margin-top: auto;
  padding: 14px;
  background: #eef4f8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.entry-card span,
.entry-card small,
.entry-card strong {
  display: block;
}

.entry-card span {
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
}

.entry-card strong {
  margin-top: 6px;
  font-size: 16px;
}

.entry-card small {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.6;
}

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

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

.topbar p,
.topbar h1 {
  margin: 0;
}

.topbar p {
  color: var(--muted);
  font-size: 13px;
}

.topbar h1 {
  margin-top: 3px;
  font-size: 26px;
}

.top-actions,
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ghost,
.primary {
  padding: 0 14px;
  border-radius: 8px;
  white-space: nowrap;
}

.ghost {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary {
  background: var(--blue);
  color: white;
  box-shadow: 0 9px 18px rgba(37, 99, 235, 0.22);
}

.hero {
  min-height: 190px;
  padding: 28px;
  border-radius: 8px;
  background:
    linear-gradient(105deg, rgba(18, 60, 105, 0.96), rgba(15, 159, 142, 0.85)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='360' viewBox='0 0 900 360'%3E%3Cg fill='none' stroke='rgba(255,255,255,.25)' stroke-width='2'%3E%3Cpath d='M40 230 C180 110 260 300 410 160 S690 90 850 220'/%3E%3Cpath d='M90 295 C230 170 300 330 460 210 S690 160 820 285'/%3E%3C/g%3E%3Cg fill='rgba(255,255,255,.18)'%3E%3Crect x='610' y='80' width='150' height='88' rx='8'/%3E%3Crect x='638' y='104' width='24' height='44'/%3E%3Crect x='674' y='120' width='24' height='28'/%3E%3Crect x='710' y='95' width='24' height='53'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.eyebrow {
  display: inline-block;
  color: #baf3e8;
  font-size: 13px;
  font-weight: 800;
}

.hero h2 {
  margin: 10px 0 8px;
  max-width: 760px;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.15;
}

.hero p {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.7;
}

.health {
  width: 132px;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  background: rgba(255, 255, 255, 0.12);
}

.health strong {
  font-size: 42px;
}

.health span {
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(150px, 1fr));
  gap: 14px;
  margin: 16px 0;
}

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

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  min-height: 132px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi span {
  color: var(--muted);
  font-weight: 700;
}

.kpi strong {
  margin-top: 16px;
  font-size: 27px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.kpi em {
  margin-top: 8px;
  font-style: normal;
  font-size: 13px;
}

.kpi.green strong,
.kpi.green em {
  color: var(--green);
}

.kpi.blue strong,
.kpi.blue em {
  color: var(--blue);
}

.kpi.red strong,
.kpi.red em {
  color: var(--red);
}

.kpi.amber strong,
.kpi.amber em {
  color: var(--amber);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(320px, 0.8fr);
  gap: 14px;
  margin-top: 14px;
}

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

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

.panel-head h3 {
  margin: 0;
  font-size: 17px;
}

.panel-head span {
  color: var(--muted);
  font-size: 13px;
}

.chart {
  height: 300px;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  align-items: end;
  padding-top: 24px;
  border-bottom: 1px solid var(--line);
}

.chart i {
  position: relative;
  display: block;
  height: var(--h);
  min-height: 34px;
  background: linear-gradient(#7db7ff, #2563eb);
  border-radius: 6px 6px 0 0;
}

.chart b {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--amber);
  font-size: 12px;
  white-space: nowrap;
}

.alerts {
  padding: 0;
  margin: 0;
  display: grid;
  gap: 12px;
  list-style: none;
}

.alerts li {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  color: var(--muted);
  line-height: 1.65;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
}

.toolbar {
  margin: 4px 0 14px;
}

.select-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.select-label select,
.table-input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.select-label select {
  min-width: 220px;
  padding: 0 10px;
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segmented button {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.segmented button.active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 1px 5px rgba(15, 23, 42, 0.08);
}

.ledger-toolbar {
  align-items: flex-end;
}

.ledger-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.ledger-summary-card {
  display: grid;
  justify-items: start;
  gap: 8px;
  min-height: 130px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.ledger-summary-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.ledger-summary-card strong {
  font-size: 28px;
}

.ledger-summary-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.ledger-summary-card.red strong {
  color: var(--red);
}

.ledger-summary-card.amber strong {
  color: var(--amber);
}

.ledger-summary-card.blue strong {
  color: var(--blue);
}

.ledger-summary-card.green strong {
  color: var(--green);
}

.kpi-grid.embedded {
  margin: 0 0 16px;
  box-shadow: none;
}

.analysis-chart {
  grid-template-columns: repeat(5, 1fr);
}

.analysis-chart i em {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 22px);
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  white-space: nowrap;
}

.rank-list {
  display: grid;
  gap: 14px;
}

.rank-list div {
  display: grid;
  gap: 7px;
}

.rank-list strong,
.rank-list span {
  font-size: 13px;
}

.rank-list span {
  color: var(--muted);
}

.rank-list i {
  display: block;
  width: var(--w);
  height: 9px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.analysis-split {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.cost-donut {
  width: 180px;
  height: 180px;
  display: grid;
  place-content: center;
  gap: 6px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--surface) 0 48%, transparent 49%),
    conic-gradient(var(--blue) 0 70%, var(--teal) 70% 85%, var(--amber) 85% 91%, var(--red) 91% 97%, var(--line) 97% 100%);
  justify-self: center;
  text-align: center;
}

.cost-donut strong {
  font-size: 20px;
}

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

.upload-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(190px, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.upload-card {
  min-height: 210px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.upload-card div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.upload-card strong,
.upload-card span {
  display: block;
}

.upload-card strong {
  font-size: 18px;
}

.upload-card span,
.upload-card p {
  color: var(--muted);
  font-size: 13px;
}

.upload-card p {
  margin: 0;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.file-button {
  margin-top: auto;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  background: #e8f3f1;
  color: #0b7169;
  font-weight: 800;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.steps div {
  min-height: 96px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: 8px;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
}

.steps strong {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--blue);
  color: white;
}

.steps span {
  color: var(--muted);
  line-height: 1.65;
}

.empty {
  min-height: 150px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  padding: 20px;
}

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

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 800;
  background: #f8fafc;
}

td.amount {
  color: var(--blue);
  font-weight: 800;
}

.table-input {
  width: 180px;
  padding: 0 10px;
}

.ghost.small {
  min-height: 34px;
  padding: 0 10px;
}

.rank-list {
  display: grid;
  gap: 12px;
}

.rank-list div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  padding: 12px;
  background: #fff6ed;
  border-radius: 8px;
}

.rank-list strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-list span {
  color: var(--amber);
  font-weight: 800;
}

.rank-list em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.rank-list i {
  grid-column: 1 / -1;
}

.tax-box {
  display: grid;
  gap: 8px;
  align-content: center;
  min-height: 220px;
  text-align: center;
}

.tax-box strong {
  color: var(--blue);
  font-size: 56px;
}

.tax-box span {
  font-weight: 800;
}

.tax-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.flow {
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 2.1;
}

.report {
  display: grid;
  grid-template-columns: minmax(290px, 0.85fr) minmax(0, 1.25fr);
  gap: 16px;
}

.report-cover {
  padding: 28px;
  min-height: 510px;
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(18, 60, 105, 0.96), rgba(13, 101, 96, 0.9)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='500' height='600' viewBox='0 0 500 600'%3E%3Cg fill='rgba(255,255,255,.14)'%3E%3Crect x='70' y='100' width='360' height='230' rx='14'/%3E%3Crect x='105' y='145' width='68' height='145' rx='4'/%3E%3Crect x='205' y='185' width='68' height='105' rx='4'/%3E%3Crect x='305' y='125' width='68' height='165' rx='4'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 14px;
}

.report-cover span {
  color: #baf3e8;
  font-weight: 800;
}

.report-cover h2 {
  margin: 0;
  font-size: 36px;
  line-height: 1.16;
}

.report-cover p {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.7;
}

.report-cover .primary {
  align-self: flex-start;
  margin-top: 6px;
  background: white;
  color: #123c69;
}

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

.report-sections article {
  padding: 18px;
  min-height: 154px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.report-sections strong {
  color: var(--teal);
  font-size: 13px;
}

.report-sections span {
  display: block;
  margin-top: 7px;
  font-weight: 800;
}

.report-sections p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.mobile-nav {
  display: none;
}

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

  .content-grid,
  .report {
    grid-template-columns: 1fr;
  }

  .upload-grid {
    grid-template-columns: repeat(2, minmax(190px, 1fr));
  }
}

@media (max-width: 780px) {
  #app {
    display: block;
    padding-bottom: 74px;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .top-actions .ghost {
    display: none;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .hero {
    min-height: 270px;
    align-items: flex-start;
    flex-direction: column;
    padding: 22px;
  }

  .hero h2 {
    font-size: 30px;
  }

  .health {
    width: 104px;
    margin-left: auto;
  }

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

  .kpi {
    min-height: 128px;
    padding: 15px;
  }

  .kpi strong {
    font-size: 22px;
  }

  .panel {
    padding: 14px;
  }

  .chart {
    height: 220px;
    gap: 8px;
  }

  .report-cover {
    min-height: 390px;
  }

  .report-cover h2 {
    font-size: 30px;
  }

  .report-sections {
    grid-template-columns: 1fr;
  }

  .upload-grid,
  .steps,
  .ledger-summary-grid,
  .analysis-split {
    grid-template-columns: 1fr;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
    box-shadow: 0 -10px 28px rgba(26, 38, 64, 0.1);
  }

  .mobile-nav button {
    min-height: 56px;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
  }

  .mobile-nav button.active {
    background: #e8f3f1;
    color: #0b7169;
    font-weight: 800;
  }
}

@media (max-width: 430px) {
  .kpi-grid,
  .kpi-grid.compact {
    grid-template-columns: 1fr;
  }

  .top-actions .primary span {
    display: none;
  }

  .toolbar .ghost {
    flex: 1 1 160px;
  }
}
