@font-face {
  font-family: "Manrope";
  src: url("assets/fonts/manrope/Manrope-VariableFont_wght.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
}

/* ==========================================================================
   Crayon Media admin - dashboard styles
   Brand tokens mirrored from ../styles.css so the two stay recognisably one
   family. This is a dense application UI, not a marketing page, so the
   marketing stylesheet is deliberately not reused.
   ========================================================================== */

:root {
  --charcoal: #0E0F11;
  --cream: #FAF9F5;
  --field: #F1EEE8;
  --blue: #3B82F6;
  --blue-dark: #2563EB;
  --blue-tint: rgba(59, 130, 246, 0.10);
  --white: #FFFFFF;
  --light-grey: #DBD2C7;
  --mid-grey: #6B6B6B;
  --star: #FBBC04;
  --danger: #DC2626;
  --danger-tint: rgba(220, 38, 38, 0.08);
  --warn: #B45309;
  --warn-tint: rgba(251, 188, 4, 0.14);
  --ok: #15803D;

  --font-head: "Manrope", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;

  --shadow-soft: 0 1px 2px rgba(14, 15, 17, 0.04), 0 6px 20px rgba(14, 15, 17, 0.06);
  --shadow-lift: 0 2px 4px rgba(14, 15, 17, 0.05), 0 14px 36px rgba(14, 15, 17, 0.12);

  --sidebar-w: 240px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--cream);
  color: var(--charcoal);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 700; line-height: 1.2; }

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--white);
  border-color: var(--light-grey);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), opacity 0.15s;
}
.btn:hover { background: var(--field); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn--primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--mid-grey); }
.btn--ghost:hover { background: var(--field); color: var(--charcoal); }
.btn--sm { padding: 6px 10px; font-size: 12px; }
.btn .icon { width: 15px; height: 15px; }

/* ---------- Login ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--charcoal);
  padding: 24px;
}
.login__card {
  width: 100%;
  max-width: 360px;
  background: var(--cream);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lift);
}
.login__mark { font-family: var(--font-head); font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }
.login__sub { color: var(--mid-grey); font-size: 13px; margin: 6px 0 22px; }
.login__card form { display: grid; gap: 12px; }

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

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--charcoal);
  color: rgba(255, 255, 255, 0.62);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__mark {
  color: var(--white);
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  padding: 4px 10px;
}
.sidebar__mark span { color: var(--blue); }
.sidebar__nav { display: grid; gap: 2px; }
.sidebar__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: rgba(255, 255, 255, 0.34);
  padding: 10px 10px 4px;
  font-family: var(--font-head);
  font-weight: 700;
}
.navitem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 500;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.navitem:hover:not(:disabled) { background: rgba(255, 255, 255, 0.07); color: var(--white); }
.navitem[aria-current="page"] { background: var(--blue); color: var(--white); }
.navitem:disabled { opacity: 0.32; cursor: default; }
.navitem .icon { width: 16px; height: 16px; flex: none; }
.navitem__soon {
  margin-left: auto;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.8;
}
.sidebar__foot { margin-top: auto; display: grid; gap: 2px; }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--light-grey);
  background: var(--cream);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 17px; }
.topbar__spacer { margin-left: auto; }

.content { padding: 24px 28px 120px; display: grid; gap: 20px; max-width: 1120px; width: 100%; }

/* ---------- Compose ---------- */

.compose {
  background: var(--white);
  border: 1px solid var(--light-grey);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}
.compose__head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.compose__head h2 { font-size: 14px; }
.compose__head .icon { width: 16px; height: 16px; color: var(--blue); }
.compose__hint { color: var(--mid-grey); font-size: 12px; margin-left: auto; }
.compose textarea {
  width: 100%;
  min-height: 74px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--light-grey);
  border-radius: var(--radius);
  background: var(--field);
  font-size: 14px;
}
.compose textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; background: var(--white); }
.compose__actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.compose__examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px dashed var(--light-grey);
  background: transparent;
  color: var(--mid-grey);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { border-style: solid; border-color: var(--blue); color: var(--blue); background: var(--blue-tint); }

