/* Licence panel: modern, compact admin skin (mockup, 2026-11-24). Written to replace public/assets/app.css:
   every class name the pages use today is kept. New: the app shell (.app .sidebar .mobilebar .nav-toggle ...), .page-head,
   .cols, .q (the "?" helper), .state. One accent (blue). Green / amber / red only for status. No gradients, no web fonts, no JS. */

/* ---- Tokens: 8px spacing scale, slate neutrals, one accent ---- */
:root {
  --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem; --s-5: 1.5rem; --s-6: 2rem;   /* 4 8 12 16 24 32 px */
  --gutter: 1rem;
  --ink: #1b2330; --ink-2: #3a4556; --muted: #5d6877;
  --accent: #2b5cd6; --accent-dark: #2149ac; --accent-soft: #eaf0fc;
  --danger: #b42323; --danger-soft: #fdecec; --danger-line: #efc3c3;
  --bg: #f6f7f9; --surface: #fff; --surface-2: #fafbfc;
  --line: #e2e6ec; --line-soft: #eceff3; --field-line: #cdd3dc;
  --radius: 8px; --radius-s: 6px; --control-h: 36px; --field-max: 30rem;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --side-w: 240px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* Type (owner 2026-11-24: better fonts). No web-font download (the panel CSP is self only): the modern system faces,
   Segoe UI Variable on Windows 11, San Francisco on Apple, Roboto on Android; Inter first if installed. */
:root { --font: Inter, "Segoe UI Variable Text", "Segoe UI Variable", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: Inter, "Segoe UI Variable Display", "Segoe UI Variable", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { margin: 0; font: 14.5px/1.55 var(--font); font-feature-settings: "cv11", "ss01"; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
h1, h2, h3, .side-brand, .bill-stats strong { font-family: var(--font-display); }
td, dl.facts dd, .bill-stats strong { font-variant-numeric: tabular-nums; }
/* Content column. Pages without the shell (login, reset) get the same centred column. */
main { width: 100%; max-width: 1280px; margin: 0 auto; padding: var(--s-5) var(--s-5) var(--s-6); min-width: 0; }
h1 { font-size: 1.5rem; line-height: 1.2; font-weight: 650; letter-spacing: -.02em; margin: 0 0 var(--s-2); }
h2 { font-size: 1.0625rem; line-height: 1.3; font-weight: 600; letter-spacing: -.01em; margin: 0 0 var(--s-2); }
h3 { font-size: .9375rem; font-weight: 600; }
main > h2, main > .rep-head { margin-top: var(--s-5); }
main > h1 + h2, main > h2:first-child { margin-top: var(--s-2); }
p { margin: 0 0 var(--s-2); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .875em; }
pre { background: #f0f2f5; padding: var(--s-2); border-radius: var(--radius-s); overflow-x: auto; max-width: 100%; white-space: pre-wrap; word-break: break-word; margin: var(--s-1) 0; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- App shell ---- */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); padding: var(--s-3) var(--s-3) var(--s-3); }
.side-brand { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-2) var(--s-3); font-weight: 650; color: var(--ink); }
.side-brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--accent); color: #fff; font-size: .8rem; font-weight: 700; }
.side-nav { flex: 1; }
.side-group { margin: 0 0 var(--s-3); }
.side-h { margin: 0; padding: var(--s-1) var(--s-2); font-size: .75rem; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.side-link { display: flex; align-items: center; gap: var(--s-2); min-height: 32px; padding: 0 var(--s-2); border-radius: var(--radius-s); color: var(--ink-2); font-size: .875rem; }
.side-link:hover { background: var(--line-soft); text-decoration: none; color: var(--ink); }
.side-link.active, .side-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.side-badge { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .72rem; font-weight: 600; line-height: 18px; text-align: center; }
.side-foot { margin: var(--s-2) 0 0; padding-top: var(--s-2); border-top: 1px solid var(--line-soft); }
.side-foot form { margin: 0; }
.side-foot button.link { display: flex; width: 100%; justify-content: flex-start; min-height: 32px; padding: 0 var(--s-2); border-radius: var(--radius-s); color: var(--ink-2); font-size: .875rem; }
.side-foot button.link:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.mobilebar { display: none; }

/* Page header: title and one line left, the main action right. */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s-2) var(--s-4); margin: 0 0 var(--s-4); }
.page-head h1 { margin: 0; }
.page-desc { margin: 2px 0 0; color: var(--muted); max-width: 64ch; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
/* Two cards side by side on wide screens, stacked below ~720px. */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: var(--s-4); align-items: start; margin: 0 0 var(--s-4); }
.cols > .card, .cols > section > .card { margin: 0; }
.cols > section > h2 { margin-top: 0; }

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--s-4) var(--s-5); margin: 0 0 var(--s-4); }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card.narrow { max-width: 420px; margin: 4rem auto; }
.card.key { border-color: #e2c27a; background: #fffbf0; }
.keybox { display: block; padding: var(--s-2) var(--s-3); background: #fff; border: 1px dashed #d4a83c; border-radius: var(--radius-s); word-break: break-all; user-select: all; }

/* ---- Forms: labels above fields ---- */
form label { display: block; margin: 0 0 var(--s-3); font-weight: 500; font-size: .875rem; color: var(--ink); }
form input[type=text], form input[type=email], form input[type=password], form input[type=number], form input[type=date],
form input[type=datetime-local], form input[type=time], form input[type=tel], form input[type=url], form input[type=search],
form select, form textarea { display: block; width: 100%; max-width: var(--field-max); min-height: var(--control-h); margin-top: var(--s-1); padding: .3rem .65rem; font: inherit; font-weight: 400; color: var(--ink); border: 1px solid var(--field-line); border-radius: var(--radius-s); background: var(--surface); }
form select { padding-right: .4rem; }
form input::placeholder, form textarea::placeholder { color: #8b95a3; }
form input:focus, form select:focus, form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
form textarea { min-height: 4.5rem; }
form input:disabled { background: var(--line-soft); color: var(--muted); }
form fieldset { min-width: 0; margin: 0 0 var(--s-3); padding: var(--s-2) var(--s-3) var(--s-3); border: 1px solid var(--line); border-radius: var(--radius-s); max-width: var(--field-max); }
form fieldset legend { font-weight: 600; font-size: .875rem; padding: 0 var(--s-1); }
form label small { font-weight: 400; color: var(--muted); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0 var(--s-2) 0 0; vertical-align: -3px; }
/* A card form whose fields are direct labels (Maintenance, My account): fields share one aligned grid; long things span the row. */
form.card:not(.bill-editor):has(> label) { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); column-gap: var(--s-4); align-items: start; }
form.card:not(.bill-editor):has(> label) > * { grid-column: 1 / -1; }
form.card:not(.bill-editor):has(> label) > label:not(.check):not(:has(textarea)) { grid-column: auto; }
form.card:not(.bill-editor):has(> label) > button, form.card:not(.bill-editor):has(> label) > a { justify-self: start; }
form.card:not(.bill-editor):has(> label) input, form.card:not(.bill-editor):has(> label) select, form.card:not(.bill-editor):has(> label) textarea { max-width: none; }
form.card:not(.bill-editor):has(> label) > fieldset { max-width: none; }
/* Tick-lists (which businesses, which modules) flow in columns instead of one long stack. */
form fieldset:has(> label.check) { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); column-gap: var(--s-4); }
form fieldset:has(> label.check) > legend { grid-column: 1 / -1; }
form fieldset.modules { max-width: var(--field-max); }
form label.check { display: flex; align-items: center; margin: var(--s-1) 0; font-weight: 400; }

/* ---- Buttons: primary solid accent, secondary white with border, danger red outline ---- */
button, a.button { display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2); min-height: var(--control-h); font: inherit; font-weight: 500; padding: .25rem .9rem; border: 1px solid var(--accent); border-radius: var(--radius-s); background: var(--accent); color: #fff; cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, a.button:hover { background: var(--accent-dark); border-color: var(--accent-dark); text-decoration: none; }
button.secondary, a.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--field-line); }
button.secondary:hover, a.button.secondary:hover { background: var(--line-soft); border-color: #b9c1cd; }
button.danger, a.button.danger { background: var(--surface); color: var(--danger); border-color: var(--danger-line); }
button.danger:hover, a.button.danger:hover { background: var(--danger-soft); border-color: #e3a3a3; }
button.danger.solid, a.button.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
button.danger.solid:hover, a.button.danger.solid:hover { background: #911c1c; }
button.link { background: none; border: 0; color: var(--accent); padding: 0; min-height: 0; font-weight: 400; }
button.link:hover { background: none; text-decoration: underline; }
td button, td a.button { min-height: 28px; padding: .1rem .6rem; font-size: .8125rem; }
form.inline { display: inline; margin: 0; }
form.spaced { margin-top: var(--s-3); }

/* ---- Messages ---- */
.flash { padding: var(--s-2) var(--s-3); border-radius: var(--radius-s); border: 1px solid transparent; margin: 0 0 var(--s-3); }
.flash-ok { background: #edf8f0; border-color: #c9e8d2; color: #1b5a31; }
.flash-error { background: var(--danger-soft); border-color: var(--danger-line); color: #8d1f1f; }
.flash-info { background: var(--accent-soft); border-color: #cddbf6; color: #1f3f8f; }
.state { text-align: center; padding: var(--s-6) var(--s-4); color: var(--muted); }
.state strong { display: block; color: var(--ink); font-size: 1rem; margin-bottom: var(--s-1); }

/* ---- Tables: no vertical lines, light row rules, quiet headers ---- */
.scroll { overflow-x: auto; margin: 0 0 var(--s-3); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
thead th { background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: .8125rem; font-weight: 500; color: var(--muted); }
th { white-space: nowrap; }
th small { display: block; font-weight: 400; font-size: .72rem; line-height: 1.3; color: #8b95a3; max-width: 24ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }   /* old helper line; kept so view_th works either way */
.card .scroll { border: 0; border-radius: 0; box-shadow: none; margin: 0 0 var(--s-2); }
.card .scroll thead th:first-child, .card .scroll td:first-child { padding-left: 0; }
td.nw, .nw { white-space: nowrap; }
.trunc { display: block; max-width: 20ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.list td.col-name { max-width: 22ch; }
table.list td.col-name a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-weight: 500; }
table.list td.col-name a:hover { color: var(--accent); }
table.list td.col-domain .trunc { max-width: 20ch; }
table.list td.col-plan .trunc { max-width: 12ch; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
/* The "?" helper: what it counts, from where, for which period. Hover, focus or tap shows it. */
.q { position: relative; display: inline-grid; place-items: center; width: 15px; height: 15px; margin-left: 5px; border: 1px solid var(--field-line); border-radius: 50%; background: var(--surface); color: var(--muted); font-size: .65rem; font-weight: 600; line-height: 1; cursor: help; vertical-align: 1px; text-transform: none; letter-spacing: 0; white-space: normal; }
.q:hover, .q:focus { border-color: var(--accent); color: var(--accent); }
.q::after { content: attr(data-help); display: none; position: absolute; top: calc(100% + 6px); left: -8px; width: max-content; max-width: 240px; padding: 8px 10px; border-radius: var(--radius-s); background: var(--ink); color: #fff; font-size: .78rem; font-weight: 400; line-height: 1.4; text-align: left; z-index: 30; }
.q:hover::after, .q:focus::after { display: block; }
th:last-child .q::after, th.num .q::after, .num .q::after { left: auto; right: -8px; }

/* ---- Status pills: soft, one dot ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 0 .55rem; border-radius: 999px; font-size: .75rem; line-height: 20px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-active { background: #e6f5ea; color: #17623a; }
.pill-grace { background: #fdf2d3; color: #86560a; }
.pill-read_only { background: #fde7d3; color: #94430a; }
.pill-suspended { background: #fce5e5; color: #a52222; }
.pill-trial { background: #e7eefc; color: #2549a0; }
.pill-trial-ended { background: #fce5e5; color: #a52222; }
.tag { font-size: .72rem; color: var(--muted); border: 1px solid var(--field-line); border-radius: 4px; padding: 0 .35rem; }

/* ---- Tabs and pager ---- */
.tabs { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); border-bottom: 1px solid var(--line); margin: 0 0 var(--s-3); }
.tabs a { display: inline-flex; align-items: center; min-height: 36px; padding: 0 2px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); margin: 0 0 var(--s-3); }
.pager a { display: inline-flex; align-items: center; min-height: 32px; padding: 0 .75rem; border: 1px solid var(--field-line); border-radius: var(--radius-s); background: var(--surface); color: var(--ink); font-size: .8125rem; }
.pager a:hover { background: var(--line-soft); text-decoration: none; }
.pager .muted { font-size: .8125rem; }
/* Filter rows: one baseline for every filter / period / per-page picker. */
:is(form.bill-filter, form.rep-period, form.inline:has(> label)) { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-3); align-items: flex-end; margin: 0 0 var(--s-3); }
:is(form.bill-filter, form.rep-period, form.inline:has(> label)) label { margin: 0; font-size: .8125rem; color: var(--muted); }
:is(form.bill-filter, form.inline:has(> label)) :is(select, input) { min-width: 11rem; color: var(--ink); }
:is(form.bill-filter, form.inline:has(> label)) :is(input[type=search]) { min-width: 15rem; }

/* ---- Billing, stat strips ---- */
.pre { white-space: pre-line; }
.bill-stats { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-5); margin: 0 0 var(--s-3); }
.bill-stats p { margin: 0; display: flex; flex-direction: column; }
.bill-stats p span { font-size: .8125rem; }
.bill-stats strong { font-size: 1.25rem; line-height: 1.3; font-weight: 650; font-variant-numeric: tabular-nums; }
.bill-overdue, td.bill-overdue { color: var(--danger); }
.bill-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin: var(--s-3) 0 0; }
.bill-actions form.inline { display: inline-block; }
.bill-links { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); margin: var(--s-3) 0 0; }
.bill-links a { margin: 0; }
.bill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); column-gap: var(--s-4); row-gap: 0; align-items: start; }
.bill-grid label small { display: block; font-weight: 400; }
.bill-editor h2 { margin-top: var(--s-3); }
table.bill-lines td { vertical-align: top; }
table.bill-lines input, table.bill-lines textarea { margin-top: 0; max-width: none; }
table.bill-lines .in-qty { width: 5rem; text-align: right; }
table.bill-lines .in-item { min-width: 12rem; }
table.bill-lines .in-desc { min-width: 16rem; }
table.bill-lines .in-price { width: 9rem; text-align: right; }
table.bill-lines .in-cost { width: 8rem; text-align: right; }
table.bill-lines textarea { min-height: 0; }
table.bill-lines select.in-follow { margin-top: .3rem; max-width: 12rem; font-size: .85rem; padding: .3rem .4rem; }
.bill-add { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: flex-end; margin: var(--s-3) 0; }
form label.inline-label { display: inline-block; margin: 0; font-weight: 400; }
form label.inline-label select, form label.inline-label input { display: inline-block; width: auto; min-width: 5rem; margin: 0 0 0 .35rem; }
.bill-totals { margin: var(--s-2) 0 var(--s-3) auto; max-width: 340px; }
.bill-totals p { display: flex; justify-content: space-between; gap: 1rem; margin: .15rem 0; font-variant-numeric: tabular-nums; }
.bill-totals p.grand { border-top: 1px solid var(--field-line); padding-top: .25rem; font-size: 1.0625rem; font-weight: 600; }
form.bill-item-form { margin-top: .5rem; }
details summary { cursor: pointer; color: var(--accent); }
h2.spaced { margin-top: var(--s-5); }
a.button.spaced, button.spaced { margin-top: var(--s-2); }

/* Forms: a short label, a grey hint under it, then the field. In a grid the fields of one row line up (subgrid). */
form label small.hint { display: block; font-weight: 400; font-size: .78rem; line-height: 1.35; color: var(--muted); margin-top: .1rem; }
h3.form-sec { font-size: .875rem; font-weight: 600; margin: var(--s-4) 0 var(--s-3); padding-bottom: var(--s-1); border-bottom: 1px solid var(--line-soft); }
form > h3.form-sec:first-of-type, .card > h3.form-sec:first-child { margin-top: .25rem; }
h3.form-sec + p.muted { margin: -.4rem 0 .75rem; font-size: .8125rem; }
.bill-grid > label:not(.check) { display: grid; grid-row: span 4; grid-template-rows: subgrid; row-gap: 0; align-content: start; margin: 0 0 var(--s-3); min-width: 0; }
.bill-grid > label:not(.check) > small.hint { grid-row: 2; }
.bill-grid > label:not(.check) > input, .bill-grid > label:not(.check) > select, .bill-grid > label:not(.check) > textarea { grid-row: 3; max-width: none; align-self: start; }
.bill-grid > label:not(.check) > small:not(.hint) { grid-row: 4; }
.bill-grid > :not(label), .bill-grid > label.check { grid-row: span 4; align-self: start; }
.bill-grid > .span-all { grid-column: 1 / -1; }
.bill-grid textarea { resize: vertical; min-height: 4.5rem; }
form fieldset.form-wide { max-width: none; }
fieldset#modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 1rem; }
fieldset#modules legend { grid-column: 1 / -1; }
@media (min-width: 760px) {
  .bill-grid > .span-2 { grid-column: span 2; }
}
fieldset.bill-newclient { max-width: none; }

/* Action tiles: heading, short help, fields, button. Tiles in a row share their rows (subgrid) so buttons line up. */
.tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); column-gap: var(--s-3); row-gap: 0; margin: var(--s-3) 0 0; }
.tools.stack { grid-template-columns: 1fr; width: min(26rem, 100%); margin-top: .6rem; }
form.tool { display: grid; grid-row: span 4; grid-template-rows: subgrid; row-gap: 0; align-content: start; min-width: 0;
  margin: 0 0 var(--s-3); padding: var(--s-3) var(--s-4); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); }
