/* The element layer. Replaced PicoCSS in D-057.
 *
 * Loaded before app.css and styles bare ELEMENTS plus three utility classes.
 * It holds no brand decision: every colour, radius and font comes through a
 * --ui-* custom property that app.css sets per theme, and the var() fallbacks
 * here are neutral greys so the file still renders something if a token is
 * ever missed.
 *
 * The division of labour, which is the thing to keep: if a rule names a
 * component (.hero, .option-row, .assessment-panel) it belongs in app.css. If
 * it names an element the browser already knows about, it belongs here. Pico
 * blurred that line by shipping both, and the result was two stylesheets
 * configuring the same thing in two ways, which is what D-053 spent a commit
 * untangling before D-057 removed the cause.
 *
 * Mobile first throughout: the base rules describe the phone and the media
 * queries add the desktop.
 *
 * Drafted by the Antigravity CLI against a token contract, then reviewed and
 * corrected by hand. The corrections are commented where they sit.
 */

/* Reset. Border box everywhere, no inherited browser margins, and media that
 * cannot overflow its column. The x-cloak rule is the one !important in this
 * file and has to be: without it every Alpine component flashes open before
 * Alpine binds. */

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

* {
  margin: 0;
}

img,
svg,
video,
canvas,
audio,
iframe,
embed,
object {
  display: block;
  max-width: 100%;
  height: auto;
}

[x-cloak] {
  display: none !important;
}

/* htmx's own indicator rules, verbatim, because htmx would otherwise inject
 * them as an inline <style> element on load and our CSP has no
 * 'unsafe-inline' to allow it. `includeIndicatorStyles: false` in the
 * htmx-config meta tag in base.html is the other half; neither half does
 * anything useful alone.
 *
 * Nothing uses hx-indicator yet. These are here so that it works when
 * something does, rather than failing silently with no rule to explain it. */
.htmx-indicator {
  opacity: 0;
  visibility: hidden;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease-in;
}

/* The document. One root font-size that everything else derives from, so the
 * phone reading-size bump in app.css stays a single declaration rather than
 * thirty that drift apart. */

:root {
  --ui-font-size: 100%;
}

