/*
 * Authelia theme overlay, matched to the SearXNG restyle.
 *
 * Authelia exposes its palette as CSS custom properties behind [data-theme].
 * Override those variables plus a small set of component details; the markup
 * and behaviour stay untouched.
 */

:root,
[data-theme="light"] {
  color-scheme: light;

  --sx-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI Variable Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --sx-bg: #f5f5f7;
  --sx-surface: #ffffff;
  --sx-surface-2: #fbfbfd;
  --sx-glass: rgba(250, 250, 252, 0.76);
  --sx-hover: rgba(0, 0, 0, 0.045);
  --sx-text: #1d1d1f;
  --sx-text-2: #4b4b50;
  --sx-text-3: #86868b;
  --sx-border: rgba(0, 0, 0, 0.08);
  --sx-border-strong: rgba(0, 0, 0, 0.16);
  --sx-accent: #0071e3;
  --sx-accent-hover: #0077ed;
  --sx-accent-soft: rgba(0, 113, 227, 0.12);
  --sx-danger: #d70015;

  --sx-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --sx-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 20px rgba(0, 0, 0, 0.05);
  --sx-shadow-md: 0 16px 42px rgba(0, 0, 0, 0.12);

  --background: var(--sx-bg);
  --foreground: var(--sx-text);
  --card: var(--sx-surface);
  --card-foreground: var(--sx-text);
  --popover: var(--sx-surface);
  --popover-foreground: var(--sx-text);
  --primary: var(--sx-accent);
  --primary-foreground: #ffffff;
  --secondary: #7a5aa6;
  --secondary-foreground: #ffffff;
  --muted: var(--sx-hover);
  --muted-foreground: var(--sx-text-3);
  --accent: var(--sx-hover);
  --accent-foreground: var(--sx-text);
  --destructive: var(--sx-danger);
  --destructive-foreground: #ffffff;
  --border: var(--sx-border);
  --input: var(--sx-border-strong);
  --ring: var(--sx-accent);
  --radius: 0.9rem;
  --custom-icon: var(--sx-text);
  --custom-loading-bar: var(--sx-accent);
  --divider: var(--sx-border);
}

[data-theme="dark"],
[data-theme="grey"],
[data-theme="oled"] {
  color-scheme: dark;

  --sx-bg: #000000;
  --sx-surface: #1c1c1e;
  --sx-surface-2: #242426;
  --sx-glass: rgba(16, 16, 18, 0.7);
  --sx-hover: rgba(255, 255, 255, 0.075);
  --sx-text: #f5f5f7;
  --sx-text-2: #c7c7cc;
  --sx-text-3: #8e8e93;
  --sx-border: rgba(255, 255, 255, 0.1);
  --sx-border-strong: rgba(255, 255, 255, 0.2);
  --sx-accent: #0a84ff;
  --sx-accent-hover: #409cff;
  --sx-accent-soft: rgba(10, 132, 255, 0.18);
  --sx-danger: #ff453a;

  --sx-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.5);
  --sx-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.4);
  --sx-shadow-md: 0 20px 48px rgba(0, 0, 0, 0.6);

  --background: var(--sx-bg);
  --foreground: var(--sx-text);
  --card: var(--sx-surface);
  --card-foreground: var(--sx-text);
  --popover: var(--sx-surface);
  --popover-foreground: var(--sx-text);
  --primary: var(--sx-accent);
  --primary-foreground: #ffffff;
  --secondary: #bf8fe0;
  --secondary-foreground: #000000;
  --muted: var(--sx-hover);
  --muted-foreground: var(--sx-text-3);
  --accent: var(--sx-hover);
  --accent-foreground: var(--sx-text);
  --destructive: var(--sx-danger);
  --destructive-foreground: #ffffff;
  --border: var(--sx-border);
  --input: var(--sx-border-strong);
  --ring: var(--sx-accent);
  --radius: 0.9rem;
  --custom-icon: var(--sx-text);
  --custom-loading-bar: var(--sx-accent);
  --divider: var(--sx-border);
}

/* ---------- Base ---------- */

html,
body {
  background: var(--sx-bg);
  color: var(--sx-text);
  font-family: var(--sx-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  background:
    radial-gradient(900px 520px at 16% -12%, rgba(0, 113, 227, 0.09), transparent 62%),
    radial-gradient(820px 520px at 88% 4%, rgba(175, 82, 222, 0.06), transparent 60%),
    var(--sx-bg);
  background-attachment: fixed;
  min-height: 100dvh;
}

[data-theme="dark"] body,
[data-theme="grey"] body,
[data-theme="oled"] body {
  background:
    radial-gradient(900px 520px at 16% -12%, rgba(10, 132, 255, 0.15), transparent 62%),
    radial-gradient(820px 520px at 88% 4%, rgba(175, 82, 222, 0.09), transparent 60%),
    var(--sx-bg);
}

#root {
  min-height: 100dvh;
  background: transparent;
}

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