form.tool.tool-warn { background: #fffafa; border-color: var(--danger-line); }
form.tool.tool-wide { grid-column: 1 / -1; }
form.tool > h3 { font-size: .9375rem; margin: 0 0 .2rem; }
form.tool > p.muted { font-size: .8125rem; line-height: 1.4; margin: 0 0 var(--s-3); }
form.tool > .tool-fields { min-width: 0; }
form.tool > .tool-fields > label:last-child { margin-bottom: var(--s-3); }
form.tool input, form.tool select, form.tool textarea { max-width: none; }
form.tool > button { align-self: end; justify-self: start; }
form.tool .bill-grid { column-gap: var(--s-3); }
form.tool > .tool-fields:not(.bill-grid) { max-width: 30rem; }
form.tool > .tool-fields.pair { display: grid; grid-template-columns: 1fr 1fr; column-gap: var(--s-3); align-items: end; }
form.tool > .tool-fields.pair > label { margin-bottom: var(--s-3); }
/* A strip of facts: small grey name over a bold value. */
dl.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: var(--s-3) var(--s-4); margin: 0 0 var(--s-4); padding: var(--s-3) var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
dl.facts div { min-width: 0; }
dl.facts dt { font-size: .78rem; color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
p.facts-note { font-size: .8125rem; margin: .4rem 0 0; }
td details[open] { min-width: min(26rem, 80vw); }

/* HMS staff permissions: one box per category; a gold edge marks a permission that differs from the role's usual set. */
form.tool > .tool-fields.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s-3); align-items: start; max-width: none; margin-bottom: var(--s-3); }
.perm-grid fieldset { min-width: 0; margin: 0; padding: var(--s-1) var(--s-3) var(--s-2); background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius-s); }
.perm-grid legend { padding: 0 .25rem; font-size: .875rem; font-weight: 600; }
.perm-grid label.check { font-size: .875rem; }
.perm-changed { box-shadow: inset 3px 0 0 #d4a83c; padding-left: .45rem; }

/* ---- Reports ---- */
form.rep-period select, form.rep-period input { min-width: 11rem; }
.rep-help { margin: var(--s-1) 0 var(--s-2); }
.rep-actions { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); align-items: center; margin: var(--s-2) 0 0; }
.rep-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: var(--s-4); margin: var(--s-3) 0; }
.rep-card h2 { margin: 0 0 var(--s-2); font-size: 1rem; }
.rep-figs { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2) var(--s-4); }
.rep-figs div { display: flex; flex-direction: column; min-width: 0; }
.rep-figs dt { font-size: .78rem; color: var(--muted); cursor: help; }
.rep-figs dd { margin: 0; font-size: 1.0625rem; font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.rep-figs dd small { font-size: .75rem; font-weight: 400; }
.rep-head { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); align-items: center; justify-content: space-between; margin: var(--s-5) 0 var(--s-2); }
.rep-head h2 { margin: 0; }
.rep-partial { cursor: help; }
table.rep-table tfoot td { border-top: 2px solid var(--line); font-weight: 600; }

