/* Tally's look for tally.hexwork.co.uk (layout_tally.php) and the customer's page (layout_tallydoc.php).
   Hexwork's family (near-black #09070A, Syne headings, Geist text) with Tally's pink-red (#F0245E), green for paid and
   amber for overdue. Money is set in tabular figures so columns line up. The one thing to remember it by: every
   document is drawn as a real white A4 sheet in the business's own colour, the same in the app and for the customer.
   Phone first: every page works at 320px with nothing scrolling sideways (wide tables scroll inside their box). */
:root {
  color-scheme: dark;
  --link: #FF4D6A;
  --link-hi: #FF7A90;
  --pink: #F0245E;
  --pink-deep: #CC1A4D;
  --ink: #F6F1F3;
  --muted: #ABA0A6;
  --paper: #09070A;
  --card: #120E13;
  --raised: #1A141C;
  --sunk: #0C090D;
  --rule: #2A222C;
  --rule-strong: #43374A;
  --tint: rgba(240, 36, 94, 0.12);
  --bad: #FF6B6B;
  --ok: #4ADE80;
  --warn: #F5B342;
  --display: "Syne", "Arial Black", system-ui, sans-serif;
  --body: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --focus: 0 0 0 2px var(--paper), 0 0 0 4px var(--link);
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 1rem/1.55 var(--body); color: var(--ink); background: var(--paper); overflow-wrap: anywhere; }
img, svg { max-width: 100%; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { color: var(--link-hi); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
h1, h2, h3 { font-family: var(--display); font-weight: 800; line-height: 1.12; letter-spacing: -0.01em; margin: 0 0 0.5em; overflow-wrap: break-word; }
h1 { font-size: clamp(1.5rem, 5.5vw, 2.1rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 20; padding: 8px 12px; background: var(--raised); color: var(--ink); border-radius: 8px; }
.skip:focus { top: 8px; }
.muted { color: var(--muted); }
.fine { font-size: 0.86rem; color: var(--muted); }

/* ---- Buttons and fields ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border: 1px solid var(--rule-strong); border-radius: 10px; background: var(--raised); color: var(--ink); font: 600 0.98rem/1.2 var(--body); text-decoration: none; cursor: pointer; transition: background 0.15s, border-color 0.15s; text-align: center; }
.btn:hover { background: var(--hover, #251C28); border-color: var(--hover-line, #5C4C63); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--pink); border-color: var(--pink); color: #fff; }
.btn-primary:hover { background: var(--pink-deep); border-color: var(--pink-deep); color: #fff; }
.btn-quiet { background: transparent; }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--bad) 55%, transparent); color: var(--bad); }
.btn-danger:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
label { display: block; font-weight: 600; font-size: 0.9rem; margin: 0 0 6px; }
.field { margin: 0 0 14px; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.84rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--rule-strong); border-radius: 9px; background: var(--sunk); color: var(--ink); font: 400 1rem/1.4 var(--body);
}
textarea { min-height: 88px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--link); }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--pink); vertical-align: middle; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.check input { flex-shrink: 0; margin-top: 2px; }
.grid2 { display: grid; gap: 0 16px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* ---- Flashes ---- */
.flash { margin: 0 0 16px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--rule-strong); background: var(--raised); }
.flash-ok { border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.flash-error { border-color: color-mix(in srgb, var(--bad) 60%, transparent); }

/* ---- The frame ---- */
.tl-top { border-bottom: 1px solid var(--rule); background: var(--paper); position: sticky; top: 0; z-index: 10; }
.tl-top-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tl-brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 800 1.3rem/1 var(--display); }
.tl-brand img { width: 32px; height: 32px; }
.tl-org { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.92rem; min-width: 0; }
.tl-org select { min-height: 36px; padding: 4px 8px; width: auto; max-width: 220px; }
.tl-acct { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.tl-acct form { margin: 0; }
.tl-tabs { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tl-tabs a { padding: 10px 12px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem; border-bottom: 2px solid transparent; white-space: nowrap; }
.tl-tabs a:hover { color: var(--ink); }
.tl-tabs a[aria-current] { color: var(--ink); border-bottom-color: var(--pink); }
.tl-main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
.tl-foot { border-top: 1px solid var(--rule); padding: 20px 16px; color: var(--muted); font-size: 0.86rem; text-align: center; }
.tl-foot p { margin: 0; display: inline-flex; gap: 8px; align-items: center; }
.page-head { display: flex; gap: 12px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---- Headline numbers ---- */
.tl-sums { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; margin-bottom: 20px; }
@media (min-width: 760px) { .tl-sums { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tl-sum { background: var(--card); padding: 14px 16px; text-decoration: none; color: var(--ink); display: block; }
a.tl-sum:hover { background: var(--raised); color: var(--ink); }
.tl-sum span { display: block; color: var(--muted); font-size: 0.85rem; }
.tl-sum strong { display: block; font: 700 1.35rem/1.25 var(--body); font-variant-numeric: tabular-nums; margin-top: 2px; }
.tl-sum.is-over strong { color: var(--warn); }

/* ---- Filters ---- */
.tl-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.tl-filters a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--rule-strong); color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.tl-filters a[aria-current] { background: var(--tint); border-color: var(--pink); color: var(--ink); }
.tl-filters form { margin-left: auto; display: flex; gap: 6px; flex: 1 1 220px; max-width: 340px; }
.tl-filters input { min-height: 38px; }

/* ---- The ledger ---- */
.tl-ledger-wrap { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); overflow-x: auto; }
.tl-ledger { width: 100%; border-collapse: collapse; min-width: 620px; }
.tl-ledger th { text-align: left; font: 600 0.78rem/1.2 var(--body); letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--rule); background: var(--sunk); }
.tl-ledger td { padding: 12px 14px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.tl-ledger tr:last-child td { border-bottom: 0; }
.tl-ledger tbody tr:hover td { background: var(--raised); }
.tl-ledger .r { text-align: right; }
.tl-ledger a.rowlink { color: var(--ink); text-decoration: none; font-weight: 600; }
.tl-ledger a.rowlink:hover { color: var(--link); text-decoration: underline; }
.tl-kind { display: block; color: var(--muted); font-size: 0.82rem; }
.tl-empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.tl-empty h2 { color: var(--ink); }

/* Status, in words: colour only adds to the word, never replaces it. */
.st { font-weight: 600; font-size: 0.92rem; white-space: nowrap; }
.st-draft { color: var(--muted); }
.st-paid, .st-accepted { color: var(--ok); }
.st-overdue, .st-expired { color: var(--warn); }
.st-declined, .st-cancelled { color: var(--bad); }
.st-cancelled { text-decoration: line-through; }

/* ---- A document's page ---- */
.tl-doc { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1000px) { .tl-doc { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; } .tl-side { position: sticky; top: 112px; } }
.tl-panel { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.tl-panel h2 { font-size: 1.02rem; margin-bottom: 12px; }
.tl-panel > :last-child { margin-bottom: 0; }
.tl-panel details summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.tl-panel details[open] summary { margin-bottom: 12px; }
.tl-facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 12px; font-size: 0.94rem; }
.tl-facts dt { color: var(--muted); }
.tl-facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.tl-big { font: 700 1.6rem/1.2 var(--body); font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.tl-timeline { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.tl-timeline li { padding: 6px 0; border-top: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 10px; }
.tl-timeline li:first-child { border-top: 0; }
.tl-note { padding: 10px 12px; border-radius: 9px; background: var(--tint); border: 1px solid color-mix(in srgb, var(--pink) 40%, transparent); font-size: 0.92rem; margin-bottom: 12px; }
.tl-note-warn { background: color-mix(in srgb, var(--warn) 10%, transparent); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

/* ---- The editor ---- */
.tl-edit h2 { font-size: 1rem; margin: 6px 0 12px; }
.tl-lines { width: 100%; border-collapse: collapse; }
.tl-lines th { text-align: left; font: 600 0.76rem/1.2 var(--body); text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0 6px 6px; }
.tl-lines td { padding: 4px 6px; vertical-align: top; }
.tl-lines textarea { min-height: 44px; height: 44px; }
.tl-lines .c-qty { width: 80px; }
.tl-lines .c-unit { width: 100px; }
.tl-lines .c-price { width: 110px; }
.tl-lines .c-vat { width: 120px; }
.tl-lines .c-amt { width: 100px; text-align: right; padding-top: 14px; font-variant-numeric: tabular-nums; }
.tl-lines .c-x { width: 44px; }
.tl-lines .needs input[name$="[p]"] { border-color: var(--warn); }
.tl-line-more { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.86rem; color: var(--muted); padding: 0 6px 10px; }
.tl-line-more label { display: inline-flex; gap: 6px; align-items: center; font-weight: 500; margin: 0; }
.tl-line-more input[type=text] { width: 72px; min-height: 32px; padding: 4px 8px; }
.tl-x { width: 40px; min-height: 40px; padding: 0; border-radius: 9px; border: 1px solid var(--rule-strong); background: transparent; color: var(--muted); cursor: pointer; font-size: 1.2rem; line-height: 1; }
.tl-x:hover { color: var(--bad); border-color: var(--bad); }
.tl-addrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 18px; }
.tl-addrow select { width: auto; flex: 1 1 220px; max-width: 360px; }
.tl-totals { margin-left: auto; max-width: 320px; font-variant-numeric: tabular-nums; }
.tl-totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.tl-totals .grand { border-top: 1px solid var(--rule-strong); margin-top: 4px; padding-top: 8px; font-weight: 700; font-size: 1.1rem; }
.tl-savebar { position: sticky; bottom: 0; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(6px); padding: 12px 0; border-top: 1px solid var(--rule); margin-top: 16px; }
@media (max-width: 720px) {
  .tl-lines thead { display: none; }
  .tl-lines, .tl-lines tbody, .tl-lines tr, .tl-lines td { display: block; width: 100% !important; }
  .tl-lines tr.tl-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 12px 0; border-top: 1px solid var(--rule); }
  .tl-lines tr.tl-row td { padding: 0; }
  .tl-lines tr.tl-row td.c-desc { grid-column: 1 / -1; }
  .tl-lines tr.tl-row td.c-amt { padding-top: 10px; }
  .tl-lines td[data-label]::before { content: attr(data-label); display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 2px; }
}

/* ---- The sheet: a white A4 page in the business's colour (--brand, --on-brand set inline) ---- */
.sheet-wrap { overflow-x: auto; padding: 4px 0 8px; }
.sheet { --brand: #C8102E; --on-brand: #fff; color-scheme: light; background: #fff; color: #1A1418; width: 100%; max-width: 794px; margin: 0 auto; border-radius: 4px; box-shadow: 0 1px 0 rgba(0,0,0,.04), 0 18px 50px -20px rgba(0,0,0,.55); border-top: 7px solid var(--brand); padding: clamp(20px, 5vw, 52px); font: 400 0.95rem/1.5 var(--body); position: relative; }
.sheet a { color: #1A1418; }
.sheet-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.sheet-from { min-width: 0; max-width: 340px; }
.sheet-logo { max-width: 180px; max-height: 70px; display: block; margin-bottom: 10px; }
.sheet-biz { font: 700 1.2rem/1.25 var(--body); margin: 0 0 6px; color: #1A1418; }
.sheet-small { font-size: 0.84rem; color: #5E5653; margin: 0; white-space: pre-line; }
.sheet-title { text-align: right; margin-left: auto; }
.sheet-title h2 { font: 800 clamp(1.5rem, 4.5vw, 2rem)/1.05 var(--display); color: var(--brand); margin: 0 0 10px; letter-spacing: -0.01em; }
.sheet-meta { display: grid; grid-template-columns: auto auto; gap: 2px 14px; justify-content: end; font-size: 0.86rem; margin: 0; }
.sheet-meta dt { color: #6B6460; text-align: right; }
.sheet-meta dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.sheet-who { display: flex; gap: 28px; flex-wrap: wrap; margin-bottom: 22px; }
.sheet-who > div { min-width: 180px; flex: 1 1 200px; }
.sheet-label { font: 700 0.72rem/1.2 var(--body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand); margin: 0 0 6px; }
.sheet-name { font-weight: 700; margin: 0; }
.sheet-subject { font: 700 1.05rem/1.3 var(--body); margin: 0 0 14px; }
.sheet-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-bottom: 14px; }
.sheet-table th { font: 700 0.7rem/1.2 var(--body); letter-spacing: 0.06em; text-transform: uppercase; color: var(--brand); text-align: left; padding: 8px 6px; border-bottom: 1.5px solid #E2DCD8; }
.sheet-table td { padding: 9px 6px; border-bottom: 1px solid #EEE9E6; vertical-align: top; }
.sheet-table .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sheet-table .d { white-space: pre-line; }
.sheet-table .d strong { display: block; }
.sheet-table tr.off td { color: #8A827E; }
.sheet-table .opt { display: block; font-size: 0.76rem; color: #6B6460; }
.sheet-table .need { color: var(--brand); font-weight: 700; }
.sheet-totals { margin-left: auto; width: min(100%, 300px); font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.sheet-totals div { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.sheet-totals .t-total { font-weight: 700; font-size: 1.02rem; border-top: 1.5px solid #E2DCD8; margin-top: 4px; padding-top: 8px; }
.sheet-totals .t-due { background: var(--brand); color: var(--on-brand); padding: 9px 10px; border-radius: 6px; font-weight: 700; margin-top: 8px; }
.sheet-block { margin-top: 20px; font-size: 0.86rem; }
.sheet-block p { margin: 0; white-space: pre-line; }
.sheet-rc { font-weight: 700; font-size: 0.86rem; margin-top: 12px; }
.sheet-foot { margin-top: 30px; padding-top: 12px; border-top: 1px solid #EEE9E6; font-size: 0.74rem; color: #6B6460; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sheet-stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-14deg); font: 800 clamp(2rem, 9vw, 4.4rem)/1 var(--display); color: rgba(185, 28, 28, 0.16); letter-spacing: 0.08em; pointer-events: none; text-transform: uppercase; }
.sheet-stamp.paid { color: rgba(17, 105, 47, 0.16); }
@media (max-width: 520px) {
  .sheet-title { text-align: left; margin-left: 0; }
  .sheet-meta { justify-content: start; }
  .sheet-meta dt { text-align: left; }
  .sheet-table .c-vat, .sheet-table .c-price { display: none; }
}

/* ---- Price list ---- */
.tl-items-add { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .tl-items-add { grid-template-columns: 2fr 1fr 1fr 1fr; align-items: end; } .tl-items-add .wide { grid-column: 1 / -1; } }
.tl-items-row details { margin-top: 8px; }
.tl-items-row form { margin-top: 10px; }
tr.is-archived td { opacity: 0.6; }

/* ---- Landing ---- */
.tl-hero { padding: clamp(24px, 6vw, 64px) 0 28px; max-width: 760px; }
.tl-hero h1 { font-size: clamp(2rem, 7vw, 3.2rem); line-height: 1.02; }
.tl-hero p { font-size: 1.12rem; color: var(--muted); max-width: 60ch; }
.tl-points { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); margin: 28px 0; padding: 0; list-style: none; }
.tl-points li { border-top: 2px solid var(--pink); padding-top: 12px; }
.tl-points strong { display: block; font-size: 1.02rem; margin-bottom: 4px; }
.tl-points span { color: var(--muted); font-size: 0.95rem; }
.tl-landing-sheet { margin-top: 36px; max-width: 560px; transform: rotate(-1.2deg); }

/* ---- Plan ---- */
.tl-plans { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.tl-plan { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px; }
.tl-plan.is-on { border-color: var(--pink); }
.tl-plan ul { padding-left: 18px; margin: 10px 0 16px; }
.tl-plan li { margin-bottom: 4px; }
.tl-price { font: 700 1.5rem/1.2 var(--body); font-variant-numeric: tabular-nums; margin: 6px 0 0; }

/* ---- Light mode extras (tokens come from theme.php) ---- */
:root[data-theme="light"] { --pink: #C2103F; --pink-deep: #A30D35; --tint: rgba(194, 16, 63, 0.07); }
:root[data-theme="light"] .sheet { box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 14px 40px -18px rgba(60,30,45,.35); border: 1px solid #E8E2E5; border-top: 7px solid var(--brand); }
:root[data-theme="light"] .st-overdue, :root[data-theme="light"] .st-expired, :root[data-theme="light"] .tl-sum.is-over strong { color: #975A04; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } .tl-landing-sheet { transform: none; } }
@media print {
  .tl-top, .tl-tabs, .tl-side, .tl-foot, .tl-savebar, .tl-actions, .skip { display: none !important; }
  body { background: #fff; }
  .tl-main { padding: 0; }
  .sheet { box-shadow: none; max-width: none; }
}