button,
input,
select,
textarea {
  font-family: var(--sx-font);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  letter-spacing: -0.02em;
}

::selection {
  background: var(--sx-accent-soft);
}

a {
  color: var(--sx-accent);
}

/* ---------- Login / 2FA top bar ---------- */

#root > div > header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 70;
  background: transparent;
  pointer-events: none;
}

#root > div > header > div {
  display: flex;
  justify-content: flex-end;
  max-width: none;
  padding: 12px 16px;
  pointer-events: auto;
}

#root > div > header > div > .grow {
  display: none;
}

#root > div > header > div > .flex {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--sx-border);
  border-radius: 999px;
  background: var(--sx-glass);
  box-shadow: var(--sx-shadow-xs);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
}

#language-button {
  margin: 0;
  padding: 7px 10px;
  border-radius: 999px;
  color: var(--sx-text-2);
  font-size: 13px;
  line-height: 1;
}

#language-button:hover {
  background: var(--sx-hover);
  color: var(--sx-text);
}

#language-button svg {
  width: 15px;
  height: 15px;
}

#language-button span {
  padding-left: 5px;
}

#account-menu,
#root > div > header button[aria-haspopup="menu"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  background: var(--sx-hover);
  color: var(--sx-text);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Login card ---------- */

[class~="min-h-[90vh]"] {
  min-height: 100dvh !important;
  padding: 92px 20px 48px;
}

[class~="min-h-[90vh]"] > div {
  box-sizing: border-box;
  width: 100%;
  max-width: 460px !important;
  margin: 0 auto;
  padding: 30px;
  border: 1px solid var(--sx-border);
  border-radius: 26px;
  background: var(--sx-surface);
  box-shadow: var(--sx-shadow-md);
}

[class~="min-h-[90vh]"] > div > div {
  gap: 2px;
}

[class~="min-h-[90vh]"] img[src*="static/media/logo.png"],
#UserSvg {
  display: block;
  width: 80px !important;
  height: 80px !important;
  margin: 0 auto 10px;
  padding: 0;
  border: 0;
  background: transparent;
  object-fit: contain;
}

[data-theme="dark"] [class~="min-h-[90vh]"] img[src*="static/media/logo.png"] {
  filter: invert(1);
}

[class~="min-h-[90vh]"] h5 {
  color: var(--sx-text);
  font-size: 28px;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.035em;
}

[class~="min-h-[90vh]"] h6 {
  color: var(--sx-text-2);
  font-size: 15px;
  font-weight: 400;
}

[class~="min-h-[90vh]"] > div > div > div.mt-2 {
  margin-top: 12px !important;
}

[class~="min-h-[90vh]"] form {
  text-align: left;
}

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

input[data-slot="floating-input"],
input[data-slot="input"] {
  height: 52px !important;
  border: 1px solid var(--sx-border-strong) !important;
  border-radius: 14px !important;
  background: var(--sx-surface) !important;
  color: var(--sx-text) !important;
  font-size: 15px !important;
  box-shadow: none !important;
}

input[data-slot="floating-input"] {
  height: 56px !important;
  padding: 20px 14px 6px !important;
}

input[data-slot="floating-input"]:focus {
  border-color: var(--sx-accent) !important;
  box-shadow: 0 0 0 4px var(--sx-accent-soft) !important;
  outline: none !important;
}

input[data-slot="floating-input"] + label,
input[data-slot="floating-input"] ~ label {
  color: var(--sx-text-3);
}

input[data-slot="floating-input"]:focus + label,
input[data-slot="floating-input"]:not(:placeholder-shown) + label {
  color: var(--sx-accent);
}

#password-textfield {
  padding-right: 44px !important;
}

[aria-label="Toggle password visibility"] {
  right: 14px;
  color: var(--sx-text-3);
}

[aria-label="Toggle password visibility"]:hover {
  color: var(--sx-text);
}

button[data-slot="button"] {
  border-radius: 12px !important;
  letter-spacing: -0.005em;
  text-transform: none;
}

button[data-slot="button"][data-size="default"] {
  min-height: 44px;
}

#sign-in-button,
#passkey-sign-in-button,
#form-login button[type="submit"] {
  height: 48px !important;
  border-radius: 999px !important;
  font-size: 15px;
  font-weight: 600;
}

#one-time-password-add,
#webauthn-credential-add {
  text-transform: none;
}

