:root {
  --ink: #1d2327;
  --muted: #5f6b72;
  --line: #d8dde0;
  --paper: #ffffff;
  --page: #f4f6f7;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --current: #e8f1f8;
  --error: #a4262c;
  --notice: #1e6b3a;
  --radius: 8px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: .9em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  min-width: 0;
}
input:focus, select:focus, textarea:focus, .rte-area:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
label > input, label > select { margin-top: 4px; font-weight: 400; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 600; font-size: .95rem;
  white-space: nowrap;
}
button:focus-visible, .button:focus-within, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.danger { color: var(--error); }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 400; }
.link.danger { color: var(--error); }
.error { color: var(--error); font-weight: 600; margin: 0 0 12px; }
.notice { color: var(--notice); font-weight: 600; margin: 0 0 12px; }
form.inline { display: inline; margin: 0; }

/* Header: brand and nav, then the search bar across the full width. */
.top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "brand search nav";
  gap: 10px 16px;
  align-items: center;
  padding: 10px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2;
}
.brand { grid-area: brand; font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; white-space: nowrap; }
.search { grid-area: search; display: flex; gap: 8px; max-width: 640px; margin: 0; }
.top nav { grid-area: nav; display: flex; gap: 14px; align-items: center; font-size: .95rem; }
.top nav a { text-decoration: none; display: inline-flex; align-items: center; }
.top nav a[aria-current="page"] { font-weight: 700; color: var(--ink); }
/* Menu icons: line drawings in the text colour. On a computer only sign-out is an icon. */
.nav-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.top nav a .nav-icon { display: none; }
.nav-divider { width: 1px; height: 22px; background: var(--line); }
.nav-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 6px; background: none; color: var(--accent); cursor: pointer;
}
.nav-icon-btn:hover { background: var(--page); }

main { padding: 16px 20px 40px; max-width: 1400px; margin: 0 auto; }

