:root {
  --bg: #f4f4f5;
  --card: #ffffff;
  --raised: #f4f4f5;
  --ink: #171717;
  --secondary: #525252;
  --muted: #737373;
  --line: rgba(23, 23, 23, 0.08);
  --accent: #8f1d1d;
  --bad: #9f1239;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 15px/22px var(--sans);
}

h1, h2, p { margin: 0; }

a { color: var(--ink); }

button, input, select, textarea { font: inherit; color: inherit; }

.shell { display: flex; min-height: 100vh; }

aside {
  width: 256px;
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 16px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

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

.mark {
  width: 28px;
  height: 28px;
  flex: none;
  color: var(--accent);
}

.brand strong {
  display: block;
  font-size: 16px;
  font-weight: 500;
  line-height: 20px;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

aside nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 24px;
}

aside a {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  color: var(--secondary);
  text-decoration: none;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}

aside a:hover { background: var(--raised); color: var(--ink); }

aside a.on {
  background: var(--raised);
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--accent);
}

.ico {
  width: 16px;
  height: 16px;
  flex: none;
  display: grid;
  place-items: center;
  color: var(--muted);
}

aside a.on .ico,
aside a:hover .ico { color: var(--secondary); }

.ico svg { width: 16px; height: 16px; display: block; }

.me {
  margin-top: auto;
  padding: 16px 8px 0;
  border-top: 1px solid var(--line);
}

.me .who { font-size: 14px; line-height: 20px; }

