
/* ================= variables ================= */
:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e2dc;
  --accent: #2f5d50;        /* main brand colour: buttons, links, active nav */
  --accent-soft: #e6efec;
  --chart: #2e8b6a;         /* chart marks: brand green with enough colour to read as a mark */
  --chart-prev: #64c08c;    /* "last year" line: a lighter green (checked to stay distinguishable) */
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
  --radius: 10px;
  --tabbar-h: 58px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ================= base ================= */
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
small, .muted { color: var(--muted); }
code { font-size: .85em; background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }

/* ================= desktop layout: sidebar + main ================= */
.shell { display: flex; min-height: 100vh; }
.nav { width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 1.25rem .75rem; }
.nav .brand { font-weight: 700; padding: 0 .6rem 1rem; display: block; color: var(--text); }
.nav a.item { display: block; padding: .45rem .6rem; border-radius: 8px; color: var(--text); }
.nav a.item:hover { background: var(--bg); text-decoration: none; }
.nav a.item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .sep { border-top: 1px solid var(--line); margin: .75rem 0; }
main { flex: 1; min-width: 0; padding: 1.5rem 2rem 4rem; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.topbar, .tabbar { display: none; }

/* ================= phone layout ================= */
@media (max-width: 800px) {
  .shell { display: block; }
  .nav { display: none; }

  /* slim bar at the top with the business name */
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
    background: var(--panel); border-bottom: 1px solid var(--line);
    padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
  }
  .topbar .brand { font-weight: 700; color: var(--text); }

  /* tab bar fixed to the bottom, clear of the iPhone home indicator */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--panel); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    height: var(--tabbar-h); font-size: .7rem; color: var(--muted); text-decoration: none;
  }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.active { color: var(--accent); font-weight: 600; }

  main { padding: 1rem .85rem calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 1.5rem); }
  h1 { font-size: 1.3rem; }
  .panel { padding: .9rem 1rem; }

  /* 16px text in fields stops iPhone zooming in when you tap a box */
  input, select, textarea { font-size: 16px !important; }
  .btn { padding: .6rem 1rem; min-height: 42px; }
  .btn.small { min-height: 36px; padding: .4rem .75rem; }
  .linkbtn { min-width: 32px; min-height: 32px; }
  .inline input[type=text], .inline input[type=date] { min-width: 0; flex-basis: 100%; }
}

/* "More" page: big tappable list (phone) */
.menu-list a { display: flex; justify-content: space-between; padding: .9rem 1rem; border-bottom: 1px solid var(--line); color: var(--text); }
.menu-list a:last-child { border-bottom: 0; }
.menu-list a::after { content: "›"; color: var(--muted); }

/* ================= panels, grids, tables ================= */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (max-width: 800px) { .grid.stats { grid-template-columns: 1fr 1fr; gap: .6rem; } .grid.stats .panel { margin: 0; } }
.stat .num { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-size: .85rem; }
@media (max-width: 800px) { .stat .num { font-size: 1.2rem; } }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

/* ================= stacked tables (phone) =================
   Add class="stack" to a table and give each <td> a data-label. On a phone each row
   becomes a little card with "Label: value" lines instead of squashed columns. */
@media (max-width: 640px) {
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr.head { display: none; }
  table.stack tr { padding: .6rem 0; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: .15rem 0; text-align: left; }
  table.stack td.num { text-align: left; }
  table.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
  table.stack td:empty { display: none; }
}

