/*
 * The printed sheet. Every number here was measured out of
 * sheets/2026-10-10/*.pdf -- see docs/RESEARCH.md, and change nothing here
 * without re-running `bin/admin sheets:verify`.
 *
 * Everything is expressed in --u, one "sheet pixel": the unit the original
 * Google Sheet is laid out in (21px rows, 16px checkboxes, 1191px of content
 * width). One sheet pixel is 0.4299411pt, which is 0.75 for 96->72dpi times
 * the 0.5732548 fit-to-width scale Sheets applied on export.
 *
 * --s is the one-page scaler: rows and type shrink together when the grid is
 * taller than the page. Column widths never scale. See docs/PLAN.md §4.2.
 */

/*
 * The page margin is zero and the sheet is centred inside the full page
 * instead. Chrome rounds @page margins to whole CSS pixels -- 0.694in becomes
 * 67px, which lands the content 0.28pt right of where Sheets puts it -- and
 * centring a known width in a known page avoids the rounding entirely.
 *
 * 612pt - 512.06pt of content, halved, is the 49.97pt left margin we measured.
 */
@page {
  size: letter;
  margin: 0;
}

:root {
  /*
   * On paper a sheet pixel is the measured 0.4299411pt. On screen it is one
   * CSS pixel -- which is exactly the size the original spreadsheet is at
   * 100%, so the page is legible instead of thumbnail-sized, and the 0.48pt
   * hairlines land on whole device pixels instead of being rounded away at
   * random. Nothing else changes: every length in this file is in --u, so
   * the two renderings are the same layout at two scales.
   */
  --u: 1px;
  --top: 124.6px;        /* the title bar's top edge: 53.57pt in sheet pixels */
  --ink:  #000;
  --box-border: #808080;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #fff;
}

/*
 * Only on paper. The sheet is centred by `margin: 0 auto` inside a page-width
 * body, which is how the measured 49.97pt side margins come out exactly. On
 * screen -- and in the editor, where the sheet is 1191px wide -- the body is
 * whatever the viewport is.
 */
@media print {
  :root { --u: 0.4299411pt; --top: 53.57pt; }
  body { width: 612pt; }
}

.sheet {
  /*
   * --s and everything derived from it live here, not on :root. A custom
   * property's var() references resolve against the element it is *declared*
   * on, so defining --row on :root would always read :root's --s of 1 and the
   * one-page scaler would silently do nothing.
   */
  --s: 1;
  /*
   * Text and checkboxes are centred in their row.
   *
   * This used to be a measured top inset, tuned so poppler reported the same
   * word position as the original. That was the wrong instrument: poppler
   * derives a word's box from font metrics, and we embed a different font to
   * Sheets', so matching those numbers put the actual ink 1.44pt low --
   * sagging below its checkbox and crowding the card's bottom border.
   * Measuring rendered ink instead showed plain centring is both correct and
   * simpler. It is also a small, deliberate improvement on the original,
   * which sits its text about 0.85pt below centre.
   */
  --row:  calc(21 * var(--u) * var(--s));
  --fs:   calc(13 * var(--u) * var(--s));
  --fs-title: calc(var(--fs) * 1.2);
  --box:  calc(16 * var(--u) * var(--s));

  /*
   * Breathing room between the first and last checkbox and the box drawn
   * round the items. A checkbox centred in a 21px row already clears the
   * edge by 2.5px, and the left inset to a checkbox is 6px, so 3.5px here
   * makes the three sides match. Not in the originals, where the items sit
   * hard against the rule -- see Lorg::SheetComparison::EXPECTED_DIFFERENCES.
   */
  --pad-y: calc(3.5 * var(--u) * var(--s));

  /*
   * 0.48pt, which is what the originals actually put on the page.
   *
   * This was 0.22pt for a long time, taken from the stroke width in the
   * original's content stream -- but rendering both at 600dpi settles it:
   * Sheets lays down four rows of solid black and we laid down two. Half the
   * weight, and thin enough that a rule either survives rasterising or does
   * not, which is what made the borders look unpredictable.
   *
   * In sheet pixels so it stays in proportion when --u changes, and declared
   * here rather than on :root for the same reason --row is: a custom
   * property resolves var() against the element it is declared on, and the
   * editor sets a different --u.
   */
  --hair: calc(1.1167 * var(--u));

  /* The blocking column is drawn over colour, where even a correct hairline
     reads as ragged along the vertical edges of a fill. */
  --rule-block: calc(1.6 * var(--u));

  width: calc(1191 * var(--u));
  margin: 0 auto;
  color: var(--ink);
  font: var(--fs)/1 Arial, "Liberation Sans", Helvetica, sans-serif;

  display: grid;
  grid-template-columns:
    calc(523 * var(--u))      /* 1 checklist cards        */
    calc(47 * var(--u))       /* 2 gutter                 */
    calc(326 * var(--u))      /* 3 special tasks          */
    calc(34 * var(--u))       /* 4 done checkbox          */
    calc(84.5 * var(--u))     /* 5 time label             */
    calc(176.5 * var(--u));   /* 6 time blocking          */
  grid-template-rows:
    calc(24 * var(--u))       /* title bar      */
    calc(20 * var(--u));      /* where the column headings were */
  grid-auto-rows: var(--row);

  /* The title bar's top edge, measured off the original. */
  padding-top: var(--top);
}

