/* ============================================================================
   A-J INVOICE THEMES (invoice-build-spec.md 3.2 tokens, 4 layout deltas)
   ============================================================================
   Every rule here is keyed on [data-theme], which order_invoice.erb only emits
   for a template carrying a valid theme. An unthemed invoice matches none of
   them and renders exactly as it did before this block existed - the same
   absent-key contract the Ruby side keeps.

   The tokens (--t-*) arrive as inline custom properties from the view, so this
   file never repeats a hex: the ten palettes live in InvoiceThemes, which the
   Prawn renderer reads too. One source, two surfaces.
   ============================================================================ */

.template-preview[data-theme] {
  max-width: var(--t-sheet, 800px);
  margin-inline: auto;
  /* The base rule makes the preview sticky, which is right for the editor's
     side-by-side pane and wrong for a document: on the print sheet it offset the
     invoice 94px down and pushed it out through the bottom of its own container.
     Relative with no offset lays out exactly like static, but keeps the sheet
     the containing block for what a theme pins inside it (E's rail, J's corner
     badge). Static let those escape to the nearest positioned ancestor - the
     order drawer, or the printed page's corner - and top: auto drops the base
     rule's 94px, which a relative sheet would otherwise shift down by. */
  position: relative;
  top: auto;
  padding: 44px 52px;
  color: var(--t-ink);
  background: var(--t-paper);
  font-family: var(--t-body);
  --invoice-accent: var(--t-accent);
}

.template-preview[data-theme] h2[data-section="company_name"],
.template-preview[data-theme] .preview-doc-title {
  font-family: var(--t-display);
}

/* The document title is the defining element of every A-J header, so it is
   always shown - unlike the legacy headers, where it is opt-in. */
.template-preview[data-theme] .preview-doc-title {
  display: block;
  color: var(--t-accent);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0 0 4px;
}

.template-preview[data-theme] .preview-header {
  border-bottom: 1px solid var(--t-hair);
  align-items: flex-start;
}

.template-preview[data-theme] .preview-meta,
.template-preview[data-theme] .totals-stack,
.template-preview[data-theme] [data-section="labels"],
.template-preview[data-theme] .eyebrow {
  color: var(--t-muted);
}