#passkey-sign-in-button {
  border: 1px solid var(--sx-border-strong) !important;
  background: var(--sx-surface) !important;
  color: var(--sx-text) !important;
  box-shadow: var(--sx-shadow-xs);
}

#passkey-sign-in-button:hover {
  background: var(--sx-hover) !important;
  color: var(--sx-text) !important;
}

#passkey-sign-in-button svg {
  color: var(--sx-text-2);
}

#remember-checkbox {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border-color: var(--sx-border-strong);
}

#remember-checkbox[data-checked] {
  border-color: var(--sx-accent);
  background: var(--sx-accent);
  color: #ffffff;
}

#remember-checkbox + label,
label[for="remember-checkbox"] {
  color: var(--sx-text-2);
  font-size: 14px;
  font-weight: 400;
}

[class~="min-h-[90vh]"] [data-slot="separator"] {
  background: var(--sx-border);
}

[class~="min-h-[90vh]"] span.uppercase,
[class~="min-h-[90vh]"] [data-slot="separator"] + span {
  color: var(--sx-text-3);
  font-size: 11px;
  letter-spacing: 0.08em;
}

[class~="min-h-[90vh]"] a {
  color: var(--sx-accent);
  font-weight: 500;
}

[class~="min-h-[90vh]"] a[href*="authelia.com"] {
  color: var(--sx-text-3);
  font-size: 11px;
  font-weight: 500;
}

/* ---------- 2FA / methods ---------- */

[class~="min-h-[90vh]"] #logout-button,
[class~="min-h-[90vh]"] #methods-button {
  padding: 6px 8px;
  border-radius: 999px;
  color: var(--sx-text-3) !important;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
}

[class~="min-h-[90vh]"] #logout-button:hover,
[class~="min-h-[90vh]"] #methods-button:hover {
  background: var(--sx-hover);
  color: var(--sx-text) !important;
}

[class~="min-h-[90vh]"] div[class~="min-w-[300px]"][class~="border-border"] {
  min-width: 0 !important;
  margin: 10px 0 0 !important;
  padding: 20px !important;
  border: 1px solid var(--sx-border) !important;
  border-radius: 20px !important;
  background: var(--sx-surface-2);
}

[id="2fa-container"] {
  height: auto !important;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

[id="2fa-container"] p {
  color: var(--sx-text-2);
  font-size: 14px;
  line-height: 1.5;
}

[id="2fa-container"] a {
  color: var(--sx-accent);
  font-weight: 500;
}

[id="2fa-container"] svg circle:nth-of-type(1) {
  stroke: var(--sx-text) !important;
}

[id="2fa-container"] svg circle:nth-of-type(2) {
  fill: var(--sx-text) !important;
}

[id="2fa-container"] svg circle:nth-of-type(3) {
  stroke: var(--sx-surface-2) !important;
}

#otp-input [role="group"] {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  justify-content: center;
  width: auto !important;
}

#otp-input input {
  flex: 0 0 42px;
  width: 42px !important;
  height: 50px !important;
  margin: 0 !important;
  border: 1px solid var(--sx-border-strong) !important;
  border-radius: 12px !important;
  background: var(--sx-surface) !important;
  color: var(--sx-text) !important;
  font-size: 20px !important;
  font-weight: 600;
}

#otp-input input:focus {
  border-color: var(--sx-accent) !important;
  box-shadow: 0 0 0 3px var(--sx-accent-soft) !important;
  outline: none !important;
}

[class~="min-h-[90vh]"] .text-muted-foreground {
  color: var(--sx-text-3) !important;
}

/* ---------- Settings shell ---------- */

#root > div > nav.fixed {
  border-bottom: 1px solid var(--sx-border);
  background: var(--sx-glass) !important;
  color: var(--sx-text) !important;
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}

#root > div > nav.fixed > div {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 24px;
}

#root > div > nav.fixed h6 {
  color: var(--sx-text) !important;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#settings-menu {
  margin-right: 10px;
  border-radius: 12px;
  color: var(--sx-text) !important;
}

#settings-menu:hover {
  background: var(--sx-hover) !important;
}

#root main {
  box-sizing: border-box;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 92px 28px 56px !important;
}

[data-slot="card"] {
  border-color: var(--sx-border) !important;
  border-radius: 22px !important;
  background: var(--sx-surface) !important;
  box-shadow: var(--sx-shadow-sm) !important;
}

[data-slot="card"] h5,
[data-slot="card"] h4,
[data-slot="card"] h3 {
  color: var(--sx-text);
  font-weight: 600;
  letter-spacing: -0.02em;
}

[data-slot="card"] h5 {
  font-size: 20px;
}

