/* Overrides for Pico.css (lib/pico, ADR-0004). Our tokens per color scheme, mapped onto Pico's variables once. */

:root {
  --accent: #2557d6;
  /* Links and the wordmark; a branded dark mode lightens it (PageBranding). */
  --accent-text: var(--accent);
  --accent-hover: #1c45ad;
  --accent-inverse: #fff;
  --accent-focus: rgba(37, 87, 214, 0.3);
  --page: #eef1f6;
  --card: #fff;
  --danger: #b42318;
  --danger-background: #b42318;
  --success: #1a7f37;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7aa2ff;
    --accent-hover: #a3bfff;
    --accent-inverse: #0b1020;
    --accent-focus: rgba(122, 162, 255, 0.35);
    --page: #0d1016;
    --card: #171b24;
    --danger: #ff8a80;
    --danger-background: #c4321f;
    --success: #56d364;
  }
}

/* Same specificity as Pico's theme selectors, and later, so it wins in light and dark. */
:root:not([data-theme=none]) {
  --pico-primary: var(--accent-text);
  --pico-primary-background: var(--accent);
  --pico-primary-border: var(--accent);
  --pico-primary-underline: var(--accent-focus);
  --pico-primary-hover: var(--accent-hover);
  --pico-primary-hover-background: var(--accent-hover);
  --pico-primary-hover-border: var(--accent-hover);
  --pico-primary-hover-underline: var(--accent-hover);
  --pico-primary-focus: var(--accent-focus);
  --pico-primary-inverse: var(--accent-inverse);
  --pico-background-color: var(--page);
  --pico-card-background-color: var(--card);
  --pico-card-sectioning-background-color: var(--card);
  --pico-dropdown-background-color: var(--card);
  --pico-border-radius: 0.5rem;
  /* Pico grows the root font with the viewport, to 125% at 1280px; keep the browser's 16px everywhere. */
  --pico-font-size: 100%;
}

/* Auth shell: one centred card. */

body > main.auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 26rem;
  margin: 0;
  padding: 2rem;
}

.auth-card h1 { font-size: 1.5rem; margin: 0 0 1rem; }

.auth-card form { margin-bottom: 0.75rem; }

.auth-card button, .auth-card [role=button] { width: 100%; margin-bottom: 0; }

.auth-card form + p { margin-top: 1rem; }

/* The card's top: a logo or the wordmark (BrandHeader). */
.brand { margin-bottom: 1.5rem; }

.brand img { display: block; width: auto; height: auto; max-width: 200px; max-height: 48px; }

@media (prefers-color-scheme: dark) {
  .brand img.tile { padding: 0.375rem 0.5rem; border-radius: 0.375rem; background: #fff; }
}

@media (max-width: 599px) {
  body > main.auth { padding: 0; place-items: stretch; }
  .auth-card { max-width: none; border-radius: 0; box-shadow: none; padding: 1.5rem 1rem; }
  /* Edge to edge there is no background around the card, so it shows as a band behind the logo. */
  .brand { margin: -1.5rem -1rem 1.5rem; padding: 1.5rem 1rem; background: var(--page); }
}

.wordmark {
  display: inline-block;
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  color: var(--accent-text);
  text-decoration: none;
}

/* App shell: top bar and wide content. */

body > header.app-bar {
  padding-block: 0;
  background: var(--card);
  border-bottom: 1px solid var(--pico-muted-border-color);
}

.app-bar nav .wordmark { margin: 0; }

.app-bar summary {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-bar details.dropdown > summary + ul { left: auto; right: 0; }

/* Admin links sit in the bar on wide screens and in the menu on narrow ones. */
.app-bar .narrow { display: none; }

@media (max-width: 599px) {
  .app-bar .wide { display: none; }
  .app-bar .narrow { display: list-item; }
  .app-bar summary { max-width: 10rem; }
}

body > main.container { padding-top: 2rem; }

.page { max-width: 48rem; }

article > h2:first-child { margin-top: 0; font-size: 1.15rem; }

body > main.container :is(button, [role=button]) { width: auto; }

/* Admin: a form beside its lists on wide screens, above them on narrow ones. */
@media (min-width: 960px) {
  .split { display: grid; grid-template-columns: minmax(18rem, 22rem) minmax(0, 1fr); gap: 1.5rem; align-items: start; }
}

article table { margin-bottom: 0; }

article :is(th, td) { background-color: var(--card); }

thead th { position: sticky; top: 0; z-index: 1; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.25rem 1.5rem; }

dt { color: var(--pico-muted-color); }

dd { margin: 0; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

.actions form { margin: 0; }

/* One Client per row: its checkboxes, then Save. */
.client-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 0;
  margin: 0;
  border-bottom: 1px solid var(--pico-muted-border-color);
}

/* A Client's checkbox, then its roles indented under it. */
.client-access { margin-bottom: 0.5rem; }

.client-access > label { margin-bottom: 0.5rem; }

.client-access > label:not(:first-child) { margin-inline-start: 2rem; }

.client-row:last-child { border-bottom: 0; }

.client-row fieldset { display: flex; flex: 1 1 0; flex-wrap: wrap; gap: 0.25rem 1.25rem; width: auto; min-width: 0; margin: 0; }

.client-row .client-access > label:not(:first-child) { margin-inline-start: 0; }

.client-row :is(label, button) { margin: 0; }

.client-row .client-access > label:first-child { font-weight: 600; }

.danger-zone { border: 1px solid var(--danger-background); }

.danger-zone h2 { color: var(--danger); }

/* Rows of "thing, then its action", such as signed-in applications. */
ul.items { padding: 0; margin: 0; }

ul.items li {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--pico-muted-border-color);
}

ul.items li:last-child { border-bottom: 0; }

ul.items form, td form { margin: 0; }

ul.items button, td button { width: auto; margin: 0; padding: 0.375rem 1rem; }

/* Shared. */

:is(button, [role=button]).danger {
  --pico-background-color: var(--danger-background);
  --pico-border-color: var(--danger-background);
  --pico-color: #fff;
}

:is(button, [role=button]).danger:is(:hover, :focus) { filter: brightness(0.9); }

.error, .validation-errors, .validation-message { color: var(--danger); }

.validation-errors { padding-left: 1rem; }

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

.badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0 0.5rem;
  border: 1px solid var(--pico-muted-border-color);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--pico-muted-color);
  vertical-align: middle;
}

.badge.success { color: var(--success); border-color: currentColor; }

label:has([type=checkbox]) { margin-bottom: var(--pico-spacing); }

code { word-break: break-all; }

/* Emails are long and unbroken; let them wrap rather than widen the page. */
h1, summary { overflow-wrap: anywhere; }

td { overflow-wrap: break-word; }

/* The email column takes the long, unbroken words; the others keep theirs whole. */
td:first-child { overflow-wrap: anywhere; min-width: 10rem; }

td button { white-space: nowrap; }

@media (max-width: 599px) {
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tr { border-bottom: 1px solid var(--pico-muted-border-color); padding: 0.5rem 0; }
  td { border: 0; padding: 0.125rem 0; background: transparent; }
  td { overflow-wrap: anywhere; }
  td[data-label]::before { content: attr(data-label) ": "; color: var(--pico-muted-color); }
}
