/* ===== cht_summary_html (HTML form, scoped) =====
   Loaded eagerly from anvil.yaml native_deps.head_html, which is also the only
   route that styles the designer canvas. The form's rules live here because
   Anvil's server strips a <style> block out of an HTML template.

   .cht-summary-wrap is this leaf's private root class, so the root rule stays a
   bare class and every other rule is scoped :where(.cht-summary-wrap), which
   adds no specificity and so cannot change which rule wins. The root keeps
   overflow: hidden as it always declared it: this form is a card inside the
   shell's slot, not the screen root the migration guide bars an overflow on.

   No second class is needed anywhere here. This form declares no .px-* class,
   so the runtime-injected dependency theme cannot win an order flip against it,
   and no name below is declared in care_home_tracker.css either (that file
   sorts first among the section's five links and declares only .cht-shell,
   .cht-grid, .cht-stack and the three header names).

   Nothing here hides content until JavaScript runs, so there is no designer
   gate and no live class. No keyframes, no url(), no @font-face, and no <svg> carrying a class: the one svg is built in cht_summary.mjs,
   carries no class, and is reached by the descendant rule .cht-card-hint svg.
   The two dark rules are not wrapped in :where() because [data-theme="dark"]
   sits on <html>. */

.cht-summary-wrap {
  background: var(--px-bg-card);
  border: 1px solid var(--px-border);
  border-radius: var(--px-radius);
  box-shadow: var(--px-shadow);
  overflow: hidden;
}
:where(.cht-summary-wrap) .cht-summary-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--px-border);
  font-family: var(--px-font);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--px-text-primary);
}
:where(.cht-summary-wrap) .cht-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1px;
  background: var(--px-border);
}
:where(.cht-summary-wrap) .cht-summary-card {
  perspective: 800px;
  cursor: pointer;
  background: var(--px-bg-card);
}
:where(.cht-summary-wrap) .cht-card-inner {
  display: grid;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
}
:where(.cht-summary-wrap) .cht-summary-card.flipped .cht-card-inner {
  transform: rotateY(180deg);
}
:where(.cht-summary-wrap) .cht-card-front,
:where(.cht-summary-wrap) .cht-card-back {
  grid-area: 1 / 1;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  padding: 1.5rem;
}
:where(.cht-summary-wrap) .cht-card-front {
  transition: background 0.15s ease;
}
:where(.cht-summary-wrap) .cht-summary-card:not(.flipped):hover .cht-card-front {
  background: var(--px-bg-elevated);
}
:where(.cht-summary-wrap) .cht-card-back {
  transform: rotateY(180deg);
  /* Tighter side padding than the front: the back holds a 4-column
     table and needs the extra horizontal room for the name column. */
  padding: 1.5rem 0.875rem;
  overflow-y: auto;
}
:where(.cht-summary-wrap) .cht-card-hint {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-family: var(--px-mono);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--px-text-muted);
  margin-top: 0.75rem;
}
:where(.cht-summary-wrap) .cht-card-hint svg {
  width: 12px;
  height: 12px;
}
:where(.cht-summary-wrap) .cht-summary-month {
  font-family: var(--px-mono);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent, var(--px-accent));
  margin-bottom: 1.25rem;
}
[data-theme="dark"] :where(.cht-summary-wrap) .cht-summary-month {
  color: color-mix(in srgb, var(--accent, var(--px-accent)) 40%, var(--px-text-primary));
}
:where(.cht-summary-wrap) .cht-summary-total {
  font-family: var(--px-font);
  font-size: 2.75rem;
  font-weight: 700;
  color: var(--px-text-primary);
  line-height: 1.1;
  margin-bottom: 0.5rem;
}
:where(.cht-summary-wrap) .cht-summary-label {
  font-family: var(--px-font);
  font-size: 0.9rem;
  color: var(--px-text-muted);
  margin-bottom: 1.25rem;
}
:where(.cht-summary-wrap) .cht-summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
:where(.cht-summary-wrap) .cht-summary-stat {
  background: var(--px-bg-elevated);
  border-radius: var(--px-radius-sm);
  padding: 0.875rem 1rem;
}
:where(.cht-summary-wrap) .cht-summary-stat-value {
  font-family: var(--px-font);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--px-text-primary);
}
:where(.cht-summary-wrap) .cht-summary-stat-label {
  font-family: var(--px-font);
  font-size: 0.8rem;
  color: var(--px-text-muted);
  margin-top: 0.2rem;
}
:where(.cht-summary-wrap) .cht-summary-growth {
  display: flex;
  justify-content: space-between;
  font-family: var(--px-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--px-text-muted);
  margin-bottom: 1.25rem;
}
:where(.cht-summary-wrap) .cht-summary-top {
  background: var(--px-bg-elevated);
  border-radius: var(--px-radius-sm);
  padding: 0.875rem 1rem;
}
:where(.cht-summary-wrap) .cht-summary-top-name {
  font-family: var(--px-font);
  font-size: 1rem;
  font-weight: 600;
  color: var(--px-text-primary);
}
:where(.cht-summary-wrap) .cht-summary-top-detail {
  font-family: var(--px-font);
  font-size: 0.85rem;
  color: var(--px-text-muted);
  margin-top: 0.3rem;
}

