/* Alfred Trauma — the presentation every form, account and administration page
 * shares (#200). Linked by templates/app.html after tokens.css, and by the two
 * refusal pages that are not built on the layout (403.html, placeholder.html),
 * which link it themselves so that a refusal looks like the application without
 * inheriting the layout's CSRF token.
 *
 * Not linked by the wall boards, the Trauma Directory, the Feedback client or
 * the tools pages: each of those has a mature sheet of its own, and this file
 * styles elements, so linking it there would redesign them.
 *
 * Every value is read from tokens.css. Nothing here writes a colour out, so
 * nothing here can drift from the palette or collide with another sheet's
 * literal.
 *
 * Element rules are wrapped in :where() so that they carry no specificity: a
 * class rule in any later sheet — the person picker's, which arrives with the
 * rotation wizard's form media — wins over them without fighting. */

/* ---- Page ------------------------------------------------------------- */

.app {
  margin: 0;
  background: var(--color-bg-page);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: var(--t-body-size);
  line-height: var(--t-body-lh);
  overflow-wrap: break-word;
  -webkit-text-size-adjust: 100%;
}

.app :where(*, *::before, *::after) { box-sizing: border-box; }

/* An element a page hides stays hidden: the rules below give controls a
 * display of their own, which would otherwise outrank the attribute's — the
 * rotation wizard carries its paste forward in a hidden textarea. */
.app [hidden] { display: none; }

/* Content and chrome share one column, so the header's text lines up with the
 * page's. The column is wide enough for the administration tables; a form on
 * its own reads in the narrow variant. */
.app {
  --app-column: 72rem;
  --app-gutter: max(var(--space-4), calc((100% - var(--app-column)) / 2));
}

/* ---- Header: the service, the reader, and the page's own title ------- */

.app-header {
  background: var(--color-bg-brand-strong);
  color: var(--color-text-inverse);
}

.app-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-2) var(--app-gutter);
  background: var(--licorice);
  color: var(--rail-text);
  font-size: var(--t-meta-size);
  line-height: var(--t-meta-lh);
}

.app-brand {
  color: var(--orange-web);
  font-weight: var(--weight-bold);
  letter-spacing: var(--t-label-tracking);
  text-transform: uppercase;
}

.app-session {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin: 0;
}

/* Reversed out of the bar, so not the brand-red link colour every other link
 * on the page takes. */
.app-session a { color: var(--rail-text); }
.app-session a:hover { color: var(--orange-web); }

.app-page {
  padding: var(--space-6) var(--app-gutter);
}

.app-page :where(h1) {
  margin: 0;
  color: var(--orange-web);
  font-size: var(--t-title-size);
  line-height: var(--t-title-lh);
  overflow-wrap: anywhere;
}

.app-page :where(p) {
  margin: var(--space-2) 0 0;
  color: var(--rail-text);
}

@media (min-width: 768px) {
  .app-page :where(h1) {
    font-size: var(--t-display-size);
    line-height: var(--t-display-lh);
  }
}

/* ---- Navigation: what this page leads to ----------------------------- */

/* The navigation block's <nav>, whichever page wrote it: a strip of links
 * under the header, wrapping rather than scrolling on a phone. */
.app > nav {
  padding: var(--space-2) var(--app-gutter);
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-default);
}

.app > nav :where(ul) {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.app > nav :where(li) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.app > nav > :where(a),
.app > nav :where(li > a, li > strong) {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height);
  margin-right: var(--space-2);
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-brand);
  font-weight: var(--weight-bold);
  text-decoration: none;
}

.app > nav :where(li > a, li > strong) { margin-right: 0; }

.app > nav :where(a:hover) { background: var(--wash-warm); text-decoration: underline; }

.app > nav :where([aria-current="page"]) {
  background: var(--wash-neutral);
  color: var(--color-text-primary);
  box-shadow: inset 0 -3px 0 var(--color-bg-brand);
}

/* A number the navigation carries — the roster exceptions on the
 * administration strip. Its words say what it counts. */
.app-count {
  display: inline-block;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-pill);
  background: var(--wash-warm);
  color: var(--color-text-secondary);
  font-size: var(--t-meta-size);
}

.app-count[data-outstanding] {
  border-color: var(--wash-critical-border);
  background: var(--wash-critical);
  color: var(--color-status-critical);
  font-weight: var(--weight-bold);
}

/* ---- Main column ------------------------------------------------------ */