.role {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

.linkish, button.linkish {
  margin-top: 8px;
  padding: 0;
  height: auto;
  background: none;
  border: 0;
  color: var(--secondary);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

main {
  flex: 1;
  min-width: 0;
  padding: 32px 32px 64px;
}

main > h1 {
  font-size: 32px;
  font-weight: 500;
  line-height: 1.15;
}

main > h2 {
  margin: 32px 0 12px;
  font-size: 18px;
  font-weight: 500;
  line-height: 24px;
}

.panel h2 {
  margin: 24px 0 12px;
  font-size: 18px;
  font-weight: 500;
  line-height: 24px;
}

.panel h2:first-of-type { margin-top: 0; }

.panel .note { margin: 0 0 16px; }

.board + .note { display: block; margin-top: 16px; }

.note, .muted {
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

main > .note,
main > .muted { margin-top: 8px; }

.flash, .error, .banner {
  margin: 24px 0;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.error { border-left-color: var(--accent); }

.board {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
  gap: 16px;
  margin-top: 32px;
}

.ledger, .stat, .panel, table, .slip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.ledger {
  min-height: 320px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  border-left: 3px solid var(--accent);
}

.ledger .kicker,
.slip .kicker,
.stat span,
.card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
}

.ledger .total {
  margin: auto 0;
  padding: 32px 0;
}

.rule {
  display: inline-block;
  border-bottom: 3px double var(--ink);
  padding-bottom: 8px;
  font-family: var(--mono);
  font-size: 56px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.unit {
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--secondary);
}

.stat .unit { font-size: 13px; }

.ledger footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--secondary);
  font-size: 14px;
  line-height: 20px;
}

.ledger footer b {
  font-family: var(--mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat {
  min-height: 154px;
  padding: 20px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat b {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat.hot b { color: var(--accent); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 24px 0 16px;
}

.filters a {
  height: 32px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  color: var(--secondary);
  text-decoration: none;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}

.filters a:hover, .filters a.on { background: var(--card); color: var(--ink); }
.filters a.on { box-shadow: inset 0 -2px 0 var(--accent); }

table {
  width: 100%;
  margin-top: 16px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}

th, td {
  padding: 0 16px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
}

th {
  height: 36px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 16px;
}

td {
  height: 48px;
  font-variant-numeric: tabular-nums;
}

tr:last-child td { border-bottom: 0; }

tbody tr:hover td { background: #fafafa; }

td .muted { margin-top: 2px; }

.num, dd.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th.num, td.num { text-align: right; }

.toolbar, .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toolbar { margin: 24px 0 0; }

input, select, textarea {
  height: 36px;
  padding: 0 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: border-color 160ms var(--ease);
}

textarea {
  height: auto;
  min-height: 96px;
  padding: 12px;
  width: min(100%, 420px);
  resize: vertical;
}

input:hover, select:hover, textarea:hover,
input:focus, select:focus, textarea:focus { border-color: rgba(23, 23, 23, 0.28); }

button, .button {
  height: 36px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 8px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 160ms var(--ease), transform 120ms var(--ease);
}

button:hover, .button:hover { background: #2a2a2a; }

button:active { transform: scale(0.98); }

button.secondary, a.secondary {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
}

button.secondary:hover, a.secondary:hover { background: var(--raised); }

button.danger {
  background: var(--card);
  color: var(--bad);
  border: 1px solid rgba(159, 18, 57, 0.28);
}

button.danger:hover { background: #fdf2f4; }

label {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  color: var(--secondary);
  font-size: 13px;
  line-height: 16px;
}

.confirm {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  color: var(--ink);
  font-size: 14px;
}

.confirm input { width: 16px; height: 16px; }

.panel { padding: 24px; border-radius: 12px; }

.form { max-width: 480px; margin-top: 24px; }

.desk {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.desk > .form { max-width: none; margin-top: 0; }

.desk textarea,
.desk input:not([type="checkbox"]) { width: 100%; }

.grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 16px;
  margin-top: 24px;
}

dl {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px 16px;
  margin: 0;
}

dt { color: var(--muted); }

dd { margin: 0; }

.slip { padding: 24px; margin-top: 24px; }

.slip-head, .tally-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.slip h1 {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0;
}

.stamp {
  flex: none;
  margin-top: 4px;
  padding: 4px 8px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  color: var(--ink);
  font-size: 12px;
  line-height: 16px;
}

.stamp.pending_review, .stamp.payment_unknown { color: var(--accent); border-color: var(--accent); }

.stamp.rejected { color: var(--bad); border-color: rgba(159, 18, 57, 0.45); }

.tally { margin-top: 32px; max-width: 420px; }

.tally-row {
  align-items: baseline;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.tally-row span { color: var(--secondary); }

.tally-row b {
  font-family: var(--mono);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.tally-row.total { border-top: 0; padding-top: 20px; }

.tally-row.total b.rule { font-size: 32px; letter-spacing: -0.02em; }

.state { font-size: 13px; }

.state.pending_review, .state.payment_unknown { color: var(--accent); }

main > form.panel { margin-top: 16px; }

.state.rejected { color: var(--bad); }

.meta {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 12px 16px;
  margin-top: 32px;
}

.meta dt { color: var(--muted); }

.meta dd { margin: 0; word-break: break-all; }

.pager {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  color: var(--secondary);
  font-size: 13px;
}

.gate {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
}

.gate-copy {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 48px;
  padding: 48px;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.gate-copy h1 {
  margin-top: 24px;
  font-size: 40px;
  font-weight: 500;
  line-height: 1.15;
}

.facts {
  margin: 32px 0 0;
  padding: 0;
  list-style: none;
}

.facts li {
  padding: 12px 0;
  border-top: 1px solid var(--line);
  color: var(--secondary);
}

.facts li:first-child { border-top: 3px double var(--ink); }

.gate form {
  max-width: 400px;
  margin: auto;
  padding: 48px 32px;
  width: 100%;
}

.gate h2 {
  margin-bottom: 8px;
  font-size: 28px;
  font-weight: 500;
  line-height: 1.15;
}

.gate .muted { display: block; margin-bottom: 24px; }

.gate label input { width: 100%; }

.gate button { width: 100%; margin-top: 8px; }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .shell { display: block; }
  .gate, .board, .grid2, .stats, .desk { grid-template-columns: 1fr; }
  aside { width: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  aside nav { flex-direction: row; flex-wrap: wrap; margin-top: 16px; }
  .me { margin-top: 16px; }
  main, .gate-copy, .gate form { padding: 24px; }
  .rule { font-size: 40px; letter-spacing: -0.02em; }
  .ledger { min-height: 0; }
  .stat { min-height: 96px; }
  dl, .meta { grid-template-columns: 1fr; gap: 4px; }
  dd, .meta dd { margin-bottom: 8px; }
  .gate-copy { border-right: 0; border-bottom: 1px solid var(--line); }
  .gate-copy h1, .gate h2 { font-size: 32px; }
}
