/* app.css — the application's own stylesheet, loaded after pico.min.css so the
   cascade does the overriding. Hand-written; there is no build step, no bundler,
   and no npm in this project, and adding one would be a stack-constraint change.

   ---------------------------------------------------------------------------
   ONE BREAKPOINT
   ---------------------------------------------------------------------------
   @media (max-width: 767.98px)

   Every rule below is unconditional, uses exactly that query, or uses its exact
   complement `@media (min-width: 768px)` — one boundary, two sides. (Only
   .app-capture needs the other side: it is the one rule that must apply at
   desktop rather than on a phone.)

   The 767.98px boundary is Pico's own `min-width: 768px` boundary expressed as a
   max-width, so Pico's .grid collapse and this file's table stacking flip at the
   same pixel. A different number would leave a band where the page is
   half-converted. There is deliberately no tablet tier: a second breakpoint is a
   decision to record, not a detail to add.

   Reference viewports: 320px is the degradation floor (no horizontal scroll, not
   a design target), 375px is the design target (iPhone 13 mini), 1280px is the
   desktop reference and must stay identical to what shipped before this file
   existed.

   ---------------------------------------------------------------------------
   PROHIBITIONS — each protects a named invariant. Breaking one is a defect even
   with a green test suite.
   ---------------------------------------------------------------------------
   P1  No rule may key off WorkflowKind, or assume how many controls a group
       contains. Protects Constitution V (the workflow seam): WorkflowRegistry is
       the only place a WorkflowKind resolves to behavior, and a media query that
       hardcoded "four buttons" would merely relocate that switch into this file.
       A third workflow shipping with six actions must lay out correctly with
       zero changes here.

   P2  No `position: fixed`, no `height: 100vh`. Protects FR-010: a landscape
       phone (812x375) must stay an ordinary scrolling document so the primary
       confirm control on /a/{token} stays reachable.

   P3  No control may be hidden by CSS that Razor would otherwise not render, and
       no `@if (Model.IsOwner)` gate may be replaced by a CSS rule. Protects
       Constitution II (tenancy): hiding an owner-only control with display:none
       still ships it in the HTML to a member. Hiding a *presentational
       alternative* (see .app-capture) is not this — that control is available to
       every viewer of the page, and only its affordance differs.

   P4  No rule may reduce a form control's computed font-size below 16px.
       Protects FR-006: Pico's `--pico-font-size: 100%` at :root is what prevents
       iOS from auto-zooming on focus today. The job here is to not break it.

   P5  No JavaScript is added. Two <script> blocks exist in the app today
       (Settings/InviteCodes.cshtml, Settings/Calendar.cshtml); this feature adds
       none and removes none.

   P6  pico.min.css is never edited. It is an upstream v2.1.1 file, replaced only
       by upgrading Pico. Everything this app wants to change about it goes here.
   --------------------------------------------------------------------------- */