/* ---------- List view ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat {
  background: var(--white);
  border: 1px solid var(--light-grey);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat__label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--mid-grey); font-family: var(--font-head); font-weight: 700;
}
.stat__value {
  font-family: var(--font-head); font-weight: 800; font-size: 22px;
  letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums;
}
.stat--alert .stat__value { color: var(--danger); }

.listbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--mid-grey); cursor: pointer; margin-left: auto; }

.group { margin-bottom: 22px; }
.group__head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 0 4px 8px; border-bottom: 1px solid var(--light-grey); margin-bottom: 2px;
}
.group__head h3 { font-size: 14px; }
.group__meta { margin-left: auto; font-size: 12px; color: var(--mid-grey); font-variant-numeric: tabular-nums; }

table.rows { width: 100%; border-collapse: collapse; background: var(--white);
  border: 1px solid var(--light-grey); border-radius: var(--radius); overflow: hidden; }
table.rows th {
  text-align: left; font-family: var(--font-head); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--mid-grey);
  padding: 10px 12px; background: var(--field); border-bottom: 1px solid var(--light-grey);
}
table.rows td { padding: 11px 12px; border-bottom: 1px solid var(--light-grey); }
table.rows tr:last-child td { border-bottom: none; }
table.rows tbody tr { cursor: pointer; }
table.rows tbody tr:hover { background: var(--field); }
table.rows .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.rows .who { font-weight: 600; font-family: var(--font-head); }
.rowlink { font-variant-numeric: tabular-nums; font-weight: 600; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; font-family: var(--font-head);
  text-transform: capitalize; white-space: nowrap;
}
.pill--draft   { background: var(--field);      color: var(--mid-grey); }
.pill--sent    { background: var(--blue-tint);  color: var(--blue-dark); }
.pill--partial { background: var(--warn-tint);  color: var(--warn); }
.pill--paid    { background: rgba(21,128,61,0.12);  color: var(--ok); }
.pill--overdue { background: var(--danger-tint); color: var(--danger); }
.pill--void    { background: var(--field); color: var(--mid-grey); text-decoration: line-through; }

.empty { text-align: center; padding: 48px 20px; color: var(--mid-grey); }
.empty h3 { font-size: 15px; margin-bottom: 6px; color: var(--charcoal); }

.invnum { font-weight: 700; font-family: var(--font-head); }

/* ---------- Modal variant of the drawer ---------- */

.drawer.drawer--center { place-items: center; justify-content: center; }
.drawer__panel.drawer__panel--modal {
  height: auto; max-height: 88vh; width: min(400px, 94vw);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lift);
  padding: 22px;
}
.paidrow {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-top: 1px solid var(--light-grey); font-size: 12px;
}
.paidrow .num { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Notices ---------- */

.notice {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.notice .icon { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.notice--warn { background: var(--warn-tint); color: var(--warn); }
.notice--error { background: var(--danger-tint); color: var(--danger); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.notice strong { font-family: var(--font-head); }

/* ---------- Invoice tabs (one per drafted client) ---------- */

.drafttabs { display: flex; flex-wrap: wrap; gap: 6px; }
.drafttab {
  border: 1px solid var(--light-grey);
  background: var(--white);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-head);
  cursor: pointer;
}
.drafttab[aria-selected="true"] { background: var(--charcoal); border-color: var(--charcoal); color: var(--white); }

/* ---------- Invoice sheet (this is what prints) ---------- */

.sheet {
  background: var(--white);
  border: 1px solid var(--light-grey);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  /* A4 portrait at 1:1 so the preview is the printed page, not an approximation. */
  width: 210mm;
  min-height: 297mm;
  padding: 16mm;
  margin: 0 auto;
  transform-origin: top center;
}

/* Scale the page down rather than reflow it, so proportions stay true. */
@media (max-width: 1180px) {
  .sheet { transform: scale(0.86); margin-bottom: -6rem; }
}
@media (max-width: 1040px) {
  .sheet { transform: scale(0.72); margin-bottom: -12rem; }
}

.sheet__top { display: flex; justify-content: space-between; gap: 32px; align-items: flex-start; }
.sheet__brand { font-family: var(--font-head); font-weight: 800; font-size: 22px; letter-spacing: -0.02em; }
.sheet__brand span { color: var(--blue); }
.sheet__from { color: var(--mid-grey); font-size: 12px; margin-top: 6px; white-space: pre-line; }
.sheet__title { text-align: left; }
.sheet__title h2 { font-size: 26px; letter-spacing: -0.02em; }
.sheet__meta { margin-top: 10px; display: grid; gap: 4px; font-size: 12px; }
.sheet__meta div { display: grid; grid-template-columns: 92px 1fr; gap: 10px; align-items: baseline; }
.sheet__meta dt { color: var(--mid-grey); }
.sheet__meta dd { font-weight: 600; text-align: left; }

.sheet__parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 30px 0 22px; }
.sheet__partylabel {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--mid-grey);
  font-family: var(--font-head);
  font-weight: 700;
  margin-bottom: 6px;
}

table.lines { width: 100%; border-collapse: collapse; }
table.lines th {
  text-align: left;
  font-family: var(--font-head);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--mid-grey);
  padding: 0 8px 8px;
  border-bottom: 1px solid var(--charcoal);
}
table.lines td { padding: 9px 8px; border-bottom: 1px solid var(--light-grey); vertical-align: top; }
table.lines th:first-child, table.lines td:first-child { padding-left: 0; }
table.lines th.num, table.lines td.num { text-align: right; white-space: nowrap; }
table.lines td.num { font-variant-numeric: tabular-nums; }
table.lines .rowdel { padding-right: 0; width: 30px; }

