:root, html[data-theme="light"] {
  /* Match Django admin's default palette */
  --header-bg:   #417690;
  --header-deep: #264b5d;
  --header-darker: #1a3543;
  --primary:     #79aec8;
  --button-hover:#205067;
  --accent:      #f5dd5d;

  --ink:         #333;
  --muted:       #666;
  --line:        #ccc;
  --hairline:    #e8e8e8;
  --darkened-bg: #f8f8f8;
  --error:       #ba2121;

  /* Tokens that flip in dark mode */
  --shell-bg:        rgba(255, 255, 255, 0.97);
  --form-input-bg:   #f7f8fb;
  --form-input-fg:   #ffffff;
  --error-bg:        #ffefef;
  --error-border:    #f5c6c6;
  --link-fg:         #417893;
  --link-hover:      #003366;
  --shell-shadow:
    0 30px 80px rgba(20, 20, 60, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* Dark theme — explicit user choice */
html[data-theme="dark"] {
  --ink:           #e5e7eb;
  --muted:         #aab1bc;
  --line:          #353a42;
  --hairline:      #2b3037;
  --darkened-bg:   #14181d;
  --error:         #f08585;

  --shell-bg:        rgba(30, 34, 39, 0.97);   /* dark gray panel */
  --form-input-bg:   #14181d;
  --form-input-fg:   #0f1318;
  --error-bg:        rgba(240, 133, 133, 0.10);
  --error-border:    rgba(240, 133, 133, 0.35);
  --link-fg:         #79aec8;
  --link-hover:      #b5d8e6;
  --shell-shadow:
    0 30px 80px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(255, 255, 255, 0.06);
}

/* Auto theme — follow system preference */
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --ink:           #e5e7eb;
    --muted:         #aab1bc;
    --line:          #353a42;
    --hairline:      #2b3037;
    --darkened-bg:   #14181d;
    --error:         #f08585;

    --shell-bg:        rgba(30, 34, 39, 0.97);
    --form-input-bg:   #14181d;
    --form-input-fg:   #0f1318;
    --error-bg:        rgba(240, 133, 133, 0.10);
    --error-border:    rgba(240, 133, 133, 0.35);
    --link-fg:         #79aec8;
    --link-hover:      #b5d8e6;
    --shell-shadow:
      0 30px 80px rgba(0, 0, 0, 0.65),
      0 0 0 1px rgba(255, 255, 255, 0.06);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--header-darker);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(65, 118, 144, 0.55), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(38, 75, 93, 0.65), transparent 60%),
    linear-gradient(135deg, #2c3e4a 0%, #1f2f3a 50%, #14222b 100%);
  position: relative;
}

button, a { -webkit-tap-highlight-color: transparent; }

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}
.orb.one   { width: 380px; height: 380px; top: -120px; left: -100px;
             background: linear-gradient(135deg, #417690, #264b5d);
             animation: drift 18s ease-in-out infinite alternate; }
.orb.two   { width: 300px; height: 300px; bottom: -90px; right: -80px;
             background: linear-gradient(135deg, #79aec8, #417690);
             animation: drift 22s ease-in-out infinite alternate-reverse; }
.orb.three { width: 220px; height: 220px; top: 40%; right: 18%;
             background: linear-gradient(135deg, #264b5d, #417690);
             animation: drift 26s ease-in-out infinite alternate; }

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(40px, -30px) scale(1.08); }
}

.login-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 980px;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--shell-bg);
  color: var(--ink);
  border-radius: 22px;
  box-shadow: var(--shell-shadow);
  overflow: hidden;
  backdrop-filter: blur(8px);
  animation: slide-up 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transition: background 0.18s ease, color 0.18s ease;
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.brand-panel {
  position: relative;
  padding: 48px 44px;
  color: #fff;
  background: linear-gradient(160deg, #417690 0%, #2f5b71 55%, #264b5d 100%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.brand-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(400px 240px at 100% 0%, rgba(255, 255, 255, 0.18), transparent 60%),
    radial-gradient(360px 240px at 0% 100%, rgba(255, 255, 255, 0.12), transparent 60%);
  pointer-events: none;
}
.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.2px;
  position: relative;
  color: #fff;
}
.brand-logo .heart {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  color: #fff;
}
.brand-logo .heart i {
  font-size: 18px;
  animation: heartbeat 1.8s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 60%, 100% { transform: scale(1); }
  20%           { transform: scale(1.18); }
  40%           { transform: scale(0.95); }
}

