/* NEIAM look for the Authelia portal (4.38.x, theme: dark).
 *
 * Injected by the `neiam-theme` rewrite-body Middleware; served from
 * /neiam-theme/ so Authelia's CSP (style-src 'self') allows it.
 *
 * Authelia renders with MUI + emotion, whose generated class names
 * (css-xxxxx) change every build. Only these are targeted:
 *   - MUI's stable global classes (.MuiButton-root, .Mui-focused, ...)
 *   - Authelia's element ids (#username-textfield, #sign-in-button, ...)
 *   - the login layout's shape: Container > Grid > [logo, title, body, footer]
 * Re-check after an Authelia upgrade.
 *
 * Scoping with :is(#root, ...) gives every rule id specificity, which beats
 * emotion's single-class rules without !important even though emotion's
 * <style> tags are inserted after this sheet.
 */

/* B612 Mono, from neiam-org priv/static/fonts (SIL OFL 1.1, see OFL-B612-Mono.txt). */
@font-face {
  font-family: "B612 Mono";
  font-style: normal;
  font-display: swap;
  font-weight: 400;
  src: url("/neiam-theme/b612-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "B612 Mono";
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url("/neiam-theme/b612-mono-latin-700-normal.woff2") format("woff2");
}

/* neiam-org's daisyUI "her" theme, plus the shader's ground colours. */
:root {
  --neiam-base: #651d1d;          /* base-100 */
  --neiam-ground: #661e1e;        /* shader base */
  --neiam-deep: #470005;          /* shader deep */
  --neiam-primary: #b57979;
  --neiam-primary-hover: #c48d8d;
  --neiam-primary-content: #2a0808;
  --neiam-secondary: #d5abab;
  --neiam-accent: #fef3c7;
  --neiam-neutral: #7f3535;
  --neiam-content: #f6e4df;       /* body text */
  --neiam-muted: rgba(246, 228, 223, 0.62);
  --neiam-line: rgba(254, 243, 199, 0.22);
  --neiam-line-hover: rgba(254, 243, 199, 0.45);
  --neiam-field: rgba(30, 4, 6, 0.35);
  --neiam-font: "B612 Mono", ui-monospace, monospace;
  color-scheme: dark;
}

/* ---- ground + shader canvas ---------------------------------------- */

/* The gradient is the fallback where WebGL2 is unavailable; the canvas
   paints over it. MUI's CssBaseline sets body's background, hence !important. */
html,
body {
  min-height: 100%;
}
body {
  background: radial-gradient(ellipse at 50% 50%, var(--neiam-ground) 35%, var(--neiam-deep) 125%) fixed !important;
  color: var(--neiam-content) !important;
  font-family: var(--neiam-font) !important;
}
#neiam-shader {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}
#root {
  position: relative;
  z-index: 1;
}
::selection {
  background: var(--neiam-primary);
  color: var(--neiam-primary-content);
}

/* ---- type ------------------------------------------------------------- */

:is(#root, .MuiDialog-root, .MuiPopover-root, .MuiTooltip-popper, .MuiSnackbar-root) :is(
    .MuiTypography-root, .MuiInputBase-root, .MuiInputBase-input, .MuiFormLabel-root,
    .MuiButtonBase-root, .MuiButton-root, .MuiLink-root, .MuiFormControlLabel-label,
    .MuiAlert-message, .MuiMenuItem-root, .MuiListItemText-primary, .MuiListItemText-secondary,
    .MuiTooltip-tooltip, input, button, legend) {
  font-family: var(--neiam-font);
}
:is(#root, .MuiDialog-root, .MuiPopover-root) .MuiTypography-root {
  color: var(--neiam-content);
}
#root .MuiTypography-h5 {
  color: var(--neiam-accent);
  font-weight: 700;
  letter-spacing: 0.02em;
}
#root .MuiTypography-h6 {
  color: var(--neiam-muted);
  font-size: 0.95rem;
}

/* ---- the card ---------------------------------------------------------- */