.sheet__foot { display: grid; grid-template-columns: 1fr minmax(240px, 300px); gap: 32px; margin-top: 26px; }
.totals { display: grid; gap: 6px; align-content: start; }
.totals div { display: flex; justify-content: space-between; gap: 16px; font-size: 13px; }
.totals .grand {
  border-top: 2px solid var(--charcoal);
  margin-top: 6px;
  padding-top: 10px;
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 17px;
}
.totals .num { font-variant-numeric: tabular-nums; }
.payblock { font-size: 12px; }
.payblock h4 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--mid-grey); margin-bottom: 6px; }
.payblock p { white-space: pre-line; }
.payblock + .payblock { margin-top: 16px; }

/* Editable fields inside the sheet: invisible until touched, so the preview
   reads as a document rather than a form, but every value stays correctable. */
.f {
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  padding: 3px 5px;
  margin: -3px -5px;
  width: 100%;
  font: inherit;
  color: inherit;
}
.f:hover { background: var(--field); }
.f[readonly] { cursor: default; }
.f[readonly]:hover { background: transparent; }
textarea.f[readonly] { resize: none; }
.f:focus { outline: none; background: var(--white); border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-tint); }
.f.num { text-align: right; font-variant-numeric: tabular-nums; }
.sheet__meta .f { text-align: left; }
.f::placeholder { color: var(--light-grey); }
.f--missing { background: var(--warn-tint); border-color: rgba(180, 83, 9, 0.35); }
textarea.f { resize: vertical; min-height: 2.6em; }
.f--brand { font: inherit; font-family: var(--font-head); }

/* ---------- Sticky action bar ---------- */

.actionbar {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-w);
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: rgba(250, 249, 245, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--light-grey);
  z-index: 6;
}
.actionbar__note { color: var(--mid-grey); font-size: 12px; margin-right: auto; }

