:root {
  color-scheme: light;
  --paper: #eef7ef;
  --paper-2: #fff8e8;
  --panel: #fffefa;
  --surface: #fffdf6;
  --surface-strong: #edf8f0;
  --ink: #102a32;
  --muted: #435b66;
  --line: #d5e1da;
  --green: #0f8a6a;
  --bottle: #11745f;
  --bottle-2: #e4f7ee;
  --gold: #d97706;
  --amber: #f59e0b;
  --wine: #b24a52;
  --blue: #2f7ba6;
  --teal: #13847c;
  --coral: #c7664c;
  --soft-blue: #eaf4fb;
  --soft-gold: #fff4d8;
  --soft-wine: #fff0f1;
  --soft-green: #e6f7ee;
  --brand-black: #15110b;
  --brand-black-2: #241a0e;
  --brand-gold: #d7b268;
  --brand-gold-soft: #f4dfad;
  --brand-cream: #fff8e6;
  --shadow: 0 18px 42px rgba(25, 72, 82, .10);
  --strong-shadow: 0 20px 42px rgba(25, 72, 82, .16);
  --radius: 8px;
  --nav-width: 276px;
  --mono: "SFMono-Regular", "Menlo", "Consolas", monospace;
  --body: "Alibaba PuHuiTi", "HarmonyOS Sans SC", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(rgba(245, 158, 11, .026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 138, 106, .024) 1px, transparent 1px),
    linear-gradient(122deg, #fff8e8 0%, #f8fbf2 38%, #edf8f4 100%);
  background-size: 28px 28px, 28px 28px, auto;
  font-family: var(--body);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: var(--nav-width) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 0;
  width: var(--nav-width);
  background:
    linear-gradient(180deg, var(--brand-black) 0%, var(--brand-black-2) 54%, #0e100e 100%);
  border-right: 1px solid rgba(215, 178, 104, .34);
  box-shadow: 12px 0 36px rgba(18, 14, 8, .18);
  pointer-events: none;
}

.side-rail {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 100vh;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: transparent;
}

.brand-lockup {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(255, 248, 230, .20);
  background: #e60012;
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  box-shadow: 0 14px 26px rgba(0, 0, 0, .32), 0 0 0 1px rgba(215, 178, 104, .24);
}

.brand-lockup strong {
  display: block;
  color: var(--brand-cream);
  font-size: 17px;
  line-height: 1.2;
}

.brand-lockup span {
  display: block;
  margin-top: 4px;
  color: var(--brand-gold);
  font-size: 12px;
}

.rail-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: rgba(255, 248, 230, .80);
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  text-align: left;
  font-weight: 720;
  transition: background .18s ease, color .18s ease, transform .18s ease, border-color .18s ease;
}

.nav-item:hover {
  background: rgba(255, 248, 230, .08);
  color: var(--brand-gold-soft);
  border-color: rgba(215, 178, 104, .28);
  box-shadow: inset 3px 0 0 var(--brand-gold);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(215, 178, 104, .24), rgba(255, 248, 230, .08));
  color: var(--brand-cream);
  border-color: rgba(215, 178, 104, .46);
  box-shadow: 0 14px 28px rgba(0, 0, 0, .24), inset 3px 0 0 var(--brand-gold);
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: currentColor;
  background: rgba(215, 178, 104, .15);
  font-size: 14px;
  font-weight: 800;
}

.identity-panel {
  border: 1px solid rgba(215, 178, 104, .24);
  background: rgba(255, 248, 230, .06);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 248, 230, .06);
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.identity-panel label {
  color: rgba(244, 223, 173, .78);
}

select,
input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.identity-panel select {
  border-color: rgba(215, 178, 104, .34);
  background-color: rgba(255, 248, 230, .09);
  color: var(--brand-cream);
}

select:focus,
input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 138, 106, .16);
}

.identity-meta {
  margin-top: 10px;
  color: rgba(244, 223, 173, .74);
  font-size: 12px;
  line-height: 1.5;
}

.rail-status {
  margin-top: auto;
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: start;
  padding: 13px 12px;
  border-top: 1px solid rgba(215, 178, 104, .22);
}

#saveStateDot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--brand-gold);
  box-shadow: 0 0 0 4px rgba(215, 178, 104, .12);
}