#root .MuiContainer-maxWidthXs {
  margin: 2rem 1rem;
  padding: 2rem 2rem 1.25rem;
  background: rgba(101, 29, 29, 0.72);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  backdrop-filter: blur(10px) saturate(1.1);
  border: 1px solid var(--neiam-line);
  border-radius: 1rem;
  box-shadow: 0 1.5rem 4rem rgba(20, 0, 3, 0.55);
}
@media (max-width: 480px) {
  #root .MuiContainer-maxWidthXs {
    padding: 1.5rem 1.25rem 1rem;
  }
}

/* Logo: hide Authelia's mark (or a logo.png override) and set the NEIAM
   wordmark, as on neiam.org's landing page: accent, black weight, caps. */
#root .MuiContainer-maxWidthXs > div > div:first-child > :is(svg, img) {
  display: none;
}
#root .MuiContainer-maxWidthXs > div > div:first-child::before {
  content: "NEIAM";
  display: block;
  margin: 0.25rem 0 1rem;
  font-family: var(--neiam-font);
  font-weight: 700;
  font-size: 2.25rem;
  line-height: 1;
  letter-spacing: 0.35em;
  /* letter-spacing trails the last glyph; pull it back to stay centred */
  margin-right: -0.35em;
  text-transform: uppercase;
  color: var(--neiam-accent);
}

/* ---- fields --------------------------------------------------------- */

:is(#root, .MuiDialog-root) .MuiOutlinedInput-root {
  background: var(--neiam-field);
  border-radius: 0.5rem;
  color: var(--neiam-accent);
}
:is(#root, .MuiDialog-root) .MuiOutlinedInput-notchedOutline {
  border-color: var(--neiam-line);
}
:is(#root, .MuiDialog-root) .MuiOutlinedInput-root:hover:not(.Mui-focused):not(.Mui-error) .MuiOutlinedInput-notchedOutline {
  border-color: var(--neiam-line-hover);
}
:is(#root, .MuiDialog-root) .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline {
  border-color: var(--neiam-primary);
  border-width: 2px;
}
:is(#root, .MuiDialog-root) .MuiInputLabel-root {
  color: var(--neiam-muted);
}
:is(#root, .MuiDialog-root) .MuiInputLabel-root.Mui-focused {
  color: var(--neiam-secondary);
}
:is(#root, .MuiDialog-root) :is(.MuiInputLabel-root, .MuiFormHelperText-root).Mui-error {
  color: #fca5a5;
}
:is(#root, .MuiDialog-root) .MuiOutlinedInput-root.Mui-error .MuiOutlinedInput-notchedOutline {
  border-color: #fca5a5;
}
:is(#root, .MuiDialog-root) .MuiInputAdornment-root .MuiIconButton-root {
  color: var(--neiam-muted);
}
/* Browser autofill paints its own background; keep the field's. */
:is(#root, .MuiDialog-root) input:-webkit-autofill,
:is(#root, .MuiDialog-root) input:-webkit-autofill:hover,
:is(#root, .MuiDialog-root) input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--neiam-accent);
  caret-color: var(--neiam-accent);
  -webkit-box-shadow: 0 0 0 100px #3d0e10 inset;
  transition: background-color 9999s ease-out 0s;
}

/* One-time-code boxes (#otp-input). */
#otp-input input {
  background: var(--neiam-field);
  border: 1px solid var(--neiam-line);
  border-radius: 0.5rem;
  color: var(--neiam-accent);
  font-family: var(--neiam-font);
}
#otp-input input:focus {
  outline: none;
  border-color: var(--neiam-primary);
  box-shadow: 0 0 0 1px var(--neiam-primary);
}

/* ---- checkbox, links ------------------------------------------------ */