@media (max-width: 767.98px) {

  /* --- Navigation (FR-003) ------------------------------------------------
     Pico sets `nav ul { display: flex }` with no wrap, so the brand cell plus
     the signed-in destinations lay out as one unbreakable row and push the
     whole document into horizontal scroll at phone widths — on every signed-in
     page, not just the dense ones.

     Wrapping is the fix rather than a hamburger or a "More" disclosure: every
     destination stays visible across two short rows, which is what FR-003 asks
     for. Nothing here hides a link.

     011 slimmed the chrome to three destinations and BOTH RULES BELOW STAYED.
     They are kept on evidence, not on arithmetic: the wrap's other consumer is
     the brand cell, and AppOptions.ProductName is an operator-supplied string
     of unbounded length — the .app-brand comment further down relies on this
     rule by name for exactly that case. No count of destinations can retire a
     guard whose other input has no upper bound; dropping it would put the 320px
     floor at the mercy of a deployment's configuration. Justifying it by a
     destination count is what made this comment stale twice — once when 008
     grew the brand a mark, and again when 011 removed an entry. */
  .app-nav,
  .app-nav ul {
    flex-wrap: wrap;
  }

  /* Two rows of links need less air between them than one row does. This only
     tightens spacing between nav items; it changes no font size (P4). */
  .app-nav {
    --pico-nav-element-spacing-horizontal: 0.25rem;
    --pico-nav-element-spacing-vertical: 0.5rem;
  }

  /* --- Grouped action controls (FR-004) -----------------------------------
     Pico's `[role=group]` is a non-wrapping inline-flex, and it gives every
     button inside it `--pico-form-element-spacing-horizontal: 2rem`. Four
     controls — what the order_then_install workflow produces — therefore lay
     out 575px wide inside a 375px viewport.

     Two things fix it, and NEITHER may count the controls (P1): the group
     wraps, and each child claims a legible minimum width and grows to fill the
     row. A workflow shipping six actions gets three rows of two with no change
     here; one shipping two gets one row. The rule reacts to how many children
     exist, it never encodes how many there should be.

     Selectors target `> *`, not `> button`, because the children differ by
     consumer: in _OccurrenceActions each child is a <form> wrapping its button
     (every mutation is its own POST with its own anti-forgery token,
     Constitution IV), while in Settings/Calendar they are a button and a link.
     Both are the same layout problem, so both get the same class. */
  .app-actions {
    flex-wrap: wrap;
    /* Pico welds a group into one segmented control with zero gap and zeroed
       inner radii. Once it is two rows that reads as a mistake, so wrapped
       controls are separated and given their corners back below. */
    gap: calc(var(--pico-spacing) * 0.5);
  }

  .app-actions > * {
    /* Grow to share the row, shrink to fit, but never narrower than a legible
       label. 8rem is about "Mark ordered" plus padding at 16px text. */
    flex: 1 1 8rem;
  }

  .app-actions button,
  .app-actions [type=submit],
  .app-actions [type=button],
  .app-actions [role=button] {
    width: 100%;
    /* 2rem of horizontal padding per button is a desktop affordance; at phone
       width it is what pushes the group off-screen. Vertical padding and font
       size are untouched — the 44px floor and P4 both depend on them. */
    --pico-form-element-spacing-horizontal: 0.75rem;
    /* With a gap separating them, Pico's welded-segment radii would leave square
       corners floating in whitespace. */
    border-radius: var(--pico-border-radius);
  }

  /* --- Touch-target floor (FR-005, SC-003) --------------------------------
     44px is the smallest reliably-tappable target on a phone; anything under it
     is how you mis-tap the neighbouring control, which SC-006 counts as a
     failure of the whole walkthrough.

     `min-height`, deliberately not `height`: a label that wraps to two lines at
     320px must be allowed to grow. A fixed height would clip it. */
  button,
  [type=submit],
  [type=button],
  [role=button] {
    min-height: 44px;
  }
}

/* --- The current-section mark (011 FR-009, SC-004) -------------------------
   Unconditional, alongside .app-brand and .app-wrap, and deliberately NOT inside
   the media query above: this file commits to exactly one breakpoint, and a
   "you are here" mark has no reason to differ between a phone and a desktop.

   Two channels, and NEITHER is hue — which rules out the three obvious choices.
   `background-color` is discarded outright in forced-colours mode. `color` is
   overridden by the user's palette there AND is hue-only, so it fails greyscale
   as well. `border-bottom` survives both but collides with the underline Pico
   already draws on nav-link hover, so the mark would read as a hover state.
   `font-weight` and `text-decoration` are both preserved under forced colours
   and both read in greyscale, and using two means the mark survives a future
   Pico upgrade neutralising one of them.

   The selector matches the attribute's PRESENCE, not its value: `page` and
   `true` look identical on purpose. That distinction is for assistive
   technology — "this link is the page you are on" vs "this link is the section
   you are in" — and rendering it visually would be inventing a difference a
   sighted reader has no use for.

   FR-010 holds by construction: no pointer-events, no aria-disabled, no href
   change, so the marked entry stays a working link to its section. None of the
   file's six prohibitions is engaged — this rule counts no controls, is not
   position:fixed, hides nothing, changes no font-size, adds no JavaScript, and
   does not touch pico.min.css. */
.app-nav a[aria-current] {
  font-weight: bold;
  text-decoration: underline;
}

/* --- Brand area (008 FR-005, FR-008) --------------------------------------
   Two consumers, both through Pages/Shared/_Brand.cshtml: the .app-nav brand
   cell, and the anonymous /a/{token} page which renders with Layout = null.

   Unconditional on purpose — this needs no media query, so it adds nothing to
   the one-breakpoint budget this file's header protects.

   flex-shrink:0 on the mark is the long-product-name case: ProductName is
   operator-settable, and a long one must compress the text rather than squash
   the mark into an unrecognizable sliver. .app-nav already sets flex-wrap:wrap
   below 767.98px, so a brand cell ~24px wider wraps instead of pushing the
   document into horizontal scroll at the 320px floor.

   No prefers-color-scheme rule, and that is deliberate rather than an omission:
   the mark is an opaque #0172ad tile carrying a white house glyph, so FR-009
   (legible under both schemes) holds by construction. A dark-mode rule here
   would be complexity against a requirement already met. */
