/*
 * Proposal page styling — shared by the on-screen editor and the PDF renderer.
 *
 * RULES (these are load-bearing, not preferences):
 *  1. No viewport units, no percentage heights on pages or slots. Every
 *     dimension that affects layout comes from the template in `in`, or from the
 *     theme in `pt`. A `vh` here would print differently than it previews.
 *  2. Fonts are vendored woff2, referenced relatively. Never a CDN, never a
 *     system font stack — the renderer's Chromium would resolve it differently
 *     than the author's browser and pagination would silently diverge.
 *  3. Anything that is editor-only chrome must be inside a `.proposal-mode-edit`
 *     or `.proposal-mode-template` selector so it cannot reach print.
 */

/* --- Fonts ------------------------------------------------------------------
 * Three brand families, all vendored in src/proposal/fonts/ (see the README in
 * that directory — `scripts/fetch_proposal_fonts.py` builds them):
 *
 *   DM Sans     headings
 *   Inter       body copy, captions, tables
 *   Geist Mono  kickers/eyebrows and page furniture
 *
 * The families are declared unconditionally; if the files are absent the fallback
 * in PageCanvas's font stack keeps text visible, and the missing-font case is
 * caught by the render fidelity e2e test rather than silently shipping a
 * differently-paginated PDF.
 *
 * Every face is a static instance pinned at one weight. Do NOT swap in a variable
 * font: Chromium in the renderer and the author's browser can resolve a weight
 * axis differently, which repaginates the PDF away from the editor.
 */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url('./fonts/Inter-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: block;
  src: url('./fonts/Inter-Medium.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: block;
  src: url('./fonts/Inter-SemiBold.woff2') format('woff2');
}
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 700;
  font-display: block;
  src: url('./fonts/DMSans-Bold.woff2') format('woff2');
}
@font-face {
  font-family: 'Geist Mono';
  font-style: normal;
  font-weight: 500;
  font-display: block;
  src: url('./fonts/GeistMono-Medium.woff2') format('woff2');
}
@font-face {
  font-family: 'Geist Mono';
  font-style: normal;
  font-weight: 600;
  font-display: block;
  src: url('./fonts/GeistMono-SemiBold.woff2') format('woff2');
}

/* --- Page geometry --------------------------------------------------------- */

/* Margins live in the templates (slot frames), never in the print dialog, so
 * the page box is the full sheet and preferCSSPageSize keeps Chromium honest. */
@page {
  size: letter;
  margin: 0;
}

.proposal-page {
  position: relative;
  box-sizing: border-box;
  overflow: hidden;
  /* A page must never split across sheets. */
  break-inside: avoid;
  page-break-inside: avoid;
}

.proposal-slot {
  box-sizing: border-box;
}

.proposal-slot-inner {
  width: 100%;
  /* Full height so a flex/overflow measurement reflects the frame, but note
   * this is percentage-of-an-inch-sized parent, not of a viewport. */
  height: 100%;
  /* Load-bearing, not tidiness: PageCanvas puts a surfaced slot's padding here,
   * and with content-box that padding would push the inner box past its frame.
   * With border-box, clientHeight stays the frame height while scrollHeight grows
   * by the padding, which is exactly what slotOverflow's arithmetic assumes. */
  box-sizing: border-box;
}

/* Text rhythm inside slots. Margins are in `em` of the slot's own type size so
 * spacing scales with the token rather than drifting from it. */
.proposal-p {
  margin: 0 0 0.75em;
  /* A newline the author typed is a line break, and parseSlotMarkdown keeps it in
   * the text as `\n` rather than joining lines the way real markdown would. This
   * is what turns it into a visible break. `pre-wrap`, not `pre`: long lines must
   * still wrap at the slot width. */
  white-space: pre-wrap;
}
.proposal-p:last-child {
  margin-bottom: 0;
}
/* Inline `code`. The mono family is already vendored for kickers and furniture, so
 * this costs no extra face. Sized down slightly because Geist Mono runs large
 * next to Inter at the same point size. */
.proposal-code {
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 0.9em;
  font-weight: 500;
}

.proposal-ul {
  margin: 0 0 0.75em;
  padding-left: 1.1em;
}
.proposal-ul li {
  margin-bottom: 0.35em;
}
.proposal-ul li:last-child {
  margin-bottom: 0;
}

/* Colour comes from the --proposal-* custom properties PageCanvas sets on the
 * page element from the theme. Anything hardcoded here would ignore the theme —
 * the fallbacks are the dark default palette, for the case where this stylesheet
 * is somehow loaded without a page element to read the properties off. */