/*
 * Fills must survive printing.
 *
 * The print dialog's "Background graphics" is off by default, and every
 * colour on these pages is a background: the card headers, the blocks, the
 * hatch over a clash. Without this they print as white boxes, and the sheet
 * stops meaning anything.
 *
 * This lived on `.sheet *` for a long time, so the daily sheets were fine
 * and the week grid -- added later, a different element -- was not. Both,
 * and their descendants, from here on.
 */
.sheet, .sheet *,
.weekgrid, .weekgrid * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }

/* ---- title bar ------------------------------------------------------- */

.sheet__title {
  grid-column: 1 / -1;
  grid-row: 1;
  background: #EAD1DC;
  box-shadow: 0 0 0 var(--hair) var(--ink);
  font-size: var(--fs-title);
  display: flex;
  align-items: center;
  justify-content: center;
}

/*
 * Row 2 held the column headings, "15 MIN" and "Time Blocking", until Kate
 * asked for them to go. The row is kept, empty: it is 20 sheet px, and
 * closing it would lift every row on the printed page by about 8pt, well
 * past what the fidelity check against her originals allows.
 */

/* ---- checklist cards ------------------------------------------------- */

/*
 * A card is an outer box with a coloured header and a borderless 3-column
 * item grid. There are no internal dividers -- verified at 600dpi.
 */
/*
 * A card is two boxes, not one ring.
 *
 *   1. the label area, always boxed
 *   2. the items, boxed unless the card says otherwise
 *
 * Both shapes are in the originals: the left-hand cards have both, while
 * Special Tasks is boxed around its label only, so there is clear paper to
 * write more tasks onto during the day.
 *
 * A ring around the whole card looked the same until items were given a
 * background to clip their neighbours' overflow -- the backgrounds then
 * painted over the line under the header, and it survived only where a
 * column happened to be empty. Two boxes cannot do that: a box's children
 * are laid out inside its border and have nothing to paint over.
 */
.card {
  display: grid;
  grid-template-rows: var(--row);
  grid-auto-rows: var(--row);
  /*
   * No overflow clipping. A line box is slightly taller than the glyphs
   * inside it, so hiding overflow trimmed the descender off the last row of
   * every card -- the "y" in "Rinse Face & Pat Almost-Dry". It also fought
   * the deliberate spill of a long label into an empty neighbouring cell.
   */
}
.card--left   { grid-column: 1; }
.card--center { grid-column: 3; }

/*
 * Rules are drawn on pseudo-elements that stack above the items, because the
 * items have backgrounds and a rule in a parent's background layer loses to
 * them every time. Measuring the boundary across one row told the whole
 * story: 0.96pt over an empty cell, where both rings drew and nothing covered
 * them; 0.48pt over an occupied one, where a white background took half; and
 * nothing at all under Special Tasks' label, where the items are not boxed so
 * there was only ever one ring to lose.
 *
 * The header draws a complete ring. The items ring is clipped at its top edge
 * so it contributes the sides and the bottom only -- the boundary belongs to
 * the header, and two rings meeting there drew a double-weight line.
 */
.card__header {
  background: var(--card-color);
  position: relative;
  z-index: 1;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card__header::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: 0 0 0 var(--hair) var(--ink);
  pointer-events: none;
}

.card__items {
  display: grid;
  grid-auto-rows: var(--row);
  padding: var(--pad-y) 0;
  /*
   * Sized by its own content, not stretched to the rows it was given. The
   * padding has to make the box taller -- stretched, it would be absorbed
   * and the last row would hang below the rule drawn round it. The few
   * pixels of growth fall into the gap below the card, which is a row deep
   * at its tightest.
   */
  align-self: start;
}