.rail-status p {
  margin: 0;
  color: rgba(244, 223, 173, .74);
  font-size: 12px;
  line-height: 1.55;
}

.workbench {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 26px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.topbar,
.control-strip,
.metric-grid,
.view-panel {
  max-width: 1560px;
  width: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -26px -26px 2px;
  padding: 26px 26px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background:
    linear-gradient(135deg, rgba(21, 17, 11, .98), rgba(53, 38, 17, .96) 56%, rgba(17, 17, 14, .98));
  border-bottom: 1px solid rgba(215, 178, 104, .34);
  box-shadow: 0 18px 34px rgba(23, 18, 10, .20);
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--brand-gold);
  font-size: 12px;
  font-weight: 820;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  color: var(--brand-cream);
  font-size: 26px;
  line-height: 1.16;
}

h2 {
  color: var(--ink);
  font-size: 18px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.action-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  background: var(--green);
  color: #fffdf7;
  padding: 0 14px;
  font-weight: 780;
  white-space: nowrap;
  box-shadow: 0 14px 28px rgba(15, 138, 106, .18);
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.action-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(15, 138, 106, .24);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 19px;
}

.action-button.secondary {
  background: rgba(255, 248, 230, .10);
  color: var(--brand-cream);
  border: 1px solid rgba(215, 178, 104, .34);
  box-shadow: none;
}

.control-strip {
  display: grid;
  grid-template-columns: 132px 154px 170px 150px 150px minmax(220px, 1fr);
  gap: 12px;
  padding: 14px;
  background: rgba(255, 254, 250, .94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-strip label {
  color: var(--muted);
}

.money-input {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
}

.money-input input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.money-input span {
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-left: 0;
  border-top-right-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  background: var(--soft-gold);
  color: #9a5606;
  font-weight: 840;
}

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

.metric-tile {
  position: relative;
  min-height: 118px;
  padding: 15px 16px;
  display: grid;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.metric-tile::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--green);
}

.metric-tile:nth-child(2)::before {
  background: var(--gold);
}

.metric-tile:nth-child(4)::before {
  background: var(--blue);
}

.metric-tile.highlight {
  background:
    linear-gradient(135deg, rgba(15, 138, 106, .96), rgba(17, 116, 95, .96));
  color: #fff9ec;
  border-color: rgba(15, 138, 106, .30);
  box-shadow: 0 18px 38px rgba(15, 90, 78, .22);
}

.metric-tile.highlight::before {
  background: var(--brand-gold);
}

.metric-tile span,
.metric-tile small {
  color: var(--muted);
}

.metric-tile.highlight span,
.metric-tile.highlight small {
  color: rgba(255, 249, 236, .78);
}

.metric-tile span {
  font-size: 12px;
  font-weight: 820;
}

.metric-tile strong {
  margin-top: 12px;
  font-size: 27px;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.metric-tile small {
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.3;
}

.view-panel {
  display: none;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 254, 250, .94);
  box-shadow: var(--shadow);
}

.view-panel.active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.segmented {
  display: flex;
  padding: 3px;
  background: var(--surface-strong);
  border: 1px solid rgba(15, 138, 106, .12);
  border-radius: var(--radius);
}

.segmented button {
  min-height: 30px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 11px;
  font-weight: 760;
}

.segmented button.active {
  background: var(--panel);
  color: var(--green);
  box-shadow: 0 8px 18px rgba(25, 72, 82, .08);
}

.add-entry-panel {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 14px;
  align-items: end;
  margin-bottom: 14px;
  padding: 13px;
  border: 1px solid rgba(15, 138, 106, .16);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(237, 248, 240, .78), rgba(255, 253, 246, .92));
}

.add-entry-title strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
}

.add-entry-title span,
.add-entry-grid label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.add-entry-title span {
  margin-top: 5px;
  line-height: 1.4;
}

.add-entry-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(170px, 1fr) 160px 82px;
  gap: 10px;
  align-items: end;
}

.add-entry-grid label {
  margin: 0;
}

.add-entry-grid label span {
  margin-bottom: 6px;
}