.template-preview[data-theme] .preview-logo-mark {
  border: 1px dashed var(--t-hair);
  background: transparent;
  color: var(--t-muted);
  /* Spec 5: the slot is reserved at 96x56 whether or not a logo exists, so the
     header does not reflow between a shop that has uploaded one and one that
     has not. */
  width: 96px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.template-preview[data-theme] .preview-line-items th {
  color: var(--t-muted);
  border-bottom: 1px solid var(--t-accent);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.template-preview[data-theme] .preview-line-items td {
  border-bottom: 1px solid var(--t-hair);
}

.template-preview[data-theme] .totals-owing,
.template-preview[data-theme] [data-section="totals"].totals-owing {
  color: var(--t-accent);
  font-weight: 700;
}

.template-preview[data-theme] .preview-paid-badge,
.template-preview[data-theme] .preview-status-banner {
  background: var(--t-status);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 3px 11px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
}

.template-preview[data-theme] [data-section="footer"] {
  border-top: 1px solid var(--t-hair);
  color: var(--t-muted);
}

/* --- A: Swiss Grid - title hard right, heavy accent rule ------------------ */
.template-preview[data-theme="A"] .preview-header {
  border-bottom-width: 3px;
  border-bottom-color: var(--t-accent);
}
.template-preview[data-theme="A"] .preview-meta,
.template-preview[data-theme="A"] .preview-doc-title { text-align: right; }
/* The 3-column bordered strip, with rules BETWEEN cells only. */
.template-preview[data-theme="A"] .preview-grid > * + * {
  border-left: 1px solid var(--t-hair);
  padding-left: 20px;
}

/* --- B: Soft Editorial - warm paper, italic serif title ------------------- */
.template-preview[data-theme="B"] .preview-doc-title,
.template-preview[data-theme="B"] [data-section="tagline"] {
  font-style: italic;
  text-transform: none;
  letter-spacing: 0;
}

/* --- C: Structured Mono - the whole sheet ruled, spec-sheet meta ---------- */
.template-preview[data-theme="C"] { border: 1px solid var(--t-hair); }
.template-preview[data-theme="C"] .preview-doc-title,
.template-preview[data-theme="C"] .totals-stack { font-family: var(--t-mono); }
.template-preview[data-theme="C"] .preview-grid > * {
  border: 1px solid var(--t-hair);
  padding: 10px 12px;
}
.template-preview[data-theme="C"] .totals-stack > * {
  border: 1px solid var(--t-hair);
  padding: 5px 9px;
}

/* --- D: Airy Line - hairlines only, oversized total, light weights -------- */
.template-preview[data-theme="D"] { padding: 56px 60px; }
.template-preview[data-theme="D"] .preview-line-items th { border-bottom-color: var(--t-hair); }
.template-preview[data-theme="D"] .preview-line-items td { padding-block: 14px; }
.template-preview[data-theme="D"] [data-section="body"] { font-weight: 300; }
.template-preview[data-theme="D"] .totals-owing { font-size: 30px; letter-spacing: -0.02em; }

/* --- E: Sidebar Accent - the dark rail ------------------------------------ */
@media (min-width: 641px) {
  /* THE RAIL IS TAKEN OUT OF FLOW. Two grid attempts failed for the same
     reason - a rail has to be as tall as the SHEET, and CSS grid can only span
     rows that exist: `1 / -1` addresses only the explicit grid (the rail stopped
     at its own content height), and `1 / span 100` created a hundred real rows
     and a 3,500px-tall invoice. Absolute positioning inside a padded container
     is height-independent, so it cannot get this wrong at any content length.
     The gradient paints the rail's ground so it reaches the sheet's full height
     even if the rail's own content is short. */
  .template-preview[data-theme="E"] {
    position: relative;
    padding: 0 52px 44px 272px;
    overflow: hidden;
    background: linear-gradient(to right, var(--t-accent) 0 220px, var(--t-paper) 220px);
  }
  .template-preview[data-theme="E"] .preview-header {
    position: absolute;
    inset: 0 auto 0 0;
    width: 220px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 18px;
    padding: 32px 24px;
    background: transparent;
    border: 0;
    margin: 0;
    color: #fff;
  }
  /* Everything in the rail, including the tagline: it inherits .muted, which on
     the dark rail rendered as unreadable low-contrast text. */
  .template-preview[data-theme="E"] .preview-header h2[data-section="company_name"],
  .template-preview[data-theme="E"] .preview-header .preview-meta,
  .template-preview[data-theme="E"] .preview-header .preview-meta span,
  .template-preview[data-theme="E"] .preview-header [data-section="tagline"],
  .template-preview[data-theme="E"] .preview-header .muted,
  .template-preview[data-theme="E"] .preview-header [data-section="labels"] { color: #fff; }
  /* The logo and wordmark stack in a 220px rail rather than sitting side by side,
     which wrapped the shop name mid-word. */
  .template-preview[data-theme="E"] .preview-brand {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .template-preview[data-theme="E"] .preview-meta { align-items: flex-start; }
  .template-preview[data-theme="E"] .preview-logo-mark { border-color: rgb(255 255 255 / 0.5); color: #fff; }
  .template-preview[data-theme="E"] > .preview-doc-title { padding-top: 36px; }
}

/* --- F: Centered Card ----------------------------------------------------- */
.template-preview[data-theme="F"] { text-align: center; }
.template-preview[data-theme="F"] .preview-header {
  flex-direction: column;
  align-items: center;
  border: 0;
}
.template-preview[data-theme="F"] .preview-brand { flex-direction: column; align-items: center; }
.template-preview[data-theme="F"] .preview-logo-mark { margin-inline: auto; }
.template-preview[data-theme="F"] .preview-line-items { text-align: left; }
/* The rounded hero card the spec puts above the items table. */
.template-preview[data-theme="F"] .totals-stack {
  background: var(--t-hair);
  border-radius: 14px;
  padding: 20px 24px;
  text-align: center;
}
.template-preview[data-theme="F"] .totals-owing { font-size: 26px; }

/* --- G: Two-Tone Split - the 50/50 banner --------------------------------- */
@media (min-width: 641px) {
  .template-preview[data-theme="G"] { padding: 0; overflow: hidden; }
  .template-preview[data-theme="G"] .preview-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border: 0;
    padding: 0;
  }
  .template-preview[data-theme="G"] .preview-brand {
    background: var(--t-accent);
    color: #fff;
    padding: 30px 28px;
    margin: 0;
  }
  .template-preview[data-theme="G"] .preview-brand h2[data-section="company_name"],
  .template-preview[data-theme="G"] .preview-brand [data-section="tagline"] { color: #fff; }
  .template-preview[data-theme="G"] .preview-logo-mark { border-color: rgb(255 255 255 / 0.5); color: #fff; }
  .template-preview[data-theme="G"] .preview-meta {
    background: var(--t-accent-light);
    padding: 30px 28px;
    margin: 0;
  }
  .template-preview[data-theme="G"] > *:not(.preview-header) { padding-inline: 52px; }
  .template-preview[data-theme="G"] > *:last-child { padding-bottom: 44px; }
}

/* --- H: Dashboard Summary - rounded sheet, stat cards --------------------- */
.template-preview[data-theme="H"] { border-radius: 16px; }
.template-preview[data-theme="H"] .totals-stack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.template-preview[data-theme="H"] .totals-stack > * {
  background: var(--t-hair);
  border-radius: 8px;
  padding: 14px 16px;
}
.template-preview[data-theme="H"] .totals-stack > *:has(.totals-owing),
.template-preview[data-theme="H"] .totals-owing {
  background: var(--t-accent);
  color: #fff;
  border-radius: 8px;
}

/* --- I: Ledger Line - dotted leaders instead of a table ------------------- */
.template-preview[data-theme="I"] .preview-line-items,
.template-preview[data-theme="I"] .preview-line-items tbody,
.template-preview[data-theme="I"] .preview-line-items tr { display: block; width: 100%; }
.template-preview[data-theme="I"] .preview-line-items thead { display: none; }
.template-preview[data-theme="I"] .preview-line-items tr {
  display: flex;
  /* CENTRE, not baseline. The row was always a single flex line - measured, not
     assumed - but a line item carries a 40px product thumbnail, and baseline
     alignment drops every other cell's text to the image's baseline, so the
     figures rendered a line below their own description. */
  align-items: center;
  /* NOWRAP is load-bearing. The row has four cells (description, qty, rate,
     amount), not the two the leader idea implies, so with wrapping allowed the
     numeric cells dropped onto a second line and the leader became a stub. */
  flex-wrap: nowrap;
  gap: 8px;
  padding: 5px 0;
}
.template-preview[data-theme="I"] .preview-line-items td {
  border: 0;
  padding: 0;
  /* The numeric cells hold their content; only the description flexes. */
  flex: none;
  white-space: nowrap;
}
/* The leader itself: a repeating dotted rule that fills whatever gap is left,
   which is what makes description ···· amount work at any width. */
/* A smaller thumbnail keeps a ledger row a ledger row. */
.template-preview[data-theme="I"] .preview-line-items .li-thumb {
  width: 22px !important;
  height: 22px !important;
  flex: none;
}
.template-preview[data-theme="I"] .preview-line-items td:first-child {
  flex: 1 1 auto;
  /* Without min-width:0 a flex child refuses to shrink below its content's
     intrinsic width - and a description cell carries a product thumbnail, so it
     never shrank and pushed everything else out of the row. */
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  overflow: hidden;
}
.template-preview[data-theme="I"] .preview-line-items td:first-child .inv-li-cell {
  min-width: 0;
  flex: 0 1 auto;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.template-preview[data-theme="I"] .preview-line-items td:first-child::after {
  content: "";
  flex: 1 1 auto;
  min-width: 24px;
  border-bottom: 1px dotted var(--t-hair);
}
.template-preview[data-theme="I"] .preview-line-items td:last-child { font-weight: 700; }
.template-preview[data-theme="I"] .totals-stack { font-family: var(--t-display); }

/* --- J: Corner Badge ------------------------------------------------------ */
.template-preview[data-theme="J"] { position: relative; overflow: hidden; }
.template-preview[data-theme="J"] .preview-paid-badge,
.template-preview[data-theme="J"] .preview-status-banner {
  position: absolute;
  top: 22px;
  right: -34px;
  transform: rotate(45deg);
  border-radius: 0;
  padding: 5px 44px;
  z-index: 1;
}

/* --- K: Classic Ledger - every cell ruled, one boxed total ---------------- */
.template-preview[data-theme="K"] .preview-line-items { border-collapse: collapse; }
.template-preview[data-theme="K"] .preview-line-items th,
.template-preview[data-theme="K"] .preview-line-items td {
  border: 1px solid var(--t-hair);
  /* A ruled cell needs inner room on BOTH sides, or right-aligned figures sit on the rule. */
  padding-inline: 10px;
}
.template-preview[data-theme="K"] .preview-line-items th {
  background: var(--t-accent-light);
  color: var(--t-ink);
}
.template-preview[data-theme="K"] .totals-stack {
  border: 1px solid var(--t-ink);
  padding: 10px 12px;
  margin-top: 16px;
}
/* The grand total sits under a double rule, in the display serif. */
.template-preview[data-theme="K"] .totals-stack [data-section="totals"] {
  border-top: 3px double var(--t-ink);
  padding-top: 8px;
  font-family: var(--t-display);
}

/* --- L: Thermal Receipt - an 80mm slip, everything stacked ---------------- */
/* --t-sheet (302px, i.e. 80mm) already narrows the sheet; these make the sheet's
   side-by-side layout stack the way the receipt PDF does, with tear-line rules. */
.template-preview[data-theme="L"] { padding: 18px 14px; font-size: 12px; text-align: center; }
.template-preview[data-theme="L"] .preview-header {
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border-bottom: 1px dashed var(--t-hair);
}
.template-preview[data-theme="L"] .preview-brand { flex-direction: column; align-items: center; }
/* No placeholder on a receipt (the PDF skips it too): an uploaded logo still shows. */
.template-preview[data-theme="L"] .preview-logo-mark { display: none; }
.template-preview[data-theme="L"] .preview-doc-title { font-size: 16px; text-align: center; }
.template-preview[data-theme="L"] .preview-grid { grid-template-columns: 1fr; text-align: left; }
.template-preview[data-theme="L"] .preview-line-items { text-align: left; font-size: 11px; }
.template-preview[data-theme="L"] .preview-line-items th,
.template-preview[data-theme="L"] .preview-line-items td {
  padding: 5px 2px;
  border-bottom: 1px dashed var(--t-hair);
}
/* A thermal head prints no photographs worth the width. */
.template-preview[data-theme="L"] .preview-line-items .li-thumb { display: none; }
.template-preview[data-theme="L"] .totals-block { justify-content: stretch; }
.template-preview[data-theme="L"] .totals-stack { width: 100%; text-align: left; }
/* Label left, figure right, as the receipt PDF prints them. */
.template-preview[data-theme="L"] .totals-stack > span { display: flex; justify-content: space-between; gap: 8px; }
.template-preview[data-theme="L"] .totals-stack [data-section="totals"] {
  border-top: 1px dashed var(--t-hair);
  padding-top: 6px;
  font-size: 14px;
}
.template-preview[data-theme="L"] [data-section="footer"] { border-top: 1px dashed var(--t-hair); }
@media print {
  .template-preview[data-theme="L"] { width: 80mm; max-width: 80mm; }
}

/* --- M: Tax & Compliance - the facts strip and the per-rate breakdown ----- */
.template-preview[data-theme="M"] .compliance-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin: 0 0 22px;
  border: 1px solid var(--t-hair);
}
.template-preview[data-theme="M"] .compliance-strip > div { padding: 8px 10px; border-left: 1px solid var(--t-hair); }
.template-preview[data-theme="M"] .compliance-strip > div:first-child { border-left: 0; }
.template-preview[data-theme="M"] .compliance-strip dt {
  margin: -8px -10px 6px;
  padding: 5px 10px;
  background: var(--t-accent-light);
  color: var(--t-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.template-preview[data-theme="M"] .compliance-strip dd { margin: 0; font-weight: 700; }
.template-preview[data-theme="M"] .tax-breakdown { margin-top: 22px; }
.template-preview[data-theme="M"] .tax-breakdown table { width: 100%; border-collapse: collapse; font-size: 13px; }
.template-preview[data-theme="M"] .tax-breakdown th {
  text-align: left;
  color: var(--t-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--t-accent);
  padding: 5px 6px;
}
.template-preview[data-theme="M"] .tax-breakdown td { border-bottom: 1px solid var(--t-hair); padding: 5px 6px; }
.template-preview[data-theme="M"] .tax-breakdown .align-right { text-align: right; }

/* --- N: Executive Letterhead - accent band, stationery centre ------------ */
.template-preview[data-theme="N"] { border-top: 6px solid var(--t-accent); }
.template-preview[data-theme="N"] .preview-header {
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}
.template-preview[data-theme="N"] .preview-brand { flex-direction: column; align-items: center; }
.template-preview[data-theme="N"] .preview-meta { text-align: center; }
.template-preview[data-theme="N"] .preview-doc-title { font-size: 24px; text-align: center; }

/* --- O / R: the header is one block of colour ----------------------------- */
/* The title is its own element above the header, so the two are pulled out to
   the sheet's edges with negative margins and painted the same colour: one band.
   The sheet keeps its padding - padding on a <table> does not inset it, so
   zeroing the sheet's (as G does) runs the line items to the edge. Flex order
   keeps a reminder's banner under the band instead of splitting it. */
@media (min-width: 641px) {
  .template-preview[data-theme="O"],
  .template-preview[data-theme="R"] { display: flex; flex-direction: column; overflow: hidden; }
  .template-preview[data-theme="O"] > *,
  .template-preview[data-theme="R"] > * { order: 3; }
  .template-preview[data-theme="O"] > .preview-doc-title,
  .template-preview[data-theme="R"] > .preview-doc-title {
    order: 0;
    margin: -44px -52px 0;
    padding: 30px 52px 0;
    background: var(--t-band);
    color: var(--t-on-band);
    text-align: right;
  }
  .template-preview[data-theme="O"] > .preview-header,
  .template-preview[data-theme="R"] > .preview-header {
    order: 1;
    margin: 0 -52px 24px;
    padding: 6px 52px 30px;
    background: var(--t-band);
    color: var(--t-on-band);
    border: 0;
  }
  /* The editor's preview has no title above the header, so there the band
     itself reaches the sheet's top edge. */
  .template-preview[data-theme="O"] > .preview-header:first-child,
  .template-preview[data-theme="R"] > .preview-header:first-child { margin-top: -44px; padding-top: 30px; }
  .template-preview[data-theme="O"] > .preview-status-banner,
  .template-preview[data-theme="R"] > .preview-status-banner { order: 2; align-self: flex-start; }
  .template-preview[data-theme="O"] .preview-header h2[data-section="company_name"],
  .template-preview[data-theme="O"] .preview-header [data-section="tagline"],
  .template-preview[data-theme="O"] .preview-header .preview-meta,
  .template-preview[data-theme="R"] .preview-header h2[data-section="company_name"],
  .template-preview[data-theme="R"] .preview-header [data-section="tagline"],
  .template-preview[data-theme="R"] .preview-header .preview-meta { color: var(--t-on-band); }
  .template-preview[data-theme="O"] .preview-header .preview-logo-mark,
  .template-preview[data-theme="R"] .preview-header .preview-logo-mark { border-color: currentColor; color: var(--t-on-band); }
  .template-preview[data-theme="O"] .preview-meta,
  .template-preview[data-theme="R"] .preview-meta { text-align: right; }
}
.template-preview[data-theme="R"] .preview-line-items th {
  background: var(--t-band);
  color: var(--t-on-band);
  font-family: var(--t-mono);
  border-bottom-color: var(--t-band);
}

/* --- P: Monoline - one ink, hairlines, lowercase -------------------------- */
.template-preview[data-theme="P"] .preview-doc-title,
.template-preview[data-theme="P"] .preview-line-items th,
.template-preview[data-theme="P"] .eyebrow,
.template-preview[data-theme="P"] [data-section="labels"],
.template-preview[data-theme="P"] .totals-stack,
.template-preview[data-theme="P"] .preview-paid-badge,
.template-preview[data-theme="P"] .preview-status-banner { text-transform: lowercase; letter-spacing: 0; }
.template-preview[data-theme="P"] .preview-doc-title { font-weight: 600; }
.template-preview[data-theme="P"] .preview-line-items th { border-bottom-color: var(--t-ink); }
.template-preview[data-theme="P"] .preview-line-items td { border-bottom-color: var(--t-ink); padding-block: 12px; }
.template-preview[data-theme="P"] [data-section="body"] { font-weight: 300; }

/* --- Q: Dense Grid - tight striped rows ----------------------------------- */
.template-preview[data-theme="Q"] .preview-line-items { font-size: 12px; }
.template-preview[data-theme="Q"] .preview-line-items th,
.template-preview[data-theme="Q"] .preview-line-items td { padding: 4px 6px; }
.template-preview[data-theme="Q"] .preview-line-items tbody tr:nth-child(odd) td { background: var(--t-accent-light); }

/* --- responsive (spec 7.2) ------------------------------------------------ */
@media (max-width: 640px) {
  .template-preview[data-theme] { padding: 24px 18px; }
  .template-preview[data-theme] .preview-doc-title { font-size: 24px; }
  /* E's rail stacks above the main column, G's banner stacks - both fall out of
     the grids being declared min-width only. */
  .template-preview[data-theme] .preview-grid { grid-template-columns: 1fr; }
  .template-preview[data-theme="A"] .preview-grid > * + * {
    border-left: 0;
    padding-left: 0;
    border-top: 1px solid var(--t-hair);
    padding-top: 12px;
  }
  /* Keep the table scrollable rather than wrapping cells (spec 7.2). */
  .template-preview[data-theme] .preview-line-items { display: block; overflow-x: auto; }
}

/* --- print / PDF (spec 7.1) ---------------------------------------------- */
@media print {
  .template-preview[data-theme] {
    max-width: none;
    width: 100%;
    margin: 0;
    box-shadow: none;
    /* Relative, not static: see the screen rule - E's rail and J's badge are
       pinned inside the sheet. */
    position: relative;
    top: auto;
    /* The warm-paper themes have to keep their ground in print, which browsers
       drop by default. */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .template-preview[data-theme] tr,
  .template-preview[data-theme] .preview-line-items tr { break-inside: avoid; }
  .template-preview[data-theme] thead { display: table-header-group; }
  /* The totals block must never orphan onto a page of its own. */
  .template-preview[data-theme] .totals-stack,
  .template-preview[data-theme] .totals-block { break-inside: avoid; }
}

/* --- A-J theme picker (editor) ------------------------------------------- */

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 10px;
}

.theme-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--panel);
}
.theme-card:hover { border-color: var(--line-strong); }
.theme-card.is-selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
/* The radio drives selection; hiding it visually keeps the whole card clickable
   without a second control, but it must stay focusable for the keyboard. */
.theme-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.theme-card:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.theme-card-name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
}
.theme-card-faces {
  font-size: 10px;
  color: var(--faint);
  line-height: 1.2;
}

/* A miniature of the sheet: mark, wordmark, three rows, a total. Same idea as
   .fthumb - CSS only, no images, because this grid renders eleven of them. */
.theme-card-thumb {
  position: relative;
  display: block;
  height: 74px;
  padding: 7px;
  border: 1px solid var(--tc-hair, var(--line));
  background: var(--tc-paper, #fff);
  overflow: hidden;
}
.theme-card-thumb i { display: block; }
.theme-card-thumb .tc-mark {
  width: 14px;
  height: 9px;
  border: 1px dashed var(--tc-hair, #ddd);
  margin-bottom: 5px;
}
.theme-card-thumb .tc-word {
  width: 60%;
  height: 6px;
  background: var(--tc-accent);
  margin-bottom: 7px;
}
.theme-card-thumb .tc-row {
  height: 3px;
  background: var(--tc-hair, #e6e6e6);
  margin-bottom: 4px;
}
.theme-card-thumb .tc-total {
  width: 38%;
  height: 5px;
  background: var(--tc-accent);
  margin-left: auto;
  margin-top: 6px;
}
.theme-card-thumb-none {
  background: repeating-linear-gradient(45deg, var(--panel-subtle) 0 5px, var(--panel) 5px 10px);
}

/* The distinctive layouts read at thumbnail size too, or every card looks the
   same and the grid tells the merchant nothing. */
[data-theme-thumb="E"] { padding-left: 30px; }
[data-theme-thumb="E"]::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 23px;
  background: var(--tc-accent);
}
[data-theme-thumb="G"]::before {
  content: "";
  position: absolute;
  inset: 0 50% auto 0;
  height: 24px;
  background: var(--tc-accent);
}
[data-theme-thumb="G"] { padding-top: 29px; }
[data-theme-thumb="F"] { text-align: center; }
[data-theme-thumb="F"] .tc-mark,
[data-theme-thumb="F"] .tc-word { margin-inline: auto; }
[data-theme-thumb="F"] .tc-total { margin-inline: auto; width: 60%; height: 12px; }
[data-theme-thumb="H"] .tc-total { width: 100%; height: 14px; }
[data-theme-thumb="C"] { outline: 1px solid var(--tc-hair, #ddd); outline-offset: -4px; }
[data-theme-thumb="D"] .tc-row { background: transparent; border-bottom: 1px solid var(--tc-hair, #e6e6e6); }
[data-theme-thumb="D"] .tc-total { height: 9px; }
[data-theme-thumb="I"] .tc-row { background: transparent; border-bottom: 1px dotted var(--tc-accent); }
[data-theme-thumb="K"] .tc-row { background: transparent; border: 1px solid var(--tc-hair, #b9c0cb); margin-top: -1px; }
[data-theme-thumb="K"] .tc-total { background: transparent; border: 1px solid var(--tc-accent); border-bottom-style: double; border-bottom-width: 3px; }
[data-theme-thumb="L"] { width: 46%; margin-inline: auto; text-align: center; }
[data-theme-thumb="L"] .tc-mark,
[data-theme-thumb="L"] .tc-word { margin-inline: auto; }
[data-theme-thumb="L"] .tc-row { background: transparent; border-bottom: 1px dashed var(--tc-accent); }
[data-theme-thumb="L"] .tc-total { width: 100%; }
/* Colour variants: a swatch dot and the colour's name. */
.theme-palettes { margin-top: 8px; }
.theme-palette-row { display: flex; flex-wrap: wrap; gap: 6px; }
/* display: flex outranks the hidden attribute's own display: none. */
.theme-palette-row[hidden] { display: none; }
.palette-swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  border: 1px solid var(--line, #d8dadf);
  border-radius: 999px;
  background: transparent;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.palette-swatch:hover { border-color: var(--swatch); }
.palette-swatch-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--swatch); }

/* N: the letterhead's top band, the name centred under it. */
[data-theme-thumb="N"] { border-top: 4px solid var(--tc-accent); text-align: center; }
[data-theme-thumb="N"] .tc-mark,
[data-theme-thumb="N"] .tc-word { margin-inline: auto; }
/* O and R: the whole header a block of colour. */
[data-theme-thumb="O"]::before,
[data-theme-thumb="R"]::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 24px;
  background: var(--tc-band, var(--tc-accent));
}
[data-theme-thumb="O"],
[data-theme-thumb="R"] { padding-top: 29px; }
/* P: thin black rules, nothing filled. */
[data-theme-thumb="P"] .tc-row { background: transparent; border-bottom: 1px solid var(--tc-accent); }
[data-theme-thumb="P"] .tc-total { height: 3px; }
/* Q: more, tighter, striped rows. */
[data-theme-thumb="Q"] .tc-row { height: 2px; box-shadow: 0 4px 0 var(--tc-hair, #e6e6e6), 0 8px 0 var(--tc-hair, #e6e6e6); margin-bottom: 10px; }
/* M: the ruled compliance band under the header. */
[data-theme-thumb="M"] .tc-word { margin-bottom: 8px; box-shadow: 0 7px 0 -2px var(--tc-hair, #c5d0d4); }
[data-theme-thumb="M"] .tc-row:first-of-type { outline: 1px solid var(--tc-accent); outline-offset: 1px; }
[data-theme-thumb="J"]::after {
  content: "";
  position: absolute;
  top: 4px;
  right: -8px;
  width: 26px;
  height: 7px;
  background: var(--tc-accent);
  transform: rotate(45deg);
}
[data-theme-thumb="A"] .tc-word { margin-left: auto; }
[data-theme-thumb="A"] { border-bottom: 3px solid var(--tc-accent); }
[data-theme-thumb="B"] .tc-word { width: 45%; transform: skewX(-12deg); }

/* The library's theme grid is the same card at a larger size - the gallery has
   full width where the editor's column does not. `button` and `div` variants
   both appear (a locked card is not a form), so the reset covers both. */

.theme-card.is-locked { opacity: 0.55; cursor: default; }

