:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --brand: #1f3864;
  --brand-soft: #e8edf6;
  --in: #1b7f4b;
  --in-soft: #dff3e8;
  --out: #b4432b;
  --out-soft: #fbe6e1;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --radius: 10px;
  /* chart colors: checked for colorblind separation and contrast on this surface */
  --series-income: #2a78d6;
  --series-costs: #eb6834;
  --acct-1: #1baf7a;
  --acct-2: #6250d6;
  --grid: #eceef2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1b2129; --text: #e6e9ee; --muted: #9aa5b3; --border: #2c3440;
    --brand: #8fb0ea; --brand-soft: #22304a; --in: #5fd197; --in-soft: #183527; --out: #f08f78; --out-soft: #3d221c;
    --warn: #f3c065; --warn-soft: #3a2f17;
    --series-income: #3987e5; --series-costs: #d95926; --acct-1: #199e70; --acct-2: #9085e9; --grid: #262d36;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 15px; margin: 0 0 10px; }
code { font-size: 12px; background: var(--brand-soft); padding: 1px 4px; border-radius: 4px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 24px; padding: 0 20px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; color: var(--brand); padding: 12px 0; }
.brand span { font-weight: 400; color: var(--muted); }
.brand .mode-tag { font-size: 11px; font-weight: 700; color: var(--warn); background: var(--warn-soft); border-radius: 5px;
  padding: 2px 7px; margin-left: 6px; vertical-align: middle; text-transform: uppercase; letter-spacing: .04em; }
.welcome { border-color: var(--brand); }
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 380px; padding: 0; }
.login-box .brand { text-align: center; margin-bottom: 12px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-box input { padding: 9px 10px; }
.msg.error { background: var(--out-soft); color: var(--out); margin: 0; }
.user-box { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.activity td { font-size: 12px; }
nav { display: flex; gap: 2px; flex-wrap: wrap; }
nav button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 14px 12px; font: inherit;
  color: var(--muted); cursor: pointer; }
nav button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.badge { background: var(--out); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; margin-left: 4px; }

main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }

button, select, input { font: inherit; color: var(--text); }
button { background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { button.primary { color: #10151c; } }
button.danger { color: var(--out); }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
select, input[type=text], input[type=search], input[type=number], input[type=password], input:not([type]) {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 6px 8px; min-width: 0; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 10px 0 16px; }
@media (max-width: 860px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.warn { border-color: var(--warn); background: var(--warn-soft); cursor: pointer; }

.months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 170px; padding-top: 6px; }
.month { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bars { display: flex; gap: 2px; align-items: flex-end; height: 140px; width: 100%; justify-content: center; }
.bar { width: 42%; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar.in { background: var(--in); } .bar.out { background: var(--out); }
.month span { font-size: 11px; color: var(--muted); margin-top: 4px; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 8px; }
.dot.in { background: var(--in); } .dot.out { background: var(--out); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--border); padding: 6px 8px; }
td { border-bottom: 1px solid var(--border); padding: 7px 8px; vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
tr.section td { font-weight: 700; padding-top: 14px; color: var(--brand); border-bottom: 0; }
.in-amt { color: var(--in); } .out-amt { color: var(--text); }
.desc { color: var(--muted); font-size: 12px; word-break: break-word; }
.nowrap { white-space: nowrap; }
#wk-list td:first-child { min-width: 170px; }
#wk-list input.notes { width: 100%; min-width: 140px; }
.tag { display: inline-block; font-size: 11px; border-radius: 5px; padding: 1px 6px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--out-soft); color: var(--out); }
.tag.good { background: var(--in-soft); color: var(--in); }
.table-wrap { overflow-x: auto; }

.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 2px dashed var(--border);
  border-radius: var(--radius); padding: 34px 16px; cursor: pointer; color: var(--muted); text-align: center; }
.drop strong { color: var(--text); font-size: 15px; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.file-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.file-row .name { flex: 1; min-width: 160px; word-break: break-all; }
.steps { padding-left: 18px; margin: 0 0 8px; } .steps li { margin-bottom: 4px; }
.result { border-radius: 8px; padding: 10px 12px; margin-top: 10px; background: var(--in-soft); }
.result.error { background: var(--out-soft); color: var(--out); }

.rv { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
  display: grid; grid-template-columns: 22px 92px 1fr 120px; gap: 4px 12px; align-items: start; }
.rv.done { opacity: .45; }
.rv .amt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.rv .why { font-size: 12px; color: var(--warn); margin-top: 3px; }
.rv .editor { grid-column: 3 / 5; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.rv .editor select.cat-select { max-width: 260px; }
.editor input.worker, .editor input.customer { width: 170px; }
.editor { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.rv .remember { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.rv .remember input[type=text] { width: 160px; font-size: 12px; padding: 4px 6px; }
@media (max-width: 700px) {
  .rv { grid-template-columns: 22px 1fr auto; }
  .rv .meta { grid-column: 2 / 4; }
  .rv .editor { grid-column: 1 / 4; }
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 12px; color: var(--muted); }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--brand-soft); }
tr.editing td { background: var(--brand-soft); }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.msg { padding: 10px 12px; border-radius: 8px; background: var(--brand-soft); margin-bottom: 10px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }

/* ---- logo ---- */
.brand { display: flex; align-items: center; gap: 8px; }
.brand img { width: 34px; height: 34px; border-radius: 50%; }
.login-box .brand { justify-content: center; flex-direction: column; font-size: 18px; }
.login-box .brand img { width: 96px; height: 96px; }

/* ---- charts ---- */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .charts { grid-template-columns: 1fr; } }
.chart { min-height: 120px; }
.chart svg { display: block; overflow: visible; }
.viz-grid { stroke: var(--grid); stroke-width: 1; }
.viz-axis { stroke: var(--border); stroke-width: 1; }
.viz-tick { fill: var(--muted); font-size: 11px; }
.viz-sub { fill: var(--text); font-size: 11px; font-weight: 600; }
.viz-end { fill: var(--text); font-size: 12px; font-weight: 600; }
.viz-end-value { fill: var(--muted); font-size: 11px; }
.viz-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.viz-hit { cursor: default; }
.viz-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 6px; flex-wrap: wrap; }
.viz-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.viz-tip { position: fixed; z-index: 30; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 150px; }
.tip-title { font-weight: 700; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr 58px; gap: 10px; align-items: center; font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.hbar.clickable { cursor: pointer; }
.hbar.clickable:hover { background: var(--brand-soft); }
.hbar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 14px; }
.hbar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- worker detail ---- */
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 14px; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; min-width: 120px; }
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; font-weight: 700; text-align: left; }
.linklike:hover { text-decoration: underline; }
.assign-row input { width: 180px; }

/* ---- transactions overview ---- */
.tx-overview .kpis { margin: 8px 0 12px; }
.tx-overview .kpi .value { font-size: 20px; }
.tx-ov-table td, .tx-ov-table th { padding: 5px 8px; }
.date-filter { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.date-filter input { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; font: inherit; color-scheme: light dark; }

/* ---- year-end and form details ---- */
.warn-msg { background: var(--warn-soft); color: var(--text); border-left: 3px solid var(--warn); }
#ye-body h2 { margin-top: 18px; }
.form-details { display: grid; grid-template-columns: 1.2fr 2fr 0.6fr; gap: 10px; margin: 6px 0 2px; }
@media (max-width: 760px) { .form-details { grid-template-columns: 1fr; } }
.form-details label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.wk-filters { position: sticky; top: 52px; z-index: 4; background: var(--bg); padding: 8px 0; margin: 0 0 8px; align-items: center; }
.wk-filters input[type=search] { max-width: 420px; }
.muted-heading { opacity: .45; }

/* ---- meals by place ---- */
.charts .wide { grid-column: 1 / -1; }
.meals-split { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .meals-split { grid-template-columns: 1fr; } }
.meal-kind { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.meal-kind:last-child { border-bottom: 0; }
.meal-kind .desc { margin-left: 6px; }
.meal-kind div.desc { margin: 2px 0 0; }
.tx-ov-table + .tx-ov-table { margin-top: 12px; }

/* ---- bank balances ---- */
.bank-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.bank-tile { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.bank-tile .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bank-tile .value { font-size: 24px; font-weight: 700; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.bank-tile .value.neg { color: var(--out); }
.bank-tile.total { border-color: var(--brand); }

/* ---- invoices and estimates ---- */
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
  padding: 6px 8px; width: 100%; resize: vertical; min-width: 0; }
input[type=date] { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px;
  font: inherit; color-scheme: light dark; }
.tag.muted { background: var(--bg); color: var(--muted); }
.doc-table td { vertical-align: middle; }
.editor-head { margin-bottom: 12px; }
.editor-head h1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.doc-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px; margin-bottom: 12px; align-items: end; }
.doc-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
@media (max-width: 760px) { .doc-grid, .doc-grid.two { grid-template-columns: 1fr; } }
.doc-grid label, label.block { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.doc-grid label input:not([type=checkbox]), .doc-grid label select { width: 100%; }
.doc-grid label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--text); padding-bottom: 6px; }
label.block { margin-top: 10px; }
.lines td { padding: 4px; vertical-align: top; }
.lines input { width: 100%; }
.lines td.l-amt { padding-top: 10px; }
.lines tr.bad-line input { border-color: var(--out); background: var(--out-soft); }
.doc-total { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.doc-total span { margin-left: 10px; }
.doc-actions { position: sticky; bottom: 0; background: var(--surface); display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  border-top: 1px solid var(--border); margin: 14px -16px 0; padding: 12px 16px; }
.doc-actions .spacer { flex: 1; }
.pdf-info { margin: 12px 0 0; }
.pdf-info code { word-break: break-all; }
.pay-form input, .pay-form select { min-width: 0; }
@media (max-width: 700px) { .pay-form > * { width: 100%; max-width: none !important; } }
@media (max-width: 700px) {
  .lines tr:first-child { display: none; }
  .lines tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto auto; gap: 4px; padding: 6px 0;
    border-bottom: 1px solid var(--border); align-items: center; }
  .lines td { border: 0; padding: 2px; }
  .lines td:first-child { grid-column: 1 / -1; }
  .lines td.l-amt { padding-top: 2px; }
}
.email-panel { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }
.email-panel label.check { display: flex; gap: 6px; align-items: center; font-size: 13px; margin-top: 6px; }
.em-sugg button { margin: 2px 4px 2px 0; }