.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.app-brand img {
  flex-shrink: 0;
  block-size: 1.5rem;
  inline-size: 1.5rem;
}

/* --- Wrapping user-supplied strings (FR-007) -------------------------------
   Unconditional, not inside the media query: a 60-character item name or a
   60-character uploaded filename has no space to break at, so it widens the
   page at any width narrow enough. The wrap is correct wherever it applies.

   `overflow-wrap: anywhere` breaks mid-word only as a last resort, after normal
   break opportunities are exhausted — which is what these strings need, since
   the whole problem is that they offer none.

   Scoped to the containers that hold user data, deliberately never to `body`:
   a global rule would break running prose mid-syllable everywhere in the app,
   trading one legibility bug for a subtler one. */
.app-wrap {
  overflow-wrap: anywhere;
}

/* The invite-code prefix is rendered in <code>, which Pico does not wrap. */
.app-wrap code,
code.app-wrap {
  overflow-wrap: anywhere;
}

/* --- The fragment target (009 FR-007) --------------------------------------
   /settings/calendar lists one <article id="feed-{homeId}"> per accessible home,
   and a home page links to /settings/calendar#feed-{id}. The browser scrolls the
   right article into view on its own; this rule is the other half — FR-007 says
   the target home is *identified*, and a bare scroll leaves "the one you came
   for" and "the one that happens to be at the top of the viewport" looking
   identical.

   Unconditional, alongside .app-brand and .app-wrap, so it adds nothing to the
   one-breakpoint budget the header protects — an accent that is correct on a
   phone is correct at 1280px too.

   P5 holds: :target plus native fragment scrolling is precisely why no script is
   needed here, and a scroll-and-flash script was rejected for that reason. P3 is
   untouched — this styles a control and hides nothing; P1 is untouched — it
   counts no controls. Colours are Pico custom properties, never literals, so
   both colour schemes are covered by Pico's own per-scheme redefinition.

   Scoped to `article` rather than `:target` alone: every other id on a page is a
   potential accidental match, and this accent is meant for one shape of thing. */
article:target {
  border: 1px solid var(--pico-primary);
  box-shadow: 0 0 0 var(--pico-outline-width) var(--pico-primary-focus);
}

/* --- Switch helper text (014 FR-021…FR-023) --------------------------------
   Pico gives any <small> immediately after a form control a -0.75rem top margin,
   to cancel most of the +1rem bottom margin it gives that control and leave ~4px
   of gap:

     :where(input,select,textarea,fieldset,.grid)+small {
       margin-top: calc(var(--pico-spacing) * -.75);   ...which is -12px
     }

   But the rule granting that bottom margin is
   `input:not([type=checkbox],[type=radio])` — a checkbox has none — so on a
   switch the -0.75rem lands on nothing and drags the helper block 12px up, into
   the switch's own line box. That is the overlap in the 014 screenshot, and it
   is a cause, not a symptom: measured on Edit.cshtml at 375px, the <small>
   started at y=28 while the switch ran 18.8→38.8 and its "Active" label
   18.5→37.5. With this rule the <small> starts at y=44 — a 10.8px overlap
   becomes a 5.2px gap.

   +0.25rem rather than 0: flush against the switch would read as a different
   relationship than every other helper <small> on the create form, which sits
   ~4px under its field. This lands on the same ~4px.

   Unconditional, outside the one media query, because the cause is a margin —
   the defect is width-independent and the fix has no reason to differ by
   viewport. Desktop gets the identical +4px correction and nothing else, which
   is what FR-023 asks for. Keyed on the input types rather than a class because
   the bug belongs to any checkbox with helper text, and a class is a thing to
   remember to apply; a second switch added later inherits the fix instead of
   re-discovering the bug.

   None of this file's six prohibitions is engaged: counts no controls (P1), not
   position:fixed (P2), hides nothing (P3), changes no font-size (P4), adds no
   JavaScript (P5), does not touch pico.min.css (P6). */
[type="checkbox"] + small,
[type="radio"] + small {
  margin-top: calc(var(--pico-spacing) * 0.25);
}

