/*
 * Stylesheet of the configuration UI (ADR 0030): system fonts, readable
 * line length, light and dark colours that follow the operating system,
 * and focus outlines that are always visible.
 */

:root {
  color-scheme: light dark;
  --text: #1b1b1f;
  --muted: #4a4a55;
  --background: #fafafa;
  --surface: #ffffff;
  --border: #8a8a96;
  /* The orange of the logo; as text on a light page it would be too faint. */
  --accent: #ff8a2b;
  --accent-text: #14161c;
  --link: #9a4500;
  --danger: #a4161a;
  --danger-text: #ffffff;
  --success: #1e6b34;
  --focus: #c75c00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #ececf1;
    --muted: #b9b9c6;
    --background: #16161a;
    --surface: #202026;
    --border: #74747f;
    --accent: #ff8a2b;
    --accent-text: #14161c;
    --link: #ff8a2b;
    --danger: #ff8a8a;
    --danger-text: #0b0b10;
    --success: #7fd893;
    --focus: #ffb366;
  }
}

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

html {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans",
    "Helvetica Neue", Arial, sans-serif;
  font-size: 100%;
  line-height: 1.5;
  color: var(--text);
  background: var(--background);
  accent-color: var(--link);
}

body {
  margin: 0;
}

/* Scripts show these elements; no rule below may reveal them before. */
[hidden] {
  display: none !important;
}

body > header,
body > main,
body > footer {
  max-width: 48rem;
  margin: 0 auto;
  padding: 1rem;
}

body > header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}

body > header p {
  margin: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand img {
  display: block;
}

.brand span {
  color: var(--muted);
}

.app-icon {
  display: block;
  margin-top: 1.5rem;
}

body > footer {
  color: var(--muted);
  font-size: 0.875rem;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.2;
}

a {
  color: var(--link);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

fieldset {
  margin: 0 0 1.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
}

legend {
  padding: 0 0.25rem;
  font-weight: 700;
}

label {
  display: block;
  margin-top: 0.75rem;
  font-weight: 600;
}

fieldset > label:first-of-type {
  margin-top: 0;
}

input,
select,
button {
  font: inherit;
  color: inherit;
}

input[type="text"],
input[type="url"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="file"],
select {
  display: block;
  width: 100%;
  max-width: 32rem;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--surface);
}

input[type="radio"] {
  margin-right: 0.5rem;
}

label:has(> input[type="radio"]) {
  font-weight: 400;
}

[aria-invalid="true"] {
  border-color: var(--danger);
  border-width: 2px;
}

button {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.25rem;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

button.secondary,
table button {
  margin-top: 0;
  border-color: var(--link);
  background: transparent;
  color: var(--link);
}

/*
 * Destructive actions: a solid danger background with its own text colour,
 * never danger text on the accent background (white on #a4161a in light
 * mode, about 7.8:1; near-black on #ff8a8a in dark mode, about 8.7:1).
 */
button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--danger-text);
}

form.inline {
  display: inline;
}

details {
  margin: 0 0 1.5rem;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

details > fieldset {
  margin-top: 0.75rem;
}

.hint,
.error {
  display: block;
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
}

.hint {
  color: var(--muted);
}

.error {
  color: var(--danger);
  font-weight: 600;
}

section[role="alert"],
output.notice {
  display: block;
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-left: 4px solid var(--danger);
  background: var(--surface);
}

output.notice {
  border-left-color: var(--success);
}

section[role="alert"] h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
}

caption {
  text-align: left;
  font-weight: 700;
  padding-bottom: 0.5rem;
}

th,
td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

/*
 * Buttons that belong together share one row with even gaps. Removing stands
 * apart at the end (Apple HIG: keep destructive actions out of the way).
 */
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.actions button {
  margin: 0;
}

.actions > .danger,
.actions > .apart {
  margin-left: auto;
}

td > .actions {
  gap: 0.5rem;
  margin: 0;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin-top: 0.5rem;
}

dialog {
  max-width: 28rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  color: var(--text);
  background: var(--surface);
}

/* In a dialog the decision sits at the trailing edge, the action outermost. */
dialog .actions {
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

dialog .actions > .danger {
  margin-left: 0;
}

dialog::backdrop {
  background: rgb(0 0 0 / 50%);
}

@media (max-width: 40rem) {
  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  table,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  tr {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
  }

  th,
  td {
    border: 0;
    padding: 0.25rem 0;
  }
}

nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

nav a[aria-current] {
  font-weight: 700;
  text-decoration-thickness: 3px;
}

main > section {
  margin-bottom: 2rem;
}

/* The settings: a row of topics and one card per subject. */
.topics ul {
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.topics a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
}

.topics a[aria-current] {
  color: var(--text);
  font-weight: 700;
  border-bottom-color: var(--link);
}

/* The pages of a group take a row of their own below the navigation. */
body > header > .topics {
  flex-basis: 100%;
}

body > header > .topics ul {
  border-bottom: 0;
}

.settings > section[aria-labelledby]:not([role]) {
  margin-top: 1.5rem;
  margin-bottom: 0;
  padding: 1.25rem;
  border: 1px solid color-mix(in srgb, var(--border) 45%, transparent);
  border-radius: 0.75rem;
  background: var(--surface);
}

.settings h2 {
  margin: 0 0 0.75rem;
  font-size: 1.125rem;
}

.settings input,
.settings select,
.settings textarea {
  background: var(--background);
}

.settings input[type="number"] {
  max-width: 8rem;
}

.settings textarea {
  display: block;
  width: 100%;
  max-width: 32rem;
  margin-top: 0.25rem;
  padding: 0.5rem;
  font: inherit;
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
}

.settings label:has(> input[type="checkbox"]) {
  font-weight: 400;
}

/* Narrow screens stack the buttons; in a dialog cancel ends up at the bottom. */
@media (max-width: 30rem) {
  .actions,
  dialog .actions {
    flex-direction: column;
    align-items: stretch;
  }

  dialog .actions {
    flex-direction: column-reverse;
  }

  .actions button {
    width: 100%;
  }

  .actions > .danger,
  .actions > .apart {
    margin-left: 0;
  }
}