.app-main {
  display: block;
  max-width: var(--app-column);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-12);
}

/* The account pages: one short form, or a sentence and a link, on a card. */
.app-main--narrow {
  max-width: 36rem;
}

.app-main--narrow > :first-child { margin-top: 0; }

@media (min-width: 600px) {
  .app-main--narrow {
    margin-top: var(--space-8);
    padding: var(--space-8);
    border: 1px solid var(--color-border-default);
    border-radius: var(--radius-md);
    background: var(--color-bg-surface);
  }
}

/* A page's sections are cards on the ground. A section inside one is not. */
.app-main > :where(section),
.app-main > form > :where(section) {
  margin: 0 0 var(--space-6);
  padding: var(--space-4);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background: var(--color-bg-surface);
}

@media (min-width: 600px) {
  .app-main > :where(section),
  .app-main > form > :where(section) { padding: var(--space-6); }
}

/* On the narrow card the card is the page, so its sections are divided by a
 * rule rather than drawn as cards within it. */
.app-main--narrow > :where(section) {
  margin: var(--space-6) 0 0;
  padding: var(--space-6) 0 0;
  border: 0;
  border-top: 1px solid var(--color-border-default);
  border-radius: 0;
  background: none;
}

.app-main :where(section) > :first-child { margin-top: 0; }
.app-main :where(section) > :last-child { margin-bottom: 0; }

/* ---- Text ------------------------------------------------------------- */

.app-main :where(h2) {
  margin: var(--space-6) 0 var(--space-3);
  color: var(--color-text-brand);
  font-size: var(--t-section-size);
  line-height: var(--t-section-lh);
  overflow-wrap: anywhere;
}

@media (min-width: 768px) {
  .app-main :where(h2) { font-size: var(--t-title-size); line-height: var(--t-title-lh); }
}

.app-main :where(h3, h4) {
  margin: var(--space-4) 0 var(--space-2);
  color: var(--color-text-primary);
  font-size: var(--t-section-size);
  line-height: var(--t-section-lh);
}

.app-main :where(p, ul, ol, dl, figure, blockquote, pre, table, details) {
  margin: 0 0 var(--space-4);
}

.app-main :where(ul, ol) { padding-left: var(--space-6); }
.app-main :where(li) { margin-bottom: var(--space-1); }

.app :where(a) { color: var(--color-text-brand); text-underline-offset: 0.15em; }
.app :where(a:hover) { color: var(--color-text-primary); }

.app-main :where(code) {
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
  background: var(--wash-neutral);
  font-size: var(--t-meta-size);
  overflow-wrap: anywhere;
}

.app-main :where(pre) {
  overflow-x: auto;
  padding: var(--space-3);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: var(--wash-warm);
  font-size: var(--t-meta-size);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.app-main :where(blockquote) {
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--color-border-default);
  background: var(--wash-warm);
}

.app-main :where(dl) {
  display: grid;
  grid-template-columns: minmax(8rem, max-content) 1fr;
  gap: var(--space-2) var(--space-4);
}

.app-main :where(dt) { color: var(--color-text-muted); font-weight: var(--weight-bold); }
.app-main :where(dd) { margin: 0; overflow-wrap: anywhere; }

.app-main :where(img) { max-width: 100%; height: auto; }

.app-main :where(figure) { margin-inline: 0; }
.app-main :where(figcaption) { color: var(--color-text-muted); font-size: var(--t-meta-size); }

.app-main :where(sup) { line-height: 0; }

/* A page's own strip of links at the foot of a section — "Back to the
 * dashboard", "Take the quiz", "On this page". */
.app-main :where(nav) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin: 0 0 var(--space-4);
}

.app-main :where(nav > span) { color: var(--color-text-muted); font-weight: var(--weight-bold); }

/* ---- Status ----------------------------------------------------------- */

/* A message announced to the reader. The role is what a screen reader acts
 * on; it does not say whether the news is good, so a status line is neutral
 * unless the page marks its outcome: status-success for something done or in
 * order, status-warning for something not done. A Django message carries its
 * level as status-<level_tag>. An alert is always an error, a note always a
 * caution. The words always say which it is. */
.app :where(p[role="status"], p[role="alert"], p[role="note"]) {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border-default);
  border-left: 4px solid var(--color-text-muted);
  border-radius: var(--radius-sm);
  background: var(--wash-neutral);
  color: var(--color-text-primary);
}

