:root {
  color-scheme: light;
  --background: #f6f5f2;
  --surface: #fff;
  --subtle: #faf9f7;
  --ink: #252321;
  --muted: #625e58;
  --line: #e6e2db;
  --control-line: #cfc9c0;
  --rail: #20201f;
  --rail-text: #f8f6f2;
  --rail-muted: #c4bfb7;
  --accent: #af3731;
  --accent-hover: #922b26;
  --accent-tint: #faece8;
  --radius: 12px;
  --page-inset: clamp(24px, 3.45vw, 56px);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  min-width: 280px;
  margin: 0;
  background: var(--background);
  color: var(--ink);
  line-height: 1.55;
}

a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent-hover); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
:focus-visible { outline: 2px solid #cd4d45; outline-offset: 3px; }
h1, h2, h3, p, ul, ol, dl { margin-top: 0; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: clamp(2rem, 3.05vw, 2.65rem); margin-bottom: 0; font-weight: 740; letter-spacing: -.045em; }
h2 { font-size: 1.25rem; font-weight: 710; margin-bottom: .65rem; }
h3 { font-size: 1.04rem; font-weight: 700; margin-bottom: .55rem; }
p { margin-bottom: .8rem; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.skip-link {
  position: fixed;
  z-index: 10;
  top: 12px;
  left: 12px;
  padding: .55rem .9rem;
  transform: translateY(calc(-100% - 20px));
  border-radius: 6px;
  background: var(--surface);
}

.skip-link:focus { transform: none; }

.site-shell {
  display: grid;
  grid-template-columns: 226px minmax(0, 1fr);
  min-height: 100vh;
}

.site-rail {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 28px 16px 20px;
  isolation: isolate;
  overflow: clip;
  background: var(--rail);
  color: var(--rail-text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  align-self: flex-start;
  margin: 0 9px 30px;
  padding: 1px 0;
  color: inherit;
  text-decoration: none;
}

.brand:hover { color: inherit; }

.brand-symbol {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  overflow: hidden;
  border-radius: 9px;
  background: #b83b34;
  box-shadow: inset 0 1px 0 #ffffff30;
}

.brand-symbol::before, .brand-symbol::after {
  position: absolute;
  top: 11px;
  width: 8px;
  height: 18px;
  transform: skewX(-24deg);
  background: #fff6f0;
  content: "";
}

.brand-symbol::before { left: 10px; }
.brand-symbol::after { left: 21px; background: #ffc4ad; }

.brand-type { display: grid; line-height: 1.25; }
.brand-type strong { font-size: 1.13rem; font-weight: 750; letter-spacing: -.035em; white-space: nowrap; }
.brand-type small { margin-top: 3px; color: var(--rail-muted); font-size: .72rem; letter-spacing: .12em; }

.site-nav { display: grid; gap: 22px; }
.nav-group { display: grid; gap: 4px; }
.nav-label { margin: 0 12px 6px; color: var(--rail-muted); font-size: .72rem; font-weight: 600; letter-spacing: .11em; }

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 43px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--rail-muted);
  font-size: .9rem;
  text-decoration: none;
}

.nav-link:hover { background: #ffffff10; color: var(--rail-text); }
.nav-link[aria-current="page"] { background: #3b2c28; border-color: #644038; color: #fff3eb; font-weight: 670; }
.nav-link[aria-current="page"]::before { position: absolute; inset: 10px auto 10px -1px; width: 3px; border-radius: 0 3px 3px 0; background: #fa846c; content: ""; }
.nav-link[aria-current="page"] .nav-icon { color: #ff9f8b; }

.nav-icon { position: relative; display: inline-block; flex: none; width: 18px; height: 18px; color: inherit; }
.nav-icon::before, .nav-icon::after { position: absolute; content: ""; }
.icon-records::before { inset: 1px 3px; border: 1.5px solid currentColor; border-radius: 2px; }
.icon-records::after { inset: 6px 6px auto; height: 1px; background: currentColor; box-shadow: 0 3px currentColor, 0 6px currentColor; }
.icon-upload::before { inset: 9px 2px 1px; border: 1.5px solid currentColor; border-top: 0; border-radius: 0 0 3px 3px; }
.icon-upload::after { top: 2px; left: 6px; width: 6px; height: 6px; transform: rotate(45deg); border-top: 1.5px solid currentColor; border-left: 1.5px solid currentColor; }
.icon-upload { background: linear-gradient(currentColor, currentColor) center 3px / 1.5px 9px no-repeat; }
.icon-ledger::before { inset: 2px 1px; border: 1.5px solid currentColor; border-radius: 2px; }
.icon-ledger::after { inset: 6px 2px 3px; border-top: 1px solid currentColor; background: linear-gradient(90deg, transparent 37%, currentColor 37% 46%, transparent 46%); }
.icon-roster::before { inset: 1px auto auto 6px; width: 7px; height: 7px; border: 1.5px solid currentColor; border-radius: 50%; }
.icon-roster::after { inset: 10px 3px 1px; border: 1.5px solid currentColor; border-radius: 6px 6px 2px 2px; }

.rail-pattern {
  position: absolute;
  z-index: -1;
  inset: auto 0 0;
  height: 180px;
  pointer-events: none;
  background: radial-gradient(ellipse at bottom right, #b83b3426, transparent 65%);
}

.rail-pattern::after {
  position: absolute;
  right: -29px;
  bottom: 32px;
  width: 166px;
  height: 66px;
  transform: skewX(-26deg);
  background: repeating-linear-gradient(90deg, #ffffff0a 0 1px, transparent 1px 22px), repeating-linear-gradient(#ffffff0a 0 1px, transparent 1px 22px);
  mask-image: linear-gradient(90deg, transparent, #000 45%);
  content: "";
}

.workspace { min-width: 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  min-height: 70px;
  padding: 10px var(--page-inset);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-title { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; font-size: .86rem; font-weight: 680; }
.topbar-marker { width: 8px; height: 8px; border: 2px solid var(--accent); transform: rotate(45deg); }
.topbar-title .badge { margin-left: 4px; }
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.account-avatar { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-tint); color: var(--accent-hover); font-size: .88rem; font-weight: 700; }
.account-meta { display: grid; min-width: 0; max-width: 205px; line-height: 1.3; }
.account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .86rem; font-weight: 680; }
.account-role { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.logout-form { flex: none; margin-left: 4px; padding-left: 10px; border-left: 1px solid var(--line); }
.logout-button { padding: 5px 7px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.logout-button:hover { background: var(--subtle); color: var(--ink); }

.content-shell { width: min(100%, 1470px); margin-inline: auto; padding: 35px var(--page-inset) 62px; }
.content-shell:focus { outline: none; }
.page-heading { display: flex; justify-content: space-between; align-items: end; flex-wrap: wrap; gap: 14px 22px; margin-bottom: 26px; }
.layout-heading:has(h1:empty):has(.eyebrow:empty):has(.page-subtitle:empty):has(.page-actions:empty), .layout-heading :is(h1, .eyebrow, .page-subtitle, .page-actions):empty { display: none; }
.page-heading p { margin: 7px 0 0; color: var(--muted); }
.page-heading .eyebrow { margin-bottom: 7px; }
.eyebrow { color: var(--accent-hover); font-size: .72rem; font-weight: 740; letter-spacing: .14em; }
.muted { color: var(--muted); }

.anonymous-shell { grid-template-columns: minmax(278px, .75fr) minmax(0, 1.25fr); }
.anonymous-shell .site-rail { justify-content: center; padding: clamp(28px, 6vw, 96px); background: linear-gradient(145deg, #272524, #1b1a19 70%); }
.anonymous-shell .brand { margin: 0 0 13vh; }
.anonymous-shell .brand-symbol { width: 54px; height: 54px; border-radius: 12px; }
.anonymous-shell .brand-symbol::before, .anonymous-shell .brand-symbol::after { top: 15px; width: 11px; height: 24px; }
.anonymous-shell .brand-symbol::before { left: 14px; }
.anonymous-shell .brand-symbol::after { left: 29px; }
.anonymous-shell .brand-type strong { font-size: clamp(1.35rem, 2.3vw, 2.15rem); }
.anonymous-shell .brand-type small { font-size: .85rem; }
.anonymous-shell .rail-pattern { height: 52%; }
.anonymous-shell .rail-pattern::after { width: 73%; height: 34%; right: -7%; bottom: 13%; }
.anonymous-shell .workspace { display: grid; place-items: center; }
.anonymous-shell .content-shell { width: min(100%, 520px); padding-block: 58px; }
.anonymous-mode { margin-bottom: 14px; }

.panel {
  min-width: 0;
  padding: clamp(16px, 2.15vw, 26px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 3px #42382a06;
}

.panel + .panel, .split + .panel, .stats + .panel, .panel + .split, .panel + .stats { margin-top: 17px; }
.panel > :last-child { margin-bottom: 0; }
.panel-header { display: flex; justify-content: space-between; align-items: start; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 16px; }
.panel-header :is(h2, p) { margin-bottom: 0; }

.button, button.primary, button.secondary, button.danger, input[type="submit"] {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .4em;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--control-line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: .88rem;
  font-weight: 650;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover, button.secondary:hover { background: var(--subtle); color: var(--ink); border-color: #afa79c; }
.button.primary, button.primary, input[type="submit"] { border-color: var(--accent); background: var(--accent); color: #fff; box-shadow: 0 1px 2px #511b1633; }
.button.primary:hover, button.primary:hover, input[type="submit"]:hover { border-color: var(--accent-hover); background: var(--accent-hover); color: #fff; }
.button.danger, button.danger { color: #a02b2c; border-color: #e3bcb8; }
.button.danger:hover, button.danger:hover { background: var(--accent-tint); border-color: #c97670; }
.button.small, button.small { min-height: 33px; padding: 5px 10px; font-size: .81rem; }
.actions, .page-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.form-stack { display: grid; align-items: start; gap: 16px; }
.form-stack > :is(.button, button) { justify-self: start; }
.anonymous-shell .form-stack > :is(.button, button) { justify-self: stretch; }
.field, .form-stack > :is(p, div):has(> label:not(.checkbox)):not(.actions) { display: grid; gap: 5px; min-width: 0; margin-bottom: 0; }
label, legend { font-size: .88rem; font-weight: 660; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 6px; padding: 0; }
.field small, .helptext { color: var(--muted); font-size: .8rem; }
.inline-form, .filter-bar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px 12px; }
.filter-bar { padding-block: 0 15px; }
.filter-bar > .field { flex: 1 1 145px; }
.filter-bar > .actions { flex: 0 0 auto; }

input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="hidden"], [type="reset"]), select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--control-line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-size: .9rem;
}

textarea { min-height: 94px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #756e64; }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--subtle); color: var(--muted); }
:is(input, select, textarea)[aria-invalid="true"] { border-color: var(--accent); }
input[type="file"] { padding: 5px; }
input::file-selector-button { margin-right: 9px; padding: 5px 9px; border: 0; border-radius: 5px; background: var(--accent-tint); color: var(--accent-hover); font: inherit; cursor: pointer; }
input:is([type="checkbox"], [type="radio"]) { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.checkbox { display: inline-flex; align-items: center; gap: 8px; min-height: 30px; font-weight: 550; }
.errorlist { margin: 0; padding-left: 17px; color: #a02b2c; font-size: .85rem; }

.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: var(--subtle); color: var(--muted); font-size: .76rem; font-weight: 680; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfaf8; }
td a { font-weight: 640; }
td :is(.field, input, select) { min-width: 75px; }
.numeric, .amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: fit-content;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 5px;
  background: #eeece7;
  color: #59544b;
  font-size: .74rem;
  font-weight: 670;
  line-height: 1.35;
  white-space: nowrap;
}

.badge.success { background: #e4f2e8; color: #236342; }
.badge.warning { background: #f8eed6; color: #785010; }
.badge.info { background: #e8f0f7; color: #24577a; }
.badge.error, .badge.danger { background: #f9e8e5; color: #982d2b; }
.badge.neutral { background: #eeece7; color: #59544b; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: 12px; margin-bottom: 17px; }
.stat { min-width: 0; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat :is(span, small, dt, p) { color: var(--muted); font-size: .81rem; }
.stat :is(strong, b, dd) { display: block; margin: 3px 0 0; color: var(--ink); font-size: clamp(1.5rem, 2.25vw, 2.1rem); font-weight: 720; letter-spacing: -.045em; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat > :last-child { margin-bottom: 0; }
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 285px), 1fr)); gap: 17px; align-items: start; }
.split > .panel { margin-top: 0; }
.empty { padding: clamp(26px, 4vw, 48px) 18px; border: 1px dashed var(--control-line); border-radius: 8px; background: var(--subtle); color: var(--muted); text-align: center; }
.empty :is(h2, h3, strong) { color: var(--ink); }
.empty > :last-child { margin-bottom: 0; }
.table-wrap .empty { border: 0; border-radius: 0; }
.callout, .alert { padding: 10px 13px; border: 1px solid var(--line); border-left: 3px solid #94877a; border-radius: 7px; background: var(--subtle); }
.callout > :last-child, .alert > :last-child { margin-bottom: 0; }
.alert.success, .callout.success { border-color: #c8e3d1; border-left-color: #437a55; background: #eff7f1; color: #22583c; }
.alert.warning, .callout.warning { border-color: #eeddb4; border-left-color: #ac7924; background: #fcf5e4; color: #6c4d16; }
.alert.info, .callout.info { border-color: #cbdfeb; border-left-color: #5a85a1; background: #eff6f9; color: #285872; }
.alert.error, .callout.error, .alert.danger { border-color: #efd1cc; border-left-color: var(--accent); background: #fdf0ee; color: #8f302e; }
.messages { display: grid; gap: 8px; margin-bottom: 17px; }

@media (max-width: 920px) {
  .site-shell { grid-template-columns: 190px minmax(0, 1fr); }
  .anonymous-shell { grid-template-columns: minmax(245px, .8fr) minmax(0, 1.2fr); }
  .site-rail { padding-inline: 12px; }
  .brand { margin-inline: 6px; }
  .account-meta { max-width: 155px; }
}

@media (max-width: 680px) {
  :root { --page-inset: 16px; }
  .site-shell, .anonymous-shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .site-rail, .anonymous-shell .site-rail { position: relative; min-height: auto; padding: 12px var(--page-inset); }
  .brand, .anonymous-shell .brand { margin: 0; }
  .brand-symbol, .anonymous-shell .brand-symbol { width: 40px; height: 40px; border-radius: 9px; }
  .anonymous-shell .brand-symbol::before, .anonymous-shell .brand-symbol::after { top: 11px; width: 8px; height: 18px; }
  .anonymous-shell .brand-symbol::before { left: 10px; }
  .anonymous-shell .brand-symbol::after { left: 21px; }
  .site-nav { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 12px; }
  .nav-group { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-label { display: none; }
  .nav-link { min-height: 38px; padding: 5px 8px; gap: 6px; font-size: .81rem; }
  .nav-link[aria-current="page"]::before { inset-block: 8px; }
  .topbar { min-height: 55px; gap: 12px; }
  .topbar-title { gap: 5px; font-size: .78rem; }
  .topbar-title .badge { margin-left: 0; }
  .account { gap: 7px; }
  .account-avatar { display: none; }
  .account-meta { max-width: min(30vw, 130px); }
  .logout-form { margin-left: 0; padding-left: 3px; }
  .content-shell { padding-block: 23px 40px; }
  .anonymous-shell .workspace { align-items: start; }
  .anonymous-shell .content-shell { padding-block: 34px; }
  .page-heading { gap: 12px; margin-bottom: 19px; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(min(100%, 136px), 1fr)); }
  th, td { padding: 8px; }
}

@media (max-height: 530px) {
  .site-rail { position: relative; }
}

/* Invoice details and source preview */
.facts { display: grid; grid-template-columns: minmax(100px, max-content) minmax(0, 1fr); gap: 9px 15px; margin: 0 0 17px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.invoice-preview { display: block; width: 100%; height: auto; max-height: 500px; object-fit: contain; background: #f7f6f3; border: 1px solid #dedbd6; border-radius: 7px; }
.record-details { margin-block: 12px; }
.record-details summary { cursor: pointer; font-weight: 600; }
.record-details[open] summary { margin-bottom: 12px; }
.table-wrap td small, .timeline-row small { display: block; }
.timeline-row { padding-block: 10px; }
.timeline-row + .timeline-row { border-top: 1px solid #ece9e4; }
.split + .split { margin-top: 17px; }

.claim-fields { display: grid; gap: 6px; max-width: 315px; }
.claim-fields label { font-size: .8rem; }
.table-wrap .claim-fields { min-width: 198px; }
