/*
 * Santa's Little Helpers: theme + site styles on top of Web Awesome.
 *
 * Theme: wa-theme-default + wa-palette-default + wa-brand-green (classes on <html>).
 * Brand overrides and app tokens live in :root below; everything else uses --wa-* tokens.
 */

:root {
  /* Brand: a deeper evergreen than the default green-50 */
  --wa-color-brand-fill-loud: var(--wa-color-green-40);
  --wa-color-brand-border-loud: var(--wa-color-green-40);
  --wa-color-text-link: var(--wa-color-green-30);

  /* Type: warm serif headings, system sans body */
  --wa-font-family-heading: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, ui-serif, serif;

  /* App tokens */
  --slh-band: var(--wa-color-green-20);
  --slh-band-deep: var(--wa-color-green-10);
  --slh-band-text: var(--wa-color-green-95);
  --slh-band-text-quiet: var(--wa-color-green-80);
  --slh-accent: var(--wa-color-red-40);
  --slh-accent-hover: var(--wa-color-red-30);
  --slh-gold: var(--wa-color-yellow-80);
  --slh-content-width: 72rem;

  /* Backoffice colours that have a dark variant below */
  --slh-comment-rule: var(--wa-color-green-70);
}

/* Dark mode, backoffice only: admin/layout.html.twig switches <html> from wa-light to wa-dark. Web Awesome's
   --wa-color-* tokens follow on their own; these are our overrides and app tokens. */
.wa-dark {
  --wa-color-text-link: var(--wa-color-green-70);

  --slh-accent: var(--wa-color-red-60);
  --slh-comment-rule: var(--wa-color-green-50);
}

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

body {
  min-height: 100dvh;
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--wa-color-surface-default);
}

.container {
  width: 100%;
  max-width: var(--slh-content-width);
  margin-inline: auto;
  padding-inline: var(--wa-space-l);
  box-sizing: border-box;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--wa-space-s);
  inset-block-start: calc(-1 * var(--wa-space-4xl));
  z-index: 100;
  padding: var(--wa-space-xs) var(--wa-space-s);
  border-radius: var(--wa-border-radius-m);
  background: var(--wa-color-brand-fill-loud);
  color: var(--wa-color-brand-on-loud);
}

.skip-link:focus {
  inset-block-start: var(--wa-space-s);
}

/* Wide content (tables) scrolls inside its wrapper instead of widening the page (main is a grid item). */
.site-main {
  min-width: 0;
}

.site-main:focus {
  outline: none;
}

/* ---------- Header ---------- */

.site-header {
  border-block-end: var(--wa-border-width-s) solid var(--wa-color-surface-border);
  background: var(--wa-color-surface-raised);
  padding-block: var(--wa-space-s);
}

.site-brand {
  font-family: var(--wa-font-family-heading);
  font-size: var(--wa-font-size-l);
  font-weight: var(--wa-font-weight-bold);
  color: var(--wa-color-text-normal);
  text-decoration: none;
}

.site-brand-icon {
  color: var(--slh-accent);
  font-size: var(--wa-font-size-xl);
}

/* ---------- Flash messages ---------- */

.flash {
  margin-block-start: var(--wa-space-m);
}

/* Warm red call-to-action: re-point the brand tokens on this one button */
.accent-button {
  --wa-color-brand-fill-loud: var(--slh-accent);
  --wa-color-brand-border-loud: var(--slh-accent);
  --wa-color-brand-on-loud: white;
  --wa-color-focus: var(--slh-gold);
}

.accent-button::part(button) {
  box-shadow: var(--wa-shadow-m);
}

/* ---------- Form errors ---------- */

/* Error state for Web Awesome controls: red border, the message is shown in the hint
   (set by validation.js on /apply, rendered server-side on the admin forms). */
.has-error {
  --wa-form-control-border-color: var(--wa-color-danger-border-loud);
}

.has-error::part(hint) {
  color: var(--wa-color-danger-on-quiet);
  font-weight: var(--wa-font-weight-semibold);
}

