/* ============================================================
   Homepay legal docs — base styles
   Brand palette from hp-share (navy #102E42, teal #75A6A6, sage #EEF3EA).
   Light theme only. Mobile-first; readable measure (~75ch); print (spec §5.3).
   ============================================================ */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f7f6f2;
  --border: #e0ddd6;
  --text: #2c2c2a;
  --muted: #5f5e5a;
  --brand: #102e42;
  --brand-contrast: #ffffff;
  --brand-muted: #a9cccc; /* teal tint, AA on navy */
  --accent: #2f6f6f; /* teal darkened for AA contrast on white */
  --accent-soft: #eef3ea;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --info-bg: #e6f0f5;
  --info-text: #0d3a55;
  --ok-bg: #eaf3de;
  --ok-text: #2f5a0d;
  --ins-bg: #dff3d8;
  --del-bg: #fbe0e0;
  --measure: 75ch;
  /* One page width in rem for header, content and footer. A width in ch would
     follow each block's own font size and misalign the smaller footer text. */
  --page: 48rem;
  --gutter: 1.25rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body > main { flex: 1 0 auto; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
h1, h2, h3, h4 { color: var(--brand); line-height: 1.3; }
h1 { font-size: 1.9rem; letter-spacing: -0.01em; margin: .5rem 0 .75rem; }

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 1rem; top: 1rem; background: var(--bg); padding: .5rem 1rem; z-index: 10; }

/* Header, main content and footer share one box, so their edges line up. */
.wrap, .site-header .bar, .site-footer .bar {
  width: 100%;
  max-width: calc(var(--page) + 2 * var(--gutter));
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}
.wrap { padding-top: 1.75rem; padding-bottom: 3rem; }
/* Admin tables need more room; header and content widen together. */
body:has(main.admin) { --page: 72rem; }

/* ── Site header / footer ── */
.site-header { background: var(--brand); color: var(--brand-contrast); }
.site-header .bar { padding-top: .8rem; padding-bottom: .8rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 650; color: var(--brand-contrast); text-decoration: none; letter-spacing: -0.01em; }
.brand span { color: var(--brand-muted); font-weight: 400; margin-left: .2rem; }
.lang-switch { display: flex; gap: .25rem; font-size: 14px; }
/* Tap targets of at least 32×32 px (WCAG 2.5.8 asks for 24). */
.lang-switch a { display: inline-flex; align-items: center; justify-content: center; min-width: 2.25rem; min-height: 2rem; padding: 0 .4rem; border-radius: 6px; color: var(--brand-muted); text-decoration: none; }
.lang-switch a:hover { color: var(--brand-contrast); }
.lang-switch a[aria-current='true'] { font-weight: 600; color: var(--brand); background: var(--brand-contrast); }
.site-header a:focus-visible { outline-color: var(--brand-contrast); }
.site-footer { background: var(--surface); border-top: 1px solid var(--border); color: var(--muted); font-size: 14px; }
.site-footer .bar { padding-top: 1.25rem; padding-bottom: 1.25rem; }
.site-footer p { margin: 0; }

/* ── Document header ── */
.doc-meta { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; color: var(--muted); font-size: 15px; margin-bottom: 1rem; }
.badge { display: inline-block; font-size: 13px; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; }
.badge-in_force { background: var(--ok-bg); color: var(--ok-text); }
.badge-scheduled { background: var(--info-bg); color: var(--info-text); }
.badge-superseded { background: var(--warn-bg); color: var(--warn-text); }
.badge-draft, .badge-withdrawn { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }

.banner { border-radius: 8px; padding: .75rem 1rem; margin: 0 0 1.25rem; }
.banner-warn { background: var(--warn-bg); color: var(--warn-text); }
.banner-info { background: var(--info-bg); color: var(--info-text); }
.banner a { color: inherit; font-weight: 600; }

/* ── TOC ── */
.toc { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem 1rem; margin-bottom: 1.5rem; font-size: 15px; }
.toc summary { cursor: pointer; font-weight: 600; padding: .25rem 0; }
.toc ol { list-style: none; padding-left: 0; margin: .5rem 0; }
.toc li { margin: .2rem 0; }
.toc li.lvl-2 { padding-left: 1rem; }
.toc li.lvl-3 { padding-left: 2rem; }

/* ── Legal body ── */
.legal-body { max-width: var(--measure); overflow-wrap: break-word; }
.legal-body > :first-child { margin-top: 0; }
.legal-body h1 { font-size: 1.5rem; }
.legal-body h2 { font-size: 1.25rem; margin-top: 2rem; }
.legal-body h3 { font-size: 1.1rem; }
.legal-body .table-wrap { overflow-x: auto; max-width: 100%; }
.legal-body table { border-collapse: collapse; min-width: 100%; font-size: 15px; }
.legal-body th, .legal-body td { border: 1px solid var(--border); padding: .4rem .6rem; text-align: left; vertical-align: top; }
.legal-body p, .legal-body li { text-wrap: pretty; }
.legal-body .clause { scroll-margin-top: 1rem; }
/* Clause structure: articles stand out, sub-clauses indent by depth
   (classes added at render time, lib/render/clauses.ts). */
