:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --ink: #393a3d;
  --muted: #6b6c72;
  --line: #d4d7dc;
  --line-strong: #8d9096;
  --sidebar: #ffffff;
  --sidebar-ink: #393a3d;
  --sidebar-muted: #6b6c72;
  --green: #2ca01c;
  --green-hover: #248617;
  --green-active: #1b6b10;
  --green-soft: #e5f6e3;
  --green-soft-ink: #0d6b0a;
  --button: #2ca01c;
  --button-ink: #ffffff;
  --link: #0077c5;
  --link-hover: #005a96;
  --good: #0d7a12;
  --bad: #d52b1e;
  --good-bg: #e5f6e3;
  --good-ink: #0d6b0a;
  --bad-bg: #fdecea;
  --bad-ink: #a11d14;
  --mid-bg: #fff4e5;
  --mid-ink: #8a4b08;
  --shadow: 0 1px 2px rgba(15, 15, 20, 0.06), 0 0 0 1px rgba(15, 15, 20, 0.02);
  --sans: "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --radius: 8px;
  --radius-control: 4px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2, h3 {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--ink);
}

h1 { margin: 0 0 0.75rem; font-size: 1.7rem; }
h2 { margin: 0 0 0.55rem; font-size: 1.2rem; }
h3 { margin: 0 0 0.35rem; font-size: 1rem; }
p { margin: 0.35rem 0; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.skip {
  position: absolute;
  left: -999px;
  background: var(--surface);
  color: var(--ink);
  padding: 0.4rem 0.6rem;
}
.skip:focus { left: 0.5rem; top: 0.5rem; z-index: 5; }

.shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: calc(100vh - env(safe-area-inset-top));
  min-height: calc(100dvh - env(safe-area-inset-top));
}

aside {
  position: sticky;
  top: 0;
  height: calc(100vh - env(safe-area-inset-top));
  height: calc(100dvh - env(safe-area-inset-top));
  overflow: auto;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  border-right: 1px solid var(--line);
  padding: 1rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

aside a { color: inherit; text-decoration: none; }
aside a:hover { text-decoration: none; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--green);
  padding: 0.15rem 0.45rem 0.35rem;
}
.brand::before {
  content: "";
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 6px;
  background-color: var(--green);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' d='M5 4.5h10.2a3.3 3.3 0 0 1 0 6.6H5V4.5zm0 8.4h12.2a3.3 3.3 0 0 1 0 6.6H5v-6.6z'/%3E%3Cpath stroke='%232ca01c' stroke-width='1.2' d='M5 4.5v15'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px 18px;
}
.brand:hover { color: var(--green-hover); text-decoration: none; }