.table-wrap,
.summary-table-wrap {
  overflow: auto;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.forecast-table {
  min-width: 1280px;
}

.summary-table {
  min-width: 760px;
}

.board-table {
  min-width: 980px;
}

.value-chain-table {
  min-width: 1320px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(180deg, #f4fbf2, #e6f1e8);
  color: #315349;
  font-size: 12px;
  text-align: left;
  font-weight: 860;
}

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid #e4eee7;
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background: rgba(237, 248, 240, .36);
}

tbody tr:hover {
  background: #fff4d8;
}

.forecast-table input {
  min-width: 108px;
  height: 34px;
  min-height: 34px;
  border-color: rgba(15, 138, 106, .30);
  background: #fffefa;
  color: var(--ink);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.value-chain-input {
  width: 124px;
  min-width: 124px;
  height: 34px;
  min-height: 34px;
  border-color: rgba(15, 138, 106, .30);
  background: #fffefa;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.forecast-table input:disabled {
  background: #eff3ef;
  color: #87928a;
}

.value-chain-input:disabled {
  background: #eff3ef;
  color: #87928a;
}

.mini-progress {
  width: 104px;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e0eadf;
}

.mini-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--green));
}

td small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.link-button {
  min-height: 30px;
  border: 1px solid rgba(15, 138, 106, .24);
  border-radius: var(--radius);
  background: var(--bottle-2);
  color: var(--green);
  padding: 0 10px;
  font-weight: 840;
}

.link-button:hover {
  border-color: rgba(15, 138, 106, .42);
  background: #d9f2e6;
}

.link-button.danger {
  margin-left: 6px;
  border-color: rgba(178, 74, 82, .26);
  background: var(--soft-wine);
  color: var(--wine);
}

.cell-main {
  display: block;
  max-width: 260px;
  color: var(--ink);
  white-space: normal;
  font-weight: 780;
  line-height: 1.32;
}

.cell-sub {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
  line-height: 1.35;
}

.money,
.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-width: 54px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(15, 138, 106, .20);
  background: var(--soft-green);
  color: var(--green);
  font-size: 12px;
  font-weight: 860;
}

.status-pill.empty {
  border-color: #edc980;
  background: var(--soft-gold);
  color: #9a5606;
}

.status-pill.warn {
  border-color: #edbdc1;
  background: var(--soft-wine);
  color: var(--wine);
}

.empty-cell {
  height: 180px;
  text-align: center;
  color: var(--muted);
}

.review-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr);
  gap: 14px;
}

.audit-panel,
.permission-grid {
  display: grid;
  gap: 10px;
}

.audit-card,
.permission-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.audit-card {
  box-shadow: inset 4px 0 0 var(--green);
}

.audit-card:nth-child(2) {
  box-shadow: inset 4px 0 0 var(--gold);
}

.audit-card:nth-child(3) {
  box-shadow: inset 4px 0 0 var(--blue);
}

.audit-card strong,
.permission-card strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
}

.audit-card p,
.permission-card p,
.permission-card a {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.permission-card a {
  color: var(--green);
  word-break: break-all;
}

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

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

  .app-shell::before {
    display: none;
  }

  .side-rail {
    position: relative;
    height: auto;
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(260px, 1.2fr);
    background:
      linear-gradient(180deg, var(--brand-black) 0%, var(--brand-black-2) 100%);
    border-bottom: 1px solid rgba(215, 178, 104, .34);
  }

  .rail-nav,
  .rail-status {
    grid-column: 1 / -1;
  }

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

  .nav-item {
    min-height: 42px;
  }

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

  .add-entry-panel {
    grid-template-columns: 1fr;
  }

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

  .control-group.wide,
  .fee-control {
    grid-column: auto;
  }

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

  .review-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .workbench,
  .side-rail {
    padding: 14px;
  }

  .topbar {
    position: relative;
    margin: -14px -14px 0;
    padding: 18px 14px;
  }

  .side-rail,
  .topbar,
  .section-head {
    display: grid;
  }

  .side-rail {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .rail-nav,
  .control-strip,
  .metric-grid,
  .permission-grid,
  .add-entry-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap,
  .summary-table-wrap {
    max-width: calc(100vw - 60px);
  }

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

  .icon-button {
    flex: 0 0 58px;
  }

  .action-button.secondary,
  .action-button {
    flex: 1 1 120px;
  }

  h1 {
    font-size: 24px;
  }

  .metric-tile {
    min-height: 98px;
  }
}
