/* Screen styles for the app. The printed invoice itself is in invoice.css. */

:root {
  --ink: #1c2733;
  --muted: #64707d;
  --line: #d9dfe6;
  --bg: #f3f5f8;
  --card: #ffffff;
  --brand: #0b4fa3;
  --brand-dark: #083b7a;
  --bar: #101a26;
  --danger: #b3261e;
  --ok: #1a7f4b;
}

* { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; font-weight: 600; }
h2 { font-size: 1rem; margin: 0 0 4px; font-weight: 600; }

.app-bar { display: flex; align-items: center; gap: 32px; background: var(--bar); padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; font-size: 1.1rem; letter-spacing: .04em; }
.brand:hover { text-decoration: none; }
.brand img { height: 38px; }
.app-bar nav { display: flex; gap: 4px; }
.app-bar nav a { color: #b9c4d0; padding: 8px 14px; border-radius: 6px; }
.app-bar nav a:hover { color: #fff; text-decoration: none; }
.app-bar nav a.active { color: #fff; background: rgba(255, 255, 255, .12); }

main { max-width: 1320px; margin: 0 auto; padding: 20px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.grow { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.table-wrap { padding: 0; overflow-x: auto; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.c { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 28px; }
.hint { color: var(--muted); font-size: .9rem; margin: 6px 0 0; }

.btn { display: inline-flex; align-items: center; height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f4f8; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); }
.btn.small { height: 28px; margin-top: 10px; }
.btn:disabled, .link:disabled { opacity: .45; cursor: not-allowed; }
.link { border: 0; background: none; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }
.link.danger { color: var(--danger); }

input, select, textarea { font: inherit; color: inherit; width: 100%; height: 34px; padding: 0 9px; border: 1px solid #c5cdd6; border-radius: 6px; background: #fff; }
textarea { height: auto; padding: 8px 9px; line-height: 1.45; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11, 79, 163, .35); border-color: var(--brand); }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }
input[type="search"] { width: 300px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--muted); }
label > input, label > select, label > textarea { font-size: 1rem; color: var(--ink); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
label.inline select { width: auto; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 1rem; }

.fields { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; }
.fields.two { grid-template-columns: repeat(2, 1fr); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span4 { grid-column: 1 / -1; }
.cust-info { align-self: end; font-size: .93rem; line-height: 1.5; padding: 4px 0; }
.num-preview { font-size: 1.05rem; color: var(--brand); font-weight: 600; padding: 3px 10px; background: #e7eef8; border-radius: 6px; }
.num-preview:empty { display: none; }

.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: .82rem; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid th.r { text-align: right; }
.grid th.c { text-align: center; }
.grid td { padding: 9px 12px; border-bottom: 1px solid #edf0f4; vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: #f8fafc; }
.grid td.r { font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid tr.cancelled td { color: var(--muted); text-decoration: line-through; }
.grid tr.cancelled td:last-child, .grid tr.cancelled td:nth-last-child(2) { text-decoration: none; }
.actions a { margin-left: 12px; }
.actions a:first-child { margin-left: 0; }

.grid.lines td { padding: 4px 4px; vertical-align: middle; }
.grid.lines th { padding: 6px 6px; }
.grid.lines tbody tr:hover { background: none; }
.grid.lines input.r { text-align: right; }
.grid.lines .narrow { min-width: 70px; }
.grid.lines input.r:not(.narrow) { min-width: 110px; }
.grid.lines td[data-net] { font-variant-numeric: tabular-nums; font-weight: 600; padding-right: 10px; min-width: 110px; }
.hsn-select { max-width: 190px; }
.grid.lines td:nth-child(2) { width: 30%; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .8rem; background: #e9edf2; color: #45525f; }
.badge.paid { background: #dff3e7; color: var(--ok); }
.badge.placed { background: #e3ecfa; color: var(--brand); }
.badge.cancelled { background: #fbe4e2; color: var(--danger); }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile span { color: var(--muted); font-size: .88rem; }
.tile b { font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.split { display: grid; grid-template-columns: 1fr 420px; gap: 16px; align-items: start; }
.totals .trow { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .trow b { font-weight: 500; }
.totals .trow.grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 1.25rem; }
.totals .trow.grand b { font-weight: 700; }
.totals .trow.muted { color: var(--muted); }
.in-words { color: var(--muted); font-size: .9rem; margin-bottom: 8px; }

dialog { border: 0; border-radius: 10px; padding: 22px; width: min(680px, 92vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(16, 26, 38, .5); }
dialog h2 { font-size: 1.2rem; margin-bottom: 14px; }
.dlg-actions { display: flex; gap: 10px; margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: #1c2733; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 80vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

@media (max-width: 980px) {
  .fields, .tiles { grid-template-columns: repeat(2, 1fr); }
  .span3 { grid-column: 1 / -1; }
  .split { grid-template-columns: 1fr; }
  input[type="search"] { width: 100%; }
}

/* work orders */
.over { color: var(--danger); }
.bar { width: 110px; height: 6px; border-radius: 3px; background: #e3e8ee; overflow: hidden; margin: 5px 0 3px; }
.bar i { display: block; height: 100%; background: var(--brand); }
.wo-box { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 8px; }
.wo-box div.over { font-size: .9rem; }
.totals .trow.over b { color: var(--danger); font-weight: 700; }
.wo-head { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; }
.wo-head div { display: flex; flex-direction: column; gap: 2px; }
.wo-head div.wide { grid-column: 1 / -1; }
.wo-head span { color: var(--muted); font-size: .88rem; }
.wo-head b { font-weight: 600; }
input[type="file"] { height: auto; padding: 6px 9px; }

/* link existing invoices dialog */
dialog.wide { width: min(900px, 94vw); }
.link-list { max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.link-list thead th { position: sticky; top: 0; background: #fff; }
label.pick { display: inline; font-size: 1rem; color: var(--ink); cursor: pointer; }
.link-sum { margin-top: 10px; }

/* payment milestones and reminders */
h3 { font-size: 1rem; font-weight: 600; margin: 18px 0 6px; }
.badge.due { background: #fdf0d5; color: #8a5a00; }
.nav-badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #d9822b; color: #fff; font-size: .78rem; line-height: 18px; text-align: center; }
.reminders { border-left: 4px solid #d9822b; }
.reminders h2 { margin-bottom: 8px; }
.rem-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; border-top: 1px solid #edf0f4; }
.rem-row .btn.small { margin-top: 0; }
.rem-row .badge { min-width: 120px; text-align: center; }
dialog.wide { max-height: 92vh; overflow: auto; }

/* payments */
.badge.part-paid { background: #fdf0d5; color: #8a5a00; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }

/* row actions: icon buttons, and the action column stays in view when a table scrolls sideways */
.grid th:last-child, .grid td.actions { position: sticky; right: 0; background: #fff; }
.grid td.actions { box-shadow: -8px 0 8px -8px rgba(16, 26, 38, .18); }
.grid tbody tr:hover td.actions { background: #f8fafc; }
.grid.lines th:last-child { position: static; }
.actions.icons { padding-top: 5px; padding-bottom: 5px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; color: var(--brand); vertical-align: middle; }
.actions .icon-btn { margin-left: 2px; }
.icon-btn:hover { background: #e3ecfa; text-decoration: none; }
.icon-btn.pay { color: var(--ok); }
.icon-btn.pay:hover { background: #dff3e7; }
.icon-btn.blank { visibility: hidden; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* clicks on an icon must land on its link, which carries the data attributes */
.icon-btn svg { pointer-events: none; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: #fbe4e2; }
.icon-btn.small { width: 22px; height: 22px; }
.icon-btn.small svg { width: 13px; height: 13px; }

/* invoices table: taxable, GST, total, TDS and net receivable stacked in one cell */
.grid td.amounts { line-height: 1.55; }
.amt-total { font-weight: 700; }
.amt-tds { color: #d01c1c; }
.amt-net { color: #1b6b2a; font-weight: 700; }
.legend { margin: -6px 0 10px; }

/* invoices table: prefixed amount lines, and number / date / customer stacked */
.grid td.amounts div { display: flex; justify-content: space-between; gap: 14px; min-width: 150px; }
.grid td.amounts div span { font-weight: 400; font-size: .82rem; color: var(--muted); }
.grid td.amounts .amt-tds span, .grid td.amounts .amt-net span { color: inherit; }
.grid td.inv-id { line-height: 1.55; }

/* document number as the headline of a stacked cell */
.doc-no { display: block; font-size: 1.15rem; font-weight: 700; color: #000; white-space: nowrap; }
.doc-no:hover { color: var(--brand); }

/* bigger action icons */
.icon-btn { width: 36px; height: 36px; }
.icon-btn svg { width: 23px; height: 23px; stroke-width: 1.9; }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn.small svg { width: 16px; height: 16px; }

/* received-on dates under the received amount; customers table stacking */
.grid td.received { line-height: 1.55; white-space: nowrap; }
.doc-no.wrap { white-space: normal; }
.grid td.amounts:not(.r) div { min-width: 240px; }

/* bigger column headers */
.grid th { font-size: .98rem; color: #3b4753; padding-top: 12px; padding-bottom: 12px; }
.grid.lines th { font-size: .9rem; padding-top: 6px; padding-bottom: 6px; }
span.doc-no:hover { color: #000; }

/* keep each prefix next to its figure when the amount column is wide */
.grid td.amounts.r div { max-width: 190px; margin-left: auto; }

/* invoices table colours */
.inv-date { color: #6b2fa0; font-weight: 600; }
.inv-cust { color: var(--brand); font-weight: 600; }

/* invoice form: stacked line items */
.grid.lines td.line-item { width: 46%; vertical-align: top; }
.grid.lines td.line-nums { vertical-align: top; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; border-bottom: 0; }
.grid.lines tr { border-bottom: 1px solid #edf0f4; }
.grid.lines td.line-item, .grid.lines td.line-nums { padding-top: 8px; padding-bottom: 8px; }
.line-name { font-weight: 600; }
.line-sub { display: flex; gap: 12px; margin-top: 6px; }
label.pre { flex-direction: row; align-items: center; gap: 8px; }
label.pre > span { flex: 0 0 44px; font-size: .82rem; color: var(--muted); }
label.pre.grow { flex: 1; min-width: 0; }
.line-sub label.pre:not(.grow) { width: 190px; }
.grid.lines td.line-net { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; vertical-align: top; padding-top: 14px; white-space: nowrap; }
button.icon-btn { border: 0; background: none; padding: 0; cursor: pointer; }

/* ---- grey theme (the printed invoice keeps its own colours) ---- */
:root { --bar: #3c4045; --brand: #4d545c; --brand-dark: #353a40; --bg: #ededee; --line: #d6d8db; --link: #0b4fa3; }
a, .link, .inv-cust { color: var(--link); }
.link.danger { color: var(--danger); }
input:focus, select:focus, textarea:focus { outline-color: rgba(77, 84, 92, .35); }
.num-preview { background: #e4e6e8; }
.badge.placed { background: #e4e6e8; color: #3f464d; }
.grid th { color: #3f4449; }

/* ---- colour-coded action icons: each action has its own colour, on a soft tile ---- */
.icon-btn.ic-payment { color: #1a7f4b; background: #e3f4ea; }
.icon-btn.ic-print   { color: #6b2fa0; background: #f0e8f8; }
.icon-btn.ic-edit    { color: #0b63c5; background: #e4eefb; }
.icon-btn.ic-copy    { color: #a85d0a; background: #fbf0df; }
.icon-btn.ic-list    { color: #0e7c86; background: #dff3f4; }
.icon-btn.ic-add     { color: #1a7f4b; background: #e3f4ea; }
.icon-btn.ic-link    { color: #4338ca; background: #e9e8fb; }
.icon-btn.ic-unlink, .icon-btn.ic-remove, button.icon-btn.danger { color: #b3261e; background: #fbe4e2; }
.icon-btn[class*="ic-"]:hover, button.icon-btn.danger:hover { filter: brightness(.93); }
.actions .icon-btn { margin-left: 5px; }
.icon-btn.blank { background: none; }

/* invoices table: short rows that open into the full row on click */
tr.sum-row, tr.detail-row { cursor: pointer; }
tr.sum-row td { vertical-align: middle; }
tr.detail-row td { background: #f6f7f8; }
tr.detail-row td.actions, .grid tbody tr.detail-row:hover td.actions { background: #f6f7f8; }
.chev { display: inline-block; width: 18px; color: var(--muted); font-size: .9rem; }
.doc-no.inline { display: inline; }
tr.sum-row td.inv-cust { font-weight: 600; }

/* drawn chevrons for collapsed / opened rows (font glyphs render too small) */
.chev { width: 0; height: 0; margin-right: 10px; border-style: solid; font-size: 0; vertical-align: middle; }
.sum-row .chev { border-width: 6px 0 6px 8px; border-color: transparent transparent transparent #6b7178; }
.detail-row .chev { border-width: 8px 6px 0 6px; border-color: #6b7178 transparent transparent transparent; }

.bar.wide { width: 100%; max-width: 220px; }

/* invoice form: payments recorded for the invoice */
.pay-card h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pay-figures { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 8px; }
.pay-figures div { display: flex; flex-direction: column; gap: 2px; }
.pay-figures span { color: var(--muted); font-size: .88rem; }
.pay-figures b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }

/* invoice form: TDS % and amount for this invoice, side by side in one grid slot */
.tds-edit { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.totals .trow.grand2 { font-weight: 600; color: #1b6b2a; }
.totals .trow.grand2 b { font-weight: 700; }

/* opened rows: line up the stacked lines under the number, past the arrow */
tr.detail-row td.inv-id > div { padding-left: 22px; }

/* the received block sits at the foot of the row, level with the receivable line */
.grid td.received { vertical-align: bottom; padding-bottom: 12px; }

/* opened rows: description, balance, status and action icons sit at mid height;
   the stacked number and amount blocks stay at the top, the received block at the foot */
tr.detail-row td { vertical-align: middle; }
tr.detail-row td.inv-id, tr.detail-row td.amounts { vertical-align: top; }
tr.detail-row td.received { vertical-align: bottom; }

/* ---------- top bar without a menu: logo and a Home button ---------- */
.app-bar { gap: 16px; }
.home-btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 8px; color: #fff; background: rgba(255, 255, 255, .14); font-weight: 600; }
.home-btn:hover { background: rgba(255, 255, 255, .24); text-decoration: none; }
.home-btn svg, .btn.big svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.btn.big { height: 44px; padding: 0 20px; font-size: 1.05rem; font-weight: 600; gap: 8px; }

/* ---------- home dashboard ---------- */
.home-hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 6px 0 20px; }
.home-hero h1 { font-size: 1.9rem; }
.home-hero p { margin: 4px 0 0; color: var(--muted); }
.home-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.tile-nav { --tone: #4d545c; --tint: #e9eaec; position: relative; display: flex; flex-direction: column; gap: 6px; min-height: 168px; padding: 16px 18px;
  background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--tone); border-radius: 12px; color: var(--ink);
  transition: transform .12s ease, box-shadow .12s ease; }
.tile-nav:hover { text-decoration: none; transform: translateY(-3px); box-shadow: 0 10px 24px rgba(16, 26, 38, .14); }
.tile-nav.wide { grid-column: span 2; }
.tn-head { display: flex; align-items: center; gap: 10px; }
.tn-icon { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 10px; background: var(--tint); color: var(--tone); }
.tn-icon svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tn-title { font-size: 1.1rem; font-weight: 600; flex: 1; }
.tn-marker { padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e4e6e8; color: #3f464d; white-space: nowrap; }
.tn-marker.warn { background: #fdf0d5; color: #8a5a00; }
.tn-marker.alert { background: #fbe4e2; color: #b3261e; }
.tn-marker.ok { background: #dff3e7; color: #1a7f4b; }
.tn-figure { margin-top: auto; font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.tn-figure small { font-size: 1rem; font-weight: 500; color: var(--muted); }
.tn-figure.small { font-size: 1.15rem; }
.tn-sub { color: var(--muted); font-size: .9rem; }
.tn-bar { height: 7px; border-radius: 4px; background: #e3e6ea; overflow: hidden; }
.tn-bar i { display: block; height: 100%; background: var(--tone); }
.t-invoices   { --tone: #0b63c5; --tint: #e4eefb; }
.t-workorders { --tone: #0e7c86; --tint: #dff3f4; }
.t-payments   { --tone: #1a7f4b; --tint: #e3f4ea; }
.t-customers  { --tone: #6b2fa0; --tint: #f0e8f8; }
.t-download   { --tone: #a85d0a; --tint: #fbf0df; }
.t-settings   { --tone: #4d545c; --tint: #e9eaec; }

.home-chart .hc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.hc-bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px; height: 170px; }
.hc-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.hc-col i { display: block; width: 100%; max-width: 46px; border-radius: 5px 5px 0 0; background: #9aa3ad; }
.hc-col.now i { background: #0b63c5; }
.hc-col.now .hc-month { color: #0b63c5; font-weight: 700; }
.hc-col.future .hc-month { opacity: .5; }
.hc-val { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.hc-month { font-size: .82rem; color: var(--muted); }

/* ---------- download invoices ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 9px 20px; font: inherit; cursor: pointer; color: var(--ink); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }
.dl-run { display: flex; align-items: center; gap: 16px; }

@media (max-width: 980px) {
  .home-grid { grid-template-columns: repeat(2, 1fr); }
  .home-hero { flex-direction: column; align-items: flex-start; }
}

/* hidden means hidden, even for elements whose class sets a display */
[hidden] { display: none !important; }

/* ---------- livelier colours on the grey theme (screen only; the printed invoice is untouched) ---------- */
:root { --brand: #2f62e0; --brand-dark: #2450c4; --accent2: #6a4fe0; --line: #d5d9e2;
  --rainbow: linear-gradient(90deg, #2f6fed, #0a9aa5 28%, #19a05c 52%, #e08a12 76%, #8a47d6); }
@media screen {
  body { background: linear-gradient(135deg, #eaeff8 0%, #f0edf7 55%, #eef4f1 100%) fixed; }
}
.app-bar { background: linear-gradient(90deg, #33373d, #454a52); }
.app-bar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: var(--rainbow); }
.home-btn { background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .22); }

/* buttons */
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--accent2)); border-color: transparent; box-shadow: 0 2px 6px rgba(47, 98, 224, .3); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { background: #b8bfcc; box-shadow: none; filter: none; }
.btn:not(.primary):hover { border-color: var(--brand); color: var(--brand); }
input:focus, select:focus, textarea:focus { outline-color: rgba(47, 98, 224, .3); border-color: var(--brand); }
input[type="checkbox"] { accent-color: var(--brand); }
.seg button.on { background: linear-gradient(135deg, var(--brand), var(--accent2)); }
.seg button:not(.on):hover { background: #eef3ff; color: var(--brand); }

/* page titles and cards */
.page-head h1 { padding-left: 12px; border-left: 5px solid var(--brand); border-image: linear-gradient(180deg, #2f6fed, #8a47d6) 1; }
.card { box-shadow: 0 1px 3px rgba(40, 50, 80, .06); }

/* figure tiles at the top of a screen: one colour each */
.tile { --tone: #2f6fed; --tint: #e6eeff; border-left: 4px solid var(--tone); background: linear-gradient(120deg, var(--tint), #fff 70%); box-shadow: 0 1px 3px rgba(40, 50, 80, .06); }
.tile b { color: var(--tone); filter: brightness(.82); }
.tiles .tile:nth-child(4n+2) { --tone: #0a9aa5; --tint: #def5f6; }
.tiles .tile:nth-child(4n+3) { --tone: #8a47d6; --tint: #f1e8fc; }
.tiles .tile:nth-child(4n+4) { --tone: #e08a12; --tint: #fdf1dc; }

/* tables */
.grid th, .grid th:last-child, .link-list thead th { background: #e9eefb; color: #2b3a5c; border-bottom: 2px solid #c3d0f0; }
.grid tbody tr:hover td, .grid tbody tr:hover td.actions { background: #f3f7ff; }
tr.detail-row td, tr.detail-row td.actions, .grid tbody tr.detail-row:hover td, .grid tbody tr.detail-row:hover td.actions { background: #f5f8ff; }
.sum-row .chev { border-left-color: var(--brand); }
.detail-row .chev { border-top-color: var(--accent2); }
.bar i, .tn-bar i { background: linear-gradient(90deg, #0a9aa5, #19a05c); }

/* status markers */
.badge { background: #e1ebff; color: #1f4fc4; font-weight: 600; }
.badge.paid { background: #cdf0db; color: #0f7a43; }
.badge.part-paid, .badge.due { background: #ffe8b8; color: #8a5200; }
.badge.cancelled { background: #fddcd9; color: #b3261e; }
.badge.placed { background: #e6e0fb; color: #5a34b8; }
.tn-marker { background: #e1ebff; color: #1f4fc4; }
.tn-marker.warn { background: #ffe8b8; color: #8a5200; }
.tn-marker.ok { background: #cdf0db; color: #0f7a43; }

/* home tiles */
.t-invoices   { --tone: #2f6fed; --tint: #e3ecff; }
.t-workorders { --tone: #0a9aa5; --tint: #dbf4f5; }
.t-payments   { --tone: #19a05c; --tint: #ddf5e7; }
.t-customers  { --tone: #8a47d6; --tint: #f0e6fc; }
.t-download   { --tone: #e08a12; --tint: #fdf0d9; }
.t-settings   { --tone: #5b6675; --tint: #e8ebf0; }
.tile-nav { background: linear-gradient(155deg, var(--tint) 0%, #fff 62%); box-shadow: 0 2px 6px rgba(40, 50, 80, .07); }
.tile-nav:hover { border-color: var(--tone); box-shadow: 0 12px 26px rgba(40, 50, 80, .16); }
.tn-icon { background: var(--tone); color: #fff; box-shadow: 0 3px 8px rgba(40, 50, 80, .18); }
.tn-title { color: var(--tone); filter: brightness(.8); }
.home-hero h1 { background: linear-gradient(90deg, #2f6fed, #8a47d6); -webkit-background-clip: text; background-clip: text; color: transparent; display: inline-block; }
.hc-col i { background: linear-gradient(180deg, #9db8f2, #c3d3f6); }
.hc-col.now i { background: linear-gradient(180deg, #2f6fed, #6a4fe0); }
.hc-col.now .hc-month { color: var(--brand); }

/* dialogs */
dialog { border-top: 5px solid var(--brand); border-image: var(--rainbow) 1; }

/* download invoices: status filter and a tick per invoice */
.dl-status { display: flex; align-items: flex-end; gap: 16px; margin-top: 12px; }
.dl-status label { width: 200px; }
.dl-status .hint { margin: 0 0 8px; }
.grid th.pick, .grid td.pick { width: 40px; text-align: center; padding-right: 0; }
.grid .pick input { width: 18px; height: 18px; cursor: pointer; vertical-align: middle; }
tr.skipped td:not(.pick) { opacity: .45; }

/* ---------- sign in, users and roles ---------- */
body.signed-out .home-btn { display: none; }
.who { display: inline-flex; align-items: center; gap: 8px; color: #fff; }
.who-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; margin-right: 4px; }
.bar-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .22);
  background: rgba(255, 255, 255, .1); color: #fff; font: inherit; cursor: pointer; }
.bar-btn:hover { background: rgba(255, 255, 255, .24); }
.bar-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.role-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; letter-spacing: .02em; }
.role-badge.r-admin { background: #e6e0fb; color: #5a34b8; }
.role-badge.r-accountant { background: #d6f1f3; color: #076f78; }
.role-badge.r-viewer { background: #e4e7ec; color: #46505c; }

.auth-wrap { display: flex; justify-content: center; padding: 6vh 16px; }
.auth-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; border-width: 5px 0 0; border-style: solid; border-image: var(--rainbow) 1;
  box-shadow: 0 14px 40px rgba(40, 50, 80, .14); }
.auth-card h1 { font-size: 1.4rem; }
.auth-card p { margin: -6px 0 2px; }
.auth-card .btn { justify-content: center; margin-top: 4px; }
.auth-logo { width: 150px; align-self: center; background: #3c4045; border-radius: 10px; padding: 8px 14px; }

.roles-help { display: grid; gap: 8px; }
.roles-help div { display: flex; align-items: baseline; gap: 12px; }
.roles-help .role-badge { flex: 0 0 96px; text-align: center; }
.t-users { --tone: #d6457a; --tint: #fde6ee; }

/* what a login may not do is not offered: Viewer sees no create buttons, only Admin sees change and delete */
body.role-viewer #view > :not(dialog):not(form) :is(a[href^="#/invoice/new"], .ic-payment, .ic-copy, .ic-add, #addWo, #addPay, #addCust),
body:not(.role-admin) #view > :not(dialog):not(form) :is(.ic-edit, .ic-link, .ic-unlink, .ic-remove, #editWo, #linkInv, #del, a.btn[href^="#/invoice/"]:not([href^="#/invoice/new"])) { display: none !important; }

/* a record opened view-only */
.view-note { margin: -8px 0 12px; padding: 7px 12px; border-radius: 6px; background: #fff4d6; color: #7a4d00; font-size: .92rem; }
dialog.locked :is(input, select, textarea) { pointer-events: none; background: #f2f3f6; }
dialog.locked :is(.btn.small, .icon-btn, button.link) { display: none; }

/* ---------- the sign-in stage: full screen, company on the left, form on the right.
   Light like the dashboard: grey and white, with a little colour. ---------- */
body.signed-out .app-bar { display: none; }
.si-stage { position: fixed; inset: 0; z-index: 20; overflow: auto; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(340px, 440px);
  grid-template-rows: 1fr auto; align-items: center; column-gap: clamp(32px, 6vw, 110px); padding: clamp(28px, 5vh, 64px) clamp(24px, 7vw, 120px) 18px;
  color: var(--ink); background: #eef0f4; }
.si-stage > * { position: relative; z-index: 1; }

/* a pale wash with a few soft patches of the dashboard's tile colours */
.si-art { position: fixed !important; inset: 0; z-index: 0 !important; overflow: hidden; pointer-events: none;
  background: linear-gradient(135deg, #eceff5 0%, #f3f2f7 55%, #eef3f1 100%); }
.si-art i { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .2; will-change: transform; animation: si-drift 24s ease-in-out infinite alternate; }
.si-art .b1 { width: 40vw; height: 40vw; left: -12vw; top: -18vw; background: #2f6fed; }
.si-art .b2 { width: 34vw; height: 34vw; right: -10vw; top: 4vh; background: #8a47d6; opacity: .16; animation-duration: 29s; animation-delay: -6s; }
.si-art .b3 { width: 30vw; height: 30vw; left: 24vw; bottom: -20vw; background: #0a9aa5; opacity: .18; animation-duration: 33s; animation-delay: -12s; }
.si-art .b4 { width: 20vw; height: 20vw; right: 20vw; bottom: -10vw; background: #e08a12; opacity: .14; animation-duration: 27s; animation-delay: -3s; }
.si-dots { position: absolute; inset: 0; background-image: radial-gradient(rgba(60, 70, 100, .16) 1px, transparent 1.4px); background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(65% 65% at 28% 42%, #000 0%, transparent 75%); mask-image: radial-gradient(65% 65% at 28% 42%, #000 0%, transparent 75%); }
@keyframes si-drift { from { transform: translate3d(0, 0, 0) scale(1); } to { transform: translate3d(5vw, 4vh, 0) scale(1.15); } }

/* left: the company. The logo stands on the page itself, large. */
.si-brand { max-width: 640px; animation: si-rise .7s ease both; }
.si-plate { display: block; margin: 0 0 clamp(18px, 3.5vh, 36px) -10px; }
.si-logo { width: clamp(300px, 34vw, 500px); display: block;
  /* no soft shadows: they smear the lettering. A hairline dark edge and firmer contrast keep it sharp on the pale page. */
  filter: contrast(1.4) brightness(.84) saturate(1.15) drop-shadow(0 0 .6px #1d2433) drop-shadow(0 0 .6px #1d2433);
  image-rendering: -webkit-optimize-contrast; }
.si-brand h1 { font-size: clamp(1.7rem, 3vw, 2.75rem); line-height: 1.15; font-weight: 700; letter-spacing: -.02em; color: #232a36; }
.si-brand h1 em { font-style: normal; background: linear-gradient(90deg, #2f6fed, #8a47d6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.si-lead { margin: 14px 0 0; font-size: 1.08rem; color: var(--muted); }
.si-points { list-style: none; margin: clamp(18px, 3.5vh, 34px) 0 0; padding: 0; display: grid; gap: 10px; }
.si-points li { display: flex; align-items: center; gap: 12px; color: #2f3744; }
.si-points span { flex: 0 0 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: #fff;
  box-shadow: 0 3px 8px rgba(40, 50, 80, .18); }
.si-stage svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.si-points li:nth-child(1) span { background: #2f6fed; } .si-points li:nth-child(2) span { background: #0a9aa5; } .si-points li:nth-child(3) span { background: #e08a12; }

/* a paper invoice drawn in outline, floating beside the text */
.si-mock { position: absolute; right: -96px; bottom: -92px; width: 190px; height: 230px; transform: rotate(7deg); animation: si-float 7s ease-in-out infinite; }
.si-sheet { position: absolute; inset: 0; padding: 16px 16px 14px; border-radius: 12px; background: #fff; border: 1px solid #e1e5ee;
  box-shadow: 0 24px 50px rgba(40, 50, 80, .18); }
.ms-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ms-head i { width: 46px; height: 12px; border-radius: 3px; background: linear-gradient(90deg, #2f6fed, #8a47d6); }
.ms-head b { font-size: .56rem; letter-spacing: .12em; color: #3b4662; }
.ms-lines i, .ms-table i { display: block; height: 6px; border-radius: 3px; background: #d9deea; margin-bottom: 7px; }
.ms-lines i:nth-child(1) { width: 70%; } .ms-lines i:nth-child(2) { width: 52%; } .ms-lines i:nth-child(3) { width: 61%; margin-bottom: 14px; }
.ms-table { border-top: 1px solid #dfe4ee; padding-top: 9px; }
.ms-table i { height: 9px; background: #eceff6; }
.ms-total { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid #dfe4ee; }
.ms-total span { font-size: .6rem; font-weight: 700; color: #3b4662; }
.ms-total b { width: 62px; height: 11px; border-radius: 3px; background: #4a5368; }
.ms-stamp { position: absolute; right: 14px; bottom: 44px; padding: 2px 9px; border: 2px solid #19a05c; border-radius: 6px; color: #19a05c; font-size: .7rem; font-weight: 800;
  letter-spacing: .14em; transform: rotate(-14deg); opacity: .9; }
.si-chip { position: absolute; display: inline-flex; align-items: center; gap: 8px; padding: 8px 13px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap;
  color: #2f3744; background: #fff; border: 1px solid #e1e5ee; box-shadow: 0 8px 22px rgba(40, 50, 80, .14); transform: rotate(-7deg); }
.si-chip b { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; font-size: .78rem; color: #fff; }
.si-chip.c1 { left: -96px; top: 30px; animation: si-float 6s ease-in-out -2s infinite; } .si-chip.c1 b { background: #19a05c; }
.si-chip.c2 { left: -128px; bottom: 34px; animation: si-float 8s ease-in-out -4s infinite; } .si-chip.c2 b { background: #e08a12; }
@keyframes si-float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -10px; } }

/* right: the form, a white card like the dashboard tiles */
.si-card { display: flex; flex-direction: column; gap: 14px; padding: clamp(24px, 3.4vw, 38px); border-radius: 18px; color: var(--ink); overflow: hidden;
  background: #fff; border: 1px solid #dfe3ec; box-shadow: 0 22px 54px rgba(40, 50, 80, .13); animation: si-rise .7s ease .08s both; }
.si-card::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--rainbow); }
.si-kicker { font-size: .8rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--brand); }
.si-card h2 { font-size: 1.6rem; font-weight: 700; margin: -6px 0 0; color: #232a36; }
.si-sub { margin: -6px 0 6px; color: var(--muted); line-height: 1.45; }

.si-field { position: relative; }
.si-field input { width: 100%; height: 56px; padding: 20px 44px 4px 46px; border-radius: 12px; font-size: 1.02rem; color: var(--ink); caret-color: var(--brand);
  background: #f5f7fb; border: 1px solid #d5d9e2; transition: border-color .15s, box-shadow .15s, background .15s; }
.si-field input:hover { border-color: #b6bfd0; }
.si-field input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 4px rgba(47, 98, 224, .16); }
.si-field label { position: absolute; left: 46px; top: 18px; font-size: 1rem; color: var(--muted); pointer-events: none; transition: all .15s ease; display: block; }
.si-field input:focus + label, .si-field input:not(:placeholder-shown) + label { top: 8px; font-size: .72rem; letter-spacing: .04em; color: var(--brand); }
.si-ic { position: absolute; left: 15px; top: 18px; color: #8a94a3; display: inline-flex; }
.si-field:focus-within .si-ic { color: var(--brand); }
.si-eye { position: absolute; right: 8px; top: 10px; width: 36px; height: 36px; border: 0; border-radius: 9px; background: none; color: #7c8695; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; }
.si-eye:hover { background: #e9edf5; color: var(--ink); }
/* keep the browser's autofill colour in step with the fields */
.si-field input:-webkit-autofill { -webkit-text-fill-color: var(--ink); -webkit-box-shadow: 0 0 0 100px #eef3ff inset; transition: background-color 9999s; }

.si-caps { margin: -6px 0 0; font-size: .85rem; color: #8a5200; }
.si-go { position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; gap: 10px; height: 54px; margin-top: 4px; border: 0; border-radius: 12px;
  font: inherit; font-size: 1.05rem; font-weight: 700; color: #fff; cursor: pointer; background: linear-gradient(135deg, var(--brand), var(--accent2));
  box-shadow: 0 8px 20px rgba(47, 98, 224, .28); transition: transform .12s ease, box-shadow .12s ease, filter .12s ease; }
.si-go::after { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%; transform: skewX(-20deg); background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .3), transparent);
  transition: left .6s ease; }
.si-go:hover { transform: translateY(-2px); box-shadow: 0 12px 26px rgba(47, 98, 224, .36); filter: brightness(1.06); }
.si-go:hover::after { left: 120%; }
.si-go:hover svg { translate: 4px 0; }
.si-go svg { transition: translate .15s ease; }
.si-go:active { transform: translateY(0); }
.si-go:disabled { opacity: .7; cursor: default; transform: none; }
.si-go.busy span::after { content: "..."; }
.si-note { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 2px 0 0; font-size: .84rem; color: var(--muted); }
.si-note svg { width: 15px; height: 15px; }
.si-err { margin: 0; padding: 10px 14px; border-radius: 10px; background: #fde8e6; border: 1px solid #f3b4ae; color: #a3231b; font-size: .93rem; }
.si-card.shake { animation: si-shake .4s ease; }
@keyframes si-shake { 20%, 60% { translate: -7px 0; } 40%, 80% { translate: 7px 0; } }
@keyframes si-rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

.si-foot { grid-column: 1 / -1; padding-top: 22px; text-align: center; font-size: .82rem; letter-spacing: .04em; color: #8a94a3; }

@media (max-width: 1280px), (max-height: 700px) { .si-mock { display: none; } }
@media (max-width: 860px) {
  .si-stage { grid-template-columns: minmax(0, 460px); justify-content: center; align-content: center; row-gap: 22px; }
  .si-brand { text-align: center; }
  .si-plate { margin: 0; }
  .si-logo { width: min(300px, 78vw); margin: 0 auto; }
  .si-brand h1, .si-lead, .si-points { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .si-art i, .si-mock, .si-chip, .si-brand, .si-card { animation: none; }
}

/* ---------- invoice template editor: form on the left, the empty invoice on the right ---------- */
.tpl-layout { display: grid; grid-template-columns: minmax(0, 1fr) 520px; gap: 16px; align-items: start; }
.tpl-form { border: 0; margin: 0; padding: 0; min-width: 0; }
.tpl-form:disabled :is(input, select, textarea) { background: #f2f3f6; color: #4a5260; }
.tpl-form:disabled :is(.btn, .link) { display: none; }
.tpl-preview { position: sticky; top: 72px; }
.tpl-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.seg.small button { padding: 5px 12px; font-size: .9rem; }
.tpl-sheet { border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; box-shadow: 0 6px 18px rgba(40, 50, 80, .1); max-height: calc(100vh - 130px); overflow-y: auto; }
.tpl-sheet #tplSheet { zoom: .652; }
.tpl-sheet .sheet { margin: 0; box-shadow: none; }
.tpl-images { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; align-items: start; }
.tpl-images > div { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.tpl-images span { font-size: .88rem; color: var(--muted); }
.tpl-thumb { width: 100%; height: 96px; border: 1px solid var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; background: #fff; padding: 6px; }
.tpl-thumb.dark { background: #f1f3f7; }
.tpl-thumb img { max-width: 100%; max-height: 100%; }
label.btn.small { flex-direction: row; color: var(--ink); cursor: pointer; }
@media (max-width: 1150px) { .tpl-layout { grid-template-columns: 1fr; } .tpl-preview { position: static; } .tpl-sheet { max-height: none; } }

/* template table: the i icon and the floating preview it shows */
.icon-btn.ic-info { color: #0e7c86; background: #dff3f4; }
.tpl-tip { position: fixed; z-index: 40; width: 372px; padding: 10px; border-radius: 12px; background: #fff; border: 1px solid var(--line);
  box-shadow: 0 18px 46px rgba(40, 50, 80, .28); pointer-events: none; }
.tpl-tip-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.tpl-tip-head span { font-size: .85rem; color: var(--muted); }
.tpl-tip-sheet { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tpl-tip-sheet .sheet { zoom: .44; margin: 0; box-shadow: none; }

/* a second, coloured action beside the main one (make a new template from this one) */
.btn.accent { gap: 7px; color: #fff; border-color: transparent; font-weight: 600; background: linear-gradient(135deg, #0a9aa5, #19a05c); box-shadow: 0 2px 6px rgba(10, 154, 165, .3); }
.btn.accent:hover, .btn.accent:not(.primary):hover { color: #fff; border-color: transparent; filter: brightness(1.08); }
.btn-ic { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
/* the Empty / With sample figures switch above the preview: a soft tint, not the strong button colour */
.tpl-preview .seg button.on { background: #e3ecff; color: var(--brand); font-weight: 600; }
.tpl-preview .seg { border-color: #cdd8f3; }

/* ---------- template list in Settings: one card per template, its period drawn as a line from start to end ---------- */
.tpl-list { display: grid; gap: 10px; }
.tpl-row { display: grid; grid-template-columns: auto minmax(300px, 1.1fr) minmax(0, 1.4fr) auto auto; align-items: center; gap: 22px; padding: 14px 16px;
  border: 1px solid var(--line); border-left: 5px solid #c3c9d6; border-radius: 12px; background: #fff; transition: box-shadow .15s ease, transform .15s ease; }
.tpl-row:hover { box-shadow: 0 8px 22px rgba(40, 50, 80, .1); transform: translateY(-1px); }
.tpl-row.current { border-left-color: #19a05c; background: linear-gradient(100deg, #eefaf3, #fff 45%); }
.tpl-row.later { border-left-color: #e08a12; background: linear-gradient(100deg, #fff7e9, #fff 45%); }
.tpl-id { display: inline-flex; align-items: center; justify-content: center; min-width: 74px; height: 44px; padding: 0 14px; border-radius: 10px; font-size: 1.15rem; font-weight: 800;
  letter-spacing: .03em; color: #fff; background: linear-gradient(135deg, var(--brand), var(--accent2)); box-shadow: 0 3px 8px rgba(47, 98, 224, .28); }
.tpl-id:hover { text-decoration: none; filter: brightness(1.08); }
.tpl-row.ended .tpl-id { background: linear-gradient(135deg, #7c8696, #5b6675); box-shadow: none; }
.tpl-period { display: flex; align-items: center; gap: 12px; }
.tp-date { display: flex; flex-direction: column; gap: 2px; white-space: nowrap; }
.tp-date small, .tpl-meta small { font-size: .76rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tp-date b { font-size: 1.02rem; font-variant-numeric: tabular-nums; }
.tp-date b.till { color: #0f7a43; }
.tp-line { position: relative; flex: 1; min-width: 40px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, #2f6fed, #19a05c); }
.tp-line::before, .tp-line::after { content: ""; position: absolute; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid #2f6fed; }
.tp-line::before { left: -2px; }
.tp-line::after { right: -2px; border-color: #19a05c; }
.tpl-row.ended .tp-line { background: #c3c9d6; }
.tpl-row.ended .tp-line::before, .tpl-row.ended .tp-line::after { border-color: #9aa3b2; }
.tpl-meta { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.tpl-meta small { text-transform: none; letter-spacing: 0; font-size: .86rem; }
.tpl-status { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.tpl-row .actions { display: flex; }
@media (max-width: 1100px) { .tpl-row { grid-template-columns: auto 1fr auto; } .tpl-meta, .tpl-status { grid-column: 2; } .tpl-row .actions { grid-row: 1; grid-column: 3; } }

/* ---------- template usage figures, the calendar and padlock icons, frozen invoices ---------- */
.tpl-usage { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.tpl-usage span { padding: 3px 10px; border-radius: 999px; font-size: .84rem; color: #46505c; background: #eef1f6; white-space: nowrap; }
.tpl-usage span:first-child { background: #e3ecff; color: #1f4fc4; }
.tpl-usage b { font-weight: 700; color: inherit; }
.icon-btn.ic-calendar { color: #b3261e; background: #fbe4e2; }
.icon-btn.ic-lock { color: #5a34b8; background: #e6e0fb; cursor: default; }
.badge.frozen { display: inline-flex; align-items: center; gap: 5px; background: #e6e0fb; color: #5a34b8; }
.badge.frozen .btn-ic { width: 13px; height: 13px; }
.btn.freeze { gap: 7px; color: #5a34b8; border-color: #cdbff5; background: #f3effd; font-weight: 600; }
.btn.freeze:hover, .btn.freeze:not(.primary):hover { color: #fff; background: #6a4fe0; border-color: #6a4fe0; }
#unfreeze { gap: 7px; }
body:not(.role-admin) #view #unfreeze, body.role-viewer #view #freeze { display: none !important; }

/* ---------- invoice form: choosing the template, each with a small picture of its empty page ---------- */
.tpl-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.tpl-opt { position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 10px 44px 10px 10px; border: 2px solid var(--line); border-radius: 12px;
  background: #fff; cursor: pointer; transition: border-color .12s ease, box-shadow .12s ease; }
.tpl-opt:hover { border-color: #9db8f2; box-shadow: 0 6px 16px rgba(40, 50, 80, .1); }
.tpl-opt.on { border-color: var(--brand); background: linear-gradient(120deg, #eef3ff, #fff 60%); box-shadow: 0 6px 16px rgba(47, 98, 224, .16); }
.tpl-mini { width: 96px; height: 135px; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: #fff; pointer-events: none; }
.tpl-mini .sheet { zoom: .12; margin: 0; box-shadow: none; }
.tpl-opt-text { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.tpl-opt-text small { color: var(--muted); font-size: .84rem; }
.tpl-id.sm { min-width: 0; height: 30px; padding: 0 12px; font-size: .98rem; border-radius: 8px; }
.tpl-tick { position: absolute; right: 12px; top: 12px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #c3c9d6; background: #fff; }
.tpl-opt.on .tpl-tick { border-color: var(--brand); background: var(--brand); box-shadow: inset 0 0 0 3px #fff; }

/* ---------- cloud version: backup / import box, activity log ---------- */
.import-box { margin-top: 16px; padding: 14px; border: 1px dashed #b6c3e4; border-radius: 10px; background: #f6f9ff; }
.import-box .hint { margin: 4px 0 10px; }
.import-box label.btn { flex-direction: row; color: #fff; cursor: pointer; display: inline-flex; }
tr.audit-bad td { color: var(--danger); }

/* ================= phones ================= */
@media (max-width: 760px) {
  html { font-size: 15px; }
  main { padding: 12px 10px 76px; }
  /* 16px inputs stop the phone's browser zooming in on every field */
  input, select, textarea { font-size: 16px !important; height: 42px; }
  textarea { height: auto; }
  input[type="checkbox"] { width: 20px; height: 20px; }
  .btn { height: 42px; }
  .btn.small { height: 36px; }
  .icon-btn { width: 40px; height: 40px; }

  /* top bar: logo, Home, who, sign out, all as compact buttons */
  .app-bar { padding: 0 10px; gap: 8px; height: 52px; }
  .brand span { display: none; }
  .brand img { height: 30px; }
  .home-btn, #outBtn { font-size: 0; gap: 0; padding: 0 11px; height: 38px; }
  .bar-btn { height: 38px; }
  .who { gap: 6px; min-width: 0; }
  .who-name { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; display: block; margin: 0; }
  .who-name .role-badge { display: none; }

  /* page heading: title on its own line, the controls share the next ones */
  .page-head { gap: 8px; }
  .page-head h1 { flex: 1 1 100%; font-size: 1.3rem; }
  .page-head .grow { display: none; }
  .page-head > label.inline { flex: 1 1 46%; flex-direction: column; align-items: stretch; gap: 2px; font-size: .8rem; }
  .page-head > label.inline select { width: 100%; }
  .page-head > label.inline.check { flex-direction: row; align-items: center; font-size: 1rem; }
  .page-head > .btn, .page-head > a.btn { flex: 1 1 auto; justify-content: center; }
  .page-head input[type="search"] { flex: 1 1 100%; width: 100%; }

  /* forms in one column */
  .fields, .fields.two { grid-template-columns: 1fr; gap: 10px; }
  .fields > *, .fields .span2, .fields .span3, .fields .span4 { grid-column: 1 / -1; }
  .tds-edit { grid-template-columns: 1fr 1fr; }
  .card { padding: 12px; border-radius: 10px; }
  .card.table-wrap { padding: 0; }
  .split { grid-template-columns: 1fr; }
  .tiles, .tiles.three, .pay-figures { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile b { font-size: 1.05rem; }

  /* tables people type into keep their columns and scroll sideways inside their card */
  .card:has(> table.lines), .card:has(> .table-wrap) { overflow-x: auto; }
  table.grid.lines { min-width: 640px; }

  /* lists become cards: one row = one card, each value under its column heading */
  table.grid.stack, table.grid.stack tbody { display: block; width: 100%; }
  table.grid.stack thead { display: none; }
  table.grid.stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 12px; border-bottom: 1px solid var(--line); }
  table.grid.stack tr:last-child { border-bottom: 0; }
  table.grid.stack td { display: block; padding: 0 !important; border: 0; min-width: 0; text-align: left !important; white-space: normal; position: static !important; background: none !important; vertical-align: top; }
  table.grid.stack td:first-child, table.grid.stack td.actions, table.grid.stack td[colspan], table.grid.stack td.wide { grid-column: 1 / -1; }
  table.grid.stack td:empty { display: none; }
  table.grid.stack td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 1px; font-size: .7rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
  table.grid.stack td:first-child::before, table.grid.stack td.actions::before { display: none; }
  table.grid.stack td.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
  table.grid.stack td.actions .icon-btn { margin: 0; }
  table.grid.stack td.actions .icon-btn.blank { display: none; }
  table.grid.stack tr.detail-row { background: #f5f8ff; }
  table.grid.stack tr.detail-row td.inv-id > div { padding-left: 0; }
  .bar.wide { max-width: none; }

  /* home */
  .home-hero { margin: 2px 0 14px; }
  .home-hero h1 { font-size: 1.5rem; }
  .home-hero .btn.big { width: 100%; justify-content: center; }
  .home-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile-nav { min-height: 124px; padding: 12px; }
  .tile-nav.wide { grid-column: 1 / -1; }
  .tn-icon { width: 36px; height: 36px; }
  .tn-title { font-size: 1rem; }
  .tn-figure { font-size: 1.35rem; }
  .tn-marker { font-size: .72rem; padding: 2px 8px; }
  .tile-nav:not(.wide) .tn-head { flex-wrap: wrap; }
  .hc-bars { gap: 3px; height: 130px; }
  .hc-val { font-size: .58rem; }
  .hc-month { font-size: .66rem; }
  .home-chart .hc-head { flex-direction: column; gap: 2px; }
  .rem-row { flex-wrap: wrap; }

  /* dialogs come up from the bottom and use the full width */
  dialog, dialog.wide { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; padding: 16px 14px 18px; border-radius: 18px 18px 0 0; overflow: auto; }
  .dlg-actions { flex-wrap: wrap; }
  .dlg-actions .btn { flex: 1 1 auto; justify-content: center; }
  .dlg-actions .grow { display: none; }
  dialog .table-wrap, dialog .link-list { overflow-x: auto; }

  /* download, templates, users */
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1; padding: 10px 6px; }
  .dl-status, .dl-run { flex-direction: column; align-items: stretch; gap: 10px; }
  .dl-status label { width: auto; }
  .tpl-row { grid-template-columns: auto 1fr; gap: 10px 12px; padding: 12px; }
  .tpl-period, .tpl-meta, .tpl-status { grid-column: 1 / -1; }
  .tpl-status { flex-direction: row; }
  .tpl-row .actions { grid-row: 1; grid-column: 2; justify-content: flex-end; gap: 6px; }
  .tpl-pick { grid-template-columns: 1fr; }
  .tpl-images { grid-template-columns: 1fr 1fr; }
  .tpl-preview-head { flex-wrap: wrap; }
  .tpl-sheet #tplSheet { zoom: .44; }
  .roles-help div { flex-direction: column; gap: 4px; }
  .roles-help .role-badge { flex: none; align-self: flex-start; }

  .sheet-host { padding-bottom: 0; overflow-x: hidden; }
  .toast { bottom: 16px; max-width: 94vw; text-align: center; }
}
@media (max-width: 400px) {
  .home-grid { grid-template-columns: 1fr; }
}
