:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans SC", sans-serif;
  color: #17211d;
  background: #f4f6f4;
  font-synthesis: none;
  --ink: #17211d;
  --muted: #68726d;
  --line: #dce2de;
  --surface: #ffffff;
  --soft: #f7f9f7;
  --brand: #176b4f;
  --brand-dark: #10513c;
  --brand-soft: #e6f3ed;
  --amber: #a66512;
  --amber-soft: #fff4df;
  --danger: #b42318;
  --shadow: 0 10px 32px rgba(24, 40, 33, 0.08);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #f4f6f4; }
body { margin: 0; min-height: 100vh; }
button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 224px; padding: 24px 16px; background: #17382e; color: #fff; display: flex; flex-direction: column; z-index: 20; }
.brand-block { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 7px; background: #f0c96b; color: #18372e; font-size: 20px; font-weight: 800; }
.brand-block strong { display: block; font-size: 19px; line-height: 1.2; }
.brand-block span { display: block; margin-top: 3px; color: #afc4bc; font-size: 12px; }
.nav-list { display: grid; gap: 6px; margin-top: 38px; }
.nav-item { width: 100%; height: 44px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: #cbd9d4; display: flex; align-items: center; gap: 11px; text-align: left; }
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: #fff; color: #17382e; font-weight: 700; }
.sidebar-note { margin-top: auto; padding: 14px 10px; border-top: 1px solid rgba(255,255,255,.14); color: #afc4bc; font-size: 12px; display: flex; gap: 8px; align-items: center; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #61d695; box-shadow: 0 0 0 3px rgba(97,214,149,.13); }

.main-content { min-height: 100vh; margin-left: 224px; }
.view { display: none; width: min(1380px, 100%); margin: 0 auto; padding: 42px 44px 70px; }
.view.active { display: block; }
.mobile-header, .mobile-nav { display: none; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 6px; color: var(--brand); font-size: 12px; font-weight: 800; }
h1, h2, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 28px; line-height: 1.25; }
.page-heading > div > p:last-child { margin: 7px 0 0; color: var(--muted); font-size: 14px; }

.primary-button, .secondary-button, .danger-button, .text-button, .icon-button { border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; border-radius: 6px; font-weight: 700; }
.primary-button { min-width: 138px; padding: 0 20px; background: var(--brand); color: #fff; }
.primary-button:hover { background: var(--brand-dark); }
.secondary-button { padding: 0 14px; background: var(--surface); color: #36423d; border: 1px solid var(--line); }
.secondary-button:hover { border-color: #a9b5af; }
.danger-button { padding: 0 14px; background: #fff1f0; color: var(--danger); }
.text-button { padding: 0 8px; color: var(--brand); background: transparent; align-self: end; }
.icon-button { width: 38px; min-height: 38px; background: var(--soft); color: #44514b; }
button svg { width: 17px; height: 17px; flex: 0 0 auto; }

#entry-form { display: grid; gap: 14px; }
.form-section { padding: 23px 24px 26px; background: var(--surface); border: 1px solid #e1e6e3; border-radius: 8px; }
.section-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 21px; }
.section-number { width: 30px; height: 24px; display: grid; place-items: center; border-radius: 4px; background: var(--brand-soft); color: var(--brand); font-size: 11px; font-weight: 800; }
.section-heading h2, .table-toolbar h2 { margin: 0; font-size: 16px; line-height: 1.35; }
.section-heading p, .table-toolbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; gap: 16px; }
.columns-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.columns-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
label { min-width: 0; }
label > span, .filters label > span { display: block; margin-bottom: 7px; color: #53605a; font-size: 12px; font-weight: 700; }
input { width: 100%; height: 40px; padding: 0 11px; border: 1px solid #d7ded9; border-radius: 5px; background: #fff; color: var(--ink); outline: none; }
input::placeholder { color: #a4ada8; }
input:hover { border-color: #b9c4be; }
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(23,107,79,.1); }
input[type="number"] { text-align: right; }
.more-fields { margin-top: 18px; border-top: 1px solid #e5eae7; }
.more-fields summary { height: 48px; display: flex; align-items: center; gap: 9px; color: var(--brand); font-size: 13px; font-weight: 700; list-style: none; cursor: pointer; }
.more-fields summary::-webkit-details-marker { display: none; }
.more-fields summary .chevron { margin-left: auto; transition: transform .18s ease; }
.more-fields[open] summary .chevron { transform: rotate(180deg); }
.details-grid { padding-top: 4px; }
.settlement-row { margin-top: 22px; padding: 18px; display: grid; grid-template-columns: 1fr 1fr 1.5fr auto; gap: 16px; align-items: end; background: #f4f8f5; border-radius: 6px; }
.live-total { min-width: 158px; padding-left: 18px; border-left: 1px solid #cfdbd4; text-align: right; }
.live-total span { display: block; color: var(--muted); font-size: 12px; }
.live-total strong { display: block; margin-top: 5px; color: var(--brand-dark); font-size: 22px; }
.form-actions { min-height: 60px; padding-top: 4px; display: flex; justify-content: flex-end; align-items: center; gap: 16px; }
#form-status { color: var(--muted); font-size: 13px; }

.filters { margin-bottom: 16px; padding: 16px 18px; display: grid; grid-template-columns: 170px 170px minmax(240px, 1fr) auto; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.input-with-icon { position: relative; }
.input-with-icon svg { position: absolute; top: 11px; left: 11px; width: 17px; height: 17px; color: #7b8781; }
.input-with-icon input { padding-left: 36px; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { min-height: 112px; padding: 19px; border: 1px solid var(--line); border-top: 3px solid #57786c; border-radius: 7px; background: var(--surface); }
.kpi > span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi strong { display: block; margin-top: 12px; font-size: 25px; line-height: 1; }
.kpi small { display: block; margin-top: 8px; color: #8a938f; font-size: 11px; }
.kpi.expense { border-top-color: var(--amber); }
.kpi.expense strong { color: #8c570f; }
.kpi.balance { border-top-color: var(--brand); background: #f4faf7; }
.kpi.balance strong { color: var(--brand-dark); }
.table-section { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.table-toolbar { min-height: 64px; padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.table-scroll { overflow-x: auto; }
table { width: 100%; min-width: 940px; border-collapse: collapse; }
th { height: 40px; padding: 0 14px; background: #f6f8f6; color: #637069; font-size: 11px; text-align: left; white-space: nowrap; }
td { height: 53px; padding: 0 14px; border-top: 1px solid #e9edea; color: #26312c; font-size: 13px; white-space: nowrap; }
tbody tr:hover { background: #fafcfb; }
th.number, td.number { text-align: right; font-variant-numeric: tabular-nums; }
.route-cell { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
.source-badge { display: inline-block; margin-left: 5px; padding: 2px 5px; border-radius: 3px; background: #edf1ef; color: #6d7772; font-size: 9px; vertical-align: 1px; }
.row-action { width: 34px; height: 34px; border: 0; border-radius: 5px; background: transparent; color: #637069; display: grid; place-items: center; }
.row-action:hover { background: var(--brand-soft); color: var(--brand); }
.empty-state { min-height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #8a948f; }
.empty-state[hidden] { display: none; }
.empty-state svg { width: 30px; height: 30px; margin-bottom: 12px; }
.empty-state strong { color: #4e5954; font-size: 14px; }
.empty-state span { margin-top: 6px; font-size: 12px; }

dialog { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; border: 0; border-radius: 8px; box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(13, 29, 23, .46); }
.dialog-header { min-height: 76px; padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; font-size: 18px; }
.detail-grid { padding: 20px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.detail-item { min-height: 74px; padding: 13px 14px; background: #fff; }
.detail-item.wide { grid-column: span 3; }
.detail-item span { display: block; color: var(--muted); font-size: 11px; }
.detail-item strong { display: block; margin-top: 7px; font-size: 14px; overflow-wrap: anywhere; }
.dialog-actions { min-height: 66px; padding: 13px 20px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 60; max-width: 320px; padding: 12px 16px; border-radius: 6px; background: #18372e; color: #fff; font-size: 13px; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  .columns-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .columns-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settlement-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-total { border-left: 0; padding: 0; text-align: left; }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  body { padding-bottom: 64px; }
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .mobile-header { height: 58px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; background: #17382e; color: #fff; }
  .brand-block.compact { padding: 0; gap: 9px; }
  .compact .brand-mark { width: 32px; height: 32px; border-radius: 5px; font-size: 16px; }
  .compact strong { font-size: 16px; }
  .mobile-status { color: #b9ccc5; font-size: 11px; }
  .mobile-nav { position: fixed; inset: auto 0 0 0; height: 64px; z-index: 40; display: grid; grid-template-columns: 1fr 1fr; background: #fff; border-top: 1px solid var(--line); }
  .mobile-nav button { border: 0; background: transparent; color: #758079; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 11px; }
  .mobile-nav button.active { color: var(--brand); font-weight: 700; }
  .mobile-nav svg { width: 19px; height: 19px; }
  .view { padding: 25px 14px 32px; }
  .page-heading { align-items: flex-start; }
  h1 { font-size: 23px; }
  .page-heading .secondary-button span { display: none; }
  .page-heading .secondary-button { width: 40px; padding: 0; }
  .form-section { padding: 19px 16px 21px; }
  .columns-5, .columns-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .settlement-row { margin: 18px -2px 0; padding: 15px; grid-template-columns: 1fr; }
  .live-total { padding-top: 12px; border-top: 1px solid #d3ddd7; }
  .form-actions { position: sticky; bottom: 70px; z-index: 10; margin: 0 -4px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.96); box-shadow: 0 8px 24px rgba(24,40,33,.1); }
  #form-status { display: none; }
  .primary-button { width: 100%; }
  .filters { grid-template-columns: 1fr 1fr; padding: 14px; }
  .search-field { grid-column: span 2; }
  .text-button { justify-self: start; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { min-height: 102px; padding: 16px; }
  .kpi strong { font-size: 21px; }
  .kpi.balance { grid-column: span 2; }
  table { min-width: 0; table-layout: fixed; }
  th:nth-child(4), td:nth-child(4),
  th:nth-child(5), td:nth-child(5),
  th:nth-child(6), td:nth-child(6),
  th:nth-child(7), td:nth-child(7),
  th:nth-child(8), td:nth-child(8) { display: none; }
  th:nth-child(1) { width: 98px; }
  th:nth-child(2) { width: 112px; }
  th:nth-child(9) { width: 48px; }
  th, td { padding-right: 10px; padding-left: 10px; overflow: hidden; text-overflow: ellipsis; }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-item.wide { grid-column: span 2; }
  .toast { right: 14px; bottom: 76px; left: 14px; max-width: none; text-align: center; }
}

@media (max-width: 420px) {
  .filters { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-item.wide { grid-column: auto; }
}