.user, .book { margin: 0; }
.user {
  color: var(--sidebar-muted);
  font-size: 0.85rem;
  padding: 0 0.55rem;
}
a.book {
  display: block;
  margin: 0.85rem 0.35rem 0.15rem;
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--ink);
  text-decoration: none;
}
a.book:hover { background: #e7e9ee; color: var(--ink); text-decoration: none; }
a.book.active { background: var(--green-soft); color: var(--green-soft-ink); }

.nav { display: grid; gap: 0.1rem; margin-top: 0.55rem; }
.nav a, .nav button.linkish {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: var(--radius);
  padding: 0.45rem 0.65rem;
  color: var(--sidebar-ink);
  background: transparent;
  border: 0;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.nav a:hover, .nav button.linkish:hover {
  background: var(--bg);
  color: var(--ink);
  text-decoration: none;
}
.nav a.active {
  background: var(--green-soft);
  color: var(--green-soft-ink);
  font-weight: 700;
}
.nav a.active:hover { background: #d8f0d4; }
.nav-label {
  margin: 0.85rem 0 0.15rem;
  padding: 0 0.65rem;
  color: var(--sidebar-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nav.foot {
  margin-top: auto;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.main { padding: 1.5rem 1.75rem calc(3.5rem + env(safe-area-inset-bottom)); }
.wrap { max-width: 1080px; }

.gate {
  min-height: calc(100vh - env(safe-area-inset-top));
  min-height: calc(100dvh - env(safe-area-inset-top));
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1rem;
  padding: 2rem 1rem 3rem;
  background: var(--bg);
}
.gate-brand { text-align: center; max-width: 26rem; }
.gate-brand .brand {
  font-size: 1.55rem;
  justify-content: center;
  padding-bottom: 0.15rem;
}
.gate-brand p { color: var(--muted); margin-top: 0.35rem; }
.gate .wrap { width: min(26rem, 100%); }
.gate .sheet { padding: 1.35rem 1.4rem 1.2rem; }
.gate button, .gate .button { width: 100%; text-align: center; }

.sheet, .empty, .card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.empty { color: var(--muted); }
.cards + .sheet, .sheet + .form, form + .sheet { margin-top: 0.85rem; }
.main .sheet { margin-bottom: 0.85rem; }
.main .stats > .sheet,
.main .cards > .sheet,
.main .form > .sheet { margin-bottom: 0; }
.sheet-gap { margin-top: 0.85rem; }

.narrow {
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 2rem 1rem;
}
.narrow .card { width: min(28rem, 100%); }

.cards {
  list-style: none;
  padding: 0;
  margin: 0.7rem 0 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.75rem;
  align-items: stretch;
}
.cards > li {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 6.5rem;
}
.card-main {
  display: flex;
  gap: 0.35rem;
  align-items: flex-start;
}
.cards > li .card-title::after {
  content: "";
  position: absolute;
  inset: 0;
}
.card-action { position: relative; z-index: 1; }
.card-action button { margin-top: 0.55rem; }
.sheet form + form, .sheet form + .note { margin-top: 0.85rem; }
.card-title {
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  color: var(--ink);
}
.card-title:hover { color: var(--link); text-decoration: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin: 0.85rem 0 1.4rem;
}
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.figure {
  margin: 0.35rem 0 0;
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}
.note { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.in { color: var(--good); }
.out { color: var(--bad); }
.transfer { color: var(--muted); }

.title-row, .year-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.title-row h1, .title-row h2 { margin-bottom: 0; flex: 1; }
.title-row { margin-bottom: 0.85rem; }
.year-nav { margin: 0.4rem 0 0.9rem; }
.year-nav span { font-weight: 700; font-size: 1.05rem; }

.form { display: grid; gap: 0.85rem; }
.row-2, .split { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.line-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1.15fr) minmax(6.5rem, 0.55fr) auto;
  gap: 0.6rem;
  align-items: end;
}
.tx-meta-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 0.9fr 0.9fr 1.3fr;
  gap: 0.55rem 0.65rem;
  align-items: end;
}
.line-total {
  margin: 0.15rem 0 0.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tx-summary {
  display: grid;
  grid-template-columns: minmax(8rem, 12rem) minmax(0, 1fr);
  gap: 0.75rem 1.5rem;
  align-items: start;
}
.tx-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem 1.1rem;
  margin: 0;
}
.tx-facts div { min-width: 0; }
.tx-facts dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.tx-facts dd { margin: 0.12rem 0 0; font-weight: 600; }
.tx-facts .tx-wide { grid-column: 1 / -1; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
dialog.popup {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.2rem;
  width: min(34rem, calc(100vw - 2rem));
  box-shadow: 0 18px 48px rgba(15, 15, 20, 0.2);
  color: var(--ink);
  background: var(--surface);
}
dialog.popup::backdrop { background: rgba(15, 15, 20, 0.45); }
dialog.popup h2 { margin-top: 0; }
.combo { position: relative; }
.combo-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.combo-button {
  display: flex;
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  padding: 0.45rem 1.7rem 0.45rem 0.6rem;
  font-weight: 500;
  position: relative;
}
.combo-button::after {
  content: "";
  position: absolute;
  right: 0.65rem;
  top: 50%;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
}
.combo-button:hover { background: #fff; color: var(--ink); border-color: #6b6c72; }
.combo-panel {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(15, 15, 20, 0.16);
  padding: 0.4rem;
}
.combo-search { margin-bottom: 0.35rem; }
.combo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow: auto;
}
.combo-group {
  margin: 0.35rem 0.45rem 0.1rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.combo-list button,
.combo-add {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: var(--radius-control);
  padding: 0.38rem 0.5rem;
  font-weight: 500;
}
.combo-list button[aria-selected="true"],
.combo-list button:hover,
.combo-add:hover {
  background: var(--green-soft);
  color: var(--ink);
}
.combo-add { color: var(--link); font-weight: 700; }
.combo-empty { margin: 0.35rem 0.45rem; color: var(--muted); }
.js-only { display: none; }
html.js .js-only { display: inline-block; }
html.js .delete-fallback { display: none; }
tr.click-row { cursor: pointer; }
tr.click-row a.stretch { color: inherit; font-weight: 600; text-decoration: none; }
tr.click-row:hover a.stretch { color: var(--link); text-decoration: underline; }
.line-row button { margin-bottom: 0.15rem; }
label { display: grid; gap: 0.3rem; font-size: 0.92rem; font-weight: 600; color: var(--ink); }
label.check { display: flex; align-items: center; grid-template-columns: none; font-weight: 500; }
label.check input { width: auto; }
th.check, td.check { width: 2.2rem; text-align: center; }
td.check input { width: auto; }
tr.is-parent td { font-weight: 700; }
details.adder {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem 0.75rem;
  background: var(--surface);
}
details.adder summary { cursor: pointer; font-weight: 700; }
.adder-fields { display: grid; gap: 0.7rem; margin-top: 0.75rem; }
.exports { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.15rem 0 0.9rem; }
.contact-address { white-space: pre-line; }

input, select, textarea, button, .button { font: inherit; }
input, select, textarea {
  width: 100%;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  padding: 0.45rem 0.6rem;
  font-weight: 500;
}
input:hover, select:hover, textarea:hover { border-color: #6b6c72; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--link);
  outline-offset: 0;
  border-color: var(--link);
}
textarea { min-height: 5.5rem; resize: vertical; }
button, .button {
  display: inline-block;
  width: fit-content;
  background: var(--button);
  color: var(--button-ink);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  padding: 0.45rem 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  line-height: 1.3;
}
button:hover, .button:hover {
  background: var(--green-hover);
  color: var(--button-ink);
  text-decoration: none;
}
button:active, .button:active { background: var(--green-active); }
button.secondary, .button.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
}
button.secondary:hover, .button.secondary:hover {
  background: var(--bg);
  color: var(--ink);
  border-color: #6b6c72;
}
button.danger { background: var(--bad); color: #fff; border-color: transparent; }
button.danger:hover { background: #b32218; color: #fff; }
.danger-zone { border-color: #f3c1bb; }

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: end;
  margin: 0.2rem 0 1rem;
}
.filter-form label { min-width: 9rem; font-weight: 600; }
.filter-form button { margin-bottom: 0.05rem; }

.presets { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.15rem 0 0.7rem; }
.chip {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.chip:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.chip.active {
  background: var(--green-soft);
  color: var(--green-soft-ink);
  border-color: #b7e2b2;
}
.chip.active:hover { background: #d8f0d4; color: var(--green-soft-ink); }
.range-label { margin-top: 0.2rem; color: var(--muted); }

.alert { padding: 0.7rem 0.85rem; border-radius: var(--radius); margin: 0 0 0.9rem; border: 1px solid transparent; }
.alert.ok { background: var(--good-bg); color: var(--good-ink); border-color: #b7e2b2; }
.alert.err { background: var(--bad-bg); color: var(--bad-ink); border-color: #f3c1bb; }
.alert.deleted { background: var(--bad-bg); color: var(--bad-ink); border-color: #f3c1bb; }
.alert.deleted .eyebrow { color: var(--bad); font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase; }
.alert.deleted p:last-child { margin: 0.15rem 0 0; }

.table-wrap { overflow-x: auto; }
.table-wrap.sheet { padding: 0.25rem 0.35rem 0.15rem; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 0.55rem 0.55rem;
  border-bottom: 1px solid #eceef1;
  vertical-align: baseline;
}
tbody tr:last-child td { border-bottom: 0; }
.audit-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.audit-line form { margin: 0; flex: none; }
tbody tr:hover td { background: #f7f8fa; }
th {
  font-size: 0.75rem;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--muted);
  font-weight: 700;
  background: transparent;
}
td.num, th.num { text-align: right; white-space: nowrap; }
.files { color: var(--muted); font-size: 0.85rem; }
ul.files img, .files img {
  display: block;
  max-width: min(420px, 100%);
  margin-top: 0.4rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
ul.plain, ul.files { list-style: none; padding: 0; margin: 0.3rem 0 0.8rem; }
ul.plain li, ul.files li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid #eceef1;
}
ul.plain a.row-end { margin-left: auto; white-space: nowrap; }
button.drag-handle {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.55rem;
  margin: 0 0.15rem 0 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  flex: none;
  vertical-align: middle;
}
button.drag-handle:hover,
button.drag-handle:active {
  background: #eef1f4;
  color: var(--ink);
}
button.drag-handle:active { cursor: grabbing; }
.grip {
  display: block;
  width: 10px;
  height: 16px;
  background-image: radial-gradient(currentColor 1.15px, transparent 1.3px);
  background-size: 5px 5.4px;
  background-position: center;
  background-repeat: repeat;
}
body.is-reordering { cursor: grabbing; user-select: none; }
td .drag-handle { margin-right: 0.35rem; }
.order-placeholder {
  box-sizing: border-box;
  background: #e8f3fc;
  border: 1px dashed var(--link);
  border-radius: var(--radius);
  list-style: none;
}
tr.order-placeholder td {
  background: #e8f3fc;
  border-bottom: 0;
  padding: 0;
}
.drag-ghost {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  margin: 0;
  padding: 0.3rem 0.55rem;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 700;
  transform: translate(10px, 12px);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button.secondary:disabled:hover {
  background: #fff;
  color: var(--ink);
  border-color: var(--line-strong);
}
ul.plain li.depth-1 { margin-left: 1.35rem; }
ul.plain li.depth-2 { margin-left: 2.85rem; }
ul.plain li.depth-1,
ul.plain li.depth-2 {
  border-left: 3px solid var(--line);
  padding-left: 0.7rem;
}
td.depth-1 { padding-left: 1.9rem; }
td.depth-2 { padding-left: 3.5rem; }
form.inline { display: inline; }
.archived { opacity: 0.72; }

.pill, .status {
  display: inline-block;
  border-radius: var(--radius-control);
  padding: 0.08rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: #eceef1;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.status-under, .status-met { background: var(--good-bg); color: var(--good-ink); }
.status-close { background: var(--mid-bg); color: var(--mid-ink); }
.status-over, .status-behind { background: var(--bad-bg); color: var(--bad-ink); }
.status-none { background: #eceef1; color: var(--muted); }

.facts { margin: 0; }
.facts div {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid #eceef1;
}
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; }

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

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  aside {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav, .nav.foot { display: flex; flex-wrap: wrap; margin-top: 0.4rem; }
  .nav.foot { border-top: 0; padding-top: 0; width: 100%; }
  .nav-label { width: 100%; }
  .stats, .row-2, .split, .facts div, .tx-facts { grid-template-columns: 1fr 1fr; }
  .tx-meta-grid { grid-template-columns: 1fr 1fr; }
  .tx-summary { grid-template-columns: 1fr; }
  .main { padding: 1rem 0.9rem calc(3rem + env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
  .stats, .facts div, .line-row, .tx-facts, .tx-meta-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.4rem; }
}

@media print {
  aside, .presets, .filter-form, .noprint, .gate-brand, .skip { display: none !important; }
  .shell { display: block; }
  body { background: white; color: black; }
  .sheet, .card { box-shadow: none; }
  a { color: black; text-decoration: none; }
}