#root main > div[class*="items-start"] > [data-slot="card"] {
  width: 100%;
  max-width: 520px;
}

#root main [class*="border-muted-foreground"] {
  padding: 12px 14px !important;
  border-color: var(--sx-border) !important;
  border-radius: 14px !important;
  background: var(--sx-surface-2);
}

#root main [class*="border-muted-foreground"] p {
  margin: 0;
  color: var(--sx-text-2);
}

/* Settings drawer */

[data-slot="sheet-overlay"] {
  background: rgba(0, 0, 0, 0.28) !important;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

[data-slot="sheet-content"] {
  width: 300px !important;
  max-width: 86vw !important;
  border-right: 1px solid var(--sx-border) !important;
  background: var(--sx-glass) !important;
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
}

[data-slot="sheet-content"] [data-slot="sheet-title"] {
  margin: 22px 0 14px !important;
  color: var(--sx-text);
  font-size: 18px;
  font-weight: 600;
}

[data-slot="sheet-content"] ul {
  padding: 8px !important;
}

[data-slot="sheet-content"] li button {
  border-radius: 12px;
  color: var(--sx-text-2);
  text-transform: none;
}

[data-slot="sheet-content"] li button:hover {
  background: var(--sx-hover) !important;
  color: var(--sx-text);
}

[data-slot="sheet-content"] li button.bg-accent {
  background: var(--sx-surface) !important;
  color: var(--sx-text);
  box-shadow: var(--sx-shadow-xs);
}

[data-slot="sheet-content"] > div > .text-center > .flex {
  margin: 0 16px;
}

/* ---------- Utilities ---------- */

[data-slot="toast-viewport"] {
  top: 64px;
  right: 16px;
  font-family: var(--sx-font);
}

/* Credential cards: the stock 4-column grid is too narrow for the metadata
   and action icons once the larger theme type is applied. */
@media (min-width: 768px) {
  #one-time-password-panel [class*="md:col-span-6"],
  #webauthn-credentials-panel .grid.gap-6 > div {
    grid-column: span 6 / span 6 !important;
  }
}

#one-time-password-panel [data-slot="card"] .p-6 > .flex,
#webauthn-credentials-panel [data-slot="card"] .p-6 > .flex {
  align-items: flex-start;
  gap: 10px;
}

#one-time-password-panel [data-slot="card"] .flex-1,
#webauthn-credentials-panel [data-slot="card"] .flex-1,
#one-time-password-panel [data-slot="card"] [id$="-description"],
#webauthn-credentials-panel [data-slot="card"] [id$="-description"] {
  min-width: 0;
  overflow-wrap: anywhere;
}

#one-time-password-panel [data-slot="card"] [id$="-description"],
#webauthn-credentials-panel [data-slot="card"] [id$="-description"] {
  line-height: 1.25;
}

#one-time-password-panel [data-slot="card"] span.px-4,
#webauthn-credentials-panel [data-slot="card"] span.px-4 {
  display: none;
}

[role="dialog"] [data-slot="card"] {
  border-radius: 20px !important;
}

[data-slot="dialog-overlay"] {
  background: rgba(0, 0, 0, 0.28) !important;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

[data-slot="dialog-content"] {
  border-color: var(--sx-border) !important;
  border-radius: 22px !important;
  background: var(--sx-surface) !important;
  box-shadow: var(--sx-shadow-md) !important;
}

[data-slot="dialog-title"] {
  color: var(--sx-text);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

[data-slot="dialog-description"] {
  color: var(--sx-text-2) !important;
  line-height: 1.55;
}

#one-time-code {
  height: 52px !important;
  border-radius: 14px !important;
  border-color: var(--sx-border-strong) !important;
  background: var(--sx-surface-2) !important;
  color: var(--sx-text) !important;
}

#one-time-code:focus {
  border-color: var(--sx-accent) !important;
  box-shadow: 0 0 0 4px var(--sx-accent-soft) !important;
  outline: none !important;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  #root > div > header > div {
    padding: 8px 12px;
  }

  [class~="min-h-[90vh]"] {
    padding: 78px 16px 32px;
  }

  [class~="min-h-[90vh]"] > div {
    padding: 24px 20px;
    border-radius: 22px;
  }

  [class~="min-h-[90vh]"] h5 {
    font-size: 25px;
  }

  #otp-input [role="group"] {
    gap: 4px;
  }

  #otp-input input {
    flex-basis: 40px;
    width: 40px !important;
    height: 46px !important;
  }

  #root main {
    padding: 84px 14px 40px !important;
  }

  #root > div > nav.fixed > div {
    padding: 10px 16px;
  }

  [data-slot="card"] {
    border-radius: 18px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