/* ---------- Settings ---------- */

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(14, 15, 17, 0.4);
  display: grid;
  justify-content: end;
  z-index: 20;
}
.drawer__panel {
  width: min(430px, 100vw);
  background: var(--cream);
  height: 100%;
  overflow-y: auto;
  padding: 24px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.drawer__head { display: flex; align-items: center; gap: 10px; }
.drawer__head h2 { font-size: 16px; margin-right: auto; }

.field { display: grid; gap: 5px; }
.field > label { font-size: 12px; font-weight: 600; font-family: var(--font-head); }
.field input, .field textarea, .field select {
  padding: 9px 11px;
  border: 1px solid var(--light-grey);
  border-radius: var(--radius-sm);
  background: var(--white);
  width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.field small { color: var(--mid-grey); font-size: 11px; }
.field--row { display: flex; align-items: center; gap: 9px; }
.field--row input { width: auto; }
.field--row label { font-size: 13px; font-weight: 500; font-family: var(--font-body); }

/* ---------- Utility ---------- */

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

.muted { color: var(--mid-grey); }
.stack { display: grid; gap: 14px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar__label, .sidebar__foot { display: none; }
  .sidebar__nav { display: flex; }
  /* The nav is a column on desktop, so items are full width. In a row they
     have to size to their label instead. */
  .sidebar__nav .navitem { flex: 0 0 auto; width: auto; white-space: nowrap; }
  /* A disabled placeholder is not worth 110px of a phone screen. */
  .sidebar__nav .navitem:disabled { display: none; }

  /* Without wrapping, Save draft and Send for signing sat off the right edge
     of the bar with no way to scroll to them. */
  .actionbar { left: 0; flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .actionbar .btn { flex: 1 1 auto; justify-content: center; }
  .actionbar__note { flex: 1 0 100%; margin: 0 0 2px; }
  /* The bar is taller once it wraps, so keep it clear of the content. */
  .content { padding-bottom: 210px; }
  .sheet { padding: 22px; }
  .sheet__top, .sheet__parties, .sheet__foot { grid-template-columns: 1fr; display: grid; }
  .sheet__title { text-align: left; }
  .sheet__meta div { justify-content: start; }
}

/* ==========================================================================
   Print - the sheet becomes the whole document.
   Same approach as referral-poster.html: render to A4, then Save as PDF.
   ========================================================================== */

@page { size: A4 portrait; margin: 14mm; }

@media print {
  .sidebar, .topbar, .compose, .actionbar, .drawer, .drafttabs,
  .notice, .rowdel, .addrow { display: none !important; }

  html, body { background: var(--white); height: auto; }
  .app { display: block; }
  .content { padding: 0; max-width: none; display: block; }

  .sheet {
    border: none;
    border-radius: 0;
    box-shadow: none;
    /* @page already supplies the A4 size and margin. */
    width: auto;
    min-height: 0;
    padding: 0;
    margin: 0;
    transform: none;
    break-inside: auto;
  }

  /* Fields must print as plain text, not as form controls. */
  .f {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
  }
  .f--missing { background: transparent !important; }
  textarea.f { overflow: hidden; }

  /* An empty field must print as nothing, not as its placeholder hint. */
  .f::placeholder { color: transparent !important; opacity: 0 !important; }

  table.lines { break-inside: auto; }
  table.lines tr { break-inside: avoid; }
  .sheet__foot { break-inside: avoid; }
}

/* ==========================================================================
   Contracts
   The document renders identically in the dashboard preview and on the page
   the client signs - same markup from js/doc-render.js, same rules here.
   ========================================================================== */

.pill--signed  { background: rgba(21, 128, 61, 0.12); color: var(--ok); }
.pill--expired { background: var(--warn-tint); color: var(--warn); }

/* ---------- The document ---------- */

.doc { font-size: 12.5px; line-height: 1.62; }
.doc__head {
  display: flex; justify-content: space-between; gap: 32px;
  align-items: flex-start; padding-bottom: 18px;
  border-bottom: 2px solid var(--charcoal);
}
.doc__brand { font-family: var(--font-head); font-weight: 800; font-size: 22px; letter-spacing: -0.02em; }
.doc__brand span { color: var(--blue); }
.doc__from { color: var(--mid-grey); font-size: 11.5px; margin-top: 6px; white-space: pre-line; }
.doc__meta { text-align: right; }
.doc__meta h2 { font-size: 21px; letter-spacing: -0.02em; }
.doc__metalist { margin-top: 8px; display: grid; gap: 3px; font-size: 11.5px; }
.doc__metalist div { display: grid; grid-template-columns: auto auto; gap: 10px; justify-content: end; }
.doc__metalist dt { color: var(--mid-grey); }
.doc__metalist dd { font-weight: 600; font-variant-numeric: tabular-nums; }

.doc__foot {
  margin-top: 28px; padding-top: 12px;
  border-top: 1px solid var(--light-grey);
  display: flex; justify-content: space-between; gap: 16px;
  color: var(--mid-grey); font-size: 10.5px;
}

/* ---------- A clause ---------- */

.clause { margin-top: 22px; }
.clause__head {
  font-size: 13.5px; letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px;
}
.clause__num { color: var(--blue); font-variant-numeric: tabular-nums; }
.clause__body > p + p { margin-top: 8px; }
.clause__sub {
  font-size: 12px; margin: 12px 0 4px;
  font-weight: 700; color: var(--charcoal);
}
.clause__list { margin: 6px 0 0; padding-left: 17px; }
.clause__list li { margin-bottom: 3px; }
.clause__list li::marker { color: var(--light-grey); }

/* Remove and lock affordances - dashboard only, never printed. */
.clause__tools { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: none; }
.clause__tool {
  border: none; background: transparent; color: var(--mid-grey);
  font-family: var(--font-body); font-size: 10.5px; cursor: pointer;
  padding: 2px 6px; border-radius: 5px; opacity: 0;
  transition: opacity 0.12s var(--ease);
}
.clause:hover .clause__tool { opacity: 1; }

/* Always on screen: these clauses change for nearly every client. */
.clause__tool--often {
  opacity: 1; background: var(--blue); color: var(--white);
  font-weight: 600; padding: 3px 9px;
}
.clause__tool--often:hover { background: var(--blue-dark); color: var(--white); }
.clause__tool:hover { background: var(--field); color: var(--charcoal); }
.clause__tool:focus-visible { opacity: 1; outline: 2px solid var(--blue); }

.clause__x {
  border: none; background: transparent;
  color: var(--light-grey); font-size: 17px; line-height: 1;
  cursor: pointer; padding: 0 4px; border-radius: 5px;
  opacity: 0; transition: opacity 0.12s var(--ease), color 0.12s var(--ease);
}
.clause:hover .clause__x { opacity: 1; }
.clause__x:hover { color: var(--danger); background: var(--danger-tint); }
.clause__x:focus-visible { opacity: 1; outline: 2px solid var(--blue); }
.clause__lock {
  font-size: 9.5px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--light-grey);
  font-family: var(--font-body); font-weight: 600;
}
.clauseedit { display: grid; gap: 8px; margin: 8px 0; }
.clauseedit textarea {
  width: 100%; min-height: 220px; padding: 12px; font-size: 12px; line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border: 1px solid var(--blue); border-radius: var(--radius-sm); background: var(--white);
  resize: vertical;
}
.clauseedit__hint { font-size: 10.5px; color: var(--mid-grey); }
.clauseedit__hint code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.clauseedit__row { display: flex; gap: 8px; }
.clause__edited {
  margin-top: 6px; font-size: 10px; color: var(--warn);
  font-weight: 600; font-family: var(--font-head);
}

/* ---------- Parties ---------- */

.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 4px 0 12px; }
.party { border: 1px solid var(--light-grey); border-radius: var(--radius-sm); padding: 12px 14px; }
.party__label {
  font-family: var(--font-head); font-weight: 700; font-size: 10px;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--mid-grey); margin-bottom: 7px;
}
.party__row { display: grid; grid-template-columns: 78px 1fr; gap: 8px; margin-bottom: 2px; }
.party__row dt { color: var(--mid-grey); font-size: 11px; }
.party__row dd { font-weight: 500; overflow-wrap: anywhere; white-space: pre-line; }

