/* One hand-written stylesheet, served by the application: no CDN, no build step
   (research R23, FR-045). Desktop browser only.

   Layered on purpose: tokens, then elements, then the shell, then components.
   A screen composes components; it never invents a colour or a spacing value. */

/* ---------------------------------------------------------------- tokens -- */

:root {
  --ink: #1a1f26;
  --ink-soft: #45505d;
  --muted: #6b7684;
  --line: #dde2e8;
  --line-soft: #eaeef2;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-sunk: #f8fafb;

  --accent: #12507a;
  --accent-ink: #0d3a59;
  --accent-soft: #e7f0f6;

  --warn: #a06a00;
  --warn-bg: #fff6e3;
  --warn-line: #e2a600;
  --danger: #a3231c;
  --danger-bg: #fdecea;
  --danger-line: #d0453c;
  --ok: #1f6b3a;
  --ok-bg: #e9f4ec;
  --ok-line: #56a06f;

  /* Spacing rhythm: everything is a multiple of 4px. */
  --s1: .25rem;
  --s2: .5rem;
  --s3: .75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;

  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .06), 0 1px 3px rgba(20, 30, 45, .04);
  --ring: 0 0 0 3px rgba(18, 80, 122, .28);
}

* { box-sizing: border-box; }

/* --------------------------------------------------------------- elements -- */

body {
  margin: 0;
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-ink); }

h1 { font-size: 1.45rem; line-height: 1.25; margin: 0 0 var(--s1); letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 var(--s2); letter-spacing: -.005em; }
h3 { font-size: .95rem; margin: 0 0 var(--s2); }

p { margin: 0 0 var(--s3); }
main > p:last-child { margin-bottom: 0; }

/* A visible, consistent focus ring everywhere — the keyboard is how a queue of
   forty accounts actually gets worked through. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ------------------------------------------------------------------ shell -- */

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: var(--s2) var(--s4);
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: var(--s5) var(--s4) 4rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s4);
  padding: 0 var(--s4); background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar nav { display: flex; gap: var(--s1); align-items: stretch; flex-wrap: wrap; }
.topbar nav a {
  text-decoration: none; color: var(--ink-soft); padding: var(--s3) var(--s3);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.topbar nav a:hover { color: var(--accent); background: var(--panel-sunk); }
.topbar nav a[aria-current="page"] {
  color: var(--accent); border-bottom-color: var(--accent); font-weight: 600;
}
.topbar .brand {
  font-weight: 700; color: var(--ink); margin-right: var(--s3);
  border-bottom-color: transparent !important;
}
.topbar .brand:hover { background: none; }
.topbar-right { display: flex; gap: var(--s3); align-items: center; }
.who { color: var(--muted); font-size: .9rem; }

.freshness {
  padding: var(--s2) var(--s4); background: var(--panel-sunk);
  border-bottom: 1px solid var(--line); color: var(--muted); font-size: .87rem;
}
.freshness-stale {
  background: var(--warn-bg); border-bottom-color: var(--warn-line); color: var(--ink);
}
.freshness-stale strong { color: var(--warn); }

/* --------------------------------------------------------------- messages -- */

.messages { list-style: none; padding: 0; margin: 0 0 var(--s4); }
.message {
  padding: var(--s3) var(--s4); border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius); margin-bottom: var(--s2); border-left-width: 4px;
}
.message.error { background: var(--danger-bg); border-color: var(--danger-line); }
.message.success { background: var(--ok-bg); border-color: var(--ok-line); }
.message.warning { background: var(--warn-bg); border-color: var(--warn-line); }
.message ul { margin: var(--s1) 0 0; padding-left: 1.1rem; }