html {
  font-size: var(--ui-font-size, 100%);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background-color: var(--ui-background, #ffffff);
  color: var(--ui-color, #111827);
  font-family: var(--ui-font-family, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
  font-weight: var(--ui-font-weight, 400);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

/* The page gutter above and below the content column, and the only place it is
 * declared. It is bottom weighted on purpose: the last thing on a form screen
 * is a submit button, and on a phone the browser's own toolbar sits right under
 * the viewport edge, so a button with nothing under it ends up half behind the
 * chrome and gets mis-tapped. The assessment is taken on a phone, which is
 * where that was found.
 *
 * Nothing in app.css may declare padding on `main` or on anything that is also
 * `.container`: both files declare at the same specificity and app.css loads
 * second, so it would win silently. tests/test_base_layer.py checks for it. */
main {
  padding-block: 1.25rem 4rem;
}

:focus-visible {
  outline: 2px solid var(--ui-primary-focus, rgba(0, 0, 0, 0.4));
  outline-offset: 2px;
}

/* Typography. Each heading level reads its own colour token, because the
 * white card inverts all six at once and needs somewhere to do it. */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin-block: 0 0.75rem;
  font-family: inherit;
  font-weight: var(--ui-font-weight, 700);
  line-height: 1.2;
}

h1 {
  font-size: 2rem;
  color: var(--ui-h1-color, #111827);
}

h2 {
  font-size: 1.5rem;
  color: var(--ui-h2-color, #111827);
}

h3 {
  font-size: 1.25rem;
  color: var(--ui-h3-color, #111827);
}

h4 {
  font-size: 1.125rem;
  color: var(--ui-h4-color, #111827);
}

h5 {
  font-size: 1rem;
  color: var(--ui-h5-color, #111827);
}

h6 {
  font-size: 0.875rem;
  color: var(--ui-h6-color, #111827);
}

@media (min-width: 768px) {
  h1 {
    font-size: 2.25rem;
  }

  h2 {
    font-size: 1.75rem;
  }

  h3 {
    font-size: 1.375rem;
  }

  h4 {
    font-size: 1.2rem;
  }
}

p {
  margin-block: 0 1rem;
  line-height: 1.5;
}

ul,
ol {
  margin-block: 0 1rem;
  padding-inline-start: 1.5rem;
}

li {
  margin-block: 0.25rem;
}

ul ul,
ul ol,
ol ul,
ol ol {
  margin-block: 0.25rem 0;
}

small {
  font-size: 0.875em;
  color: var(--ui-muted-color, #6b7280);
}

strong,
b {
  font-weight: 700;
}

hr {
  height: 0;
  border: 0;
  border-top: 1px solid var(--ui-muted-border, #e5e7eb);
  margin-block: 1.5rem;
}

blockquote {
  margin-block: 0 1rem;
  margin-inline: 0;
  padding-block: 0.25rem;
  padding-inline: 1rem 0;
  border-inline-start: 4px solid var(--ui-muted-border, #e5e7eb);
  color: var(--ui-muted-color, #4b5563);
}

blockquote p:last-child {
  margin-bottom: 0;
}

code,
pre,
kbd,
samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.875em;
}

code {
  padding: 0.15em 0.35em;
  border-radius: var(--ui-border-radius, 0.25rem);
  background-color: var(--ui-field-background, #f3f4f6);
  color: var(--ui-field-color, #111827);
}

pre {
  display: block;
  margin-block: 0 1rem;
  padding: 1rem;
  overflow-x: auto;
  border-radius: var(--ui-border-radius, 0.375rem);
  background-color: var(--ui-field-background, #f3f4f6);
  color: var(--ui-field-color, #111827);
}

pre code {
  padding: 0;
  background-color: transparent;
  color: inherit;
  font-size: inherit;
}

/* Links. The colour here is only a floor. app.css paints them per context,
 * because the sage that passes on the navy is 1.9:1 on the white card. */

a {
  color: var(--ui-color, #111827);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  cursor: pointer;
}

a:hover {
  text-decoration-thickness: 2px;
}

/* Buttons. Every variant rebinds the same three local variables rather than
 * declaring colours of its own, which is D-053: one way to theme a button, so
 * a new variant never has to out-specify an old one. 44px minimum height,
 * because this is taken on a phone at a conference stand. */

button,
[type="button"],
[type="submit"],
[type="reset"],
[role="button"] {
  --btn-background: var(--ui-primary-background, #1f2937);
  --btn-border: var(--ui-primary-border, #1f2937);
  --btn-color: var(--ui-primary-inverse, #ffffff);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.5rem 1.25rem;
  border-width: 1px;
  border-style: solid;
  border-color: var(--btn-border);
  border-radius: var(--ui-border-radius, 0.375rem);
  background-color: var(--btn-background);
  color: var(--btn-color);
  font-family: inherit;
  font-size: 1rem;
  font-weight: inherit;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:hover,
[type="button"]:hover,
[type="submit"]:hover,
[type="reset"]:hover,
[role="button"]:hover {
  --btn-background: var(--ui-primary-hover-background, #111827);
  --btn-border: var(--ui-primary-hover-border, #111827);
  background-color: var(--btn-background);
  border-color: var(--btn-border);
}

button:focus-visible,
[type="button"]:focus-visible,
[type="submit"]:focus-visible,
[type="reset"]:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--ui-primary-focus, rgba(0, 0, 0, 0.4));
  outline-offset: 2px;
}

button.secondary,
[type="button"].secondary,
[type="submit"].secondary,
[type="reset"].secondary,
[role="button"].secondary {
  --ui-primary-background: var(--ui-secondary-background, #4b5563);
  --ui-primary-border: var(--ui-secondary-border, #4b5563);
  --ui-primary-inverse: var(--ui-secondary-inverse, #ffffff);
  --ui-primary-hover-background: var(--ui-secondary-hover-background, #374151);
  --ui-primary-hover-border: var(--ui-secondary-hover-border, #374151);
  --ui-primary-focus: var(--ui-secondary-focus, rgba(0, 0, 0, 0.4));
}

button.outline,
[type="button"].outline,
[type="submit"].outline,
[type="reset"].outline,
[role="button"].outline {
  --btn-background: transparent;
  --btn-color: var(--ui-primary-border, #1f2937);
  background-color: var(--btn-background);
  color: var(--btn-color);
}

button.outline:hover,
[type="button"].outline:hover,
[type="submit"].outline:hover,
[type="reset"].outline:hover,
[role="button"].outline:hover {
  --btn-background: var(--ui-primary-hover-background, #111827);
  --btn-border: var(--ui-primary-hover-border, #111827);
  --btn-color: var(--ui-primary-inverse, #ffffff);
  background-color: var(--btn-background);
  border-color: var(--btn-border);
  color: var(--btn-color);
}

button:disabled,
button[aria-disabled="true"],
[type="button"]:disabled,
[type="button"][aria-disabled="true"],
[type="submit"]:disabled,
[type="submit"][aria-disabled="true"],
[type="reset"]:disabled,
[type="reset"][aria-disabled="true"],
[role="button"]:disabled,
[role="button"][aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* A submit button spans its form, which is what every staff form expects.
 * Still inline-flex, not block: the rule above centres the label with flex,
 * and switching the display here would quietly undo that. app.css narrows the
 * handful of submits that should not be full width. */
button[type="submit"],
[type="submit"] {
  width: 100%;
}

/* Form controls. Checkboxes and radios are drawn here rather than left to the
 * platform, because the platform draws them in its own accent colour and pays
 * no attention to the dark ground. No icon font and no url(): the marks are a
 * rotated border and a dot. */

label {
  display: block;
  margin-bottom: 1rem;
  font-weight: var(--ui-font-weight, 500);
  color: var(--ui-color, #111827);
}

label > input:not([type="checkbox"]):not([type="radio"]),
label > select,
label > textarea {
  margin-top: 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="password"],
input[type="number"],
input:not([type]),
select,
textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--ui-field-border, #d1d5db);
  border-radius: var(--ui-border-radius, 0.375rem);
  background-color: var(--ui-field-background, #ffffff);
  color: var(--ui-field-color, #111827);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 5.5rem;
  resize: vertical;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input:not([type]):focus,
select:focus,
textarea:focus {
  outline: none;
  background-color: var(--ui-field-active-background, var(--ui-field-background, #ffffff));
  border-color: var(--ui-field-active-border, var(--ui-primary-border, #111827));
  box-shadow: 0 0 0 3px var(--ui-primary-focus, rgba(0, 0, 0, 0.25));
}

::placeholder {
  color: var(--ui-field-placeholder, #9ca3af);
  opacity: 1;
}

input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--ui-field-background, #f3f4f6);
}

/* Invalid reads as the error colour, never as the active one. The active
 * border is the brand amber, which is also the selected state, so an invalid
 * radio marked with it would look like the answer the respondent chose. */
[aria-invalid="true"] {
  border-color: var(--field-error-color, #b91c1c);
}

[aria-invalid="false"] {
  border-color: var(--ui-field-border, #9ca3af);
}

[aria-invalid="true"]:focus {
  border-color: var(--field-error-color, #b91c1c);
  box-shadow: 0 0 0 3px var(--ui-primary-focus, rgba(0, 0, 0, 0.25));
}

input[type="checkbox"],
input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  display: inline-grid;
  place-content: center;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  vertical-align: middle;
  border: 1px solid var(--ui-field-border, #9ca3af);
  background-color: var(--ui-field-background, #ffffff);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

input[type="checkbox"] {
  border-radius: var(--ui-border-radius, 0.25rem);
}

input[type="radio"] {
  border-radius: 50%;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background-color: var(--ui-primary-background, #111827);
  border-color: var(--ui-primary-border, #111827);
}

input[type="checkbox"]::before {
  content: "";
  width: 0.35rem;
  height: 0.65rem;
  border: solid var(--ui-primary-inverse, #ffffff);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  margin-bottom: 0.15rem;
  transition: transform 0.1s ease;
}

input[type="checkbox"]:checked::before {
  transform: rotate(45deg) scale(1);
}

input[type="radio"]::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  transform: scale(0);
  background-color: var(--ui-primary-inverse, #ffffff);
  transition: transform 0.1s ease;
}

input[type="radio"]:checked::before {
  transform: scale(1);
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 2px solid var(--ui-primary-focus, rgba(0, 0, 0, 0.4));
  outline-offset: 2px;
}

input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Stripped to a margin on purpose. A fieldset is a grouping element, not a
 * surface: the two in this application both paint themselves, and a border or
 * a background here would be a second one underneath. */
fieldset {
  margin-block: 0 1.5rem;
  padding: 0;
  border: 0;
  min-width: 0;
}

legend {
  display: table;
  max-width: 100%;
  margin-bottom: 0.5rem;
  padding-inline: 0.5rem;
  font-weight: var(--ui-font-weight, 600);
  color: var(--ui-color, #111827);
}

/* Tables. Sixteen of them, all on the staff side. Whether one scrolls
 * sideways on a phone is the caller's decision, so nothing here sets
 * overflow. */

table {
  width: 100%;
  margin-block: 0 1rem;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 0.95rem;
  line-height: 1.4;
}

caption {
  caption-side: top;
  margin-bottom: 0.5rem;
  font-weight: var(--ui-font-weight, 600);
  text-align: left;
  color: var(--ui-color, #111827);
}

th,
td {
  padding: 0.625rem 0.625rem;
  border-bottom: 1px solid var(--ui-table-border, #e5e7eb);
  text-align: left;
  vertical-align: middle;
}

th {
  font-weight: var(--ui-font-weight, 600);
  color: var(--ui-color, #111827);
}

thead th {
  border-bottom: 2px solid var(--ui-table-border, #e5e7eb);
}

@media (min-width: 768px) {
  th,
  td {
    padding: 0.75rem 1rem;
  }
}

/* An article is a card, and this is the rule that makes the tripwire in
 * tests/test_page_ground.py worth having: a public article without
 * .assessment-card is a white surface holding the page's light text. */

article {
  display: block;
  margin-block: 0 1.5rem;
  padding: 1.25rem;
  border: 1px solid var(--ui-card-border, #e5e7eb);
  border-radius: var(--ui-border-radius, 0.5rem);
  background-color: var(--ui-card-background, #ffffff);
}

article > header {
  margin-bottom: 1rem;
}

article > footer {
  margin-top: 1rem;
}

@media (min-width: 768px) {
  article {
    padding: 2rem;
  }
}

/* Disclosure. One use in the whole application, on the staff side. */

details {
  display: block;
  margin-block: 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--ui-muted-border, #e5e7eb);
}

summary {
  display: list-item;
  cursor: pointer;
  padding-block: 0.5rem;
  font-weight: var(--ui-font-weight, 600);
  color: var(--ui-color, #111827);
  user-select: none;
}

summary:focus-visible {
  outline: 2px solid var(--ui-primary-focus, rgba(0, 0, 0, 0.4));
  outline-offset: 2px;
}

details[open] > summary {
  margin-bottom: 0.5rem;
}

/* The two layout utilities the templates use by name. Anything else that lays
 * something out is a named component and lives in app.css. */

/* The gutter is the width, not padding inside it. Every box here is
 * border-box, so a percentage width plus padding-inline would be one gutter
 * subtracted from another and the content column would not be the percentage
 * asked for. 80% of the viewport caps out at 1280px, which is a 1600px screen;
 * past that the margins take the rest. */
.container {
  width: 90%;
  max-width: 1280px;
  margin-inline: auto;
}

@media (min-width: 768px) {
  .container {
    width: 80%;
  }
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.grid > * {
  margin-bottom: 0;
}

/* Equal columns, one per child, without knowing how many there are. The
 * explicit template has to be cleared first or the first child sits in it and
 * the rest land in implicit tracks, which happens to look the same and is not
 * the same thing. */
@media (min-width: 768px) {
  .grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
  }
}
