/* ==========================================================================
   Auth Theme — shared styles for login, MFA, and password-reset screens.
   Matches the Next.js client app design system.
   ========================================================================== */

/* ---------- Design Tokens (light) ---------- */
:root {
  --auth-primary: rgb(0, 159, 231);
  --auth-primary-hover: rgb(0, 145, 218);
  --auth-primary-ring: rgba(0, 159, 231, 0.25);

  --auth-bg: rgb(249, 250, 251);
  --auth-card-bg: #ffffff;
  --auth-text: rgb(17, 24, 39);
  --auth-text-muted: rgb(107, 114, 128);
  --auth-border: rgb(229, 231, 235);
  --auth-input-bg: #ffffff;
  --auth-input-border: rgb(209, 213, 219);
  --auth-input-focus-border: rgb(0, 159, 231);
  --auth-input-focus-ring: rgba(0, 159, 231, 0.2);

  --auth-error: rgb(220, 38, 38);
  --auth-error-bg: rgb(254, 242, 242);
  --auth-error-border: rgb(254, 202, 202);
  --auth-success: rgb(22, 163, 74);
  --auth-success-bg: rgb(240, 253, 244);
  --auth-success-border: rgb(187, 247, 208);
  --auth-warning: rgb(217, 119, 6);
  --auth-warning-bg: rgb(255, 251, 235);
  --auth-warning-border: rgb(253, 230, 138);
  --auth-info: rgb(37, 99, 235);
  --auth-info-bg: rgb(239, 246, 255);
  --auth-info-border: rgb(191, 219, 254);

  --auth-link: rgb(37, 99, 235);

  --auth-font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --auth-radius: 0.625rem;
  --auth-radius-sm: 0.375rem;
  --auth-shadow-card: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.06);
  --auth-shadow-card-hover: 0 8px 25px -5px rgb(0 0 0 / 0.1), 0 4px 10px -6px rgb(0 0 0 / 0.08);
  --auth-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Dark mode tokens ---------- */
[data-auth-theme="dark"] {
  --auth-bg: rgb(17, 24, 39);
  --auth-card-bg: rgb(31, 41, 55);
  --auth-text: rgb(243, 244, 246);
  --auth-text-muted: rgb(156, 163, 175);
  --auth-border: rgb(55, 65, 81);
  --auth-input-bg: rgb(17, 24, 39);
  --auth-input-border: rgb(55, 65, 81);
  --auth-input-focus-border: rgb(56, 189, 248);
  --auth-input-focus-ring: rgba(56, 189, 248, 0.25);

  --auth-error-bg: rgba(127, 29, 29, 0.35);
  --auth-error-border: rgb(153, 27, 27);
  --auth-success-bg: rgba(20, 83, 45, 0.35);
  --auth-success-border: rgb(22, 101, 52);
  --auth-warning-bg: rgba(120, 53, 15, 0.35);
  --auth-warning-border: rgb(146, 64, 14);
  --auth-info-bg: rgba(30, 58, 138, 0.35);
  --auth-info-border: rgb(30, 64, 175);

  --auth-link: rgb(96, 165, 250);

  --auth-shadow-card: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.2);
  --auth-shadow-card-hover: 0 8px 25px -5px rgb(0 0 0 / 0.4), 0 4px 10px -6px rgb(0 0 0 / 0.3);
}

/* ---------- Entrance animation ---------- */
@keyframes authFadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Body / page wrapper ---------- */
.auth-body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--auth-bg);
  color: var(--auth-text);
  font-family: var(--auth-font);
  font-size: 0.875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

/* ---------- Card ---------- */
.auth-card {
  background: var(--auth-card-bg);
  border: 1px solid var(--auth-border);
  border-radius: var(--auth-radius);
  box-shadow: var(--auth-shadow-card);
  width: 100%;
  max-width: 28rem;
  padding: 2rem;
  text-align: left;
  animation: authFadeInUp 0.3s ease-out forwards;
}

/* ---------- Logo ---------- */
.auth-logo {
  display: block;
  margin: 0 auto 1.25rem;
  height: 48px;
  width: auto;
}

/* ---------- Typography ---------- */
.auth-h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--auth-text);
  margin: 0 0 0.5rem;
  line-height: 1.25;
  text-align: center;
}