/* ================= client cards ================= */
.cards { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }
.client-card { display: flex; gap: .85rem; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; color: var(--text); }
.client-card:hover { border-color: var(--accent); text-decoration: none; }
.avatar { flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.client-card .who { min-width: 0; flex: 1; }
.client-card .name { font-weight: 600; }
.client-card .line { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-card .facts { display: flex; flex-wrap: wrap; gap: .35rem .9rem; margin-top: .45rem; font-size: .85rem; }

/* ================= pipeline board ================= */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.col { background: #efede8; border-radius: var(--radius); padding: .75rem; min-height: 120px; }
@media (max-width: 800px) { .col { min-height: 0; } }
.col h3 { display: flex; justify-content: space-between; }
.card { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; margin-bottom: .5rem; color: var(--text); }
.card:hover { border-color: var(--accent); text-decoration: none; }
.card .t { font-weight: 600; }
/* Renamable column titles and drag and drop (ui/board.tsx, public/js/board-drag.js) */
.board-title { align-items: center; gap: .4rem; position: relative; }
.board-rename summary { list-style: none; cursor: pointer; color: var(--muted); font-weight: 400; font-size: .9rem; padding: 0 .2rem; border-radius: 4px; opacity: .45; }
.board-rename summary::-webkit-details-marker { display: none; }
.board-title:hover .board-rename summary, .board-rename[open] summary, .board-rename summary:focus-visible { opacity: 1; }
.board-rename summary:hover { background: var(--panel); color: var(--accent); }
.board-rename-form { position: absolute; right: 0; top: 1.8rem; z-index: 5; width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .6rem; box-shadow: 0 6px 18px rgba(0,0,0,.08); font-weight: 400; display: grid; gap: .5rem; }
[data-drag-id][draggable=true] { cursor: grab; }
[data-drag-id].is-dragging { opacity: .4; }
[data-drag-id].is-saving { opacity: .65; }
[data-board].is-drag-active [data-drop] { transition: background .1s, outline-color .1s; outline: 2px dashed transparent; outline-offset: -2px; }
[data-board].is-drag-active [data-drop].is-drop-target { background: var(--accent-soft); outline-color: var(--accent); }

/* ================= chart ================= */
.chart { margin: 0; }
.chart figcaption { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .25rem 1rem; margin-bottom: .75rem; }
.chart figcaption h2 { margin: 0; }
.chart-plot { position: relative; height: 180px; margin: 1.4rem 0 0 2.6rem; }
.chart-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.chart-grid span { position: absolute; right: calc(100% + .4rem); top: -.6rem; font-size: .72rem; color: var(--muted); white-space: nowrap; }
.chart-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.chart-col { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; cursor: default; }
.chart-bar { position: relative; width: min(24px, 60%); background: var(--chart); border-radius: 4px 4px 0 0; }
.chart-col:hover .chart-bar, .chart-col:focus .chart-bar { filter: brightness(1.15); }
.chart-tip { position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%); font-size: .72rem; font-weight: 600; color: var(--text); white-space: nowrap; display: none; background: var(--panel); padding: 0 .2rem; border-radius: 3px; }
.chart-tip.always { display: block; }
.chart-col:hover .chart-tip, .chart-col:focus .chart-tip { display: block; z-index: 2; }
.chart-x { display: flex; margin-left: 2.6rem; border-top: 1px solid var(--text); }
.chart-x span { flex: 1; text-align: center; font-size: .72rem; color: var(--muted); padding-top: .3rem; }
/* On narrow phones show every other month label, always keeping the latest month. */
@media (max-width: 480px) { .chart-x span:nth-last-child(even) { visibility: hidden; } }
.chart-table { margin-top: .75rem; font-size: .9rem; }
.chart-table summary { cursor: pointer; color: var(--accent); }

/* ================= line chart ================= */
.lchart-legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .85rem; color: var(--muted); }
.lchart-legend strong { color: var(--text); }
.key { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--chart); vertical-align: middle; margin-right: .2rem; }
.key.prev { border-top: 2px dashed var(--chart-prev); }
.lchart-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.lchart-lines .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lchart-lines .line.now { stroke: var(--chart); }
.lchart-lines .line.prev { stroke: var(--chart-prev); stroke-dasharray: 6 5; }
.lchart .dot { position: absolute; width: 8px; height: 8px; margin: 0 0 -4px -4px; border-radius: 50%; box-shadow: 0 0 0 2px var(--panel); pointer-events: none; }
.lchart .dot.now { background: var(--chart); }
.lchart .dot.prev { background: var(--chart-prev); }
.lchart-peak { position: absolute; transform: translate(-50%, -1.45rem); font-size: .72rem; font-weight: 600; white-space: nowrap; background: var(--panel); padding: 0 .2rem; border-radius: 3px; pointer-events: none; }
.lchart-hits { position: absolute; inset: 0; display: flex; }
.lchart-hit { position: relative; flex: 1; outline: none; }
.lchart-hit::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; border-left: 1px solid var(--muted); opacity: 0; }
.lchart-hit:hover::before, .lchart-hit:focus::before { opacity: .5; }
.lchart-tip { display: none; position: absolute; top: -.5rem; left: 50%; transform: translate(-50%, -100%); z-index: 5;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; font-size: .78rem; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.lchart-hit.left .lchart-tip { left: 0; transform: translate(0, -100%); }
.lchart-hit.right .lchart-tip { left: auto; right: 0; transform: translate(0, -100%); }
.lchart-hit:hover .lchart-tip, .lchart-hit:focus .lchart-tip { display: block; }
.lchart .chart-plot { margin-top: 1.6rem; }

/* ================= forms ================= */
form.stack > * + * { margin-top: .8rem; }
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=time], input[type=number],
input[type=password], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: .8rem; }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline > form { display: inline-flex; margin: 0; }
.inline input[type=text], .inline input[type=date] { width: auto; flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: .4rem; font-weight: 400; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .2rem; }