.brand-copy { position: relative; }
.brand-copy h1 {
  font-size: 34px;
  line-height: 1.15;
  margin: 0 0 14px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.brand-copy p {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.85);
  max-width: 360px;
}

.brand-footnote {
  position: relative;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-footnote i { opacity: 0.85; }

.form-panel {
  padding: 48px 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.form-panel h2 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.form-panel .subtitle {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 14px;
}

.field {
  position: relative;
  margin-bottom: 18px;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.field-input { position: relative; }
.field-input i.lead {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 16px;
  color: #9aa1b3;
  font-size: 14px;
  pointer-events: none;
}
html[dir="rtl"] .field-input i.lead { left: auto; right: 16px; }

.field-input input,
.form-panel input[type="text"],
.form-panel input[type="password"],
.form-panel input[type="email"] {
  width: 100%;
  height: 48px;
  padding: 0 44px 0 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--form-input-bg);
  font-size: 16px;
  color: var(--ink);
  font-family: inherit;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
html[dir="rtl"] .field-input input { padding: 0 44px 0 44px; }

.field-input input:focus {
  border-color: var(--header-bg);
  background: var(--form-input-fg);
  box-shadow: 0 0 0 4px rgba(65, 118, 144, 0.18);
}

.toggle-pw {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 6px;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #9aa1b3;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease;
}
html[dir="rtl"] .toggle-pw { right: auto; left: 6px; }
.toggle-pw:hover { color: var(--header-bg); background: rgba(65, 118, 144, 0.10); }

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0 22px;
  font-size: 13px;
}
.row-between a {
  color: var(--link-fg);
  text-decoration: none;
  font-weight: 600;
}
.row-between a:hover { color: var(--link-hover); text-decoration: underline; }

.submit-btn {
  width: 100%;
  height: 50px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  color: #fff;
  letter-spacing: 0.2px;
  background: var(--header-bg);
  box-shadow:
    0 8px 18px rgba(38, 75, 93, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: background 0.18s ease, box-shadow 0.18s ease, transform 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.submit-btn:hover  { background: var(--button-hover);
                     box-shadow: 0 12px 24px rgba(38, 75, 93, 0.45),
                                 inset 0 1px 0 rgba(255, 255, 255, 0.18); }
.submit-btn:active { transform: translateY(1px); }

.errornote {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin: 0 0 18px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.errornote::before {
  content: "\f071";
  font-family: "Font Awesome 5 Free";
  font-weight: 900;
  color: var(--error);
  flex-shrink: 0;
  margin-top: 1px;
}
ul.errorlist {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
  color: var(--error);
  font-size: 12.5px;
}
ul.errorlist li { margin-top: 4px; }

.field-input label { display: none; }

.helper-row {
  margin-top: 22px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .login-shell {
    grid-template-columns: 1fr;
    max-width: 460px;
    border-radius: 18px;
  }
  .brand-panel { padding: 32px 28px; gap: 22px; }
  .brand-copy h1 { font-size: 24px; }
  .brand-copy p  { font-size: 14px; }
  .form-panel    { padding: 32px 28px; }
}

@media (max-width: 560px) {
  body.login {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
             max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    align-items: flex-start;
  }
  .login-shell { border-radius: 16px; }
  .brand-panel { padding: 22px 22px 20px; gap: 12px; }
  .brand-copy h1 { font-size: 20px; margin-bottom: 6px; }
  .brand-copy p { font-size: 13px; line-height: 1.5; }
  .brand-footnote { display: none; }
  .form-panel { padding: 24px 22px; }
  .form-panel h2 { font-size: 22px; }
  .form-panel .subtitle { margin-bottom: 22px; font-size: 13.5px; }
  .field { margin-bottom: 14px; }
  .submit-btn { height: 52px; }
}

@media (max-width: 360px) {
  .brand-panel { padding: 18px 18px 16px; }
  .form-panel  { padding: 22px 18px; }
  .brand-copy h1 { font-size: 18px; }
  .brand-copy p  { display: none; }
}

@media (max-height: 520px) and (orientation: landscape) {
  body.login { align-items: flex-start; padding-top: 16px; padding-bottom: 16px; }
  .brand-panel { padding: 18px 24px; }
  .brand-copy h1 { font-size: 20px; margin-bottom: 4px; }
  .brand-copy p  { font-size: 13px; }
  .form-panel { padding: 22px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .orb,
  .brand-logo .heart i,
  .login-shell { animation: none !important; }
}

@media (max-width: 480px) {
  .orb { display: none; }
}

/* === Theme toggle (shared by login + MFA challenge) ============================ */
/* Class `theme-toggle` is required for Django's admin/js/theme.js to bind the
   click handler. `theme-toggle-pill` is the visual rule.
   Selectors use button[class]... to win over user-agent button styles without
   needing !important. */
button.theme-toggle.theme-toggle-pill {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  width: 40px; height: 40px;
  margin: 0;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  transition: background .15s ease, transform .12s ease, border-color .15s ease;
  -webkit-appearance: none;
  appearance: none;
}
button.theme-toggle.theme-toggle-pill:hover {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.42);
}
button.theme-toggle.theme-toggle-pill:active { transform: scale(0.94); }
button.theme-toggle.theme-toggle-pill:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}
button.theme-toggle.theme-toggle-pill i {
  display: none;
  line-height: 1;
  pointer-events: none;
}
/* default = auto (matches the bootstrap script which writes 'auto' when no
   localStorage value is present). */
button.theme-toggle.theme-toggle-pill .when-auto  { display: inline-block; }
html[data-theme="auto"]  button.theme-toggle.theme-toggle-pill .when-auto  { display: inline-block; }
html[data-theme="auto"]  button.theme-toggle.theme-toggle-pill .when-light,
html[data-theme="auto"]  button.theme-toggle.theme-toggle-pill .when-dark  { display: none; }
html[data-theme="light"] button.theme-toggle.theme-toggle-pill .when-auto,
html[data-theme="light"] button.theme-toggle.theme-toggle-pill .when-dark  { display: none; }
html[data-theme="light"] button.theme-toggle.theme-toggle-pill .when-light { display: inline-block; }
html[data-theme="dark"]  button.theme-toggle.theme-toggle-pill .when-auto,
html[data-theme="dark"]  button.theme-toggle.theme-toggle-pill .when-light { display: none; }
html[data-theme="dark"]  button.theme-toggle.theme-toggle-pill .when-dark  { display: inline-block; }

/* === MFA method picker (challenge page) ======================================== */
.method-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 0;
}
.method-card {
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 18px 16px 16px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--form-input-bg);
  cursor: pointer;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--ink);
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease, transform .15s ease;
}
.method-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0; height: 0;
}
.method-card:hover { border-color: var(--header-bg); transform: translateY(-1px); }
.method-card:has(input[type="radio"]:checked) {
  border-color: var(--header-bg);
  background: rgba(65, 118, 144, 0.08);
  box-shadow: 0 6px 18px rgba(38, 75, 93, 0.18);
}
.method-card:has(input[type="radio"]:focus-visible) {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.method-card-icon {
  font-size: 22px;
  color: var(--header-bg);
  line-height: 1;
  margin-bottom: 2px;
  transition: color .15s ease, transform .15s ease;
}
.method-card:has(input[type="radio"]:checked) .method-card-icon { transform: scale(1.05); }
.method-card-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  align-items: center;
}
.method-card-title {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  line-height: 1.2;
}
.method-card-sub {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.3;
}
.method-card-check {
  position: absolute;
  top: 10px; right: 10px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--header-bg);
  color: #ffffff;
  font-size: 9px;
  display: none;
  align-items: center;
  justify-content: center;
}
.method-card:has(input[type="radio"]:checked) .method-card-check { display: inline-flex; }

@media (max-width: 480px) {
  .method-picker { grid-template-columns: 1fr; }
  .method-card { flex-direction: row; text-align: left; gap: 14px; padding: 14px 32px 14px 16px; }
  .method-card-text { align-items: flex-start; }
}

/* Hide the email "Send code" affordance unless email is the selected method */
form:has(input[name="method"]:checked[value="email"])    .send-code { display: flex; }
form:has(input[name="method"][type="hidden"][value="email"]) .send-code { display: flex; }
.send-code { display: none; }