.auth-h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--auth-text);
  margin: 0 0 0.5rem;
  line-height: 1.25;
}

.auth-p {
  color: var(--auth-text-muted);
  margin: 0 0 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

/* ---------- Links ---------- */
.auth-card a:not([class*="auth-btn"]) {
  color: var(--auth-link);
  text-decoration: none;
  transition: color var(--auth-transition);
}
.auth-card a:not([class*="auth-btn"]):hover {
  text-decoration: underline;
}

/* ---------- Form ---------- */
.auth-form {
  margin: 0;
}

.auth-form-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

/* ---------- Fields wrapper (form.as_p) ---------- */
.auth-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.auth-fields p {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.auth-fields label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--auth-text);
}
.auth-fields input[type="text"],
.auth-fields input[type="password"],
.auth-fields input[type="email"],
.auth-fields input[type="url"],
.auth-fields input[type="number"],
.auth-fields input[type="tel"],
.auth-fields textarea,
.auth-fields select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  font-family: var(--auth-font);
  color: var(--auth-text);
  background: var(--auth-input-bg);
  border: 1px solid var(--auth-input-border);
  border-radius: var(--auth-radius-sm);
  transition: border-color var(--auth-transition), box-shadow var(--auth-transition);
  box-sizing: border-box;
}
.auth-fields input:focus,
.auth-fields textarea:focus,
.auth-fields select:focus {
  outline: none;
  border-color: var(--auth-input-focus-border);
  box-shadow: 0 0 0 3px var(--auth-input-focus-ring);
}
/* Errors rendered by form.as_p */
.auth-fields .errorlist {
  list-style: none;
  margin: 0;
  padding: 0;
}
.auth-fields .errorlist li {
  color: var(--auth-error);
  font-size: 0.8125rem;
}

/* ---------- Field (element template) ---------- */
.auth-field {
  margin-bottom: 1rem;
}
.auth-field:last-child {
  margin-bottom: 0;
}

.auth-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--auth-text);
  margin-bottom: 0.375rem;
}

.auth-input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  font-family: var(--auth-font);
  color: var(--auth-text);
  background: var(--auth-input-bg);
  border: 1px solid var(--auth-input-border);
  border-radius: var(--auth-radius-sm);
  transition: border-color var(--auth-transition), box-shadow var(--auth-transition);
  box-sizing: border-box;
}
.auth-input:focus {
  outline: none;
  border-color: var(--auth-input-focus-border);
  box-shadow: 0 0 0 3px var(--auth-input-focus-ring);
}

.auth-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.auth-check input[type="checkbox"],
.auth-check input[type="radio"] {
  accent-color: var(--auth-primary);
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.auth-check label {
  font-size: 0.875rem;
  color: var(--auth-text);
  cursor: pointer;
}

.auth-help-text {
  display: block;
  font-size: 0.8125rem;
  color: var(--auth-text-muted);
  margin-top: 0.25rem;
}

.auth-field-errors {
  list-style: none;
  margin: 0 0 0.25rem;
  padding: 0;
}
.auth-field-errors li {
  color: var(--auth-error);
  font-size: 0.8125rem;
}

/* ---------- Buttons ---------- */
.auth-btn-primary,
.auth-btn-danger,
.auth-btn-secondary,
.auth-btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--auth-font);
  line-height: 1.5;
  border-radius: var(--auth-radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--auth-transition), border-color var(--auth-transition),
              box-shadow var(--auth-transition), transform var(--auth-transition);
  border: 1px solid transparent;
  box-sizing: border-box;
}

.auth-btn-primary {
  background: linear-gradient(135deg, var(--auth-primary), var(--auth-primary-hover));
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 159, 231, 0.2);
}
.auth-btn-primary:hover {
  background: linear-gradient(135deg, rgb(56, 189, 248), var(--auth-primary));
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 159, 231, 0.3);
}

.auth-btn-danger {
  background: var(--auth-error);
  color: #ffffff;
}
.auth-btn-danger:hover {
  background: rgb(185, 28, 28);
}

.auth-btn-secondary {
  background: var(--auth-card-bg);
  color: var(--auth-text);
  border-color: var(--auth-border);
}
.auth-btn-secondary:hover {
  background: var(--auth-bg);
}

