/*
 * FlexPad styles — one hand-written file, no build step.
 *
 * DESIGN INTENT
 *   Used on a phone in a van as often as on a laptop in an office, so:
 *   - Atkinson Hyperlegible Next: a typeface designed for maximum legibility
 *     (clear 1/l/I, 0/O), good in sunlight and at small sizes.
 *   - Calm "Liffey ink" blue for structure; HI-VIS AMBER is reserved for the
 *     one thing that needs attention (money overdue, deadlines due). If
 *     amber appears, act on it. Nothing else uses it.
 *   - Big tap targets (min 44px) and a bottom tab bar on phones.
 *
 * STRUCTURE OF THIS FILE
 *   1. Fonts and design tokens (colours, spacing) — change the look here.
 *   2. Base elements.   3. App shell (sidebar / bottom bar).
 *   4. Components (buttons, forms, tables, badges...).   5. Pages.
 */

/* ---------- 1. Fonts and tokens ---------- */

@font-face { font-family: "Atkinson Next"; src: url("../fonts/atkinson-hyperlegible-next-latin-400-normal.e8da57bc0c3d.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Next"; src: url("../fonts/atkinson-hyperlegible-next-latin-600-normal.9204a77cef78.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Atkinson Next"; src: url("../fonts/atkinson-hyperlegible-next-latin-700-normal.617b4197a93a.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --ink: #17212b;          /* Body text. */
  --ink-soft: #52606d;     /* Secondary text, labels. */
  --liffey: #14304a;       /* Brand blue: sidebar, primary buttons. */
  --liffey-2: #234d73;     /* Hover/active blue. */
  --paper: #f4f6f8;        /* Page background: cool, not cream. */
  --surface: #ffffff;      /* Panels. */
  --line: #d9dfe5;         /* Borders and rules. */
  --hivis: #f2a900;        /* ATTENTION ONLY: overdue, due soon. */
  --hivis-wash: #fff4d6;   /* Background behind hi-vis items. */
  --good: #1f7a5c;         /* Paid, done. */
  --good-wash: #e3f3ec;
  --bad: #b42318;          /* Errors, destructive actions. */
  --bad-wash: #fdecea;
  --focus: #2f6fed;        /* Keyboard focus ring. */
  --radius: 10px;
  --radius-sm: 6px;
  --space: 1rem;
  --font: "Atkinson Next", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- 2. Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 1rem; line-height: 1.5; color: var(--ink); background: var(--paper); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; max-width: 70ch; }
a { color: var(--liffey-2); text-underline-offset: 2px; }
a:hover { color: var(--liffey); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.num, td.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.muted { color: var(--ink-soft); }
.small { font-size: .875rem; }
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 1rem; top: 1rem; z-index: 100; background: var(--surface); padding: .5rem 1rem; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- 3. App shell ---------- */

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--liffey); color: #dfe8f1; padding: 1.25rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { color: #fff; font-weight: 700; font-size: 1.3rem; text-decoration: none; padding: 0 .75rem; display: block; }
.brand-business { color: #a9bccf; font-size: .875rem; padding: .25rem .75rem 1.25rem; display: block; overflow-wrap: anywhere; }
.nav a { display: flex; align-items: center; gap: .6rem; color: #dfe8f1; text-decoration: none; padding: .6rem .75rem; border-radius: var(--radius-sm); min-height: 44px; }
.nav a:hover { background: var(--liffey-2); color: #fff; }
.nav a[aria-current="page"] { background: #fff; color: var(--liffey); font-weight: 600; }
.nav-group { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,.12); }
.nav-foot { margin-top: auto; padding-top: 1rem; font-size: .875rem; }
.nav-foot form { margin: 0; }
.nav-foot button { background: none; border: 0; color: #a9bccf; font: inherit; padding: .5rem .75rem; cursor: pointer; text-decoration: underline; }
.icon { width: 20px; height: 20px; flex: none; }

.main { padding: 1.5rem 2rem 3rem; max-width: 1180px; width: 100%; }
.topbar { display: none; }
.tabbar { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.is-open { display: flex; position: fixed; inset: 0 25% 0 0; z-index: 50; height: 100%; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--liffey); color: #fff; padding: .5rem 16px; position: sticky; top: 0; z-index: 40; }
  .topbar .brand { padding: 0; font-size: 1.1rem; }
  .topbar button { background: none; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: var(--radius-sm); min-height: 40px; padding: 0 .8rem; font: inherit; }
  .main { padding: 1rem 16px 6rem; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 40; padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45rem 0; font-size: .72rem; color: var(--ink-soft); text-decoration: none; min-height: 52px; }
  .tabbar a[aria-current="page"] { color: var(--liffey); font-weight: 700; }
}

/* Public pages (login, sign-up): a single centred column. */
.public { min-height: 100vh; display: grid; place-items: start center; padding: 3rem 16px; }
.public-card { width: 100%; max-width: 440px; }
.public-brand { font-weight: 700; font-size: 1.5rem; color: var(--liffey); margin-bottom: .25rem; }
.public-lede { color: var(--ink-soft); margin-bottom: 1.5rem; }

/* ---------- 4. Components ---------- */

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--ink-soft); margin: .25rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: 0 1.1rem; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-primary { background: var(--liffey); border-color: var(--liffey); color: #fff; }
.btn-primary:hover { background: var(--liffey-2); border-color: var(--liffey-2); color: #fff; }
.btn-danger { color: var(--bad); border-color: #f1b8b2; }
.btn-danger:hover { background: var(--bad-wash); color: var(--bad); border-color: var(--bad); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--liffey-2); padding: 0 .6rem; }
.btn-quiet:hover { background: #e8eef4; border-color: transparent; }
.btn-flex { border-style: dashed; border-color: var(--liffey-2); color: var(--liffey-2); }
.btn[disabled] { opacity: .55; cursor: progress; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: .75rem; }
.panel-head h2 { margin: 0; }

/* Messages after an action. */
.messages { list-style: none; padding: 0; margin: 0 0 1.25rem; display: grid; gap: .5rem; }
.msg { padding: .75rem 1rem; border-radius: var(--radius-sm); border-left: 4px solid var(--liffey-2); background: #e8eef4; }
.msg-success { border-color: var(--good); background: var(--good-wash); }
.msg-error { border-color: var(--bad); background: var(--bad-wash); }
.msg-warning { border-color: var(--hivis); background: var(--hivis-wash); }

/* Forms. */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1.25rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field .help { color: var(--ink-soft); font-size: .85rem; margin-top: .25rem; }
.field .errorlist { list-style: none; padding: 0; margin: .3rem 0 0; color: var(--bad); font-size: .9rem; font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=url], input[type=search], input:not([type]), select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .7rem; font: inherit; color: var(--ink); background: #fff; border: 1px solid #b9c4ce; border-radius: var(--radius-sm);
}
textarea { min-height: 88px; resize: vertical; }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: .6rem; align-items: flex-start; margin-bottom: 1rem; }
.check input { width: 22px; height: 22px; margin-top: .1rem; flex: none; }
.check label { font-weight: 600; }
.check .help { color: var(--ink-soft); font-size: .85rem; font-weight: 400; display: block; }
fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; }
legend { font-weight: 700; font-size: 1.1rem; margin-bottom: .75rem; padding: 0; }
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; padding-top: .5rem; }
.non-field-errors { color: var(--bad); font-weight: 600; background: var(--bad-wash); padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.non-field-errors ul { margin: 0; padding-left: 1.2rem; }

/* Filters above lists. */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input[type=search], .filters input[type=month], .filters input[type=date], .filters select { width: auto; min-width: 12rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { display: inline-flex; align-items: center; min-height: 36px; padding: 0 .85rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: .9rem; }
.chip[aria-current="true"] { background: var(--liffey); color: #fff; border-color: var(--liffey); }

/* Tables: on phones each row becomes a stacked block using data-label. */
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th { text-align: left; font-size: .85rem; color: var(--ink-soft); font-weight: 600; padding: .6rem .75rem; border-bottom: 2px solid var(--line); }
.table td { padding: .7rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th.num { text-align: right; }
.table tr:last-child td { border-bottom: 0; }
.table a.row-link { font-weight: 600; text-decoration: none; }
.table a.row-link:hover { text-decoration: underline; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; }
@media (max-width: 700px) {
  .table.stack thead { display: none; }
  .table.stack tr { display: block; padding: .6rem .25rem; border-bottom: 1px solid var(--line); }
  .table.stack td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem .6rem; text-align: right; }
  .table.stack td::before { content: attr(data-label); color: var(--ink-soft); font-size: .85rem; text-align: left; }
  .table.stack td.primary { font-size: 1.05rem; }
  .table.stack td.primary::before { content: none; }
  .table.stack td.primary { display: block; text-align: left; }
}
.empty { padding: 2rem 1.25rem; text-align: center; color: var(--ink-soft); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty p { margin: 0 auto 1rem; }

/* Status badges. Only "overdue"/"due soon" use hi-vis amber. */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: #e8eef4; color: var(--liffey); white-space: nowrap; }
.badge-paid, .badge-accepted, .badge-completed, .badge-done, .badge-credited { background: var(--good-wash); color: var(--good); }
.badge-overdue, .badge-soon { background: var(--hivis); color: #3a2a00; }
.badge-draft { background: #eceff1; color: var(--ink-soft); border: 1px dashed #b9c4ce; }
.badge-declined, .badge-cancelled, .badge-missed { background: var(--bad-wash); color: var(--bad); }

.pagination { display: flex; gap: .5rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* Definition lists for detail pages. */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.25rem; margin: 0; }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 960px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- 5. Pages ---------- */

/* Dashboard: the hi-vis attention strip is the one bold element of the app. */
.attention { background: var(--hivis-wash); border: 2px solid var(--hivis); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.attention h2 { font-size: 1.05rem; margin-bottom: .5rem; display: flex; align-items: center; gap: .5rem; }
.attention h2::before { content: ""; width: 12px; height: 12px; border-radius: 2px; background: var(--hivis); box-shadow: 0 0 0 3px #3a2a00; }
.attention ul { margin: 0; padding: 0; list-style: none; display: grid; gap: .35rem; }
.attention li { display: flex; justify-content: space-between; gap: .25rem 1rem; flex-wrap: wrap; padding: .15rem 0; }
@media (max-width: 700px) { .attention li { padding: .4rem 0; border-bottom: 1px solid rgba(58,42,0,.15); } .attention li:last-child { border-bottom: 0; } }
.all-clear { background: var(--good-wash); border-left: 4px solid var(--good); padding: .9rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem; }

.figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 1.5rem; }
.figure { padding: 1rem 1.25rem; border-right: 1px solid var(--line); }
.figure:last-child { border-right: 0; }
.figure .label { color: var(--ink-soft); font-size: .9rem; }
.figure .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.figure .value.is-alert { color: #8a5a00; }
@media (max-width: 700px) { .figures { grid-template-columns: 1fr; } .figure { border-right: 0; border-bottom: 1px solid var(--line); } .figure:last-child { border-bottom: 0; } }

.quick { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.5rem; }

/* Document (quote/invoice) editor. */
.lines-table td { padding: .4rem .35rem; vertical-align: top; }
.lines-table th { padding: .4rem .35rem; }
.lines-table .col-desc { width: 44%; }
.lines-table .col-qty { width: 9%; }
.lines-table .col-price { width: 14%; }
.lines-table .col-disc { width: 9%; }
.lines-table .col-vat { width: 15%; }
.lines-table .col-del { width: 5%; text-align: center; }
.lines-table tr.is-removed { display: none; }
.lines-table .errorlist { list-style: none; margin: .2rem 0 0; padding: 0; color: var(--bad); font-size: .85rem; }
@media (max-width: 760px) {
  .lines-table thead { display: none; }
  .lines-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; padding: .75rem; border-bottom: 1px solid var(--line); }
  .lines-table td { padding: 0; border: 0; }
  .lines-table td.col-desc, .lines-table td.col-vat { grid-column: 1 / -1; }
  .lines-table td::before { content: attr(data-label); display: block; font-size: .8rem; color: var(--ink-soft); }
}
.live-totals { margin-left: auto; max-width: 340px; }
.live-totals div { display: flex; justify-content: space-between; padding: .2rem 0; }
.live-totals .grand { font-weight: 700; font-size: 1.15rem; border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .4rem; }
.flex-box { border: 1px dashed var(--liffey-2); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; background: #f7fafc; }
.flex-box summary { cursor: pointer; font-weight: 700; color: var(--liffey-2); min-height: 32px; }
.flex-note { font-size: .85rem; color: var(--ink-soft); }
.flex-status { font-weight: 600; margin-top: .5rem; }

.totals-box { margin-left: auto; max-width: 360px; }
.totals-box div { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; }
.totals-box .grand { border-top: 2px solid var(--ink); font-weight: 700; font-size: 1.15rem; margin-top: .3rem; padding-top: .5rem; }
.problems { border-left: 4px solid var(--hivis); background: var(--hivis-wash); padding: .9rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.problems ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.locked-note { color: var(--ink-soft); font-size: .9rem; }

/* Compliance calendar. */
.deadline { display: grid; grid-template-columns: 7.5rem 1fr auto; gap: .5rem 1rem; align-items: start; padding: .9rem 0; border-bottom: 1px solid var(--line); }
.deadline:last-child { border-bottom: 0; }
.deadline .when { font-weight: 700; font-variant-numeric: tabular-nums; }
.deadline .when small { display: block; font-weight: 400; color: var(--ink-soft); }
.deadline.is-soon .when { color: #8a5a00; }
.deadline p { margin: .25rem 0 0; font-size: .92rem; color: var(--ink-soft); }
@media (max-width: 640px) { .deadline { grid-template-columns: 1fr; } }

/* VAT report. */
.vat-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 1.25rem; }
.vat-box { padding: .9rem 1.1rem; border-right: 1px solid var(--line); }
.vat-box:last-child { border-right: 0; }
.vat-box .code { font-weight: 700; color: var(--liffey); }
.vat-box .value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Legal pages. */
.prose { max-width: 72ch; }
.prose h2 { margin-top: 1.75rem; }
.draft-banner { background: var(--hivis-wash); border: 1px solid var(--hivis); padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem; }

/* Small utilities (the Content-Security-Policy forbids inline style="" attributes, so spacing tweaks live here). */
.verify-banner { margin-bottom: 1rem; }
.public-foot { margin-top: 2rem; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.inline-form { display: inline; margin: 0; }
.right { text-align: right; }
.stack-sm > * + * { margin-top: .5rem; }
.hidden { display: none; }