/* ---------- Rate table ---------- */

.feetable { width: 100%; border-collapse: collapse; margin: 4px 0 10px; font-size: 11.5px; }
.feetable th {
  text-align: left; font-family: var(--font-head); font-size: 9.5px;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--mid-grey);
  border-bottom: 1px solid var(--charcoal); padding: 0 8px 5px 0;
}
.feetable th.num, .feetable td.num { text-align: right; padding-right: 0; }
.feetable td { padding: 7px 8px 7px 0; border-bottom: 1px solid var(--light-grey); vertical-align: top; }
.feetable__service { font-weight: 600; white-space: nowrap; }
.feetable td.num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ---------- Signatures ---------- */

.signblock { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 8px; }
.signbox { border: 1px solid var(--light-grey); border-radius: var(--radius-sm); padding: 14px; }
.signbox__name { font-family: var(--font-head); font-weight: 700; font-size: 16px; margin-top: 4px; }
.signbox__name--empty { color: var(--light-grey); }
.signbox__meta { color: var(--mid-grey); font-size: 11px; margin-top: 3px; }
.signbox__mark {
  margin-top: 9px; font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ok); font-weight: 700; font-family: var(--font-head);
}
.signbox__rule { margin-top: 22px; border-bottom: 1px solid var(--light-grey); }
.signblock__hash {
  grid-column: 1 / -1; margin-top: 6px; font-size: 9.5px; line-height: 1.5;
  color: var(--mid-grey); overflow-wrap: anywhere; white-space: pre-line;
}

/* ==========================================================================
   The public page at /c/<token>
   ========================================================================== */

.pubbody { background: var(--field); height: auto; min-height: 100%; }
.pubhead { position: sticky; top: 0; z-index: 5; }
.pubbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; background: var(--cream);
  border-bottom: 1px solid var(--light-grey);
}

/* Two pills, pinned under the header on narrow screens where the steps sit
   below a long document. They fill in as each step is done. */