/* Jobs: list on the left, form on the right; stacked on phones. */
.jobs { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 20px; align-items: start; }
.list, .editor, .lookup, .reports section { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.editor { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; }
/* Jobs heading: the title with its count as a pill, and on the right the total of the jobs listed as a
   labelled summary figure (it sits over the Cost column it adds up), then New job. */
.list-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin-bottom: 14px; }
.list-head h1 { display: flex; align-items: center; gap: 8px; }
.count-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2em; height: 1.5em; padding: 0 .55em; border-radius: 999px;
  background: #e6e9eb; color: var(--muted); font-size: .6em; font-weight: 600; font-variant-numeric: tabular-nums;
}
.list-summary { margin: 0 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; white-space: nowrap; }
.summary-label { font-size: .7rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.summary-amount { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }

.count { color: var(--muted); font-weight: 400; font-size: .9em; }
.filter { margin: 0 0 8px; font-size: .95rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: .85rem; color: var(--muted); white-space: nowrap; }
thead th a { color: inherit; text-decoration: none; }
thead th a:hover { color: var(--accent); }
.col-cost, .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-date { white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr.current { background: var(--current); }
tbody tr:hover { background: #f8fafb; }
tbody tr.current:hover { background: var(--current); }
.col-name a { font-weight: 600; text-decoration: none; }
.empty { color: var(--muted); text-align: center; padding: 20px; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.new-field[hidden] { display: none; }
/* "Done by" is one field: no box around the group, and the legend looks like every other field label. */
fieldset.providers { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
fieldset.providers legend { font-weight: 600; font-size: .9rem; padding: 0; margin-bottom: 4px; }
label.check { display: flex; gap: 8px; align-items: baseline; font-weight: 400; margin: 4px 0; }
label.check input { width: auto; }
/* Form card: title with New job on the right; one action row at the bottom (Delete left, Cancel and Save
   right). On a computer the row stays visible at the bottom of the scrolling card. */
#form { scroll-margin-top: 120px; } /* clears the sticky header when a refused save scrolls here */
.editor .error:focus { outline: none; } /* focused only so it is read out; the text is already red */
.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.editor-head h2 { margin: 0; }
.form-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line);
  position: sticky; bottom: -14px; background: var(--paper); padding-bottom: 14px; margin-bottom: -14px;
}
.form-actions .delete-job { margin: 0; }
.delete-link { text-decoration: underline; text-underline-offset: 3px; }
.save-group { margin-left: auto; display: flex; align-items: center; gap: 14px; }

/* Notes editor */
.rte { border: 1px solid var(--line); border-radius: 6px; margin: 4px 0 12px; background: var(--paper); }
.rte-bar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); }
.rte-bar button { padding: 4px 8px; font-size: .85rem; }
.rte-area { min-height: 120px; padding: 8px 10px; }
.rte-area p { margin: 0 0 8px; }
textarea[data-editor] { margin: 4px 0 12px; }

/* Attachments */
.files { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.attachments { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.att { display: grid; grid-template-columns: 88px 1fr auto; gap: 10px; align-items: center; }
.thumb img { width: 88px; height: 88px; object-fit: cover; border-radius: 6px; display: block; background: var(--page); }
.thumb.icon { width: 88px; height: 88px; border-radius: 6px; background: var(--page); display: grid; place-items: center; font-weight: 700; color: var(--muted); text-decoration: none; font-size: .8rem; }
.att-name { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.uploader { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; }
.uploader .button { position: relative; }
.upload-status { flex-basis: 100%; margin: 4px 0 0; font-size: .95rem; text-align: center; }
.files-hint { margin-top: 16px; }

/* Lists and reports */
/* Reports and Lists are a centred reading column; the Jobs page keeps its list-and-form layout. */
.manage, .reports { display: grid; gap: 18px; max-width: 900px; margin: 0 auto; }
.lookup-list { list-style: none; padding: 0; margin: 0 0 12px; }
.lookup-list li { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.row { display: flex; gap: 8px; align-items: center; flex: 1; margin: 0; }
.row input { flex: 1; }
.row.provider input[name="address"] { flex: 2; }
.row a.muted { white-space: nowrap; }
/* Report filter: the label sits above the select, so the row lines up on the bottom edge and the select and
   Show button share one height (otherwise the button centres on label + select and sits too high). */
.report-filter { max-width: 420px; margin-bottom: 12px; align-items: flex-end; }
.report-filter label { flex: 1; margin: 0; }
.report-filter select, .report-filter button { height: 40px; }
.lookup .row input, .lookup .row button { height: 40px; } /* Lists rows: field and button the same height too */

/* Sign in */
body.signin { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 380px; }
.card .brand { display: block; margin-bottom: 16px; }
.card .primary { width: 100%; margin-top: 4px; }
code { overflow-wrap: anywhere; }

/* Todo list: the same two-card layout as Jobs. */
.todo-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.status-tabs { display: flex; gap: 2px; }
.status-tabs a { padding: 6px 10px; border-radius: 6px; text-decoration: none; }
.status-tabs a[aria-current] { background: var(--current); color: var(--ink); font-weight: 600; }
.todo-find { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 320px; margin: 0; }
.todo-find select { flex: 1 1 130px; min-width: 0; }
.todo-find input { flex: 3 1 140px; min-width: 0; }
.todo-table { width: 100%; }
.todo-table .col-check { width: 40px; padding: 2px 4px; }
.todo-table .col-item a { font-weight: 600; text-decoration: none; }
.todo-table .col-action { width: 45%; max-width: 0; }
.todo-table .clip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo-table .col-opened { white-space: nowrap; font-variant-numeric: tabular-nums; }
.todo-table tr.done td { color: var(--muted); }
.todo-table tr.done .col-item a, .todo-table tr.done .clip { color: var(--muted); text-decoration: line-through; }
.todo-check { margin: 0; }
/* Priority: a small word, so it is never colour alone. High is filled; Medium and Low are quieter. */
.todo-table .col-priority { white-space: nowrap; }
.prio { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .78rem; font-weight: 600; line-height: 1.5; border: 1px solid var(--line); color: var(--muted); }
.prio-High { background: #fdecea; border-color: #f3b8b1; color: #a52a1a; }
.prio-Medium { background: #fff6e0; border-color: #ecd49a; color: #7a5600; }
.todo-table tr.done .prio { opacity: .6; }
.check-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 6px; background: none; color: var(--accent); cursor: pointer;
}
.check-btn:hover { background: var(--page); }
.check-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.check-btn .tick { display: none; }
.check-btn[aria-pressed="true"] .tick { display: inline; }
.check-btn[aria-pressed="true"] rect { fill: var(--current); }
textarea.plain-text { margin: 4px 0 12px; resize: vertical; }
.editor .hint { font-size: .85rem; margin: 0 0 8px; }

@media (max-width: 960px) {
  .jobs { grid-template-columns: minmax(0, 1fr); }
  .editor { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 640px) {
  .top {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand nav" "search search";
    padding: 10px 16px;
  }
  .search { max-width: none; }
  main { padding: 12px 16px 32px; }
  .pair { grid-template-columns: 1fr; }
  /* Phone menu: icons with 44 px targets; the names stay for screen readers. */
  .top nav { gap: 0; }
  .top nav a .nav-icon { display: block; }
  .top nav a, .nav-icon-btn { min-width: 44px; min-height: 44px; justify-content: center; border-radius: 8px; }
  .top nav a[aria-current="page"] { background: var(--current); }
  .top nav .nav-text { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
  .nav-divider { margin: 0 4px; }
  .form-actions { position: static; margin-bottom: 0; padding-bottom: 0; }
  /* The jobs list becomes two-line rows: name and cost, then date, type and category. The headings stay
     as a row of sort links, so every column can still be sorted. */
  .jobs-table, .jobs-table thead, .jobs-table tbody { display: block; }
  .jobs-table thead tr { display: flex; flex-wrap: wrap; gap: 2px 14px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
  .jobs-table thead th { border: 0; padding: 4px 0; text-align: left; }
  .jobs-table tbody tr {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "name name name cost" "date type category category";
    gap: 2px 10px;
    padding: 9px 6px;
    border-bottom: 1px solid var(--line);
  }
  .jobs-table td { border: 0; padding: 0; }
  .jobs-table .col-name { grid-area: name; }
  .jobs-table .col-cost { grid-area: cost; font-weight: 600; }
  .jobs-table .col-date { grid-area: date; }
  .jobs-table .col-type { grid-area: type; }
  .jobs-table .col-category { grid-area: category; }
  .jobs-table .col-date, .jobs-table .col-type, .jobs-table .col-category { color: var(--muted); font-size: .88rem; }
  .jobs-table tbody tr td.empty { grid-column: 1 / -1; }
  /* Todo rows: the checkbox on the left (a 44 px target), item and date, then the action and category. */
  .todo-table, .todo-table thead, .todo-table tbody { display: block; }
  .todo-table thead tr { display: flex; flex-wrap: wrap; gap: 2px 14px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
  .todo-table thead th { border: 0; padding: 4px 0; text-align: left; }
  .todo-table thead .col-check { display: none; }
  .todo-table tbody tr {
    display: grid;
    grid-template-columns: 44px auto minmax(0, 1fr) auto;
    grid-template-areas: "check item item opened" "check action action action" "check priority category category";
    gap: 2px 8px; padding: 8px 2px; border-bottom: 1px solid var(--line);
  }
  .todo-table td { border: 0; padding: 0; }
  .todo-table .col-check { grid-area: check; width: auto; align-self: start; }
  .todo-table .col-item { grid-area: item; }
  .todo-table .col-opened { grid-area: opened; color: var(--muted); font-size: .88rem; }
  .todo-table .col-action { grid-area: action; width: auto; max-width: none; }
  .todo-table .col-priority { grid-area: priority; }
  .todo-table .col-priority:empty { display: none; }
  .todo-table .col-priority:empty ~ .col-category { grid-column: 2 / -1; }
  .todo-table .col-category { grid-area: category; color: var(--muted); font-size: .88rem; }
  .todo-table .clip { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .todo-table tbody tr td.empty { grid-column: 1 / -1; }
  .check-btn { width: 44px; height: 44px; }
  .brand { font-size: 1rem; }
  .lookup-list li { flex-wrap: wrap; }
  .row.provider { flex-wrap: wrap; }
  .row.provider input { flex: 1 1 100%; }
  .att { grid-template-columns: 64px 1fr auto; }
  .thumb img, .thumb.icon { width: 64px; height: 64px; }
}

/* Narrow phones: brand, five 44 px menu targets, the divider and sign-out need about 345 px, so the header
   gives up a little side padding and gap to keep them on one row at 360 px. */
@media (max-width: 400px) {
  .top { padding: 10px 12px; column-gap: 8px; }
  .nav-divider { margin: 0 2px; }
}

/* Providers on the Lists page: one small form per provider. */
.provider-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 12px; }
.provider-list > li { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.provider-grid .wide { grid-column: 1 / -1; }
.provider-grid label { margin-bottom: 8px; }
.provider-grid textarea { margin-top: 4px; font-weight: 400; resize: vertical; }
.provider-actions { display: flex; gap: 12px; align-items: center; }
.provider-delete { margin-top: 6px; }
details.add-provider summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 10px; }
@media (max-width: 640px) {
  .provider-grid { grid-template-columns: 1fr; }
}
.provider-list > li { padding: 0; }
.provider-list details > form, .provider-list details > .provider-delete { padding: 0 12px; }
.provider-list details[open] { padding-bottom: 10px; }
.provider-summary { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; padding: 10px 12px; cursor: pointer; }
.provider-summary strong { margin-right: auto; }

/* Provider picker: chips inside the field, a list of matches under it. The plain checkboxes stay in the
   form (hidden) and are what the form posts. */
.picker-on > label.check, .picker-on > p.muted { display: none; }
.combo { position: relative; margin-bottom: 6px; }
.combo-field {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 44px; padding: 5px 36px 5px 8px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--paper); cursor: text;
  position: relative; scroll-margin-top: 130px;
}
.combo-field:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips { display: contents; list-style: none; margin: 0; padding: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 2px;
  background: #e6e9eb; border-radius: 999px; padding: 2px 2px 2px 10px; font-size: .9rem; line-height: 1.3;
}
.chip-x {
  border: 0; background: none; padding: 0; width: 28px; height: 28px; border-radius: 50%;
  font-size: 1.1rem; line-height: 1; color: var(--muted); font-weight: 400;
}
.chip-x:hover { background: #d3d8db; color: var(--ink); }
.chip-x { flex: none; min-width: 28px; }
.chip-new { font-style: italic; background: #eef3e6; }
.picker-msg { color: var(--error); font-size: .92rem; font-weight: 600; margin: 4px 0 6px; }
.combo-input { flex: 1 1 8ch; min-width: 8ch; border: 0; padding: 4px 2px; outline: none; background: transparent; }
.combo-input:focus { outline: none; }
.combo-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; width: 30px; height: 30px; padding: 0; color: var(--muted); font-size: 1rem;
}
.combo-list {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px 0; list-style: none; overflow-y: auto; max-height: 320px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .12);
}
.combo-list[hidden] { display: none; }
.combo-option { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px; cursor: pointer; }
.combo-option .muted { margin-left: auto; }
.combo-option:hover, .combo-option.active { background: var(--current); }
.combo-check {
  flex: none; width: 18px; height: 18px; border: 2px solid var(--muted); border-radius: 3px;
  display: grid; place-items: center; font-size: 13px; line-height: 1; color: #fff;
}
.combo-option[aria-selected="true"] .combo-check { background: var(--accent); border-color: var(--accent); }
.combo-option[aria-selected="true"] .combo-check::after { content: "✓"; }
.combo-name mark { background: #fde68a; color: inherit; border-radius: 2px; padding: 0; }
.combo-add { color: var(--accent); font-weight: 600; }
.combo-empty { padding: 10px 12px; color: var(--muted); }
.no-cost { color: var(--muted); }

/* Reports: each report has its name and a Print button on one line; the line under it is for paper only. */
.report-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.print-meta { display: none; }

/* Printing: reports (and the jobs list) as plain documents. Site navigation, search, buttons and forms are
   left out; black on white; table headers repeat on each page and rows are not split. A Print button
   prints only its own report (body.print-one); Ctrl+P prints every report, each starting a new page. */
@media print {
  @page { margin: 15mm; }
  html, body { background: #fff; color: #000; }
  body { font-size: 11pt; }
  .top, .print-btn, .report-filter, .screen-only, .reports > h1, .editor, .list-head .button { display: none !important; }
  main { padding: 0; max-width: none; }
  .reports { display: block; max-width: none; }
  .reports section, .list { border: 0; padding: 0; border-radius: 0; background: none; }
  .report-section + .report-section { break-before: page; }
  body.print-one .report-section:not(.print-this) { display: none; }
  body.print-one .report-section.print-this { break-before: auto; }
  .report-head h2 { font-size: 16pt; margin: 0 0 4pt; }
  .print-meta { display: block; margin: 0 0 12pt; font-size: 10pt; }
  .muted { color: #333; }
  .table-wrap { overflow: visible; }
  table { width: 100%; font-size: 10.5pt; }
  thead { display: table-header-group; }
  tfoot { display: table-row-group; } /* totals print once, at the end */
  tr, th, td { break-inside: avoid; }
  th, td { color: #000; border-bottom: 1px solid #999; padding: 3pt 6pt; }
  thead th { color: #000; border-bottom: 1.5px solid #000; }
  a { color: #000; text-decoration: none; }
  a[href]::after { content: none; }
  .jobs { display: block; }
  tbody tr.current { background: none; }
}

/* Providers page: a centred column like Reports and Lists; filter and Add at the top, one line per provider. */
.providers-page { max-width: 900px; margin: 0 auto; display: grid; gap: 12px; }
.providers-page h1 { display: flex; align-items: center; gap: 8px; }
.provider-filter { margin: 0; }
.provider-filter input { height: 40px; }
.provider-filter button { height: 40px; }
.filter-count { margin: 0; min-height: 1em; }
.filter-count:empty { display: none; }
.providers-page .provider-list > li { background: var(--paper); }