.proposal-table {
  width: 100%;
  border-collapse: collapse;
  /* Prices have to line up column-to-column; the vendored faces carry tnum. */
  font-variant-numeric: tabular-nums;
}
.proposal-table th,
.proposal-table td {
  padding: 0.055in 0.06in;
  border-bottom: 0.5pt solid var(--proposal-rule, #2a2440);
  vertical-align: top;
}
.proposal-table th {
  font-weight: 600;
  border-bottom: 1pt solid var(--proposal-accent, #eb7e67);
  background: var(--proposal-tint, transparent);
  /* Body copy runs at `muted`, so an unstyled header would read as quieter than
   * the rows it labels. */
  color: var(--proposal-ink, #ffffff);
}
.proposal-table tbody tr:last-child td {
  border-bottom: none;
}

/* --- Brand furniture ------------------------------------------------------- */

/* Behind every slot, and never affecting slot geometry. */
.proposal-decorations {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.proposal-slot {
  position: absolute;
  z-index: 1;
}
.proposal-brand-logo {
  z-index: 1;
}

/* On an accent-filled cover, inherited ink would be unreadable. */
.proposal-page.is-accent-cover {
  color: var(--proposal-ink-on-accent, #fff);
}
.proposal-page.is-accent-cover .proposal-slot {
  color: var(--proposal-ink-on-accent, #fff);
}

/* Slot surfaces — the brand's cards. The fill, border and radius themselves are
 * inline from the theme (PageCanvas), because they're theme values rather than
 * layout; what belongs here is only what must not vary. A surfaced slot must not
 * let a rounded corner clip its own background paint. */
.proposal-surface-panel,
.proposal-surface-outline {
  background-clip: padding-box;
}

/* A heading immediately under a panel's top padding already has the padding as
 * its space; the token's own leading on top of that reads as a misaligned card. */
.proposal-surface-panel .proposal-slot-inner > *:first-child,
.proposal-surface-outline .proposal-slot-inner > *:first-child {
  margin-top: 0;
}

/* --- Print mode ------------------------------------------------------------ */

.proposal-doc-print .proposal-page {
  /* Each page is its own sheet. */
  break-after: page;
  page-break-after: always;
}
.proposal-doc-print .proposal-page:last-child {
  break-after: auto;
  page-break-after: auto;
}

/* --- Editor chrome (screen only) ------------------------------------------- */

.proposal-page-wrap {
  position: relative;
}

.proposal-mode-edit,
.proposal-mode-template {
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 25%);
}

.proposal-mode-edit .proposal-slot,
.proposal-mode-template .proposal-slot {
  outline: 1px dashed rgb(148 163 184 / 45%);
  outline-offset: 0;
}

.proposal-mode-edit .proposal-slot:hover {
  outline-color: rgb(56 189 248 / 70%);
  cursor: pointer;
}

.proposal-mode-edit .proposal-slot.is-selected,
.proposal-mode-template .proposal-slot.is-selected {
  outline: 2px solid #38bdf8;
}

.proposal-mode-edit .proposal-slot.is-overflowing {
  outline: 2px solid #f87171;
}

.proposal-mode-edit .proposal-slot.is-overridden,
.proposal-mode-template .proposal-slot.is-overridden {
  outline-style: solid;
  outline-color: rgb(251 191 36 / 80%);
}

.proposal-slot-placeholder {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 8pt;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
  background: rgb(148 163 184 / 10%);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.proposal-overflow-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: #f87171;
  color: #1f2937;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 7pt;
  font-weight: 600;
  padding: 1px 4px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.proposal-page-missing {
  padding: 1in 0.75in;
  font-family: ui-sans-serif, system-ui, sans-serif;
  color: #f87171;
  background: #1e293b;
  border: 1px solid #f87171;
}

/* --- Template editor grid + handles --------------------------------------- */

.proposal-grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.proposal-grid-col {
  background: rgb(56 189 248 / 7%);
}
.proposal-grid-row {
  border-top: 0.5px solid rgb(148 163 184 / 12%);
}
.proposal-grid-margin {
  border: 1px solid rgb(56 189 248 / 30%);
}

.proposal-slot-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  background: #38bdf8;
  border: 1px solid #0f172a;
  z-index: 3;
}
/* Flush inside the corners, not straddling them. A slot clips its content
 * (`overflow: hidden`, which the overflow measurement depends on), so a handle
 * offset outward is clipped to whatever quadrant falls inside the frame — a 9px
 * grab target becomes about 4px. Inside means the whole handle stays clickable. */
.proposal-slot-handle-nw { left: 0; top: 0; cursor: nwse-resize; }
.proposal-slot-handle-ne { right: 0; top: 0; cursor: nesw-resize; }
.proposal-slot-handle-sw { left: 0; bottom: 0; cursor: nesw-resize; }
.proposal-slot-handle-se { right: 0; bottom: 0; cursor: nwse-resize; }
.proposal-slot-move {
  position: absolute;
  inset: 0;
  cursor: move;
  z-index: 2;
}

.proposal-mode-template .proposal-slot {
  /* Frames are the subject of the edit here, so content must not eat pointers. */
  user-select: none;
}