/* Back face — top 10 table */
:where(.cht-summary-wrap) .cht-back-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.625rem;
}
:where(.cht-summary-wrap) .cht-back-title-text {
  font-family: var(--px-font);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--px-text-primary);
}
:where(.cht-summary-wrap) .cht-back-close {
  font-family: var(--px-mono);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--px-text-muted);
}
:where(.cht-summary-wrap) .cht-back-table {
  width: 100%;
  max-width: 100%;
  /* Fixed layout: column widths come from the header row, never from
     content min-content width, so the table can never outgrow the card. */
  table-layout: fixed;
  border-collapse: collapse;
  font-family: var(--px-font);
  font-size: 0.7rem;
}
:where(.cht-summary-wrap) .cht-back-table th,
:where(.cht-summary-wrap) .cht-back-table td {
  /* Last-resort break so a single long word can never push the table
     past the column it was allotted. */
  overflow-wrap: break-word;
}
:where(.cht-summary-wrap) .cht-back-table th {
  text-align: left;
  color: var(--px-text-muted);
  font-weight: 600;
  font-size: 0.66rem;
  line-height: 1.15;
  white-space: normal;
  vertical-align: bottom;
  padding: 0.25rem 0.3rem;
  border-bottom: 1px solid var(--px-border);
}
/* Numeric/rank columns get only what their widest content needs, so the
   Care Home column keeps the rest and its names wrap on word boundaries. */
:where(.cht-summary-wrap) .cht-back-table th:nth-child(1) { width: 1.4rem; }
:where(.cht-summary-wrap) .cht-back-table th:nth-child(3) { width: 2.9rem; }
:where(.cht-summary-wrap) .cht-back-table th:nth-child(4) { width: 1.9rem; }
:where(.cht-summary-wrap) .cht-back-table th:nth-child(1),
:where(.cht-summary-wrap) .cht-back-table td:nth-child(1) {
  padding-left: 0.15rem;
  padding-right: 0.15rem;
}
:where(.cht-summary-wrap) .cht-back-table th:nth-child(3),
:where(.cht-summary-wrap) .cht-back-table th:nth-child(4) {
  text-align: right;
}
:where(.cht-summary-wrap) .cht-back-table td {
  padding: 0.3rem 0.3rem;
  color: var(--px-text-primary);
  border-bottom: 1px solid var(--px-bg-elevated);
}
:where(.cht-summary-wrap) .cht-back-table td:nth-child(3),
:where(.cht-summary-wrap) .cht-back-table td:nth-child(4) {
  text-align: right;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
:where(.cht-summary-wrap) .cht-rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--px-bg-elevated);
  color: var(--px-text-muted);
}
:where(.cht-summary-wrap) .cht-rank-1 { background: var(--px-warning-bg); color: var(--px-warning-text); }
:where(.cht-summary-wrap) .cht-rank-2 { background: var(--px-border); color: var(--px-text-secondary); }
:where(.cht-summary-wrap) .cht-rank-3 { background: #fed7aa; color: #9a3412; }
@media not print {
  [data-theme="dark"] :where(.cht-summary-wrap) .cht-rank-3 { background: #431407; color: #fdba74; }
}
:where(.cht-summary-wrap) .cht-back-empty {
  font-family: var(--px-font);
  font-size: 0.8rem;
  color: var(--px-text-muted);
  text-align: center;
  padding: 1.5rem 0;
}