/* --- The photo form's two affordances (FR-011, FR-012, FR-016; 006 FR-001…004)
   Two pages render this pair: the artifact-upload form (/entities/{id}/artifacts/
   upload) and the add-item form (/entities/new), which adopted it in 006 after
   shipping with the pre-001 single-input markup the pattern exists to replace.
   The rules are deliberately generic — nothing here is page-specific.

   The camera control exists only on phones. Hiding it at desktop width leaves
   exactly one ordinary file picker there — byte-for-byte the screen that shipped
   before this feature, which is what FR-016 asks for.

   This is NOT the thing P3 forbids. P3 is about authorization: an owner-only
   control must be absent from a member's HTML, not merely invisible. `Photo` is
   available to every viewer of this page; only its affordance is width-specific,
   and both controls post to the same endpoint either way. */
@media (min-width: 768px) {
  .app-capture {
    display: none;
  }
}

@media (max-width: 767.98px) {
  /* Below the breakpoint the existing-file path stays clearly labelled and fully
     usable — this is the only route to a PDF manual — but reads as secondary to
     the camera above it (FR-012). Secondary in emphasis, never in reachability:
     no disclosure, no extra tap, same screen. */
  .app-attach-alt {
    --pico-color: var(--pico-muted-color);
    margin-top: var(--pico-spacing);
    padding-top: var(--pico-spacing);
    border-top: 1px solid var(--pico-muted-border-color);
  }

  /* --- The picker's own wording, on the control (007 FR-001, FR-002) -------
     006 put each control's wording in the label text ABOVE the input and left
     the input unstyled, so both controls rendered the UA's identical stock
     "Choose File" button — the thumb was aimed at a box that said nothing about
     the camera. The wording therefore moves ONTO the control: the label's text
     is now a <span class="app-picker-action"> styled as a full-width pill, and
     the UA's button is suppressed below.

     ::file-selector-button cannot be re-worded — it selects a real button in the
     input's shadow tree, not a generated-content pseudo-element, so `content`
     does not apply and the "Choose File" string is unreachable from CSS (007
     R2). Promoting the label text is the only no-JavaScript way to satisfy
     FR-001, and P5 still holds: nothing here needs a script.

     THE DISTINCTION THE WHOLE TECHNIQUE RESTS ON, and the one a later reader is
     most likely to "clean up": the UA **button** is hidden, the **input** never
     is. The input stays in normal flow, so the UA keeps rendering its own text
     run — "No file chosen", and after a pick the filename. That is what gives
     FR-006 (visible chosen-file feedback) natively, with no script, and it is
     why the degradation path adds a visible control rather than removing one
     (FR-013). Hiding the input instead — opacity:0, position:absolute — would
     discard that text and force JavaScript back in. Do not.

     Because the input is a descendant of its <label>, the pill (and in fact the
     whole card) opens the picker in one tap — no `for`, no id plumbing. */
  .app-picker-action {
    display: block;
    width: 100%;
    /* min-height, not height: at 320px this wording wraps to two lines and must
       be allowed to grow rather than clip. 44px is the touch floor. */
    min-height: 44px;
    /* 1rem, never smaller — P4 / FR-012: anything under 16px computed makes iOS
       auto-zoom the page on focus. */
    font-size: 1rem;
    line-height: 1.25;
    padding: 0.75rem;
    box-sizing: border-box;
    text-align: center;
    border: 1px solid transparent;
    border-radius: var(--pico-border-radius);
    cursor: pointer;
    /* Separates the pill from the UA's filename text on the line below. */
    margin-bottom: calc(var(--pico-spacing) * 0.5);
  }

  /* The stock "Choose File" box, and ONLY it. The input keeps its box, so the
     UA still renders "No file chosen" / the chosen filename beneath the pill —
     FR-006 with zero JavaScript. See the note above before deleting either of
     these rules or merging them into one selector list. */
  .app-capture input[type=file]::file-selector-button,
  .app-attach-alt input[type=file]::file-selector-button {
    display: none;
  }

  /* Deliberately a SEPARATE rule, not a fourth selector above: one unknown
     pseudo-element invalidates an entire selector list, so folding the -webkit-
     alias in would drop the standard rule on the very WebKit builds (pre-Safari
     16.4) the alias exists to serve. */
  .app-capture input[type=file]::-webkit-file-upload-button,
  .app-attach-alt input[type=file]::-webkit-file-upload-button {
    display: none;
  }

  /* Focus stays on the input — it is still the focusable control, still reached
     by Tab, and Enter/Space on it still opens the chooser. But with its button
     suppressed the input's own box is just a text run, so a ring drawn there
     would point at the filename rather than at the thing you press. :focus-within
     on the label moves the ring to the pill, which is what the eye and the thumb
     both treat as the control (FR-007).

     `outline-offset` is load-bearing, not polish. Pico's
     --pico-form-element-focus-color resolves to the SAME value as
     --pico-primary-background, so a ring drawn flush against the camera pill is
     the pill's own fill colour painted on the pill's own fill — measurably
     present and completely invisible. Offsetting it by the ring's own width
     lifts it onto the page background, where it reads on the filled variant and
     the outlined one alike. Do not drop the offset to "tidy up", and do not swap
     in a literal colour to solve it (FR-014): both schemes are covered because
     Pico redefines these properties per scheme. */
  .app-capture:focus-within .app-picker-action,
  .app-attach-alt:focus-within .app-picker-action {
    outline: var(--pico-outline-width) solid var(--pico-form-element-focus-color);
    outline-offset: var(--pico-outline-width);
  }

  /* The camera path is the primary one, so it takes Pico's filled-accent
     treatment; the existing-file path below takes the outlined one. Every colour
     is a Pico custom property and never a literal — Pico redefines these per
     colour scheme, so a hex value here would be wrong in light or in dark
     (FR-014). Fill, colour and glyph give three non-text differences between the
     two controls where FR-003 asks for one. */
  .app-capture .app-picker-action {
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
    border-color: var(--pico-primary-background);
  }

  /* U+1F4F7 CAMERA plus a no-break space. The glyph is injected here rather than
     written into the markup so it stays out of the accessible name and out of
     the two behavioral specs' HTML text assertions (007 R5). The ` / ""` is
     content-alt: it tells assistive technology to announce nothing for the
     generated content. Belt and braces, each input also carries an aria-label
     equal to its visible wording, which pins the name even where content-alt is
     unsupported (FR-007). */
  .app-capture .app-picker-action::before {
    content: "\1F4F7\00a0" / "";
  }

  /* The existing-file path: outlined rather than filled. Secondary in EMPHASIS
     only — it is still full width, still ≥44px, still on the same screen behind
     no disclosure and no extra tap, because it is the only route to a PDF manual
     (FR-004). The `color` here also overrides the muted `--pico-color` the
     .app-attach-alt rule above sets for its <small>: the pill is the control,
     not supporting text, and must not read as disabled. */
  .app-attach-alt .app-picker-action {
    background: transparent;
    color: var(--pico-primary);
    border-color: var(--pico-primary);
  }

  /* U+1F4C1 FILE FOLDER, same content-alt treatment as the camera glyph. */
  .app-attach-alt .app-picker-action::before {
    content: "\1F4C1\00a0" / "";
  }

  /* --- Stacked tables (FR-018, FR-020) ------------------------------------
     Four tables in this app are genuinely multi-column — People, Invitations,
     Maintenance, and Your codes — and a table cannot narrow past the sum of its
     columns. On a phone they force the whole document sideways.

     Below the breakpoint each row becomes a card and each cell a labelled line,
     so the row reads top-to-bottom in one pass instead of sideways. The column
     header moves from the <th> into each cell via `data-label`, which is why
     that attribute is REQUIRED on every cell of a stacked table: a cell without
     one renders as an unlabelled orphan value, exactly the failure FR-018
     describes. Action cells carry `data-label=""` and get no label line.

     Above the breakpoint none of this exists and the tables are untouched, which
     is what FR-020 and SC-007 require. */
  .stacked,
  .stacked tbody,
  .stacked tr,
  .stacked td {
    display: block;
    width: 100%;
  }

  /* The header row's job is done by the per-cell labels now. */
  .stacked thead {
    display: none;
  }

  .stacked tr {
    margin-bottom: var(--pico-spacing);
    padding: calc(var(--pico-spacing) * 0.5) 0;
    border-bottom: 1px solid var(--pico-muted-border-color);
  }

  .stacked td {
    /* Pico's cell borders draw as full-width rules between stacked lines, which
       reads as a row separator and hides where one record ends. */
    border-bottom: none;
    padding: calc(var(--pico-spacing) * 0.25) 0;
  }

  .stacked td::before {
    content: attr(data-label);
    display: block;
    color: var(--pico-muted-color);
    font-weight: bold;
  }

  /* An action cell has no column header to show. */
  .stacked td[data-label=""]::before {
    display: none;
  }
}