.stepnav {
  display: none; gap: 8px; padding: 9px 20px;
  background: var(--cream); border-bottom: 1px solid var(--light-grey);
}
.steppill {
  flex: 1; padding: 9px 12px; border-radius: 999px;
  border: 1px solid var(--light-grey); background: var(--white);
  font-family: var(--font-head); font-weight: 700; font-size: 12.5px;
  color: var(--mid-grey); cursor: pointer;
}
.steppill--done {
  background: var(--blue); border-color: var(--blue); color: var(--white);
}
@media (max-width: 1080px) { .stepnav { display: flex; } }

/* A step heading is also how you get to it. */
.step__link {
  display: flex; align-items: center; gap: 9px;
  border: none; background: none; padding: 0;
  font: inherit; color: inherit; cursor: pointer; text-align: left;
}
.step__link:hover { color: var(--blue-dark); }
.step__link:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 4px; }
.pubbar__brand { font-family: var(--font-head); font-weight: 800; letter-spacing: -0.02em; }
.pubbar__brand span { color: var(--blue); }
.pubbar__spacer { flex: 1; }

.pubmain { padding: 24px 20px 64px; }
.pubload { text-align: center; color: var(--mid-grey); padding: 60px 0; }
.pubfatal { max-width: 640px; margin: 24px auto; }

.pubgrid {
  display: grid; gap: 24px; justify-content: center;
  grid-template-columns: minmax(0, 210mm) minmax(300px, 360px);
  align-items: start;
}
/* Fluid on the public page so it reads on a phone. Print resets it to A4. */
.pubbody .sheet { width: 100%; max-width: 210mm; min-height: 0; transform: none; margin-bottom: 0; }

/* Sticky, but never taller than the screen - otherwise the Sign button sits
   permanently below the fold on a short viewport and cannot be reached. */
/* The two step cards live in their own container, which needs the same gap as
   the panel - without it they sit flush and read as one merged block. */
#stepHost { display: grid; gap: 16px; }

.pubpanel {
  position: sticky; top: 76px; display: grid; gap: 16px;
  max-height: calc(100dvh - 92px); overflow-y: auto;
  scrollbar-width: thin;
}
.step {
  /* Clears the sticky header, so a jumped-to card is not hidden behind it. */
  scroll-margin-top: 70px;
  background: var(--cream); border: 1px solid var(--light-grey);
  border-radius: var(--radius); padding: 18px; display: grid; gap: 12px;
  align-content: start;
}
.step h2 { font-size: 15px; }
.step__n {
  width: 21px; height: 21px; border-radius: 50%; flex: none;
  background: var(--charcoal); color: var(--white);
  display: grid; place-items: center; font-size: 11px;
}
.step--done { background: rgba(21, 128, 61, 0.08); border-color: rgba(21, 128, 61, 0.3); }
.step > p { font-size: 12px; }

.check { display: flex; gap: 9px; align-items: flex-start; font-size: 12px; cursor: pointer; }
.check input { margin-top: 2px; flex: none; }
.fineprint { font-size: 10.5px; color: var(--mid-grey); line-height: 1.5; }
.pubhelp { font-size: 11.5px; color: var(--mid-grey); text-align: center; }

@media (max-width: 1080px) {
  .pubgrid { grid-template-columns: minmax(0, 210mm); }
  .pubpanel { position: static; max-width: 210mm; max-height: none; overflow: visible; }
  /* The pills add a second row to the header, so the clearance grows with it. */
  .step { scroll-margin-top: 145px; }
}
@media (max-width: 640px) {
  .pubbody .sheet { padding: 20px; border-radius: var(--radius); }
  .parties, .signblock { grid-template-columns: 1fr; }
  .doc__head { flex-direction: column; gap: 14px; }
  .doc__meta { text-align: left; }
  .doc__metalist div { justify-content: start; }
  .feetable__service { white-space: normal; }
}

/* ==========================================================================
   Contracts in the dashboard
   ========================================================================== */