.app :where(p[role="status"].status-success) {
  border-color: var(--wash-ok-border);
  border-left-color: var(--color-status-ok);
  background: var(--wash-ok);
}

.app :where(p[role="note"], p[role="status"].status-warning) {
  border-color: var(--wash-warning-border);
  border-left-color: var(--wash-warning-text);
  background: var(--wash-warning);
}

.app :where(p[role="alert"]) {
  border-color: var(--wash-critical-border);
  border-left-color: var(--color-status-critical);
  background: var(--wash-critical);
}

/* An error beside the field it is about. */
.app :where(form span[role="alert"], td span[role="alert"]) {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-status-critical);
  font-size: var(--t-meta-size);
  font-weight: var(--weight-bold);
}

/* ---- Forms ------------------------------------------------------------ */

.app :where(fieldset) {
  min-width: 0;
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
}

.app :where(legend) {
  padding: 0 var(--space-2);
  color: var(--color-text-brand);
  font-weight: var(--weight-bold);
}

.app :where(fieldset > p, form > p, form > div, details > p) { margin: 0 0 var(--space-4); }

.app :where(label) {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--color-text-secondary);
  font-weight: var(--weight-bold);
}

/* A label written around its control — the quiz's options, a radio list —
 * and one written beside a checkbox are read across, not above. */
.app :where(label:has(> input[type="radio"], > input[type="checkbox"])) {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-sm);
  font-weight: var(--weight-regular);
  cursor: pointer;
}

.app :where(label:has(> input:checked)) {
  border-color: var(--color-border-focus);
  background: var(--wash-warm);
}

/* A checkbox and the label after it, one per line: the membership bundles. */
.app :where(p:has(> input[type="checkbox"] + label, > input[type="radio"] + label)) {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
}

.app :where(input[type="checkbox"] + label, input[type="radio"] + label) {
  display: inline;
  margin: 0;
  font-weight: var(--weight-regular);
  cursor: pointer;
}

/* A label wrapping a text field rather than naming one by id: its words, then
 * the field beneath. */
.app :where(label > input:not([type="radio"], [type="checkbox"])) {
  margin-top: var(--space-1);
}

.app :where(.help) {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--t-meta-size);
  font-weight: var(--weight-regular);
}

.app :where(
  input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="file"], [type="submit"], [type="button"]),
  select,
  textarea
) {
  display: block;
  width: 100%;
  max-width: 32rem;
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--neutral-400);
  border-radius: var(--radius-sm);
  background: var(--color-bg-surface);
  color: var(--color-text-primary);
  font: inherit;
  font-weight: var(--weight-regular);
}

.app :where(textarea) { max-width: none; min-height: 8rem; resize: vertical; }

.app :where(td) :where(input, select, textarea) { min-width: 8rem; }

.app :where(input[readonly]) { background: var(--wash-warm); }

.app :where(input[type="checkbox"], input[type="radio"]) {
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  accent-color: var(--penn-red);
  flex: none;
}

.app :where(input[type="file"]) {
  display: block;
  max-width: 100%;
  margin: var(--space-1) 0 var(--space-2);
  font: inherit;
}

.app :where(input, select, textarea):focus {
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-focus);
}

/* Keyboard focus is always visible, on every control and link. */
.app :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--color-border-focus);
  outline-offset: 2px;
}

/* The focus colour is the brand red, which all but disappears on the dark
 * header; there the ring takes the orange the header's own title does. */
.app-header :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline-color: var(--orange-web);
}

.app :where(details) {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: var(--color-bg-surface);
}

.app :where(summary) {
  color: var(--color-text-brand);
  font-weight: var(--weight-bold);
  cursor: pointer;
}

.app :where(details[open] > summary) { margin-bottom: var(--space-3); }

/* ---- Buttons ---------------------------------------------------------- */

/* Primary: the one act a form is for. A link drawn as a button, a.button, is
 * the one act a page with no form is for — leaving for a channel elsewhere. */
.app :where(button, input[type="submit"], a.button) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  margin: 0 var(--space-2) var(--space-2) 0;
  padding: var(--space-2) var(--control-padding-x);
  border: 1px solid var(--penn-red);
  border-radius: var(--radius-sm);
  background: var(--penn-red);
  color: var(--color-text-inverse);
  font: inherit;
  font-weight: var(--weight-bold);
  line-height: var(--t-ui-lh);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard);
}