.card__items--boxed::after {
  content: "";
  position: absolute;
  inset: 0;
  /*
   * Sides and bottom only: the boundary is the header's to draw.
   *
   * Drawn as three shadows offset outward rather than one ring clipped at
   * the top. The clip-path was snapped to the printer's pixels, and shaved
   * the bottom rule by however far the card's edge fell from a pixel
   * boundary -- 0.24pt under one card, 0.6pt under the next, on the same
   * page. Kate saw it on paper. Offset shadows are plain filled shapes with
   * nothing to snap; the two corner shadows close the gaps the side and
   * bottom ones leave.
   */
  box-shadow:
    calc(-1 * var(--hair)) 0 0 0 var(--ink),
    var(--hair) 0 0 0 var(--ink),
    0 var(--hair) 0 0 var(--ink),
    calc(-1 * var(--hair)) var(--hair) 0 0 var(--ink),
    var(--hair) var(--hair) 0 0 var(--ink);
  pointer-events: none;
  z-index: 2;
}
/* Tracks come from the card's own widths, written inline -- see
   SheetsHelper#card_columns. Unequal by design: column one holds the longest
   labels. */

/*
 * Special Tasks is indented more than the left-hand cards -- measured at
 * 15.5 sheet px to the checkbox and another 18.6 to the label, against 6 and
 * 9 on the left. Sheets lets each column carry its own padding and this one
 * does.
 */
.card--center .item { padding-left: calc(15.5 * var(--u)); gap: calc(18.56 * var(--u) * var(--s)); }

.item {
  display: flex;
  align-items: center;
  gap: calc(9 * var(--u) * var(--s));
  padding-left: calc(6 * var(--u));
  min-width: 0;
}
/* Only the text carries the inset; the checkbox is positioned off the row top. */
.item__label { white-space: nowrap; }

/*
 * Special Tasks wraps instead of running off the edge.
 *
 * The left-hand cards cannot: their rows are the sheet's 15-minute grid and a
 * second line would put every item below out of step. The centre column has
 * nothing beneath it, so its rows are free to grow and the card simply gets
 * taller -- which is also what happens on paper when Kate writes a long one.
 */
.card--center .item__label { white-space: normal; }
.card--center .card__items { grid-auto-rows: minmax(var(--row), auto); }

/*
 * A label longer than its column spills into the next one when that one is
 * empty, and is cut off when it is not. That is what a spreadsheet does, and
 * what Kate's own sheets rely on -- "Cicaplast on cheeks" runs into the empty
 * cell beside it and reads fine.
 *
 * Grid children paint in document order, so an occupied cell covers whatever
 * its neighbour to the left spilled. An empty one has no background and lets
 * the spill through.
 */
.item:not(.item--empty) { background: #fff; }
.item { overflow: visible; }

/* ---- checkboxes ------------------------------------------------------ */

.box {
  flex: none;
  width: var(--box);
  height: var(--box);
  border: calc(1.2 * var(--u) * var(--s)) solid var(--box-border);
  border-radius: calc(2 * var(--u) * var(--s));
  background: #fff;
  position: relative;
}
/*
 * Done is an X through the box, not a tick: it is what Kate draws on the
 * printed sheets, and at this size a checkmark reads as a stray V.
 *
 * Two bars rotated about the centre rather than a background gradient, so
 * they stay crisp vector fills at 5.7pt on paper as well as at 21px on
 * screen. 113% is the diagonal of the box (root two times its width, less a
 * little) so the bars reach the corners and stop.
 */
.box--checked::before,
.box--checked::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 113%;
  height: calc(1.6 * var(--u) * var(--s));
  background: var(--ink);
}
.box--checked::before { transform: translate(-50%, -50%) rotate(45deg); }
.box--checked::after  { transform: translate(-50%, -50%) rotate(-45deg); }

/* ---- timeline -------------------------------------------------------- */

/* The done-checkbox gutter and the time labels carry no borders at all. */
.done {
  grid-column: 4;
  display: flex;
  align-items: center;
  /*
   * Kate's seven day tabs have slightly different column widths: this gutter
   * ranges over 2.65pt across the exports (442.49pt on Saturday to 445.14pt on
   * Wednesday). 18.5 puts us on the midpoint of that range, which is the
   * closest a single layout can be to all seven -- worst case 1.33pt.
   */
  padding-left: calc(18.5 * var(--u));
}

.timelabel {
  grid-column: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: calc(3.7 * var(--u));
  white-space: nowrap;
}

/*
 * A tiled column: every block, and a plain cell for each gap between them.
 * Each cell draws its own top rule and nothing else, so a boundary between
 * two of them is one line rather than two meeting. The column's own edges
 * belong to the frame around it.
 */
.segment {
  grid-column: 6;
  position: relative;
  display: flex;
  /* Safe: a name with more lines than the block has room for loses its
     last lines, not its first and last both. */
  align-items: safe center;
  justify-content: center;
  text-align: center;
  font-weight: bold;
  overflow: hidden;
  padding: 0 calc(3 * var(--u));
}
.segment--filled { background: var(--segment-color); }