.seclist { display: grid; gap: 4px; }
.secgroup + .secgroup { margin-top: 18px; }
.secgroup__head { font-family: var(--font-head); font-weight: 700; font-size: 12px; }
.secgroup__hint { color: var(--mid-grey); font-size: 11px; margin: 2px 0 8px; }
.secitem {
  display: grid; grid-template-columns: auto 1fr; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.secitem:hover { background: var(--field); }
.secitem input { margin-top: 3px; }
.secitem input:disabled { cursor: not-allowed; }
.secitem__title { font-weight: 600; font-size: 12.5px; }
.secitem__note { color: var(--mid-grey); font-size: 11px; line-height: 1.45; margin-top: 2px; }
.secitem__preview {
  margin-top: 5px; padding: 0; border: none; background: none;
  color: var(--blue-dark); font-family: var(--font-body); font-size: 11px;
  font-weight: 600; cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}
.secitem__preview:hover { color: var(--charcoal); }

.secpreview {
  margin: 2px 0 10px 30px; padding: 12px 14px;
  background: var(--white); border: 1px solid var(--light-grey);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-sm);
  font-size: 12px; line-height: 1.6;
}
.secpreview p + p { margin-top: 7px; }
.secpreview ul { margin: 6px 0 0; padding-left: 17px; }
.secpreview li { margin-bottom: 3px; }
.secpreview__sub { font-size: 11.5px; margin: 10px 0 3px; font-weight: 700; }
.secpreview__sub:first-child { margin-top: 0; }

.secitem--locked .secitem__title::after {
  content: "Core"; margin-left: 7px; font-size: 9px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--light-grey); font-weight: 700;
}

/* ---------- The contract editor: document left, variables right ---------- */

.content--wide { max-width: 1320px; }

.ceditor {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px; align-items: start;
}
.ceditor__main { display: grid; gap: 16px; min-width: 0; }

/* Sticky, but never taller than the screen, so the last group stays reachable. */
.ceditor__side {
  position: sticky; top: 20px;
  max-height: calc(100dvh - 40px); overflow-y: auto;
  display: grid; gap: 10px; align-content: start;
  scrollbar-width: thin;
  padding-right: 4px;
}

/* Reflow rather than scale: with a panel beside it there is not enough room to
   keep the sheet at a true A4 width, and a long document reads fine narrower.
   The print rules put it back to A4. */
#contractEditorView .sheet {
  width: 100%; max-width: 210mm; min-height: 0;
  transform: none; margin: 0;
}

/* The 240px sidebar comes off the top before this layout gets any room:
   240 sidebar + 56 padding + 560 readable document + 24 gap + 320 panel ≈ 1200.
   Below that the panel goes above the document instead of squeezing it. */
@media (max-width: 1260px) {
  .ceditor { grid-template-columns: minmax(0, 1fr); }
  .ceditor__side {
    position: static; max-height: none; overflow: visible;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    padding-right: 0;
  }
}

/* ---------- Variable groups ---------- */

.vargroup {
  background: var(--cream); border: 1px solid var(--light-grey);
  border-radius: var(--radius); padding: 14px;
}
.vargroup--fill { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-tint); }
.vargroup__head {
  font-family: var(--font-head); font-weight: 700; font-size: 12.5px;
  display: flex; align-items: center; gap: 8px;
}
.vargroup__hint { color: var(--mid-grey); font-size: 11px; margin: 3px 0 10px; line-height: 1.45; }
.vargroup__body { display: grid; gap: 11px; }

/* A collapsed group is still a group - summary carries the same heading. */
details.vargroup > summary { cursor: pointer; list-style: none; }
details.vargroup > summary::-webkit-details-marker { display: none; }
details.vargroup > summary::after {
  content: "+"; margin-left: auto; color: var(--mid-grey); font-size: 15px; line-height: 1;
}
details.vargroup[open] > summary::after { content: "\2013"; }
details.vargroup > summary .vargroup__hint { display: none; }
details.vargroup[open] > summary .vargroup__hint { display: block; }
details.vargroup[open] > summary { margin-bottom: 10px; }

/* Blue is "you fill this in", grey is "there is already a sensible number here". */
.varfield { display: grid; gap: 4px; }
.varfield > label { font-size: 11px; font-weight: 600; font-family: var(--font-head); }
.varfield input {
  padding: 7px 9px; border: 1px solid var(--light-grey);
  border-radius: var(--radius-sm); background: var(--white);
  width: 100%; font-size: 12.5px; font-family: inherit; color: inherit;
}
.varfield input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-tint); }
.varfield small { font-size: 10.5px; color: var(--mid-grey); line-height: 1.45; }

.varfield--req > label { color: var(--blue-dark); }
.varfield--req input { border-color: var(--blue); font-weight: 600; }

.varfield--opt > label { color: var(--mid-grey); }
.varfield--opt input { background: var(--field); border-color: transparent; }
.varfield--opt input:focus { background: var(--white); border-color: var(--blue); }

