:root {
  --bg: #f5f7f6; --card: #ffffff; --ink: #1c2421; --muted: #6b7873; --line: #dde3e0;
  --brand: #1f7a5a; --brand-ink: #ffffff; --bad: #c0392b; --warn-bg: #fdecea;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121715; --card: #1b221f; --ink: #e8eeeb; --muted: #93a09a; --line: #2c3631;
          --brand: #3fae86; --brand-ink: #0b1511; --bad: #ff7b6b; --warn-bg: #3a1f1c; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 12px; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.mini { padding: 0 6px; border-radius: 6px; margin-left: 4px; }
input, select { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-width: 0; }

.top { display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px; }
.top h1 { font-size: 1.15rem; margin: 0; }
.ver { display: block; font-size: .7rem; color: var(--muted); }
.sync { font-size: .78rem; color: var(--muted); }
.sync.error { color: var(--bad); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 10px 0; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--brand); color: var(--brand-ink); }
main { padding: 4px 12px 96px; max-width: 760px; margin: 0 auto; }
main.wide { max-width: none; }

.pbar { display: flex; gap: 8px; margin: 0 0 10px; }
/* Period, totals and Plan / Real stay at the top while the rows scroll (Setup > Display). */
.phead.pinned { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-top: 6px; }
.phead.pinned .lhead { position: static; }
.pbar select { flex: 1; font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: .8rem; }
.card h3 { margin: 0 0 4px; font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card div { display: flex; justify-content: space-between; gap: 4px; }
.card b { font-variant-numeric: tabular-nums; }
.neg { color: var(--bad); }

.search { width: 100%; margin: 6px 0 4px; }
/* Not pinned: only the Plan / Real header sticks, as before; it needs main as its sticky container. */
.phead:not(.pinned) { display: contents; }
.phead:not(.pinned) .pbar { margin-top: 6px; }
.lhead, .row { display: grid; grid-template-columns: 1fr 92px 92px; gap: 6px; align-items: center; }
.lhead { position: sticky; top: 0; background: var(--bg); padding: 4px 0; font-size: .75rem; color: var(--muted);
  text-transform: uppercase; z-index: 2; }
.lhead span:not(:first-child) { text-align: right; padding-right: 8px; }
h2.sec { font-size: .85rem; margin: 14px 0 4px; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.row { padding: 3px 0; border-bottom: 1px solid var(--line); }
.row .nm { overflow: hidden; text-overflow: ellipsis; }
.row input.num { text-align: right; width: 100%; font-variant-numeric: tabular-nums; padding: 7px 8px; }
.row.over { background: var(--warn-bg); border-radius: 8px; }
.row.over input[data-f="r"] { color: var(--bad); font-weight: 600; }

.gridwrap { overflow: auto; max-height: calc(100vh - 170px); border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
table.grid { border-collapse: separate; border-spacing: 0; font-size: .82rem; }
table.grid th, table.grid td { padding: 3px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--card); }
table.grid thead th { position: sticky; top: 0; z-index: 3; text-align: center; }
table.grid thead tr:nth-child(2) th { top: 29px; font-weight: 400; color: var(--muted); }
table.grid th[data-cur] { background: var(--brand); color: var(--brand-ink); }
table.grid .sticky { position: sticky; left: 0; z-index: 2; text-align: left; min-width: 150px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
table.grid thead .sticky { z-index: 4; }
table.grid input { width: 84px; text-align: right; padding: 4px 6px; border-radius: 6px; }
table.grid tr.secrow td { background: var(--bg); color: var(--brand); font-weight: 700; text-transform: uppercase; font-size: .72rem; }
table.grid tfoot td, table.grid tfoot th { position: sticky; bottom: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
table.grid tfoot tr:nth-child(1) td, table.grid tfoot tr:nth-child(1) th { bottom: 58px; }
table.grid tfoot tr:nth-child(2) td, table.grid tfoot tr:nth-child(2) th { bottom: 29px; }
table.grid tfoot th.sticky { text-align: left; z-index: 4; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 10px 0; }
.panel h2 { margin: 0 0 8px; font-size: 1rem; }
.panel p { margin: 4px 0 8px; color: var(--muted); font-size: .88rem; }
.catrow { display: grid; grid-template-columns: 1fr 96px auto auto auto; gap: 4px; margin-bottom: 4px; }
.prow { display: grid; grid-template-columns: 1fr auto; gap: 4px; margin-bottom: 4px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: flex; align-items: flex-start; gap: 10px; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; padding: 0; flex: none; accent-color: var(--brand); }

.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; text-align: center; }
.login button { display: inline-flex; align-items: center; gap: 10px; padding: 12px 18px; }
.err { color: var(--bad); }
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 18px 16px 14px; width: min(92vw, 420px);
  background: var(--card); color: var(--ink); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dlg:focus { outline: none; }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg h2 { margin: 0 0 8px; font-size: 1.05rem; }
.dlg p { margin: 0 0 16px; line-height: 1.45; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; }
.dlg-btns.stack { flex-direction: column; }
.dlg-btns button { min-width: 88px; padding: 10px 14px; }
.dlg-btns.stack button { text-align: left; display: flex; flex-direction: column; gap: 2px; }
.dlg-btns.stack button span { font-weight: 600; }
.dlg-btns small { color: var(--muted); font-size: .8rem; }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); font-weight: 600; }

/* Phones: smaller cards so the pinned block leaves more room for rows. */
@media (max-width: 759px) {
  .phead.pinned .pbar { margin-bottom: 6px; }
  .phead.pinned .cards { gap: 6px; margin-bottom: 4px; }
  .phead.pinned .card { padding: 5px 8px; font-size: .76rem; }
  .phead.pinned .card h3 { margin-bottom: 2px; font-size: .7rem; }
}

@media (min-width: 760px) {
  .tabs { position: static; max-width: 760px; margin: 0 auto 6px; padding: 0 12px; border: 0; background: transparent; }
  .tabs button { border: 1px solid var(--line); }
  main { padding-bottom: 40px; }
  .gridwrap { max-height: calc(100vh - 150px); }
}