/* ---- Automations and Outbox ---- */
.au-head { display: flex; align-items: center; gap: var(--s-2); }
.au-head h2 { margin: 0; }
.au-meta { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); margin: var(--s-2) 0; }
dl.au-preview { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .9rem; margin: 0 0 .5rem; }
dl.au-preview dt { font-weight: 600; color: var(--muted); }
dl.au-preview dd { margin: 0; overflow-wrap: anywhere; }
pre.au-text { max-height: 12rem; overflow-y: auto; font-family: inherit; font-size: .875rem; border-left: 3px solid var(--line); }
form.au-decide textarea { max-width: 640px; }
.au-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.au-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-2) var(--s-4); }
.au-desc { flex: 1 1 22rem; }
.au-desc p { margin: .2rem 0; }
form label.au-mode { flex: 0 1 18rem; margin: 0; }
.au-auto details { margin-top: var(--s-2); }
ul.au-sent { margin: .4rem 0 0; padding-left: 1.1rem; }
ul.au-sent li { margin: .15rem 0; overflow-wrap: anywhere; }
.au-none { margin: .4rem 0 0; }
.au-result h3 { font-size: 1rem; margin: .75rem 0 .25rem; }

/* ---- Clients, billing board ---- */
.bill-board-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s-3); }
.bill-board-item { display: flex; flex-direction: column; gap: .15rem; padding: var(--s-3) var(--s-4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.bill-board-item strong { font-size: 1.25rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.bill-board-item span { font-size: .8125rem; overflow-wrap: anywhere; }
.bill-board-alert { border-color: var(--danger-line); background: #fffafa; }
.bill-board-alert strong { color: var(--danger); }
.bill-profit { margin: .25rem 0 .5rem; }
.bill-profit strong { margin-right: .75rem; }
.bill-contact .pre { margin: .5rem 0; }

/* ---- Tablet and phone: sidebar becomes a top bar with a Menu button ---- */
@media (max-width: 900px) {
  .app { display: block; }
  .mobilebar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; height: 52px; padding: 0 var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line); }
  .mobilebar .side-brand { padding: 0; }
  .nav-btn { display: inline-flex; align-items: center; min-height: 36px; padding: 0 .85rem; border: 1px solid var(--field-line); border-radius: var(--radius-s); background: var(--surface); color: var(--ink); font-weight: 500; cursor: pointer; }
  .nav-toggle:focus-visible ~ .app .nav-btn { outline: 2px solid var(--accent); outline-offset: 1px; }
  .sidebar { display: none; }
  .sidebar .side-brand { display: none; }
  .nav-toggle:checked ~ .app .sidebar { display: flex; position: fixed; top: 52px; left: 0; right: 0; bottom: 0; z-index: 40; height: auto; border-right: 0; padding: var(--s-3) var(--gutter) var(--s-5); }
  .nav-toggle:checked ~ .app .nav-btn { background: var(--accent-soft); border-color: #cddbf6; color: var(--accent-dark); }
  body:has(.nav-toggle:checked) { overflow: hidden; }
  main { padding: var(--s-4) var(--gutter) var(--s-5); }
}
@media (max-width: 640px) {
  :root { --control-h: 44px; }
  body { font-size: 15px; }
  input, select, textarea, form input, form select, form textarea { font-size: 16px; }
  .side-link, .side-foot button.link { min-height: 44px; }
  .page-actions, .page-actions a.button { width: 100%; }
  .card { padding: var(--s-3) var(--s-4); }
  /* Tables become one compact card per row: two columns of label over value; the first cell is the title. */
  .scroll { border: 0; border-radius: 0; background: none; box-shadow: none; }
  table, thead, tbody { display: block; }
  thead { display: none; }
  tbody tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: var(--s-3); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: var(--s-2); padding: var(--s-2) var(--s-3); background: var(--surface); box-shadow: var(--shadow); }
  tbody tr:hover td { background: none; }
  th, td { display: block; }
  tbody tr:last-child td { border-bottom: 0; }
  td { border: 0; padding: var(--s-1) 0; min-width: 0; }
  td:first-child, td.col-wide { grid-column: 1 / -1; }
  td::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); }
  td:first-child::before { display: none; }
  td, td.nw { white-space: normal; }
  td.num { text-align: left; }
  td button, td a.button { min-height: 36px; }
  .card .scroll thead th:first-child, .card .scroll td:first-child { padding-left: 0; }
  .trunc, table.list td.col-domain .trunc, table.list td.col-plan .trunc { max-width: 100%; }
  table.list td.col-name { max-width: none; }
  /* "?" help opens as a bar at the bottom of the screen so it never runs off the edge. */
  .q::after { position: fixed; top: auto; bottom: var(--s-4); left: var(--gutter); right: var(--gutter); width: auto; max-width: none; }
  th:last-child .q::after, th.num .q::after, .num .q::after { left: var(--gutter); right: var(--gutter); }
  .bill-totals { max-width: none; }
  table.bill-lines .in-qty, table.bill-lines .in-price, table.bill-lines .in-item, table.bill-lines .in-desc, table.bill-lines .in-cost { width: 100%; min-width: 0; }
  :is(form.bill-filter, form.inline:has(> label)) :is(select, input), :is(form.bill-filter, form.inline:has(> label)) input[type=search] { min-width: 0; }
  :is(form.bill-filter, form.rep-period, form.inline:has(> label)) label { flex: 1 1 100%; }
  form.rep-period select, form.rep-period input { min-width: 0; width: 100%; }
  .rep-figs { grid-template-columns: 1fr; }
  dl.au-preview { grid-template-columns: 1fr; }
  form label.au-mode { flex-basis: 100%; }
  dl.facts { grid-template-columns: 1fr 1fr; }
  form fieldset:has(> label.check) { grid-template-columns: 1fr; }
  .tabs { gap: 0 var(--s-4); }
  .tabs a { white-space: nowrap; min-height: 44px; }
  .pager a { min-height: 44px; }
  .pager { justify-content: space-between; }
  .pager .muted { order: -1; flex: 1 1 100%; }
}