.varnote {
  font-size: 11px; color: var(--mid-grey); line-height: 1.5;
  padding: 12px 14px; background: var(--field); border-radius: var(--radius);
}

.sharebox {
  display: grid; gap: 8px; padding: 14px;
  background: var(--blue-tint); border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: var(--radius);
}
.sharebox__link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; word-break: break-all; background: var(--white);
  border: 1px solid var(--light-grey); border-radius: var(--radius-sm); padding: 8px 10px;
}
.evidence { font-size: 11px; color: var(--mid-grey); display: grid; gap: 3px; }
.evidence code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }

/* ---------- Jump to the form (mobile) ---------- */

.jumpdown {
  display: none;
  position: fixed; right: 16px; bottom: 16px; z-index: 8;
  align-items: center; gap: 7px;
  padding: 11px 16px 11px 14px; border-radius: 999px;
  background: var(--charcoal); color: var(--white); border: none;
  box-shadow: var(--shadow-lift); cursor: pointer;
  font-family: var(--font-head); font-weight: 700; font-size: 13px;
}
.jumpdown__arrow {
  width: 0; height: 0; flex: none;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 7px solid currentColor;
}
.jumpdown--done { background: var(--blue); }
@media (max-width: 1080px) { .jumpdown:not([hidden]) { display: flex; } }

/* ---------- Signed ---------- */

.signdone {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(14, 15, 17, 0.55);
  display: grid; place-items: center; padding: 20px;
}
.signdone__card {
  background: var(--cream); border-radius: var(--radius-lg);
  padding: 30px 26px; max-width: 380px; width: 100%;
  text-align: center; box-shadow: var(--shadow-lift);
  display: grid; gap: 10px; justify-items: center;
}
.signdone__tick {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(21, 128, 61, 0.12); color: var(--ok);
  display: grid; place-items: center; font-size: 26px; font-weight: 700;
}
.signdone__card h2 { font-size: 20px; }
.signdone__card p { font-size: 13px; }
.signdone__actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }

/* ---------- "Preview as client" overlay ---------- */

.cpreview {
  position: fixed; inset: 0; z-index: 30;
  background: var(--field); overflow-y: auto;
}
.cpreview__bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; background: var(--cream);
  border-bottom: 1px solid var(--light-grey);
}
.cpreview__tag {
  font-family: var(--font-head); font-weight: 700; font-size: 12px;
  color: var(--blue-dark); background: var(--blue-tint);
  padding: 5px 11px; border-radius: 999px;
}
.cpreview__spacer { flex: 1; }
.cpreview__body {
  padding: 24px 20px 64px;
  display: grid; gap: 24px; justify-content: center;
  grid-template-columns: minmax(0, 210mm) minmax(280px, 340px);
  align-items: start;
}
.cpreview .sheet { width: 100%; max-width: 210mm; min-height: 0; transform: none; margin: 0; }
.cpreview__panel { display: grid; gap: 16px; position: sticky; top: 76px; align-content: start; }
.cpreview__panel .step__link { cursor: default; }
.cpreview #clientPreviewNav .stepnav { display: flex; padding: 0; border: none; background: none; }
.cpreview .steppill { flex: none; padding: 5px 12px; font-size: 11.5px; }

@media (max-width: 1080px) {
  .cpreview__body { grid-template-columns: minmax(0, 210mm); }
  .cpreview__panel { position: static; }
}

/* ==========================================================================
   Printing a contract
   ========================================================================== */

@media print {
  .pubhead, .pubbar, .stepnav, .pubpanel, .pubhelp, .pubload, .pubfatal,
  .jumpdown, .signdone,
  .ceditor__side, .sharebox { display: none !important; }
  .ceditor { display: block; }
  #contractEditorView .sheet { width: auto; max-width: none; }
  .pubbody { background: var(--white); }
  .pubgrid { display: block; }
  .pubbody .sheet { width: auto; max-width: none; }

  .clause__tools, .clause__x, .clause__tool, .clause__lock, .clause__edited { display: none !important; }
  .clauseedit { display: none !important; }

  /* A heading must never be the last thing on a page. */
  .clause { break-inside: auto; }
  .clause__head { break-after: avoid; break-inside: avoid; }
  .clause__sub { break-after: avoid; break-inside: avoid; }
  .parties, .signblock, .party, .signbox, .feetable tr { break-inside: avoid; }
  .doc__head, .doc__foot { break-inside: avoid; }
  .clause__list li { break-inside: avoid; }
}