/* ----------------------------------------------------------------- panels -- */

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--s4); margin-bottom: var(--s4); box-shadow: var(--shadow);
}
.panel > :last-child { margin-bottom: 0; }
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3);
  margin-bottom: var(--s3);
}
.panel-head > * { margin-bottom: 0; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-flush .panel-head { padding: var(--s4) var(--s4) var(--s3); margin-bottom: 0; }
.panel-flush table { border-radius: 0; }

/* The account screen's primary action gets the only tinted panel on the page. */
.panel-primary { border-color: var(--accent); border-top: 3px solid var(--accent); }

/* A `<details>` that looks like a panel until you open it. */
.disclosure {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: var(--s4);
}
.disclosure > summary {
  padding: var(--s3) var(--s4); cursor: pointer; font-weight: 600; font-size: .95rem;
  color: var(--ink-soft); list-style: none; display: flex; align-items: center; gap: var(--s2);
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before {
  content: "▸"; color: var(--muted); font-size: .85em; transition: transform .12s ease;
}
.disclosure[open] > summary::before { transform: rotate(90deg); }
.disclosure > summary:hover { color: var(--accent); }
.disclosure .disclosure-body {
  padding: 0 var(--s4) var(--s4); border-top: 1px solid var(--line-soft); padding-top: var(--s4);
}
.disclosure .disclosure-body > :last-child { margin-bottom: 0; }

/* ------------------------------------------------------------------ stats -- */

/* The account and overview headline figures: scannable at arm's length. */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 1px; background: var(--line-soft); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; margin-bottom: var(--s4);
}
.stat { background: var(--panel); padding: var(--s3) var(--s4); }
.stat dt {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); margin-bottom: var(--s1);
}
.stat dd { margin: 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat dd .sub { display: block; font-size: .82rem; font-weight: 400; color: var(--muted); }
.stat-lead dd { font-size: 1.5rem; color: var(--accent-ink); }

/* ----------------------------------------------------------------- tables -- */

table { border-collapse: collapse; width: 100%; background: var(--panel); }
.panel > table:only-child, .panel-flush table { margin: 0; }

th, td {
  text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
thead th {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; background: var(--panel-sunk); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1;
}
tbody tr:hover td { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* The queue's sort key, drawn. The order is a product of the amount and the
   age, so a list sorted by it looks unsorted by either column on screen: the
   bar is the only thing that makes the sequence read as a sequence. */
th.stake, td.stake { width: 5.5rem; }
td.stake { vertical-align: middle; }
.stake-bar {
  background: var(--line-soft); border-radius: 999px; height: .45rem; overflow: hidden;
}
.stake-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* A table row's own empty state, and page-level empty states. */
.empty { padding: var(--s6) var(--s4); text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink-soft); font-size: 1.05rem; margin-bottom: var(--s1); }

/* ------------------------------------------------------------------- text -- */

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.nowrap { white-space: nowrap; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-lead { font-weight: 600; }
.lede { color: var(--ink-soft); max-width: 62ch; }
.page-head { margin-bottom: var(--s4); }
.page-head .lede { margin-bottom: 0; }

/* ------------------------------------------------------------------ pills -- */

.pill {
  display: inline-block; padding: .1rem .45rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; line-height: 1.5;
  background: var(--panel-sunk); color: var(--ink-soft); border: 1px solid var(--line);
  white-space: nowrap;
}
.pill-tracked { background: var(--accent-soft); color: var(--accent-ink); border-color: #b9d3e4; }
.pill-settled { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.pill-step { background: var(--accent-soft); color: var(--accent-ink); border-color: #b9d3e4; font-weight: 600; }
.pill-pending { background: var(--panel-sunk); color: var(--muted); }
.pill-partial { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }

.tag {
  display: inline-block; padding: 0 .35rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: .8rem; color: var(--muted); background: var(--bg);
}

/* ------------------------------------------------------------------ forms -- */

form.inline { display: inline-flex; gap: var(--s2); align-items: center; }
button, input, select, textarea { font: inherit; }

button {
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: var(--radius-sm); padding: .4rem .9rem; cursor: pointer; font-weight: 500;
  white-space: nowrap;
}
button:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
button.secondary { background: var(--panel); color: var(--accent); border-color: var(--line); }
button.secondary:hover { background: var(--accent-soft); border-color: var(--accent); }
button.link {
  background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline;
  font-weight: 400;
}
button.link:hover { background: none; color: var(--accent-ink); }
button.small { padding: .2rem .55rem; font-size: .85rem; }
button.ghost { background: none; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--panel-sunk); color: var(--ink); border-color: var(--line); }

/* A link that must look like a button: the queue's row actions are links so
   they still work as navigation when htmx is unavailable. */
.btn {
  display: inline-block; text-decoration: none; font-weight: 500; font-size: .85rem;
  padding: .2rem .6rem; border-radius: var(--radius-sm); white-space: nowrap;
  border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer;
}
.btn:hover { background: var(--accent-ink); border-color: var(--accent-ink); color: #fff; }

input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=search], select, textarea {
  padding: .4rem .5rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; min-height: 3.5rem; resize: vertical; }
label { display: inline-block; margin-bottom: var(--s1); }
.field { margin-bottom: var(--s3); }
/* The label sits on its own line, above what it names — a field must never be
   pushed sideways by the length of its own label, and then cropped. */
.field > label, .field > label:first-child {
  display: block; font-weight: 600; font-size: .87rem; color: var(--ink-soft);
}
.field > input[type=text], .field > input[type=email], .field > input[type=password],
.field > textarea, .field > select { width: 100%; }
.errorlist { color: var(--danger); list-style: none; padding: 0; margin: var(--s1) 0; font-size: .87rem; }
.helptext { display: block; color: var(--muted); font-size: .85rem; margin-top: var(--s1); }

/* Radio groups read as a row of choices, not a stacked list. */
.field ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: var(--s3); }
.field ul li { display: flex; align-items: center; gap: var(--s1); }
.field ul li label { margin: 0; font-weight: 400; font-size: 1rem; color: var(--ink); }
.field input[type=radio] { margin: 0; }

/* The two outcomes of the follow-up form, side by side and held apart by a
   rule that reads as « ou ». Sending R2 and sending nothing are not two
   neighbouring answers to one question — but stacking the second under a
   separator made it belong to nothing at all. */
.step-choice { display: flex; flex-wrap: wrap; align-items: stretch; gap: var(--s3) var(--s4); }
.field .step-choice ul { margin: 0; align-items: center; }
.field ul.step-none {
  padding-left: var(--s4); border-left: 2px solid var(--line-soft);
}
.field ul.step-none li label { color: var(--ink-soft); }

/* The invoices, the date and the note: three short fields, read side by side.
   Stacked, they made the sheet taller than the queue it opens over — it
   covered the very list it exists to leave in view. */
.form-split {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr) minmax(0, 1fr);
  gap: var(--s4); align-items: start;
}
.form-split textarea { min-height: 5.2rem; }
/* One invoice: it is stated above rather than asked, so the row is two. */
.form-split-2 { grid-template-columns: minmax(0, .9fr) minmax(0, 1fr); }
@media (max-width: 1000px) { .form-split { grid-template-columns: 1fr 1fr; } }
@media (max-width: 720px) { .form-split, .form-split-2 { grid-template-columns: 1fr; } }

/* A field that states a fact instead of asking for one. */
.field-inline { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--s2); }
.field-inline > label { margin-bottom: 0; }
.field-inline .stated { font-variant-numeric: tabular-nums; }

/* Invoices are ticked one per line: each carries its amount, its date and the
   step it has reached, which is what decides whether it belongs in this mail. */
.field.checkboxes ul { display: block; }
.field.checkboxes ul li { padding: .15rem 0; }
.field.checkboxes ul li label { font-variant-numeric: tabular-nums; }

/* The ready-made delays, one per line, and the free date on the line of the
   option it belongs to — never floating beside the list. */
.field ul.when { display: block; }
/* The option keeps its wording on one line and lets the date input drop below
   it instead: broken mid-label, « à une date / précise : » reads as two rows. */
.field ul.when li { padding: .15rem 0; gap: var(--s2); flex-wrap: wrap; }
.field ul.when li label { white-space: nowrap; }
.field ul.when input[type=date] { margin-left: var(--s1); }

.form-actions { display: flex; gap: var(--s2); align-items: center; margin-top: var(--s4); }

.search-bar { display: flex; gap: var(--s2); align-items: flex-end; }
.search-bar .field { flex: 1; margin-bottom: 0; }
.search-bar input { width: 100%; }

/* ---------------------------------------------------------------- history -- */

.history { list-style: none; padding: 0; margin: 0; }
.history > li {
  border-left: 3px solid var(--line); padding: var(--s2) var(--s3); margin-bottom: var(--s2);
  background: var(--panel-sunk); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.history > li { border-left-color: var(--accent); }
/* A postponement is an entry, not a rung: it reads apart from the reminders. */
.history > li.postponed { border-left-color: var(--line); }
.entry-meta { color: var(--muted); font-size: .85rem; margin-bottom: var(--s1); }
.history form { margin-top: var(--s2); display: flex; gap: var(--s2); }
.history form input[type=text] { flex: 1; }

/* -------------------------------------------------------- queue act sheet -- */

/* FR-028: the queue is where the day is worked. Acting on a row must not cost a
   page load — but every control degrades to a link to the account screen when
   JavaScript is unavailable, so no screen depends on the fragment path.

   Anchored to the foot of the viewport rather than opened between two rows:
   inline, the form pushed the rest of the day half a screen down and the
   ordering the queue exists to show scrolled away the moment it was used. */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--panel); border-top: 3px solid var(--accent);
  box-shadow: 0 -4px 16px rgba(20, 30, 45, .13);
  max-height: 72vh; overflow-y: auto;
}
.sheet[hidden] { display: none; }
.sheet-body { max-width: 1180px; margin: 0 auto; padding: var(--s3) var(--s4) var(--s4); }
.sheet .form-actions { margin-top: var(--s3); }
.sheet-head {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--s3);
  margin-bottom: var(--s3); padding-bottom: var(--s2);
  border-bottom: 1px solid var(--line-soft);
}
.sheet-head h3 { color: var(--accent-ink); font-size: 1.05rem; margin: 0; }
.sheet-head .amount-lead { color: var(--ink); }
.sheet-head a { margin-left: auto; }
.sheet-close {
  align-self: center; background: none; border: 1px solid transparent;
  color: var(--muted); font-size: 1.5rem; line-height: 1; font-weight: 400;
  padding: 0 var(--s2); border-radius: var(--radius-sm); cursor: pointer;
}
.sheet-close:hover {
  background: var(--panel-sunk); color: var(--ink); border-color: var(--line);
}

.htmx-request .spinner { visibility: visible; }
.spinner { visibility: hidden; color: var(--muted); font-size: .85rem; }

/* ------------------------------------------------------------------ misc -- */

.login { max-width: 22rem; margin: 4rem auto; }
.login h1 { text-align: center; margin-bottom: var(--s4); }
.login button[type=submit] { width: 100%; }

.counts { list-style: none; padding: 0; margin: 0; }
.counts li {
  padding: var(--s2) 0; border-bottom: 1px solid var(--line-soft);
  display: flex; justify-content: space-between; gap: var(--s4);
}
.counts li:last-child { border-bottom: none; }

.plain-list { margin: 0; padding-left: 1.15rem; }
.plain-list li { margin-bottom: var(--s1); }

.section-label {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 600; padding: var(--s3) var(--s3) var(--s2); background: var(--panel-sunk);
}

@media (max-width: 900px) {
  main { padding: var(--s4) var(--s3) 3rem; }
  .topbar { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