/*
 * A block the column had no room for. A hatched stripe down the right-hand
 * edge of the cell, over the time it wanted: the block that won stays
 * readable, and the page says plainly that something is unresolved instead of
 * leaving it out.
 */
.clash {
  grid-column: 6;
  justify-self: end;
  width: 28%;
  position: relative;
  z-index: 2;
  box-shadow: inset 0 0 0 var(--hair) var(--ink);
  background: repeating-linear-gradient(
    135deg,
    var(--segment-color) 0 calc(3 * var(--u)),
    #fff calc(3 * var(--u)) calc(6 * var(--u)));
}

.timeline__frame {
  grid-column: 6;
  position: relative;
  pointer-events: none;
}
.timeline__frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--rule-block) solid var(--ink);
  border-top: 0;
  z-index: 3;
}

.segment::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: var(--rule-block);
  background: var(--ink);
  pointer-events: none;
  z-index: 2;
}

/* ---- the editor ------------------------------------------------------ */

/*
 * Same markup, --u switched from 0.4299411pt to 1px, which lands the sheet at
 * the size the original spreadsheet is at 100% zoom. The only additions are
 * affordances: a cursor, a hover state, and a tick you can actually hit.
 */

.sheet--interactive,
.sheet--ticking {
  margin: 0 auto 3rem;
}

