:root {
  --bg: #f6f4ef; --surface: #fffefb; --surface-2: #f0ede5; --ink: #1c2320; --muted: #66706b; --line: #e2ddd2;
  --accent: #1d6b52; --accent-ink: #ffffff; --accent-soft: #e3f0ea; --danger: #a63a2b; --danger-soft: #f8e6e2;
  --warn: #8a5a00; --warn-soft: #fbf1d9; --info-soft: #e7eef6; --neg: #a63a2b;
  --radius: 10px; --shadow: 0 1px 2px rgba(28, 35, 32, .06), 0 4px 16px rgba(28, 35, 32, .04);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131715; --surface: #1a1f1d; --surface-2: #222826; --ink: #e6ebe8; --muted: #95a09a; --line: #2e3532;
    --accent: #5cc29b; --accent-ink: #0d1411; --accent-soft: #1c3329; --danger: #f08a7a; --danger-soft: #3a2320;
    --warn: #e7b85a; --warn-soft: #34291a; --info-soft: #1d2836; --neg: #f08a7a; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
h1, h2 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0 0 .5rem; }
h1 { font-size: 1.85rem; line-height: 1.2; }
h2 { font-size: 1.2rem; }
h2 small { font-family: var(--sans); font-size: .8rem; font-weight: 400; }
p { margin: 0 0 .75rem; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }
.muted { color: var(--muted); } .small, small { font-size: .82rem; } .nowrap { white-space: nowrap; }
.right { text-align: right; } .empty { padding: 2rem 1.25rem; color: var(--muted); text-align: center; margin: 0; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); margin-bottom: .25rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Layout */
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 1.75rem; padding-bottom: 4rem; }
main.wrap.narrow { max-width: 760px; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: inline-flex; align-items: center; gap: .45rem; color: var(--ink); text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 1.1rem; }
.brand svg { color: var(--accent); }
.brand.big { font-size: 1.5rem; margin-bottom: 1.25rem; justify-content: center; }
.ws-head { background: var(--surface); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: .7rem .8rem; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; font-size: .92rem; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: 1rem 0; }
.page-head .actions { margin: 0; }
.crumbs { margin: 0 0 .25rem; font-size: .85rem; }
.grid { display: grid; gap: 1.25rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.grid.side { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.span2 { grid-column: span 2; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.pad { padding: 1rem 1.25rem .5rem; margin: 0; }
@media (max-width: 860px) {
  .grid.two, .grid.side { grid-template-columns: 1fr; }
  .grid.three { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .hide-sm { display: none; }
  h1 { font-size: 1.5rem; }
}

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.subtle { background: transparent; box-shadow: none; border-style: dashed; }
.card > summary { cursor: pointer; font-weight: 600; }
.center-card { max-width: 520px; margin: 3rem auto; text-align: center; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: stretch; max-width: 420px; margin: 0 auto; padding: 2rem 16px; }
.auth-card { padding: 1.75rem; }
.auth-card h1 { font-size: 1.6rem; }

/* Forms */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 600; }
label small { font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: baseline; gap: .5rem; font-weight: 400; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: .55rem .65rem; min-width: 0; width: 100%; font-weight: 400; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[readonly], input:disabled { background: var(--surface-2); color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: .9rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; display: flex; flex-direction: column; gap: .6rem; }
legend { font-weight: 600; font-size: .88rem; padding: 0 .3rem; }
form.inline { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
form.inline label { flex-direction: row; align-items: center; gap: .4rem; }
form.inline select { width: auto; padding: .3rem .4rem; }
.narrow-field { max-width: 380px; margin: 1rem 0; }
.num-in { text-align: right; font-family: var(--mono); font-size: .9rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .9rem; padding: .55rem .95rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: .3rem .6rem; font-size: .8rem; }
.btn.block { width: 100%; }
.linklike { background: none; border: 0; padding: .55rem .9rem; font: inherit; color: var(--ink); cursor: pointer; width: 100%; text-align: left; }
.linklike:hover { background: var(--surface-2); }

/* Menus */
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker { display: none; }
.switcher { margin-right: auto; }
.switcher > summary { display: flex; flex-direction: column; line-height: 1.15; padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 8px; max-width: 260px; }
.switcher > summary strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.switcher > summary strong::after { content: " ▾"; color: var(--muted); font-weight: 400; }
.ws-type { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.menu-panel { position: absolute; top: calc(100% + 6px); left: 0; min-width: 260px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: .35rem 0; z-index: 20; }
.menu-panel.right { left: auto; right: 0; }
.menu-panel a { display: flex; flex-direction: column; padding: .5rem .9rem; color: var(--ink); text-decoration: none; }
.menu-panel a:hover { background: var(--surface-2); }
.menu-panel a.current { box-shadow: inset 3px 0 var(--accent); }
.menu-panel a small { color: var(--muted); }
.menu-panel a.add { color: var(--accent); border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .6rem; }
.menu-head { padding: .5rem .9rem .6rem; border-bottom: 1px solid var(--line); margin-bottom: .3rem; display: flex; flex-direction: column; }
.menu-head small { color: var(--muted); }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* Flash */
.flash { border-radius: 8px; padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid transparent; }
.flash ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.flash.success { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.flash.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.flash.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.flash.info { background: var(--info-soft); }
.flash p:last-child { margin: 0; }
.copy-row { display: flex; gap: .5rem; margin-top: .5rem; }
.copy-row input { font-family: var(--mono); font-size: .8rem; }
.warn-text { color: var(--warn); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: .6rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .2rem; box-shadow: var(--shadow); }
.stat.inline { box-shadow: none; padding: .6rem 1rem; }
.stat > span:first-child { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
@media (max-width: 860px) { .stats { grid-template-columns: 1fr 1fr; } }

/* Numbers */
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: .9rem; }
.num.big { font-size: 1.3rem; font-weight: 600; font-family: var(--serif); font-variant-numeric: tabular-nums lining-nums; }
.num.neg { color: var(--neg); }
.num.missing { color: var(--warn); }
.ccy { font-size: .72em; color: var(--muted); margin-left: .3em; font-family: var(--sans); font-weight: 400; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .6rem .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th.right, .table td.right { text-align: right; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table.compact td, .table.compact th { padding: .42rem .9rem; }
.table tr.group th { background: transparent; font-family: var(--serif); font-size: .95rem; padding-top: .9rem; color: var(--ink); text-transform: none; letter-spacing: 0; }
.table tr.total th, .table tr.total td { border-top: 2px solid var(--ink); font-weight: 700; }
.table tr.row-draft td { background: color-mix(in srgb, var(--warn-soft) 55%, transparent); }
.table tr.row-reversed td, .row-archived td { color: var(--muted); }
.table tr.row-reversed a { color: var(--muted); }
.row-warn td { background: var(--danger-soft); }
.details { word-break: break-all; }

/* Badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); text-transform: capitalize; vertical-align: middle; }
.role-owner, .role-admin { background: var(--accent-soft); color: var(--accent); }
.status-draft { background: var(--warn-soft); color: var(--warn); }
.status-reversed, .status-archived { background: var(--surface-2); }
.status-posted { background: var(--accent-soft); color: var(--accent); }

/* Filters & pager */
.filters { display: flex; gap: .3rem; margin-bottom: .9rem; flex-wrap: wrap; }
.filters a { padding: .3rem .75rem; border-radius: 999px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); font-size: .85rem; }
.filters a.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pager { display: flex; gap: .5rem; justify-content: center; }
ul.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .6rem; }
.report-filter { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; }
.report-filter label { min-width: 160px; }

/* Entry form */
.lines { display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; }
.line { display: grid; grid-template-columns: minmax(180px, 2.2fr) 1fr 1fr 1.25fr 1.4fr; gap: .5rem; align-items: start; }
.line-head { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.line > label.sr { position: absolute; }
.qty-cell { display: flex; flex-direction: column; gap: .15rem; }
.qty-cell input { opacity: .45; }
.qty-cell.needed input { opacity: 1; border-color: var(--warn); }
.qty-label { color: var(--warn); font-weight: 600; min-height: 1em; }
.lines-foot { margin-top: .75rem; }
.totals { margin: 0; font-family: var(--mono); font-size: .85rem; color: var(--muted); }
.totals.ok { color: var(--accent); } .totals.off { color: var(--danger); }
.help { margin: 1rem 0; font-size: .88rem; } .help summary { cursor: pointer; color: var(--accent); }
.help p { margin: .5rem 0; }
.form-actions { display: flex; gap: .6rem; align-items: center; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1rem; flex-wrap: wrap; }
@media (max-width: 860px) {
  .line { grid-template-columns: 1fr 1fr; padding: .75rem; border: 1px solid var(--line); border-radius: 8px; }
  .line > select { grid-column: 1 / -1; }
  .line > input[name=line_memo], .line > .qty-cell { grid-column: 1 / -1; }
  .line-head { display: none; }
}
.rate-row { display: grid; grid-template-columns: auto 1fr auto 1.4fr 1fr; gap: .4rem; align-items: center; }
.table td.depth-1 { padding-left: 1.9rem; } .table td.depth-2 { padding-left: 3rem; } .table td.depth-3 { padding-left: 4.1rem; }
.table td.depth-4 { padding-left: 5.2rem; } .table td.depth-5 { padding-left: 6.3rem; }