.auth-btn-outline {
  background: transparent;
  color: var(--auth-primary);
  border-color: var(--auth-border);
}
.auth-btn-outline:hover {
  background: var(--auth-bg);
  border-color: var(--auth-primary);
}

.auth-btn-link {
  display: inline;
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  font-family: var(--auth-font);
  color: var(--auth-link);
  cursor: pointer;
  text-decoration: none;
}
.auth-btn-link:hover {
  text-decoration: underline;
}

.auth-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Full-width button inside form actions */
.auth-form-actions .auth-btn-primary {
  width: 100%;
}

/* ---------- Panel ---------- */
.auth-panel {
  background: var(--auth-card-bg);
  border: 1px solid var(--auth-border);
  border-radius: var(--auth-radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.auth-panel:last-child {
  margin-bottom: 0;
}

.auth-panel-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--auth-text);
  padding: 0.875rem 1rem;
  margin: 0;
  border-bottom: 1px solid var(--auth-border);
  background: var(--auth-bg);
}

.auth-panel-body {
  padding: 1rem;
}

.auth-panel-actions {
  list-style: none;
  margin: 0;
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-top: 1px solid var(--auth-border);
}
.auth-panel-actions li {
  display: inline;
}

/* ---------- Alert ---------- */
.auth-alert {
  padding: 0.75rem 1rem;
  border-radius: var(--auth-radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  border: 1px solid var(--auth-info-border);
  background: var(--auth-info-bg);
  color: var(--auth-info);
}

/* ---------- Messages ---------- */
.auth-messages {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.auth-messages li {
  padding: 0.625rem 0.875rem;
  border-radius: var(--auth-radius-sm);
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--auth-info-border);
  background: var(--auth-info-bg);
  color: var(--auth-info);
}
.auth-messages li.success {
  border-color: var(--auth-success-border);
  background: var(--auth-success-bg);
  color: var(--auth-success);
}
.auth-messages li.error {
  border-color: var(--auth-error-border);
  background: var(--auth-error-bg);
  color: var(--auth-error);
}
.auth-messages li.warning {
  border-color: var(--auth-warning-border);
  background: var(--auth-warning-bg);
  color: var(--auth-warning);
}

/* ---------- Horizontal rule ---------- */
.auth-hr {
  border: none;
  border-top: 1px solid var(--auth-border);
  margin: 1.25rem 0;
}

/* ---------- Image / QR ---------- */
.auth-img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--auth-radius-sm);
}
.auth-qr {
  display: block;
  margin: 1rem auto;
  max-width: 200px;
  height: auto;
  border-radius: var(--auth-radius-sm);
  border: 1px solid var(--auth-border);
  padding: 0.5rem;
  background: #ffffff;
}

/* ---------- Badge ---------- */
.auth-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  background: var(--auth-bg);
  color: var(--auth-text-muted);
  border: 1px solid var(--auth-border);
}

/* ---------- Details / Accordion ---------- */
.auth-details {
  border: 1px solid var(--auth-border);
  border-radius: var(--auth-radius-sm);
  margin-bottom: 1rem;
}
.auth-details summary {
  padding: 0.625rem 0.875rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  color: var(--auth-text);
}
.auth-details summary:hover {
  background: var(--auth-bg);
}
.auth-details-body {
  padding: 0.625rem 0.875rem;
  border-top: 1px solid var(--auth-border);
}

/* ---------- Table ---------- */
.auth-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.auth-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--auth-text-muted);
  border-bottom: 2px solid var(--auth-border);
}
.auth-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--auth-border);
  color: var(--auth-text);
}
.auth-table tr:last-child td {
  border-bottom: none;
}
.auth-table tbody tr:hover {
  background: var(--auth-bg);
}

/* ---------- Dark-mode toggle ---------- */
.auth-dark-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--auth-card-bg);
  border: 1px solid var(--auth-border);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--auth-shadow-card);
  transition: background var(--auth-transition), border-color var(--auth-transition);
  z-index: 50;
  padding: 0;
  color: var(--auth-text-muted);
}
.auth-dark-toggle:hover {
  border-color: var(--auth-primary);
  color: var(--auth-primary);
}
.auth-dark-toggle svg {
  width: 1.125rem;
  height: 1.125rem;
}