wa-checkbox.has-error::part(control) {
  border-color: var(--wa-color-danger-border-loud);
}

/* ---------- Sections ---------- */

.section {
  padding-block: var(--wa-space-3xl);
}

/* ---------- Footer ---------- */

.site-footer {
  padding-block: var(--wa-space-l);
  background: var(--slh-band-deep);
  color: var(--slh-band-text-quiet);
  font-size: var(--wa-font-size-s);
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--slh-band-text);
}

/* ---------- Error page ---------- */

.error-card {
  max-width: 36rem;
  margin-inline: auto;
  text-align: center;
}

.error-card h1 {
  margin: 0;
  font-size: var(--wa-font-size-2xl);
}

.error-card p {
  margin: 0;
}

.error-icon {
  color: var(--slh-accent);
  font-size: var(--wa-font-size-4xl);
}

.error-status {
  color: var(--wa-color-text-quiet);
  font-size: var(--wa-font-size-s);
  font-weight: var(--wa-font-weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- Admin ---------- */

.admin-login-form {
  max-width: 24rem;
}

.admin-form {
  max-width: 28rem;
}

/* ---------- Admin header: section links, theme toggle, Sign out ---------- */

/* One control group at the right: pill-shaped links in a lowered track (the current section filled evergreen),
   then the round theme toggle and a quiet Sign out button, all the same height. */
.admin-header {
  --admin-control-height: 2.25rem;
  --admin-nav-active-fill: var(--wa-color-green-40);
  --admin-nav-active-text: white;
}

/* Dark mode: a step lighter, so the current pill stands out from the dark track (3:1). */
.wa-dark .admin-header {
  --admin-nav-active-fill: var(--wa-color-green-50);
}

.admin-header > .container {
  flex-wrap: nowrap;
}

.admin-nav {
  margin-inline-start: auto;
}

.admin-nav-list {
  display: flex;
  gap: var(--wa-space-3xs);
  margin: 0;
  padding: var(--wa-space-3xs);
  border-radius: var(--wa-border-radius-pill);
  background: var(--wa-color-surface-lowered);
  list-style: none;
}

.admin-nav-list > li {
  margin: 0;
}

.admin-nav-link,
.admin-signout-button,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--wa-space-xs);
  box-sizing: border-box;
  height: var(--admin-control-height);
  margin: 0;
  border: none;
  border-radius: var(--wa-border-radius-pill);
  background: none;
  color: var(--wa-color-text-quiet);
  font: inherit;
  font-size: var(--wa-font-size-s);
  font-weight: var(--wa-font-weight-semibold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

/* Inside the track: a little lower than the tools, so the track lines up with them. */
.admin-nav-link {
  height: calc(var(--admin-control-height) - 2 * var(--wa-space-3xs));
  padding-inline: var(--wa-space-m);
}

.admin-signout-button {
  padding-inline: var(--wa-space-s) var(--wa-space-m);
}

.theme-toggle {
  width: var(--admin-control-height);
  padding: 0;
}

.admin-nav-link:hover,
.admin-signout-button:hover,
.theme-toggle:hover {
  background: var(--wa-color-neutral-fill-quiet);
  color: var(--wa-color-text-normal);
}

.admin-nav-link:hover {
  background: var(--wa-color-surface-raised);
}

.admin-nav-link[aria-current='page'] {
  background: var(--admin-nav-active-fill);
  color: var(--admin-nav-active-text);
}

.admin-nav-link:focus-visible,
.admin-signout-button:focus-visible,
.theme-toggle:focus-visible {
  outline: var(--wa-focus-ring);
  outline-offset: var(--wa-focus-ring-offset);
}

.admin-nav-link wa-icon,
.admin-signout-button wa-icon {
  font-size: 0.9em;
}

.admin-tools {
  display: flex;
  align-items: center;
  gap: var(--wa-space-3xs);
}

/* A hairline between the section links and the tools. */
.admin-nav + .admin-tools {
  padding-inline-start: var(--wa-space-xs);
  border-inline-start: var(--wa-border-width-s) solid var(--wa-color-surface-border);
}

.admin-signout {
  display: contents;
}

/* The sign-in page: just the toggle, at the right. */
.site-brand + .admin-tools {
  margin-inline-start: auto;
}

:root:not(.wa-dark) .theme-toggle-sun,
.wa-dark .theme-toggle-moon {
  display: none;
}

/* Without JS the button would do nothing (the theme stays light). */
@media (scripting: none) {
  .theme-toggle {
    display: none;
  }
}

/* Phones: the brand and the tools (icons only) on top, the section links below as a full-width segmented row. */
@media (max-width: 40rem) {
  .admin-header > .container {
    display: grid;
    grid-template-areas: 'brand tools' 'nav nav';
    grid-template-columns: minmax(0, 1fr) auto;
    row-gap: var(--wa-space-s);
  }

  .admin-header .site-brand {
    grid-area: brand;
  }

  .admin-nav {
    grid-area: nav;
    margin-inline-start: 0;
  }

  .admin-nav-list > li {
    flex: 1 1 0;
    min-width: 0;
  }

  .admin-nav-link {
    width: 100%;
    padding-inline: var(--wa-space-xs);
  }

  .admin-tools {
    grid-area: tools;
  }

  .admin-nav + .admin-tools {
    padding-inline-start: 0;
    border-inline-start: none;
  }

  .admin-signout-button {
    width: var(--admin-control-height);
    padding: 0;
  }

  .admin-signout-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Application status badges (templates/admin/applications/_status_badge.html.twig). "New" uses the brand
   variant, but the brand colour is green like "Approved": show it in blue. */
wa-badge.status-new {
  --wa-color-brand-fill-loud: var(--wa-color-blue-50);
  --wa-color-brand-on-loud: white;
}

/* Dark mode: solid badges glare on the near-black page and their small white text is hard to read. Give them a
   tinted fill with light text instead; the outlined warning badges get lighter text and a clearer rule. */
.wa-dark wa-badge[appearance='accent'] {
  border-color: var(--wa-color-border-normal);
  background-color: var(--wa-color-fill-quiet);
  color: var(--wa-color-on-normal);
}

.wa-dark wa-badge.status-new {
  --wa-color-brand-fill-quiet: var(--wa-color-blue-10);
  --wa-color-brand-border-normal: var(--wa-color-blue-30);
  --wa-color-brand-on-normal: var(--wa-color-blue-80);
}

.wa-dark wa-badge[variant='warning'][appearance='outlined'] {
  border-color: var(--wa-color-fill-loud);
  color: var(--wa-color-on-normal);
}

/* Backoffice cards (application page, stats page): an evergreen header band with a gold rule and a serif title
   with a gold icon. */
.admin-cards wa-card::part(header) {
  padding-block: var(--wa-space-s);
  border-block-end: 3px solid var(--slh-gold);
  background: var(--slh-band);
  color: var(--slh-band-text);
}

.card-title {
  display: flex;
  align-items: center;
  gap: var(--wa-space-s);
  margin: 0;
  color: inherit;
  font-size: var(--wa-font-size-l);
  line-height: var(--wa-line-height-condensed);
}

.card-title wa-icon {
  color: var(--slh-gold);
  font-size: 0.9em;
}

/* Dark mode: the bands are too heavy on a near-black page. A raised neutral header with a thin green rule instead
   (the gold icon stays). */
.wa-dark .admin-cards wa-card::part(header) {
  border-block-end: 2px solid var(--wa-color-brand-border-loud);
  background: var(--wa-color-surface-raised);
  color: var(--wa-color-text-normal);
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  padding: var(--wa-space-xs) var(--wa-space-s);
  border-block-end: var(--wa-border-width-s) solid var(--wa-color-surface-border);
  text-align: start;
  white-space: nowrap;
}

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

@media (max-width: 40rem) {
  .container {
    padding-inline: var(--wa-space-m);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