.app :where(button, input[type="submit"], a.button):hover {
  border-color: var(--blood-red);
  background: var(--blood-red);
}

/* Secondary: going back, choosing among options, a second act beside the
 * first. A choice already made is marked as pressed. */
.app :where(.button-secondary, button[aria-pressed]) {
  border-color: var(--neutral-400);
  background: var(--color-bg-surface);
  color: var(--color-text-primary);
}

.app :where(.button-secondary, button[aria-pressed]):hover {
  border-color: var(--color-text-primary);
  background: var(--wash-warm);
}

.app :where(button[aria-pressed="true"]),
.app :where(button[aria-pressed="true"]):hover {
  border-color: var(--color-text-primary);
  background: var(--color-text-primary);
  color: var(--color-text-inverse);
}

/* Destructive: outlined in the status colour, so it never reads as the act a
 * form is for. The words say what is removed. */
.app :where(.button-destructive) {
  border-color: var(--color-status-destructive);
  background: var(--color-bg-surface);
  color: var(--color-status-destructive);
}

.app :where(.button-destructive):hover {
  background: var(--wash-critical);
  border-color: var(--blood-red);
  color: var(--blood-red);
}

/* A button sitting in a table cell or a list, among others like it. */
.app :where(td, li) :where(button) {
  min-height: 0;
  padding: var(--space-1) var(--space-3);
  font-size: var(--t-meta-size);
}

@media (max-width: 920px) {
  .app :where(td, li) :where(button) { min-height: var(--control-height); }
}

.app :where(li > form, td > form) {
  display: inline-block;
  margin: var(--space-1) var(--space-2) 0 0;
  vertical-align: middle;
}

.app :where(li > form) :where(button),
.app :where(td > form) :where(button) { margin: 0; }

/* ---- Tables ----------------------------------------------------------- */

.app-main :where(table) {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--color-border-default);
  background: var(--color-bg-surface);
  font-size: var(--t-meta-size);
  line-height: var(--t-meta-lh);
}

.app-main :where(caption) {
  padding: 0 0 var(--space-2);
  color: var(--color-text-muted);
  text-align: left;
}

.app-main :where(th, td) {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border-default);
  text-align: left;
  vertical-align: top;
}

.app-main :where(thead th) {
  background: var(--wash-warm);
  color: var(--color-text-secondary);
  font-size: var(--t-label-size);
  letter-spacing: var(--t-label-tracking);
  text-transform: uppercase;
  white-space: nowrap;
}

.app-main :where(tbody th) { font-weight: var(--weight-bold); }
.app-main :where(tbody tr:hover) { background: var(--wash-line); }

.app-main :where(td > a) { display: inline-block; margin: 0 var(--space-3) var(--space-1) 0; }

/* A table wider than a phone scrolls inside itself rather than pushing the
 * page sideways. */
@media (max-width: 920px) {
  .app-main :where(table) {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }
}

/* ---- Lists of people -------------------------------------------------- */

/* The photograph list on the add screen: one row per person. */
.app-people {
  margin: 0;
  padding: 0;
  list-style: none;
}

.app-people > li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  margin: 0;
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border-soft);
}

.app-people > li > form {
  display: flex;
  flex: 1 1 18rem;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin: 0;
}

.app-people img {
  border-radius: var(--radius-pill);
  background: var(--avatar-ground);
  object-fit: cover;
  flex: none;
}

.app-people label { flex: 1 1 12rem; margin: 0; }

/* The filter above a list: the field and its button on one line where they fit. */
.app-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-4);
}

.app-filter > p { flex: 1 1 16rem; margin: 0; }
.app-filter :where(input) { max-width: none; }
.app-filter :where(button, a) { margin: 0; }
.app-filter :where(a) { align-self: center; }

/* What the list is showing, under the filter. */
.app-meta {
  color: var(--color-text-muted);
  font-size: var(--t-meta-size);
}

/* A step list: where a multi-step form has got to. */
.app-steps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.app-steps > li {
  margin: 0;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-pill);
  background: var(--color-bg-surface);
  color: var(--color-text-muted);
  font-size: var(--t-meta-size);
  counter-increment: step;
}

.app-steps > li::before { content: counter(step) ". "; }

.app-steps > li:has([aria-current]) {
  border-color: var(--color-text-primary);
  background: var(--color-text-primary);
  color: var(--color-text-inverse);
}