/* ---------- Nav link ---------- */
.auth-nav {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.8125rem;
}
.auth-nav a {
  color: var(--auth-text-muted);
  text-decoration: none;
}
.auth-nav a:hover {
  color: var(--auth-primary);
  text-decoration: underline;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .auth-card {
    padding: 1.5rem 1.25rem;
  }
  .auth-panel-title,
  .auth-panel-body,
  .auth-panel-actions {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* =====================================================================
   LOGIN-PAGE overrides (when auth-theme is used with Unfold login)
   Unfold provides the centering layout (#page > flex > sm:w-96).
   We style the card + body background and let Unfold handle position.
   ===================================================================== */

/* Override Unfold body background */
body.login {
  background: var(--auth-bg) !important;
}
body.login::before {
  content: "";
  position: fixed;
  inset: 0;
  background: url("/static/epph-logo.a6c203bf3a45.png") no-repeat center center;
  background-size: clamp(800px, 90vmin, 1600px);
  opacity: 0.15;
  z-index: 0;
  pointer-events: none;
}
body.login #page {
  background: transparent !important;
  position: relative;
  z-index: 1;
}
[data-auth-theme="dark"] body.login,
[data-auth-theme="dark"] body.login #page {
  background: rgb(17, 24, 39) !important;
}
[data-auth-theme="dark"] body.login::before {
  opacity: 0.06;
}

/* The card sits directly inside Unfold's sm:w-96 centering wrapper */
.auth-login-card {
  background: var(--auth-card-bg);
  border: 1px solid var(--auth-border);
  padding: 2rem;
  border-radius: var(--auth-radius);
  box-shadow: var(--auth-shadow-card);
  width: 100%;
  text-align: center;
  animation: authFadeInUp 0.3s ease-out forwards;
}

.auth-login-card input[type="text"],
.auth-login-card input[type="password"],
.auth-login-card input[type="email"],
.auth-login-card input[type="url"],
.auth-login-card select {
  width: 100%;
  border: 1px solid var(--auth-input-border);
  border-radius: var(--auth-radius-sm);
  padding: 0.625rem 0.75rem;
  background: var(--auth-input-bg);
  color: var(--auth-text);
  font-family: var(--auth-font);
  font-size: 0.875rem;
  transition: box-shadow var(--auth-transition), border-color var(--auth-transition);
  box-sizing: border-box;
}
.auth-login-card input:focus,
.auth-login-card select:focus {
  outline: none;
  border-color: var(--auth-input-focus-border);
  box-shadow: 0 0 0 3px var(--auth-input-focus-ring);
}
.auth-login-card input[type="radio"],
.auth-login-card input[type="checkbox"] {
  accent-color: var(--auth-primary);
}

.auth-login-card .submit-row button[type="submit"],
.auth-login-card button.submit-row[type="submit"] {
  background: linear-gradient(135deg, var(--auth-primary), var(--auth-primary-hover));
  color: #ffffff;
  border: none;
  border-radius: var(--auth-radius-sm);
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-family: var(--auth-font);
  font-size: 0.875rem;
  box-shadow: 0 1px 3px rgba(0, 159, 231, 0.2);
  cursor: pointer;
  transition: background var(--auth-transition), transform var(--auth-transition), box-shadow var(--auth-transition);
}
.auth-login-card .submit-row button[type="submit"]:hover,
.auth-login-card button.submit-row[type="submit"]:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, rgb(56, 189, 248), var(--auth-primary));
  box-shadow: 0 4px 12px rgba(0, 159, 231, 0.3);
}

.auth-login-card details {
  text-align: left;
  margin-top: 1rem;
  border: 1px solid var(--auth-border);
  border-radius: var(--auth-radius-sm);
  overflow: hidden;
}
.auth-login-card details summary {
  padding: 0.625rem 0.75rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--auth-text);
  font-size: 0.875rem;
}
.auth-login-card details summary:hover {
  background: var(--auth-bg);
}
.auth-login-card details > div {
  padding: 0 0.75rem 0.75rem;
}
.auth-login-card .help {
  color: var(--auth-text-muted);
}