:is(#root, .MuiDialog-root) .MuiCheckbox-root {
  color: var(--neiam-line-hover);
}
:is(#root, .MuiDialog-root) .MuiCheckbox-root.Mui-checked {
  color: var(--neiam-primary);
}
:is(#root, .MuiDialog-root) .MuiFormControlLabel-label {
  color: var(--neiam-content);
  font-size: 0.85rem;
}
:is(#root, .MuiDialog-root) .MuiLink-root,
#reset-password-button,
#register-link,
#selection-link,
#methods-button,
#logout-button {
  color: var(--neiam-secondary);
  font-family: var(--neiam-font);
  text-decoration-color: rgba(213, 171, 171, 0.4);
}
:is(#root, .MuiDialog-root) .MuiLink-root:hover,
#reset-password-button:hover {
  color: var(--neiam-accent);
}
/* "Powered by Authelia" footer: keep it, quietly. */
#root a.MuiLink-root[href="https://www.authelia.com"] {
  color: var(--neiam-muted);
  white-space: nowrap;
}
#root .MuiDivider-root {
  border-color: var(--neiam-line);
}

/* ---- buttons --------------------------------------------------------- */

:is(#root, .MuiDialog-root) .MuiButton-contained {
  background: var(--neiam-primary);
  color: var(--neiam-primary-content);
  border-radius: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  box-shadow: none;
}
:is(#root, .MuiDialog-root) .MuiButton-contained:hover {
  background: var(--neiam-primary-hover);
  box-shadow: 0 0 0 1px var(--neiam-accent) inset;
}
:is(#root, .MuiDialog-root) .MuiButton-contained.Mui-focusVisible {
  outline: 2px solid var(--neiam-accent);
  outline-offset: 2px;
}
:is(#root, .MuiDialog-root) .MuiButton-contained.Mui-disabled {
  background: var(--neiam-neutral);
  color: var(--neiam-muted);
}
:is(#root, .MuiDialog-root) :is(.MuiButton-outlined, .MuiButton-text) {
  color: var(--neiam-secondary);
  border-color: var(--neiam-line-hover);
  border-radius: 0.5rem;
}
#root .MuiCircularProgress-root {
  color: var(--neiam-accent);
}

/* ---- second factor, alerts, dialogs, menus ------------------------- */

#root :is(#one-time-password-method, #webauthn-method, #push-notification-method) svg {
  color: var(--neiam-accent);
}
:is(#root, .MuiDialog-root, .MuiSnackbar-root) .MuiAlert-root {
  border-radius: 0.75rem;
  font-family: var(--neiam-font);
}
/* Every MUI Paper (settings and 2FA pages' cards, app bar, drawers) and the
   portal ones (dialogs, popovers, menus) get the card's glass instead of
   MUI's grey: base at 72% over the shader, blurred. MUI's dark mode also
   lays an elevation gradient on Paper (background-image); drop it.
   Alerts are Papers too, and keep their own severity colours. */
#root .MuiPaper-root:not(.MuiAlert-root),
.MuiDialog-root .MuiDialog-paper,
.MuiPopover-root .MuiPaper-root,
.MuiMenu-root .MuiPaper-root,
.MuiDrawer-root .MuiPaper-root {
  background-color: rgba(101, 29, 29, 0.72);
  background-image: none;
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  backdrop-filter: blur(10px) saturate(1.1);
  color: var(--neiam-content);
  border: 1px solid var(--neiam-line);
  border-radius: 1rem;
}
/* The app bar is a full-width Paper: glass, but square, with one rule
   underneath instead of a frame. */
#root .MuiPaper-root.MuiAppBar-root {
  border: 0;
  border-bottom: 1px solid var(--neiam-line);
  border-radius: 0;
  box-shadow: none;
}
.MuiDialog-root .method-option {
  border-color: var(--neiam-line);
  border-radius: 0.75rem;
}
.MuiDialog-root .method-option:hover {
  background: rgba(254, 243, 199, 0.06);
}
.MuiTooltip-popper .MuiTooltip-tooltip {
  background: var(--neiam-deep);
  color: var(--neiam-accent);
  border: 1px solid var(--neiam-line);
}

@media (prefers-reduced-transparency: reduce) {
  #root .MuiContainer-maxWidthXs,
  #root .MuiPaper-root:not(.MuiAlert-root),
  .MuiDialog-root .MuiDialog-paper,
  .MuiPopover-root .MuiPaper-root,
  .MuiMenu-root .MuiPaper-root,
  .MuiDrawer-root .MuiPaper-root {
    background: var(--neiam-base);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