.box--button {
  padding: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.box--button:hover { border-color: #3a4b8f; background: #f4f5fa; }
.box--button:focus-visible { outline: 2px solid #3a4b8f; outline-offset: 1px; }

/* button_to wraps each control in a form; it must not disturb the grid. */
.sheet--interactive .item form,
.sheet--interactive .done form,
.sheet--ticking .item form,
.sheet--ticking .done form { display: contents; }

.sheet--interactive .item:hover .item__label { text-decoration-color: #c9c9d2; }

/*
 * A ticked item reads as done at a glance. On screen only -- on paper the tick
 * is the whole signal, and striking the text through would be a departure
 * from the original.
 *
 * :has(), not an adjacent sibling: button_to wraps each control in a form, so
 * the button is not the label's sibling.
 */
.sheet--interactive .item:has(.box--checked) .item__label,
.sheet--ticking .item:has(.box--checked) .item__label {
  color: #6b6b70;
  text-decoration: line-through;
  text-decoration-color: #b9b9c0;
}

/* ---- dragging the timeline ------------------------------------------ */

/*
 * An invisible surface covering every row of the blocking column. It sits
 * under the blocks, so a drag that starts on empty space creates and a drag
 * that starts on a block moves it.
 */
.surface {
  grid-column: 6;
  z-index: 0;
}
.sheet--interactive .surface,
.weekgrid--interactive .surface { cursor: crosshair; }
.sheet--interactive .segment,
.weekgrid--interactive .segment { position: relative; z-index: 1; }

.segment--editable { cursor: grab; }
.sheet--dragging .segment--editable { cursor: grabbing; }
.sheet--dragging { user-select: none; }

.sheet--interactive .segment--editable:hover {
  box-shadow: 0 0 0 var(--hair) var(--ink), inset 0 0 0 1px rgba(58, 75, 143, 0.45);
}

/* The bottom edge, for resizing. Tall enough to hit without being in the way
   of the label. */
.segment__handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  cursor: ns-resize;
}
.segment__handle:hover { background: rgba(58, 75, 143, 0.35); }

/*
 * A drag that would double-book. Shown while the button is still down, so
 * the refusal arrives before the gesture is finished and there is no error
 * to read afterwards -- docs/UI_OPTIONS.md §2.
 */
.segment--invalid {
  background: repeating-linear-gradient(
    135deg, #f6d4d4 0 6px, #fbeaea 6px 12px) !important;
  box-shadow: 0 0 0 2px #b4453f;
  cursor: no-drop;
}
.segment--invalid .segment__label { color: #7d2a26; }

/* What a drag-to-create looks like before it is committed. */
.segment--ghost {
  grid-column: 6;
  background: rgba(58, 75, 143, 0.14);
  box-shadow: 0 0 0 1px rgba(58, 75, 143, 0.6);
  pointer-events: none;
  z-index: 2;
}

/* A block created by a drag opens with its name field focused, so it can be
   named without a second gesture. */
.segment__naming { display: contents; }
.segment__input {
  width: 92%;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: bold;
  line-height: 1.15;
  text-align: center;
  color: inherit;
  padding: 0;
  /* A textarea, so a name can have a second line; it grows to fit. */
  resize: none;
  overflow: hidden;
  display: block;
}
.segment__input:focus { outline: 1px solid rgba(58, 75, 143, 0.7); }

/* A name of more lines than a short block has room for spills out of it
   while it is being typed, rather than being cut off by the block's own
   overflow -- painted in the block's colour so it reads as the block. */
.segment:has(.segment__naming) { overflow: visible; z-index: 6; }
.segment:has(.segment__naming) .segment__input { background: var(--segment-color, #fff); }

/* The lines it was typed with. */
.segment__label { white-space: pre-line; }

/* ---- editing a card's tasks ----------------------------------------- */

/* A freeform card (Special Tasks) is edited in place: each task is a field,
   and an empty one at the end adds another. */
.item__edit { display: contents; }
.item__form { display: contents; }

/*
 * `display: contents` beats the browser's own `[hidden] { display: none }`,
 * because that rule lives in the user-agent stylesheet and this one does not.
 * Without this, every item on a card rendered its label *and* the rename
 * field sitting next to it, which read as each task being listed twice.
 */
[hidden] { display: none !important; }

/* Text until clicked, so a card of twenty items is not a wall of fields. */
.sheet--interactive .item__label { cursor: text; }
.sheet--interactive .item__label:hover {
  box-shadow: 0 1px 0 rgba(58, 75, 143, 0.35);
}

.item__input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 0;
}
.item__input:focus {
  outline: 0;
  box-shadow: 0 1px 0 rgba(58, 75, 143, 0.6);
}
.item__input::placeholder { color: #9a9aa2; font-style: italic; }

.item__remove {
  flex: none;
  border: 0;
  background: none;
  color: #b0b0b8;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0 calc(3 * var(--u));
  opacity: 0;
}
.item:hover .item__remove { opacity: 1; }
.item__remove:hover { color: var(--alert, #8f2f2f); }

/* The placeholder box on an empty, fillable cell. */
.box--ghost { border-style: dashed; opacity: 0.35; }
.item--empty .box--ghost { opacity: 0; }
.item--empty:hover .box--ghost { opacity: 0.45; }

/* An empty cell offers itself quietly: nothing until the pointer is over it,
   then a faint outline and a +. The whole cell is the target, so there is no
   small glyph to aim at. */
.sheet--interactive .item--empty { cursor: text; }
.sheet--interactive .item--empty:hover {
  box-shadow: inset 0 0 0 1px rgba(58, 75, 143, 0.25);
}

.item__add {
  flex: 1;
  align-self: stretch;
  display: flex;
  align-items: center;
  color: #9a9aa2;
  opacity: 0;
  min-width: 0;
}
.item--empty:hover .item__add { opacity: 1; }

/* The card header doubles as its grab handle, and carries a column stepper
   that stays out of the way until the card is hovered. */
.sheet--interactive .card__header { position: relative; cursor: grab; }
.sheet--dragging .card__header { cursor: grabbing; }

.card__columns {
  position: absolute;
  right: calc(3 * var(--u));
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: calc(2 * var(--u));
  opacity: 0;
}
.card:hover .card__columns { opacity: 1; }
.card__columns form { display: contents; }

.card__step {
  border: 0;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 2px;
  font: inherit;
  font-weight: normal;
  line-height: 1;
  cursor: pointer;
  padding: 0 calc(3 * var(--u));
}
.card__step:disabled { opacity: 0.3; cursor: default; }
.card__step:hover:not(:disabled) { background: #fff; }
.card__count { font-weight: normal; opacity: 0.7; }

/* Deleting the card: the last of its controls, and red only when meant. */
.card__delete { display: inline-flex; align-items: center; padding: calc(1 * var(--u)) calc(3 * var(--u)); }
.card__delete .icon { width: calc(10 * var(--u)); height: calc(10 * var(--u)); }
.card__delete:hover { color: #b42318; }

/*
 * A card selected as a whole -- by clicking its header, or Up from its top
 * row -- so Delete or Backspace means the card. Outlined clear of its own
 * rules, which belong to the printed page, and with its controls showing,
 * since the keyboard has no hover.
 */
.card--selected { outline: 2px solid rgba(58, 75, 143, 0.75); outline-offset: calc(3 * var(--u)); }
.card--selected .card__columns { opacity: 1; }
@media print { .card--selected { outline: none; } }
.card__fit { font-size: 0.85em; padding: 0 calc(4 * var(--u)); }

/* The boundary between two columns, draggable. Invisible until the card is
   hovered, because the sheet should not look like a spreadsheet. */
.card__items { position: relative; }
.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(7 * var(--u));
  margin-left: calc(-3.5 * var(--u));
  cursor: col-resize;
  z-index: 3;
}
.card:hover .divider { background: rgba(58, 75, 143, 0.12); }
.divider:hover { background: rgba(58, 75, 143, 0.4) !important; }

.segment--selected {
  box-shadow: 0 0 0 var(--hair) var(--ink), inset 0 0 0 2px rgba(58, 75, 143, 0.75);
}

/* ---- the week grid --------------------------------------------------- */

/*
 * Seven days on one time axis (docs/PLAN.md §4.5). The same page, the same
 * sheet pixel, the same everything-is-a-row discipline as the daily sheet --
 * with one rule reversed. The daily sheet never scales up, because its cards
 * are anchored and stretching them down the page would be wrong; the week
 * grid has nothing below it and Kate's own export fills the sheet, so its
 * row height is the page height divided by the rows, handed in as --week-row.
 *
 * The day columns are 1fr rather than a measured width. Hers are unequal
 * (115 / 134 / 127x4 / 114 px), which reads as incidental spreadsheet sizing
 * rather than intent, and equal columns put each day a little wider than her
 * widest.
 */
.weekgrid {
  --s: 1;
  --fs: calc(15.79 * var(--u));     /* 6.79pt on paper, measured off hers */
  --hair: calc(1.1167 * var(--u));
  --rule-block: calc(1.6 * var(--u));

  width: calc(1191 * var(--u));
  margin: 0 auto;
  display: grid;
  grid-template-columns: calc(90 * var(--u)) repeat(7, 1fr);
  grid-template-rows: calc(28.38 * var(--u));   /* 12.2pt of day-name row */
  grid-auto-rows: var(--week-row);
  font: var(--fs)/1 Arial, Helvetica, sans-serif;
  color: var(--ink);
}

/*
 * On paper the grid is the page: the same 49.97pt side margins as the daily
 * sheet, which fall out of centring 1191 sheet px in a 612pt body, and the
 * measured 52.98pt above. On screen that top margin would just be a gap, so
 * it only applies when printing.
 */
@media print {
  .weekgrid { padding-top: calc(123.2263 * var(--u)); }
}

.weekgrid__dayhead {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: calc(8 * var(--u));
  font-weight: bold;
  text-transform: uppercase;
}
.weekgrid__dayhead a { color: inherit; text-decoration: none; }
.weekgrid__dayhead a:hover { text-decoration: underline; }
.weekgrid__dayhead--today { text-decoration: underline; }

/* Only on screen: hers has day names and no dates, but you are planning a
   particular week, so the date belongs there. */
.weekgrid__date { font-weight: normal; text-transform: none; opacity: 0.6; }
@media print { .weekgrid__date { display: none; } }

.weekgrid__time {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: calc(5 * var(--u));
  white-space: nowrap;
}

/*
 * Every rule is drawn exactly once, by whichever element owns that edge.
 *
 * A spread shadow round each box cannot do this, and the week grid is where
 * that shows worst: the shadow sits *outside* the box, so two columns side by
 * side each spread into the gap between them and the line comes out double
 * weight -- except where a block happens to sit, whose own fill and shadow
 * paint over half of it, so the same boundary is heavy over paper and light
 * over colour. Measured on the page: 1.38pt of black between two empty
 * columns against 0.69pt beside a block.
 *
 * So the column owns its left edge and its bottom, the last column owns the
 * right, and a cell owns its top. Drawn on pseudo-elements stacked above the
 * fills, because a fill in a later grid item would otherwise paint over them.
 */
.weekgrid__column { position: relative; pointer-events: none; }
.weekgrid__column::after {
  content: "";
  position: absolute;
  inset: 0;
  border-left: var(--rule-block) solid var(--ink);
  border-bottom: var(--rule-block) solid var(--ink);
  pointer-events: none;
  z-index: 3;
}
.weekgrid__column--last::after { border-right: var(--rule-block) solid var(--ink); }

/* A day with no sheet yet is paper, not a mistake. */
.weekgrid__column--empty { background: repeating-linear-gradient(
  135deg, transparent, transparent calc(6 * var(--u)),
  rgba(0, 0, 0, 0.045) calc(6 * var(--u)), rgba(0, 0, 0, 0.045) calc(12 * var(--u))); }

/* Blocks are the daily sheet's .segment, minus its fixed column. */
.weekgrid .segment {
  grid-column: auto;
  padding: 0 calc(4 * var(--u));
  line-height: 1.1;
  white-space: normal;
}

.weekgrid .surface,
.weekgrid .clash { grid-column: auto; }

/* A week printed as seven daily sheets. */
.page--break { break-before: page; }

/* ---- screen-only chrome --------------------------------------------- */

/* Shown when looking at a sheet in the browser; never on paper, and never in
   the standalone layout the PDF renderer uses. */
.sheet-nav {
  font: 13px/1 system-ui, sans-serif;
  padding: 0.75rem 1rem;
}
.sheet-nav a { color: #3a4b8f; }

@media print {
  .sheet-nav { display: none; }
}

/*
 * With something on the clipboard, the cursor says where it can go.
 *
 * It used to say the opposite. The rule was on .surface, which is the lowest
 * thing in the column -- over empty time the pointer is actually over a gap
 * cell, which got the default cursor, and the only place the copy cursor
 * showed was over a real block, which is the one place a paste is refused.
 */
.grid--pasting .segment,
.grid--pasting .surface { cursor: copy; }
.grid--pasting .segment--editable,
.grid--pasting .clash { cursor: no-drop; }

/*
 * Where the keyboard is, when it is not on a block. A block says so by being
 * outlined; empty time needs something of its own, and a dashed cell is what
 * a spreadsheet uses for the same job.
 */
.cell-cursor {
  grid-column: 6;
  outline: 2px dashed var(--ink);
  outline-offset: -2px;
  background: rgba(58, 75, 143, 0.08);
  pointer-events: none;
  z-index: 4;
}
.weekgrid .cell-cursor { grid-column: auto; }
@media print { .cell-cursor { display: none; } }

/* Only on screen: a clash can be clicked to open the block it stands for. */
.sheet--interactive .clash,
.weekgrid--interactive .clash { cursor: pointer; }

/*
 * An all-day entry a calendar put here, hidden from the page. Shown only in
 * the editor -- `items` leaves it out everywhere else -- so there is
 * somewhere to bring it back from.
 */
.item--hidden .item__label { opacity: 0.4; text-decoration: line-through; }
.item--hidden .box { opacity: 0.3; }

.item__hide {
  border: 0;
  background: none;
  padding: 0 0.2em;
  font-size: 11px;
  line-height: 1;
  color: #8a8a90;
  cursor: pointer;
  opacity: 0;
}
.item:hover .item__hide,
.item--hidden .item__hide { opacity: 1; }
@media print { .item__hide { display: none; } }

/* ---------------------------------------------------------------------------
 * A week template, drawn as the week it produces.
 *
 * Only on screen: a template is never printed, and these rules would be
 * drawing furniture on paper that has no business there.
 * ------------------------------------------------------------------------ */

/* The day-name row is a measured 28.38 sheet px on the planner, because that
   is what Kate's own grid is. A template's heading stacks a control under
   the name and needs more, so this one row is sized to its content -- safe
   here and nowhere else: a template is never printed, and the fidelity
   harness only ever renders the planner. */
.weekgrid--layered { grid-template-rows: auto; }

/* The heading carries a control on a template grid, so it stacks rather than
   sitting on one baseline, and nothing is allowed to push a column wider
   than the column -- the grid is a fixed 1191 sheet px and a long day
   template name would otherwise shove the whole axis sideways. */
.weekgrid--layered .weekgrid__dayhead {
  display: grid;
  justify-items: center;
  align-content: end;
  gap: calc(2 * var(--u));
  min-width: 0;
  padding: calc(6 * var(--u)) calc(2 * var(--u)) calc(4 * var(--u));
}
.weekgrid--layered .weekgrid__dayhead > * { max-width: 100%; }

.weekgrid__wday { font-size: calc(11 * var(--u)); letter-spacing: 0.02em; }

.weekgrid__assign { display: block; max-width: 100%; }
.weekgrid__select {
  max-width: 100%;
  font: inherit;
  font-size: calc(10 * var(--u));
  font-weight: normal;
  text-transform: none;
  padding: 0 calc(2 * var(--u));
  border: 1px solid #c9ccd6;
  border-radius: 3px;
  background: #fff;
  color: #3a4b8f;
}
.weekgrid__select:hover { border-color: #3a4b8f; }

.weekgrid__hours {
  font-size: calc(9 * var(--u));
  font-weight: normal;
  font-style: normal;
  text-transform: none;
  color: #7a6a3a;
  background: #fdf6e3;
  border-radius: 2px;
  padding: 0 calc(3 * var(--u));
}

/*
 * Provenance.
 *
 * An inherited block is drawn lighter and labelled with where it came from.
 * Figma's own users complain that an override is invisible until the base
 * stops updating (docs/TEMPLATE_UI.md §2) -- so the marking is the half that
 * has to be unmissable, and it is on the block rather than in a panel you
 * have to open.
 */
.segment--inherited { opacity: 0.72; }
.segment--inherited.segment--filled { background-image: repeating-linear-gradient(
  135deg, rgba(255, 255, 255, 0.55) 0 calc(4 * var(--u)),
  rgba(255, 255, 255, 0) calc(4 * var(--u)) calc(8 * var(--u))); }

.segment__from {
  position: absolute;
  left: calc(2 * var(--u));
  bottom: calc(1 * var(--u));
  max-width: calc(100% - 4 * var(--u));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(8 * var(--u));
  line-height: 1.2;
  font-style: italic;
  color: #5a5a5a;
  pointer-events: none;
}

/* Suppressed: shown struck through rather than vanished. Browsers' dev tools
   keep the losing declaration on screen for the same reason -- "what wins"
   is only answerable if you can see what lost. */
.segment--suppressed { opacity: 0.4; }
.segment--suppressed .segment__label { text-decoration: line-through; }
.segment--suppressed.segment--filled { background: repeating-linear-gradient(
  135deg, #ededed 0 calc(4 * var(--u)), #f7f7f7 calc(4 * var(--u)) calc(8 * var(--u))); }
.segment--suppressed .segment__from { color: #9a3b3b; }

/*
 * A day template's cards, marked the same way a template's blocks are: what
 * this layer owns is solid, what it inherited is lighter and says where it
 * came from, what it took away is struck through rather than gone.
 */
.card--inherited { opacity: 0.78; }
.card--inherited .card__header { background-image: repeating-linear-gradient(
  135deg, rgba(255, 255, 255, 0.5) 0 calc(4 * var(--u)),
  rgba(255, 255, 255, 0) calc(4 * var(--u)) calc(8 * var(--u))); }

.card__from {
  margin-left: calc(6 * var(--u));
  font-size: calc(9 * var(--u));
  font-weight: normal;
  font-style: italic;
  text-transform: none;
  color: #4a4a4a;
}

.card--suppressed { opacity: 0.42; }
.card--suppressed .card__header { text-decoration: line-through; }

/*
 * Editing a card where it is: its name, its colour, and which column it
 * sits in. Screen only -- none of it prints, and the header has to look
 * exactly as it did on paper.
 */
.card__name { display: inline; }
.card__label { cursor: text; }
.card__label:hover { text-decoration: underline dotted; }
.card__form { display: inline; }
.card__input {
  font: inherit; font-weight: inherit; text-align: inherit;
  width: 60%; padding: 0; margin: 0;
  border: none; border-bottom: 1px solid rgba(58, 75, 143, 0.6); background: transparent;
}
.card__input:focus { outline: none; }

.card__look { display: inline-flex; align-items: center; gap: calc(3 * var(--u)); }
.card__swatch { display: inline-flex; }
.card__swatch input[type="color"] {
  width: calc(14 * var(--u)); height: calc(14 * var(--u));
  padding: 0; border: 1px solid rgba(0, 0, 0, 0.25); border-radius: 2px;
  background: none; cursor: pointer;
}
.card__step--region { font-size: calc(11 * var(--u)); line-height: 1; }

@media print {
  .card__look, .card__columns { display: none; }
}

/*
 * The grid is focusable, so that the keyboard shortcuts have somewhere to be
 * (finding 20): tab to it, or click it, and the keys are the grid's. Only
 * :focus-visible, so a pointer click does not draw a ring round the page.
 */
.sheet--interactive:focus-visible,
.weekgrid--interactive:focus-visible {
  outline: 2px solid #3a4b8f;
  outline-offset: 3px;
}

/*
 * Targets on the card's own chrome (round-two finding 21).
 *
 * The steppers that change a card's columns and borders sit in an absolutely
 * positioned strip over the header, so they can be given a real 24x24 target
 * -- WCAG 2.2 SC 2.5.8 -- without the header growing and the sheet's
 * geometry moving with it. They overflow the header a little and nothing
 * else moves.
 *
 * The sheet's own controls are a different matter and are deliberately left
 * alone: a tick box is 16 sheet pixels because that is what is printed on
 * the page, and a 24px one needs rows taller than a 15-minute slot -- a
 * different screen layout, not a bigger button. The keyboard reaches every
 * one of them (decision 27), and the agenda view that would carry
 * touch-sized rows is a design piece rather than a fix:
 * docs/codex-design/07-mobile-and-accessibility.md.
 *
 * Screen only: none of this chrome is printed.
 */
@media screen {
  .card__columns .card__step {
    min-width: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /*
   * The colour and the left/right step move out of the header's flow and on
   * top of it, the way the column steppers already sit: the header keeps the
   * height the paper gives it and the controls get their 24 pixels. The
   * title stays centred because neither strip takes part in the centring.
   */
  .card__look {
    position: absolute;
    left: calc(3 * var(--u));
    top: 0;
    bottom: 0;
    gap: calc(2 * var(--u));
  }
  .card__look .card__step {
    min-width: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .card__swatch input[type="color"] { width: 24px; height: 24px; }

  /* Shown rather than hovered where there is no hover to give. */
  @media (pointer: coarse) {
    .card__columns, .card__look, .item__remove { opacity: 1; }
  }
}