/* ================= buttons ================= */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center; }
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: .25rem .55rem; font-size: .85rem; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

/* ================= badges & messages ================= */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eee; color: #333; }
.badge.lead { background: #eef4ff; color: #3538cd; }
.badge.booked { background: #ecfdf3; color: var(--ok); }
.badge.completed { background: #f2f4f7; color: #344054; }
.badge.lost { background: #fef3f2; color: var(--danger); }
.badge.due { background: #fffaeb; color: var(--warn); }
.badge.overdue { background: #fef3f2; color: var(--danger); }
.badge.paid { background: #ecfdf3; color: var(--ok); }
.badge.void, .badge.draft { background: #f2f4f7; color: #344054; }
.badge.written_off { background: #f2f4f7; color: #6b7280; text-decoration: line-through; }
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--accent-soft); color: var(--accent); }
.flash.error { background: #fef3f2; color: var(--danger); }
.empty { color: var(--muted); padding: .5rem 0; }
.done { text-decoration: line-through; color: var(--muted); }

/* ================= public pages (login, enquiry form) ================= */
.public { max-width: 560px; margin: 3rem auto; padding: 0 1rem; }
.public .panel { padding: 1.75rem; }
@media (max-width: 800px) {
  .public { margin: 1.25rem auto; }
  .public .panel { padding: 1.25rem; }
  .public input, .public select, .public textarea { font-size: 16px; }
}
.hp { position: absolute; left: -9999px; } /* honeypot field that hides from humans */

/* ================= outreach ================= */
/* Kanban scrolls sideways (one fixed-width column per status) instead of wrapping. */
.kanban { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); overflow-x: auto; padding-bottom: .5rem; scroll-snap-type: x proximity; }
.kanban .col { scroll-snap-align: start; }
@media (max-width: 800px) { .kanban { grid-auto-columns: 82vw; } }
.lead-card { position: relative; padding-right: 2rem; overflow-wrap: anywhere; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lead-card:hover { border-color: var(--line); }
.corner-edit { position: absolute; top: .35rem; right: .4rem; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; color: var(--muted); }
.corner-edit:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.lead-card select.status-select { font-size: .85rem; padding: .25rem .4rem; }
.badge.prio-s { background: #f4ebff; color: #6941c6; }
.badge.prio-a { background: #ecfdf3; color: var(--ok); }
.badge.prio-b { background: #eef4ff; color: #3538cd; }
.badge.prio-c { background: #f2f4f7; color: #344054; }
.lead-table input, .lead-table select { min-width: 0; }
.lead-table .status-select { min-width: 8.5rem; }
.lead-table input[name="contact_name"] { min-width: 7rem; }
.lead-table input[name="email"] { min-width: 11rem; }
.lead-table .btn { white-space: nowrap; }
.nowrap { white-space: nowrap; }
.facts-list { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; margin: 0; }
.facts-list dt { color: var(--muted); }
.facts-list dd { margin: 0; overflow-wrap: anywhere; }
.draft { margin-top: .75rem; }
.draft pre { white-space: pre-wrap; font: inherit; font-size: .9rem; background: #f7f6f3; border-radius: 8px; padding: .6rem .75rem; margin: .4rem 0 0; max-height: 18rem; overflow: auto; }
.msg { position: relative; border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; margin-bottom: .6rem; }
.msg.in { background: var(--accent-soft); border-color: transparent; margin-right: 1.5rem; }
.msg.out { margin-left: 1.5rem; }
.msg-head { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; font-size: .85rem; margin-bottom: .3rem; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-delete { text-align: right; font-size: .75rem; }
.err-text { color: var(--danger); }
.grid.two.lead-grid { grid-template-columns: 1fr; align-items: start; }
@media (min-width: 1000px) {
  .grid.two.lead-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; }
  .lead-grid .lead-convo { grid-column: 2; grid-row: 1 / span 2; }
}

/* ================= sort controls & VIP ================= */
.sort-by { display: inline-flex; align-items: center; gap: .4rem; margin: 0 0 1rem; }
.sort-by label { margin: 0; white-space: nowrap; color: var(--muted); font-size: .85rem; }
.sort-by select { width: auto; max-width: 70vw; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--accent); text-decoration: none; }
th[aria-sort] .sort-link { color: var(--accent); }
.vip-star { color: #7b3fc4; margin-left: .3rem; font-size: .95em; line-height: 1; }
h1 .vip-star { font-size: .8em; vertical-align: .1em; }
.section-head { display: flex; align-items: center; gap: .4rem; margin: 1.25rem 0 .6rem; font-size: 1rem; }
.page-head .actions { align-items: center; }
.page-head .actions form { margin: 0; display: inline-flex; }
/* The VIP button on a client's page: purple with white text, whether or not they're VIP yet
   (the label changes: "☆ Make VIP" / "★ VIP"). */
.btn.vip { background: #7b3fc4; border-color: #7b3fc4; color: #fff; }

/* ================= collapsible sections (ui/section.tsx) ================= */
/* A panel whose title row opens and closes it. The arrow (a rotated border) points
   right when closed and down when open. Only the section's own title row is styled,
   so a <details> nested inside one keeps its normal look. */
details.section > summary { display: flex; align-items: center; gap: .6rem; cursor: pointer; list-style: none; user-select: none; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary h2 { margin: 0; }
details.section > summary::after {
  content: ""; margin-left: auto; width: .5rem; height: .5rem; flex-shrink: 0;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s;
}
details.section[open] > summary::after { transform: rotate(45deg); }
details.section > summary:hover h2, details.section > summary:hover::after { color: var(--accent); border-color: var(--accent); }
details.section > .section-body { margin-top: .9rem; }
/* ================= products on a job ================= */
.items .item { border-top: 1px solid var(--line); padding: .6rem 0; }
.items .item:first-child { border-top: 0; }
.item-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.item-desc { font-size: .85rem; white-space: pre-line; }
.item-tasks { list-style: none; margin: .35rem 0 0; padding: 0 0 0 .1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 0 1rem; }
.item-tasks li { display: flex; align-items: center; gap: .35rem; font-size: .9rem; line-height: 1.6; }
.item-tasks form { display: inline-flex; }
.item-tasks .linkbtn { min-width: 0; min-height: 0; line-height: 1; font-size: 1.05rem; padding: 0; }
@media (max-width: 800px) { .item-tasks li { line-height: 2.1; } .item-tasks .linkbtn { font-size: 1.25rem; } }
.item-tasks .done { text-decoration: line-through; color: var(--muted); }
.item-edit summary { cursor: pointer; font-size: .82rem; margin-top: .3rem; width: max-content; }
table.totals { margin-top: .5rem; border-top: 2px solid var(--line); }
table.totals td { padding: .35rem .25rem; }
/* Quick add (routes/jobItems.tsx + public/js/quick-add.js). The product dropdown or the custom
   name box shows depending on the radio buttons; the description box only shows when
   "+ Description" is ticked. Both work without JavaScript (CSS :has). */
.quick-add-form { margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--line); }
.qa-source { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; margin-bottom: .5rem; }
.quick-add { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.quick-add .qa-product, .quick-add .qa-custom { flex: 1 1 14rem; width: auto; }
.quick-add .qa-qty { display: inline-flex; align-items: center; gap: .3rem; }
.quick-add .qa-qty input { max-width: 4.5rem; }
.quick-add .qa-unit:empty { display: none; }
.quick-add .qa-price { max-width: 6.5rem; }
.quick-add-form:has(input[name="source"][value="custom"]:checked) .qa-product,
.quick-add-form:has(input[name="source"][value="product"]:checked) .qa-custom { display: none; }
.qa-desc-toggle { display: inline-block; margin-top: .5rem; color: var(--accent); font-size: .85rem; font-weight: 500; cursor: pointer; user-select: none; }
.qa-desc-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.qa-desc-toggle:has(input:focus-visible) { outline: 2px solid var(--accent-soft); border-radius: 4px; }
.qa-desc-toggle .when-open, .qa-desc-toggle:has(input:checked) .when-closed { display: none; }
.qa-desc-toggle:has(input:checked) .when-open { display: inline; }
.quick-add-form .qa-desc { display: none; margin-top: .4rem; }
.quick-add-form:has(.qa-desc-toggle input:checked) .qa-desc { display: block; }

/* ================= quotes, invoices and the client pages ================= */
.public.wide { max-width: 860px; }
.doc-sheet { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem 2.25rem; margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
@media (max-width: 800px) { .doc-sheet { padding: 1.25rem 1rem; } }
.doc-head { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.doc-biz { font-weight: 700; font-size: 1.15rem; }
.doc-title { font-size: 1.6rem; font-weight: 700; text-align: right; }
.doc-meta dl { display: grid; grid-template-columns: auto auto; gap: .1rem .9rem; margin: .4rem 0 0; font-size: .9rem; }
.doc-meta dt { color: var(--muted); }
.doc-meta dd { margin: 0; text-align: right; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.25rem; font-size: .95rem; }
@media (max-width: 560px) { .doc-parties { grid-template-columns: 1fr; } .doc-head { flex-direction: column; } .doc-title, .doc-meta dd { text-align: left; } }
.doc-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .2rem; }
.doc-lines { width: 100%; border-collapse: collapse; }
.doc-lines th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--line); padding: .4rem .3rem; }
.doc-lines td { border-bottom: 1px solid var(--line); padding: .55rem .3rem; vertical-align: top; }
.doc-lines .num, .doc-totals .num, .doc-schedule .num { text-align: right; white-space: nowrap; }
.doc-totals { margin: .75rem 0 0 auto; min-width: 16rem; }
.doc-totals td { padding: .2rem .3rem; }
.doc-totals .grand td, .doc-schedule .grand td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--text); padding-top: .4rem; }
.doc-block { margin-top: 1.25rem; }
.doc-block h3 { font-size: .95rem; margin: 0 0 .35rem; }
.doc-schedule { width: 100%; }
.doc-schedule td { padding: .25rem .3rem; }
.doc-schedule tr.paid td { color: var(--ok); }
.doc-schedule tr.written_off td, .doc-schedule tr.void td { color: var(--muted); text-decoration: line-through; }
.doc-extras input[type=checkbox] { width: 1.15rem; height: 1.15rem; vertical-align: -.2rem; }
.doc-stamp { position: absolute; top: 1.25rem; left: 50%; transform: translateX(-50%) rotate(-4deg); border: 3px solid var(--danger); color: var(--danger); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; padding: .2rem .8rem; border-radius: 6px; opacity: .8; }
.doc-stamp.ok { border-color: var(--ok); color: var(--ok); }
/* On a phone the stamp sits beside the "Quote"/"Invoice" title instead of over the business name,
   and the lines table tightens up so the amounts column fits. */
@media (max-width: 560px) {
  .doc-stamp { top: 4.6rem; left: auto; right: 1rem; transform: rotate(-4deg); font-size: .8rem; }
  .doc-lines { font-size: .88rem; }
  .doc-lines th, .doc-lines td { padding-left: .15rem; padding-right: .15rem; }
  .doc-lines th { font-size: .68rem; letter-spacing: .02em; }
}
.pre { white-space: pre-wrap; margin: 0; }
.small { font-size: .82rem; }
.accept-box label { display: block; }
.quote-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
@media (max-width: 1000px) { .quote-grid { grid-template-columns: 1fr; } }
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: .55rem; }
.history li { display: grid; gap: .05rem; }

/* ================= file deliveries ================= */
/* Files page: drop area and upload list (public/js/uploader.js) */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .25rem; min-height: 150px; padding: 1.5rem; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--bg); text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { font-size: 1.1rem; }
.dropzone input[type=file] { display: none; }
.upload-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.upload-list:empty { display: none; }
.upload-list li { display: grid; grid-template-columns: 1fr auto; gap: .1rem .75rem; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: 8px; }
.upload-list .upload-name { font-weight: 600; word-break: break-all; }
.upload-list .upload-meta { grid-column: 1; font-size: .85rem; }
.upload-list .upload-bar { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.upload-list .upload-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-list button { grid-column: 2; grid-row: 1 / 3; align-self: center; }
.upload-list li.is-done .upload-bar span { background: var(--ok); }
.upload-list li.is-failed { border-color: var(--danger); }
.upload-list li.is-failed .upload-meta { color: var(--danger); }
.ok-text { color: var(--ok); }

/* Client download page (routes/delivery.tsx) */
.delivery { max-width: 680px; margin: 0 auto; }
.delivery-head { text-align: center; padding: 1rem 0 1.25rem; }
.delivery-brand { font-size: .8rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: .6rem; }
.delivery-head h1 { font-size: 2rem; letter-spacing: -.01em; }
.delivery-head p { margin: .35rem 0 0; }
.delivery-expiry { background: var(--accent-soft); color: var(--accent); border-radius: var(--radius); padding: .75rem 1rem; text-align: center; margin-bottom: 1rem; }
.delivery-expiry.urgent { background: #fef3f2; color: var(--danger); }
.delivery-message { white-space: pre-wrap; text-align: center; font-size: 1.05rem; margin: 0 0 1.25rem; }
.public .delivery-files { padding: 0; overflow: hidden; }
.delivery-all { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.delivery-files ul { list-style: none; padding: 0; margin: 0; }
.delivery-files li { display: flex; align-items: center; gap: .85rem; padding: .8rem 1.25rem; border-bottom: 1px solid var(--line); }
.delivery-files li:last-child { border-bottom: 0; }
.file-kind { flex-shrink: 0; width: 42px; height: 42px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: .7rem; font-weight: 700; letter-spacing: .04em; }
.file-name { flex: 1; min-width: 0; display: flex; flex-direction: column; word-break: break-all; font-weight: 600; }
.file-name .muted { font-weight: 400; font-size: .85rem; }
.delivery-foot { text-align: center; font-size: .85rem; margin-top: 1.25rem; }
@media (max-width: 800px) {
  .delivery-head h1 { font-size: 1.5rem; }
  .delivery-files li, .delivery-all { padding: .75rem 1rem; }
  .delivery-all .btn { width: 100%; }
}
