:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a66;
  --line: #dddbd4;
  --accent: #1f5f99;
  --accent-ink: #ffffff;
  --ok: #2e7d32;
  --warn: #a35d00;
  --warn-bg: #fdf0dc;
  --bad: #b3261e;
  --chip: #ecebe6;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
#app { max-width: 1280px; margin: 0 auto; padding: 0 16px 48px; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
.hint, .muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, "Courier New", monospace; }

/* top bar */
.topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 0; }
.brand strong { font-size: 18px; }
.brand .tag { font-size: 12px; background: var(--chip); border-radius: 10px; padding: 1px 8px; color: var(--muted); }
.brand .flow { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.top-actions select { max-width: 260px; }

/* controls */
button, .btn {
  font: inherit; padding: 6px 12px; border-radius: 6px; border: 1px solid #c9c7bf; background: #fff;
  color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #9e9c94; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--bad); border-color: #e3b3ae; }
button.link { border: none; background: none; color: var(--accent); text-decoration: underline; padding: 6px 4px; }
button.small { padding: 2px 8px; font-size: 12px; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid #c9c7bf; border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; }
textarea { width: 100%; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--ink); font-size: 14px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; max-width: 100%; }
label.inline select { max-width: 100%; min-width: 0; flex: 1 1 auto; }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
label.check input { width: auto; }

/* layout */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 12px 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.card-head .actions { margin-top: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 8px 0; }
.row .grow { flex: 1 1 260px; }
.row .narrow { flex: 0 1 130px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 10px; }
.card > label { margin-top: 10px; }
.welcome { max-width: 760px; margin: 40px auto; padding: 28px; }
.welcome p { font-size: 15px; }
.empty { color: var(--muted); font-style: italic; }
.banner { border-radius: 8px; padding: 10px 14px; margin: 8px 0; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { background: #e6f2e7; color: var(--ok); }
.flash { position: fixed; right: 16px; bottom: 16px; background: var(--ink); color: #fff; padding: 6px 12px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.flash.show { opacity: .85; }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--muted); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .step { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--chip); font-size: 12px; margin-right: 4px; }
.tabs button.on .step { background: var(--accent); color: #fff; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stats span { display: block; color: var(--muted); font-size: 12px; }
.stats strong { font-size: 18px; }
.danger-zone { background: transparent; border-style: dashed; }

/* tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.grid thead th { background: #f7f6f2; font-weight: 600; font-size: 12px; color: var(--muted); }
table.grid tfoot td { font-weight: 600; border-bottom: none; }
table.grid tr.chapter td { background: #f7f6f2; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
table.grid.compact td, table.grid.compact th { padding: 4px 6px; }
table.grid tr.over td { background: #fff7ea; }
table.grid.claim { width: 100%; }
table.grid.claim td:nth-child(2) { min-width: 150px; max-width: 260px; }
table.grid.claim th { white-space: normal; }
table.grid.claim td, table.grid.claim th { padding: 6px 4px; }
table.grid.claim .claim-line-notes td { padding-top: 0; }
table.grid.claim .claim-line-notes .line-notes { min-width: 0; }
table.grid tr.editing td { background: #eaf2fb; }
.n { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.c { text-align: center !important; }
.r { text-align: right !important; }
.strong { font-weight: 600; }
.row-actions { white-space: nowrap; text-align: right; }
.small-text { font-size: 12px; color: var(--muted); }
table.totals { margin: 14px 0 0 auto; border-collapse: collapse; min-width: 360px; }
table.totals th { text-align: left; font-weight: 400; padding: 4px 16px 4px 0; color: var(--muted); }
table.totals td { padding: 4px 0; }
table.totals tr.payable th, table.totals tr.payable td { font-weight: 700; color: var(--ink); border-top: 2px solid var(--ink); padding-top: 6px; }
table.preview { border-collapse: collapse; font-size: 12px; margin: 10px 0; }
table.preview th, table.preview td { border: 1px solid var(--line); padding: 3px 6px; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
table.preview th { background: #f7f6f2; color: var(--muted); }
table.preview tr.hdr td { background: #eaf2fb; font-weight: 600; }
.item-form td { background: #f2f7fc; }

/* chips */
.chip { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: var(--chip); color: var(--muted); vertical-align: middle; }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.status-submitted { background: #e3edf8; color: var(--accent); }
.chip.status-reviewed, .chip.rv-approved { background: #e6f2e7; color: var(--ok); }
.chip.rv-partial { background: var(--warn-bg); color: var(--warn); }
.chip.rv-disputed { background: #fbe4e2; color: var(--bad); }
.notices { display: grid; gap: 4px; margin-bottom: 10px; }
.notices .ok { color: var(--ok); }
.warn-text { color: var(--warn); }

/* period bar */
.period-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.period-bar p { margin: 0; }

/* measurement form */
.progress { background: #f7f6f2; border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.progress .bar { height: 6px; background: #e3e1da; border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.progress .bar div { height: 100%; background: var(--accent); }
.progress.over .bar div { background: var(--warn); }
.kv-row { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); }
.kv-row strong { color: var(--ink); }
.formula-row .result { display: flex; flex-direction: column; gap: 3px; min-width: 180px; font-size: 13px; color: var(--muted); }
.formula-row output { font-size: 18px; font-weight: 600; color: var(--ink); padding: 3px 0; }
.formula-row output.bad { color: var(--bad); font-size: 13px; font-weight: 400; }
.formula-row output.ok { color: var(--ok); }
#m-formula { font-size: 16px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.thumb-wrap { position: relative; display: inline-block; }
.thumb-wrap img { width: 84px; height: 64px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: #eee; }
.thumbs.small .thumb-wrap img { width: 48px; height: 36px; }
.thumb-wrap .x { position: absolute; top: -6px; right: -6px; padding: 0 6px; border-radius: 50%; font-size: 12px; line-height: 18px; }
.m-group .unit { color: var(--muted); font-weight: 400; }
.import-panel { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.timer { display: flex; gap: 12px; align-items: center; }

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar > *, .top-actions > * { min-width: 0; }
  .top-actions label.inline { flex: 1 1 100%; }
  .top-actions select, .period-bar select { width: 100%; max-width: none; }
  .period-bar label.inline { flex: 1 1 100%; }
  .tabs button { padding: 8px 8px; }
  table.totals { min-width: 0; width: 100%; }
}

/* ---------- printed documents ---------- */
#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  body { background: #fff; }
}
.doc { font: 9.5pt/1.3 "Times New Roman", Times, serif; color: #000; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 10px; }
.doc-kv th { text-align: left; font-weight: 400; padding: 0 8px 0 0; vertical-align: top; }
.doc-kv td { font-weight: 700; }
.doc-title { text-align: center; flex: 1; }
.doc-title h1 { font-size: 15pt; margin: 4px 0; }
.doc-grid { width: 100%; border-collapse: collapse; }
.doc-grid th, .doc-grid td { border: 0.6pt solid #000; padding: 2px 4px; vertical-align: top; }
.doc-grid th { font-weight: 700; text-align: center; background: #eee; }
.doc-grid .doc-chapter td { font-weight: 700; background: #f3f3f3; }
.doc-grid tfoot td { font-weight: 700; }
.doc-grid thead { display: table-header-group; }
.doc-grid tr { break-inside: avoid; }
.doc-desc { min-width: 35%; }
.doc-formula { font-family: "Courier New", monospace; }
.doc-totals { margin: 8px 0 0 auto; border-collapse: collapse; min-width: 45%; }
.doc-totals th { text-align: left; font-weight: 400; padding: 1px 12px 1px 0; }
.doc-totals td { padding: 1px 0; }
.doc-totals .doc-payable th, .doc-totals .doc-payable td { font-weight: 700; border-top: 1pt solid #000; }
.doc-words { margin-top: 8px; }
.doc-notes { margin-top: 8px; font-size: 8.5pt; }
.doc-sign { display: flex; justify-content: space-between; gap: 30px; margin-top: 28px; break-inside: avoid; }
.doc-sign > div { flex: 1; text-align: center; }
.doc-sign-line { border-bottom: 0.6pt solid #000; height: 34px; margin-bottom: 4px; }
.doc-book-item { margin-top: 14px; break-inside: avoid-page; }
.doc-book-item h2 { font-size: 10.5pt; margin: 0 0 4px; }
.doc-book-item h2 span { font-weight: 400; }
.doc-progress { margin-top: 3px; font-size: 8.5pt; }
.doc-photos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.doc-photos figure { margin: 0; width: 31%; break-inside: avoid; }
.doc-photos img { width: 100%; height: auto; border: 0.5pt solid #999; }
.doc-photos figcaption { font-size: 7.5pt; }

/* Accounts and save recovery remain usable on narrow screens. */
.cloud-panel { margin: 12px 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
/* One line: where the data is, who is signed in, and the account button. */
.cloud-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.cloud-who { flex: 1 1 200px; min-width: 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: none; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
/* Signed out: three views, one narrow form at a time. */
.cloud-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 14px 0 0; border-bottom: 1px solid var(--line); }
.cloud-tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.cloud-tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.cloud-auth { display: flex; flex-direction: column; gap: 12px; max-width: 360px; padding: 16px 0 6px; }
.cloud-auth h2, .cloud-section h2 { margin: 0; font-size: 15px; }
.cloud-auth p { margin: 0; }
.cloud-auth input { width: 100%; }
.cloud-auth .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* Signed in: account, organization, members and local projects as separate blocks. */
.cloud-sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-top: 12px; align-items: start; }
.cloud-section { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.cloud-section p { margin: 0; overflow-wrap: anywhere; }
.cloud-section select, .cloud-section input { max-width: 100%; }
.cloud-inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; max-width: 100%; }
.cloud-sections > .migration-preview { grid-column: 1 / -1; }
.member-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 10px; width: 100%; padding-top: 8px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.member-row > span { flex: 1 1 180px; }
.migration-preview { padding: 12px; border: 1px solid var(--line); }
.certification-notices, .review-provenance { font-size: 0.9em; break-inside: avoid; }
.import-issues { max-height: 240px; overflow: auto; }
#save-state { overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .cloud-auth { max-width: none; }
  .cloud-inline > label, .cloud-inline input, .cloud-section select { flex-basis: 100%; width: 100%; }
  .cloud-panel button { min-height: 44px; }
  .cloud-tabs button { flex: 1 1 auto; }
}
@media print {
  .certification-notices, .review-provenance { color: #000; font: 9pt/1.3 "Times New Roman", serif; }
}
.line-notes { font-size: 12px; line-height: 1.4; min-width: 190px; white-space: normal; overflow-wrap: anywhere; }
.line-notes > div + div { margin-top: 4px; }
.price-pair { white-space: normal; min-width: 100px; }
.output-selection { padding: 10px; border: 1px solid var(--line); margin: 10px 0; overflow-wrap: anywhere; }
.problem-report { border-left: 3px solid var(--warn); padding: 6px 12px; overflow-wrap: anywhere; }
.doc .line-notes { min-width: 0; font-size: 8pt; line-height: 1.25; margin-top: 4px; }
.doc .price-pair { min-width: 0; font-size: 8pt; }
.doc .output-mode { border: 1pt solid #000; padding: 4px; font-weight: bold; }
@media (max-width: 640px) { .output-selection, .problem-report { max-width: 100%; } }

/* Let numeric content set a minimum column width; only prose can wrap. */
.doc-claim .doc-grid { table-layout: auto; font-size: 8.5pt; }
.doc-claim .doc-grid th, .doc-claim .doc-desc { overflow-wrap: anywhere; }
.doc-claim .doc-desc { min-width: 0; }
.doc-claim .doc-grid .n { white-space: nowrap; }
.doc-claim .doc-grid td { padding: 2px 3px; }

/* Keep signatures with the amounts and notes they accompany. */
.doc-settlement { break-inside: avoid-page; }

/* ---------- first use and phone layout (T-031) ---------- */
a { color: var(--accent); }
.welcome h2 { margin-top: 18px; }
.welcome nav { margin: 10px 0; line-height: 1.9; }

/* The local-demo note is one quiet line, not a box. */
.local-note { margin: 0 0 6px; color: var(--muted); font-size: 12px; }

/* Shown on phones only: the menu and period switches, the column switch, units beside quantities, short totals. */
.menu-toggle, .period-toggle, .table-tools, .unit-suffix, .narrow-only, .status-inline { display: none; }
/* On wide screens the project actions and the period dates sit in their rows as before. */
.project-actions, .period-dates { display: contents; }

/* Guide for the fictional sample. */
.guide {
  display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; justify-content: space-between;
  margin: 12px 0 0; padding: 10px 14px; background: #eaf2fb; border: 1px solid #c5d9ee; border-radius: 10px;
}
.guide p { margin: 0; flex: 1 1 420px; }
.guide-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.guide .link { padding: 2px 0; }

/* File buttons: the real field stays reachable by keyboard, only out of sight. */
label.btn { position: relative; }
label.btn > input[type="file"][hidden] { display: block; position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* What just happened, said where it happened. */
.banner p { margin: 4px 0; }
.next-steps { margin-top: 12px; }
.next-steps .mono { overflow-wrap: anywhere; }
.saved-note { margin: 12px 0 0; }
table.grid tr.just-saved td { background: #e6f2e7; }

/* Measurement tables share one column grid, so the groups line up. */
.m-table { table-layout: fixed; }
.m-table .c-date { width: 104px; }
.m-table .c-loc { width: 24%; }
.m-table .c-qty { width: 110px; }
.m-table .c-note { width: 22%; }
.m-table .c-act { width: 150px; }
.m-table td { overflow-wrap: anywhere; }

/* The pilot timer stays available but out of a visitor's way. */
.timer-box { padding: 10px 16px; }
.timer-box summary { cursor: pointer; color: var(--muted); }
.timer-box .timer { margin-top: 10px; flex-wrap: wrap; }

/* A table that scrolls sideways shows a shadow on the side where more is hidden. */
.table-wrap {
  background:
    linear-gradient(to right, var(--panel) 40%, rgba(255, 255, 255, 0)) left center / 28px 100% no-repeat local,
    linear-gradient(to left, var(--panel) 40%, rgba(255, 255, 255, 0)) right center / 28px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .22), rgba(0, 0, 0, 0)) left center / 10px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .22), rgba(0, 0, 0, 0)) right center / 10px 100% no-repeat scroll;
}

/* Footer of the public demo: what this is, how to write, the way back to the site. */
.demo-foot { margin: 28px 0 0; padding: 14px 0 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.demo-foot p { margin: 4px 0; }

@media (max-width: 640px) {
  /* iOS zooms into fields smaller than 16px, and fingers need taller controls. */
  input, select, textarea, label > input, label > select, label > textarea { font-size: 16px; }
  button, .btn { min-height: 40px; }
  button.small { min-height: 36px; padding: 4px 10px; font-size: 13px; }
  button.link { min-height: 36px; }
  .thumb-wrap .x { min-height: 0; }
  label.check { min-height: 36px; }
  label.check input { width: 18px; height: 18px; }

  .topbar { padding: 10px 0 6px; gap: 8px; }
  .brand .flow { display: none; }
  .top-actions { flex-wrap: wrap; }
  .top-actions label.inline { flex: 1 1 0; min-width: 0; }
  .menu-toggle { display: inline-flex; flex: none; }
  .project-actions { display: none; flex: 1 1 100%; flex-wrap: wrap; gap: 6px; }
  .project-actions.open { display: flex; }

  /* One row of tabs that scrolls sideways. */
  .tabs { position: relative; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; min-height: 44px; padding: 8px 10px; }

  .period-bar { gap: 8px 12px; padding: 12px; }
  .period-toggle { display: inline-flex; }
  .period-dates { display: none; flex: 1 1 100%; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
  .period-dates.open { display: flex; }
  .period-dates label.inline { flex: 1 1 100%; }

  .card { padding: 12px; }
  .welcome { margin: 16px auto; padding: 18px; }
  .guide { padding: 10px 12px; }
  .guide p { flex-basis: 100%; }
  .guide-actions { flex: 1 1 100%; justify-content: space-between; }

  /* The print and export note and the notices take less room above the table. */
  .output-selection { padding: 8px 10px; font-size: 13px; }
  .output-selection p { margin: 4px 0 0; }
  .notices { font-size: 13px; }

  /* Important columns first; "Сите колони" brings the rest back. */
  .table-tools { display: flex; justify-content: flex-end; }
  .cols-key .opt, .cols-key .wide-only, .cols-key .status-col { display: none; }
  .cols-key .status-inline { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
  .cols-key .narrow-only { display: table-row; }
  .cols-key .unit-suffix { display: inline; color: var(--muted); font-weight: 400; }
  .cols-key table.grid.claim td:nth-child(2) { min-width: 0; }
  .cols-key table.grid td:nth-child(2) { overflow-wrap: anywhere; }

  /* Before a review there is nothing to choose, so the table comes first and the notes follow it. */
  .claim-card:not(.is-reviewed) { display: flex; flex-direction: column; }
  .claim-card:not(.is-reviewed) .output-selection { order: 3; margin-top: 14px; }
  .claim-card:not(.is-reviewed) .notices { order: 4; margin-bottom: 0; }

  /* Each measurement becomes a block, so nothing is hidden to the right. */
  .m-table { table-layout: auto; }
  .m-table colgroup, .m-table thead { display: none; }
  .m-table, .m-table tbody, .m-table tfoot { display: block; }
  .m-table tbody tr { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.grid.m-table tbody td { display: block; padding: 0; border: 0; }
  .m-table tbody td:nth-child(1) { color: var(--muted); font-size: 12px; }
  .m-table tbody td:nth-child(2) { font-weight: 600; }
  .m-table tbody td:nth-child(3) { margin: 2px 0; }
  .m-table tbody td:nth-child(4) { grid-area: 1 / 2 / span 3; align-self: center; font-size: 16px; font-weight: 600; }
  .m-table tbody td:nth-child(5) { grid-column: 1 / -1; color: var(--muted); }
  .m-table tbody td:nth-child(6) { grid-column: 1 / -1; margin-top: 6px; text-align: left; }
  .m-table tfoot tr { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0 0; }
  table.grid.m-table tfoot td { display: block; padding: 0; }
  table.grid.m-table tfoot td:nth-child(3) { display: none; }
  .m-group h3 { margin-top: 18px; }

  .formula-row .result { min-width: 0; flex: 1 1 100%; flex-direction: row; align-items: baseline; gap: 8px; }
  .timer { flex-wrap: wrap; }
}

/* ---------- T-041: one top bar, a project menu and calmer pages ----------
   Screen only: printed documents keep their own sizes and rules. */
@media screen {
  :root { font-size: 15px; }
  #app { max-width: 1200px; padding: 0 20px 56px; }
  h1 { font-size: 24px; }
  h2 { font-size: 17px; margin-bottom: 12px; }

  /* One bar that stays in view: name, project, menu, language. */
  .topbar { position: sticky; top: 0; z-index: 30; flex-wrap: nowrap; gap: 16px; padding: 10px 0; margin-bottom: 14px; background: var(--bg); border-bottom: 1px solid var(--line); }
  .brand { flex: none; }
  .brand strong { font-size: 20px; letter-spacing: -0.01em; }
  .top-actions { position: relative; flex: 0 1 auto; flex-wrap: nowrap; gap: 8px; min-width: 0; }
  .top-actions label.inline { min-width: 0; }
  .top-actions select { max-width: 340px; }
  .top-actions .lang { flex: none; }
  .menu-toggle { display: inline-flex; flex: none; }
  .menu-toggle::after { content: "\25BE"; font-size: 11px; color: var(--muted); }
  /* The project actions are a menu under that button, on every screen width. */
  .project-actions { display: none; position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; flex: none; flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 2px; min-width: 240px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12); }
  .project-actions.open { display: flex; }
  .project-actions button, .project-actions .btn { flex-direction: row; justify-content: flex-start; align-items: center; padding: 9px 12px; border: none; border-radius: 6px; background: none; color: var(--ink); font-size: inherit; }
  .project-actions button:hover:not(:disabled), .project-actions .btn:hover { background: var(--chip); }

  /* Where the data is and who is signed in: one quiet line, as wide as the content. */
  .cloud-panel { margin: 0 0 14px; padding: 14px 16px; }
  .cloud-panel:not(:has(.cloud-tabs, .cloud-auth, .cloud-sections)) { padding: 0; border: none; background: none; }
  .local-note { margin: 0 0 10px; }

  /* Steps. */
  .tabs { gap: 2px; }
  .tabs button { padding: 12px 16px; }
  .tabs .step { width: 22px; height: 22px; line-height: 22px; }

  /* Pages: more air, fewer hard edges. */
  .card { margin: 14px 0; padding: 20px; border-radius: 12px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }
  .row { gap: 14px; margin: 12px 0; }
  input, select, textarea { padding: 8px 10px; }
  button, .btn { padding: 7px 14px; }
  button.small { padding: 3px 9px; }
  button.link { padding: 6px 4px; }
  input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, .btn:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
  main > p { margin: 16px 2px; color: var(--muted); }
}
@media screen and (max-width: 900px) {
  .brand .flow { display: none; }
}
@media screen and (max-width: 640px) {
  #app { padding: 0 12px 48px; }
  .topbar { position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
  .brand { flex: 1 1 100%; }
  .top-actions { flex: 1 1 100%; }
  .top-actions label.inline { flex: 1 1 0; }
  .project-actions { left: 0; right: 0; }
  .card { padding: 14px; }
}

/* T-041, second part: the screens themselves. Still screen only. */
@media screen {
  /* The claim switcher is a toolbar above the page, not one more card. */
  .card.period-bar { margin: 4px 0 14px; padding: 0; border: none; background: none; box-shadow: none; }

  /* What will be printed and exported: a quiet note. */
  .output-selection { margin: 12px 0; padding: 12px 14px; border: none; border-radius: 8px; background: #f7f6f2; }
  .output-selection strong { display: block; font-size: 13px; }
  .output-selection p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

  /* Notices sit side by side as labels. */
  .notices { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin: 12px 0; }
  .notices > .muted, .notices > .warn-text, .notices > .ok { padding: 3px 10px; border-radius: 8px; background: var(--chip); font-size: 13px; }
  .notices > .warn-text { background: var(--warn-bg); }
  .notices > .ok { background: #e6f2e7; }
  .notices > .certification-notices { flex: 1 1 100%; }
  .notices > .certification-notices:empty { display: none; }

  /* Tables: lighter header and chapter rows, more room, the row under the pointer marked. */
  table.grid { font-size: 13.5px; }
  table.grid th, table.grid td { padding: 9px 10px; }
  table.grid thead th { background: none; border-bottom: 2px solid var(--line); }
  table.grid tr.chapter td { padding-top: 16px; background: none; color: var(--muted); }
  table.grid tbody tr:not(.chapter):not(.over):not(.editing):not(.just-saved):not(.claim-line-notes):hover td { background: #faf9f6; }
  table.grid.compact td, table.grid.compact th { padding: 6px 8px; }
  table.grid.claim td, table.grid.claim th { padding: 8px 6px; }

  /* The settlement under the claim: one block, the payable amount largest. */
  table.totals { margin-top: 18px; min-width: 420px; border-collapse: separate; border-spacing: 0; border-radius: 10px; background: #f7f6f2; }
  table.totals th { padding: 6px 28px 6px 16px; }
  table.totals td { padding: 6px 16px 6px 0; }
  table.totals tr:first-child th, table.totals tr:first-child td { padding-top: 12px; }
  table.totals tr.payable th, table.totals tr.payable td { padding-top: 12px; padding-bottom: 12px; border-top: 1px solid var(--line); font-size: 17px; }

  .stats strong { font-size: 20px; }
  .progress { padding: 10px 12px; }
}
@media screen and (max-width: 640px) {
  table.totals { min-width: 0; }
  table.grid th, table.grid td { padding: 8px 6px; }
}