.legal-body .clause.title { font-weight: 650; color: var(--brand); margin-top: 1.75rem; margin-bottom: .5rem; break-after: avoid; }
.legal-body .clause.d3 { padding-left: 1.5rem; }
.legal-body .clause.d4 { padding-left: 3rem; }
.legal-body .clause.d5, .legal-body .clause.d6 { padding-left: 4.5rem; }
@media (max-width: 480px) {
  .legal-body .clause.d3 { padding-left: 1rem; }
  .legal-body .clause.d4 { padding-left: 2rem; }
  .legal-body .clause.d5, .legal-body .clause.d6 { padding-left: 2.5rem; }
}
/* Copy-link: shown on hover or keyboard focus only, so it doesn't clutter
   the text. On touch screens it stays hidden (the URL can be shared). */
.legal-body .clause-link { margin-left: .4rem; font-size: .8em; text-decoration: none; opacity: 0; transition: opacity .15s; }
.legal-body .clause:hover .clause-link, .legal-body .clause-link:focus-visible { opacity: .7; }
@media (hover: none) { .legal-body .clause-link:not(:focus-visible) { display: none; } }
.legal-body .placeholder { background: var(--warn-bg); color: var(--warn-text); border-radius: 4px; padding: 0 .3rem; font-family: ui-monospace, monospace; font-size: .9em; }

/* ── Lists / tables in chrome ── */
.doc-list { list-style: none; padding: 0; }
.doc-list li { border-bottom: 1px solid var(--border); padding: .75rem 0; }
.version-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.version-table th, .version-table td { padding: .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.scroll-x { overflow-x: auto; }

.hash { font-family: ui-monospace, monospace; font-size: 13px; }

/* ── Admin / forms ── */
.card { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem; margin-bottom: 1.25rem; }
.card > :first-child { margin-top: 0; }
.btn-primary, .btn-secondary, .btn-danger { font: inherit; font-size: 15px; border-radius: 8px; padding: .55rem 1rem; cursor: pointer; border: 1px solid transparent; }
.btn-primary { background: #102e42; color: #fff; }
.btn-secondary { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-danger { background: #8a1c1c; color: #fff; }
button:disabled { opacity: .5; cursor: default; }
.field { display: grid; gap: .3rem; margin-bottom: 1rem; }
.field label { font-size: 14px; font-weight: 600; }
.field input, .field select, .field textarea { font: inherit; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.form-error { color: #b42318; }
.report { font-size: 14px; }
.report .error { color: #b42318; }
.report .warning { color: var(--warn-text); }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 1rem; }
.login-title { font-size: 1.1rem; margin: 0; }
.login-title span { color: var(--muted); font-weight: 400; }

/* ── Print / PDF: the same stylesheet drives PDF generation ── */
/* A4, as Italian legal documents are printed. */
@page { size: A4; margin: 18mm 16mm; }

@media print {
  :root { --bg: #fff; --text: #000; --muted: #333; --brand: #000; --border: #999; }
  body { font-size: 11pt; }
  .site-header .lang-switch, .toc, .clause-link, .no-print, .skip-link { display: none !important; }
  .site-header, .site-footer { background: none; color: #000; border: 0; }
  .brand, .brand span { color: #000; }
  .legal-body { max-width: none; }
  .legal-body h2, .legal-body h3 { break-after: avoid; }
  .legal-body table { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* ── Document footer (links, hash) ── */
.doc-footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 15px; }
.doc-links { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.doc-footer .btn-secondary { font-size: 13px; padding: .2rem .6rem; margin-left: .4rem; }
[data-copied='true']::after { content: ' ✓'; }

/* ── Changelog / redline ── */
.changelog { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem 1rem; margin-bottom: 1.25rem; }
.changelog summary { cursor: pointer; font-weight: 600; }
.diff-summary { padding-left: 1.2rem; }
.diff-block { margin: .6rem 0; padding: .15rem 0; }
/* Changed blocks: the bar sits in the left gutter so text stays aligned. */
.diff-block[class*='op-'] { margin-left: -.85rem; padding: .3rem .6rem .3rem calc(.85rem - 3px); border-left: 3px solid transparent; }
del + ins { margin-left: .2em; }
.diff-block.op-added { border-color: #2f7a2f; background: var(--ins-bg); }
.diff-block.op-removed { border-color: #a12a2a; background: var(--del-bg); }
.diff-block.op-modified, .diff-block.op-moved, .diff-block.op-renumbered { border-color: var(--accent); }
.diff-note { display: block; font-size: 13px; color: var(--muted); }
ins { background: var(--ins-bg); text-decoration: underline; text-decoration-thickness: 1px; }
del { background: var(--del-bg); text-decoration: line-through; }
.diff-block.op-added ins, .diff-block.op-removed del { background: none; }
.diff-label { font-weight: 600; margin-right: .3rem; }
@media print { .diff-block { break-inside: avoid; } }
