/* PF-01 Self-Administered Audit Protocol and Inventory.
   Loaded after shared/style.css on both pages. */

/* ---- Step two: the eight patterns as a grid ---- */

.pattern-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin-top: .75rem; }
.pattern-choice {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  min-height: 2.75rem;
  margin: 0;
  padding: .6rem .65rem;
  border: 1px solid var(--rule);
  background: var(--bg);
  font-family: var(--sans);
  font-size: .975rem;
  line-height: 1.3;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pattern-choice input { margin-top: .1rem; }
.pattern-choice input:focus-visible { outline: none; }
.nowrap { white-space: nowrap; }
.pattern-choice:hover { border-color: var(--text); }
.pattern-choice:has(input:checked) { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); background: var(--panel); font-weight: 600; }
.pattern-choice:has(input:focus-visible) { outline: 2px solid var(--text); outline-offset: 2px; }
.pattern-num { font-family: var(--mono); font-size: .85em; font-weight: 400; color: var(--muted); letter-spacing: .04em; }
@media (min-width: 640px) {
  .pattern-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.pattern-definition { margin: .75rem 0 0; font-size: 1rem; }
.pattern-definition:empty { margin: 0; }
.key-hint { display: none; margin: .6rem 0 0; font-size: .8rem; }
@media (hover: hover) and (pointer: fine) {
  .key-hint { display: block; }
}
/* Never on a device with a touch screen. */
@media (any-pointer: coarse) {
  .key-hint { display: none; }
}

/* The outcome sits at the top of the form, where the page returns after
   filing. */
#protocol-form { scroll-margin-top: 1rem; }
.protocol-outcome:not(:empty) { margin-bottom: 1rem; }

/* ---- The record ---- */

.entry-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.entry-list > li {
  margin: 0;
  padding: .75rem .75rem .6rem;
  border-bottom: 1px solid var(--rule);
  border-left: 3px solid transparent;
  break-inside: avoid;
  transition: background-color 1.2s ease, border-color 1.2s ease;
}
.entry-list > li.just-filed { background: rgba(17, 17, 17, .09); border-left-color: var(--text); transition: none; }
.entry-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .75rem; margin: 0 0 .25rem; }
.entry-pattern { font-weight: 600; }
.entry-noticed { margin: 0 0 .4rem; font-size: 1rem; }
.entry-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .25rem .75rem; }
.entry-foot .metadata { margin: 0; }
#record-heading:focus { outline: none; }
#record-heading:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.button-small { padding: .45rem .85rem; font-size: .75rem; }

/* ---- The weekly tally: bars, monochrome, with the count in text ---- */

.tally-bars tbody th { font-weight: 400; font-family: var(--sans); font-size: .95rem; }
.tally-bars td { text-align: left; width: 50%; }
.tally-bars tbody tr:last-child > * { border-bottom: 1px solid var(--rule); }
.tally-cell { display: flex; align-items: center; justify-content: flex-end; gap: .6rem; }
.tally-bar { flex: 1 1 auto; height: .55rem; background: rgba(17, 17, 17, .07); }
.tally-fill { display: block; height: 100%; background: var(--text); }
.tally-count { flex: 0 0 2.5ch; text-align: right; font-weight: 700; }
.tally-zero th, .tally-zero td { color: var(--muted); }
.tally-zero .tally-count { font-weight: 400; }
.tally-collapsed .tally-zero { display: none; }
#tally-all { margin: 0 0 1rem; }
.tally-empty { margin-top: 1rem; }
#week { margin-bottom: 1rem; }

/* ---- Inventory: the question stage ---- */

.question-head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: .6rem 0 .5rem; margin-bottom: .75rem; }
.question-head h2 { margin-bottom: .5rem; }
.question-head h2:focus { outline: none; }
.question-head h2:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.progress-line { max-width: none; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .1rem 1rem; margin: 0 0 .4rem; font-family: var(--mono); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.progress-count { font-weight: 700; color: var(--text); }
.progress-rule { height: 3px; background: var(--rule); }
.progress-rule > span { display: block; height: 100%; width: 0; background: var(--text); transition: width .3s ease; }
html:has(#stage-questions:not([hidden])) { scroll-padding-top: 7.5rem; }

#question-form fieldset { margin: 0 0 1rem; border-left: 3px solid var(--rule); }
/* The legend sits inside the box, so the question does not straddle the
   border. */
#question-form legend { float: left; width: 100%; padding: 0 0 .6rem; }
.scale-options { clear: both; }
#question-form fieldset:has(input:checked) { border-left-color: var(--text); }
.scale-options .done-label { min-height: 2.75rem; -webkit-tap-highlight-color: transparent; }

/* Wider screens: the five answers as one segmented row. */
@media (min-width: 640px) {
  .scale-options { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--text); background: var(--bg); }
  .scale-options .done-label {
    flex-direction: column;
    justify-content: center;
    gap: .35rem;
    padding: .55rem .25rem;
    border-left: 1px solid var(--rule);
    font-family: var(--mono);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    line-height: 1.25;
    text-align: center;
  }
  .scale-options .done-label:first-child { border-left: 0; }
  .scale-options .done-label:hover { background: var(--panel); }
  .scale-options .done-label:has(input:checked) { background: rgba(17, 17, 17, .1); box-shadow: inset 0 0 0 2px var(--text); font-weight: 700; }
  .scale-options .done-label:has(input:focus-visible) { outline: 2px solid var(--text); outline-offset: -5px; }
}

/* ---- Small screens ---- */

@media (max-width: 600px) {
  body { padding-top: 1rem; }

  /* A compact header. The record block runs on as one paragraph. */
  .page-header { padding-bottom: .9rem; margin-bottom: 1.1rem; }
  .page-header .tool-icon { position: absolute; top: 0; right: 0; width: 2.25rem; height: 2.25rem; margin: 0; }
  .page-header .eyebrow { padding-right: 2.75rem; letter-spacing: .07em; }
  h1 { font-size: 1.6rem; margin-bottom: .5rem; }
  .record-block { font-size: .7rem; line-height: 1.5; padding: .4rem 0; margin-bottom: .6rem; }
  .record-block .record-ref { display: inline; margin: 0; }
  .record-block .record-ref::after { content: " · "; }
  .record-block dl { display: inline; }
  .record-block dt, .record-block dd { display: inline; }
  .record-block dd { margin-left: .35em; }
  .record-block dd::after { content: " · "; }
  .record-block dd:last-child::after { content: none; }
  .page-header > .record-block + p { margin-top: .5rem; font-size: 1rem; line-height: 1.5; }

  .purpose { margin-bottom: 1.25rem; }
  .purpose h2 { margin-bottom: .6rem; }
  .protocol-purpose { font-size: .95rem; line-height: 1.5; padding: .6rem .85rem; margin-bottom: 0; }

  #protocol-form fieldset { margin: .75rem 0; }
  #protocol-form label:not(.pattern-choice) { margin-top: .75rem; }
  #protocol-form textarea { min-height: 4.75rem; }
  .pattern-choice { font-size: .9rem; padding: .55rem .5rem; gap: .45rem; }

  /* Step three stays at the foot of the screen while the form is in view.
     It is sticky, not fixed, so it keeps its place in the form and nothing
     after it is hidden; it leaves with the form once the form scrolls past.
     Fields moved into view by the keyboard stop clear of it. */
  html:has(.respond-step) { scroll-padding-bottom: 9rem; }
  .respond-step {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 1rem -1.25rem 0;
    padding: .45rem 1.25rem .6rem;
    background: var(--bg);
    border: 0;
    border-top: 2px solid var(--text);
    box-shadow: 0 -4px 10px rgba(17, 17, 17, .08);
  }
  .respond-step legend { float: left; width: 100%; padding: 0; font-size: .7rem; }
  .respond-step legend + * { clear: both; }
  .respond-step .metadata { font-size: .7rem; line-height: 1.35; margin: 0 0 .4rem; }
  .protocol-responses { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; margin: 0; }
  .protocol-responses button { -webkit-tap-highlight-color: transparent; padding: .4rem .3rem; font-size: .72rem; letter-spacing: .02em; min-height: 3rem; }

  .entry-list > li { padding-left: .6rem; padding-right: .25rem; }

  /* Inventory */
  .question-head h2 { margin-bottom: .35rem; }
  .progress-line { font-size: .72rem; letter-spacing: .05em; }
  #question-form fieldset { padding: .75rem .85rem .5rem; }
  #question-form legend .legend-question { font-size: 1.0625rem; line-height: 1.45; }
  .scale-options .done-label + .done-label { border-top: 1px solid var(--grid); }
}

@media (prefers-reduced-motion: reduce) {
  .entry-list > li, .progress-rule > span { transition: none; }
}

@media print {
  .key-hint, .pattern-definition { display: none; }
  .respond-step { position: static; }
  .tally-collapsed .tally-zero { display: table-row; }
  .tally-fill { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .entry-list > li { padding: .3rem 0; border-left: 0; }
  .question-head { position: static; }
}
