:root {
  --login-ease-out: cubic-bezier(.23, 1, .32, 1);
  --login-shadow: 0 4px 16px rgba(10, 20, 24, .05);
  --login-muted: #8a8579;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #faf8f4; }

body {
  min-height: 100vh;
  margin: 0;
  color: #1a1a1a;
  background: #faf8f4;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 8px;
  color: #faf8f4;
  background: #1f3a2e;
  font-size: 13px;
  font-weight: 700;
  transition: transform 160ms var(--login-ease-out);
}
.skip-link:focus { transform: translateY(0); }

.login-layout {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
  background: #faf8f4;
}

.brand-panel {
  position: relative;
  display: flex;
  flex: 1 1 420px;
  flex-direction: column;
  justify-content: space-between;
  min-width: 390px;
  min-height: 100vh;
  overflow: hidden;
  gap: 48px;
  padding: clamp(32px, 5vw, 64px);
  color: #faf8f4;
  background: #1f3a2e;
}
.brand-panel::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  background: #8b6914;
}

.brand-lockup,
.mobile-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  width: fit-content;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  display: block;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  object-fit: contain;
}
.brand-lockup .brand-mark { filter: brightness(0) invert(1); }
.brand-name-group {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-name {
  color: #fff;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -.02em;
}
.brand-tagline {
  color: rgba(250, 248, 244, .55);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.brand-message {
  width: min(100%, 460px);
  margin: 0;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--login-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.eyebrow-light {
  margin-bottom: 20px;
  color: #c6a24a;
}
.brand-message h1 {
  margin: 0 0 20px;
  color: #fff;
  font-family: var(--serif);
  font-size: clamp(38px, 4.6vw, 60px);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -.025em;
  text-wrap: pretty;
}
.brand-message h1 em {
  color: #c6a24a;
  font-weight: 400;
}
.brand-copy {
  max-width: 40ch;
  margin: 0;
  color: rgba(250, 248, 244, .72);
  font-size: 17px;
  line-height: 1.6;
}

.access-steps {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 36px 0 0;
  padding: 28px 0 0;
  border-top: 1px solid rgba(198, 162, 74, .4);
  list-style: none;
}
.access-steps li {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.step-number {
  min-width: 24px;
  padding-top: 3px;
  color: #c6a24a;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .08em;
}
.access-steps strong {
  display: block;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.access-steps small {
  display: block;
  margin-top: 2px;
  color: rgba(250, 248, 244, .58);
  font-size: 13px;
  line-height: 1.45;
}

.access-panel {
  display: flex;
  flex: 1 1 520px;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  gap: 24px;
  padding: clamp(24px, 3.5vw, 40px) clamp(20px, 4vw, 56px);
}
.access-panel-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #5c5c5c;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: color 150ms ease;
}
.secure-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  border-radius: 999px;
  padding: 4px 11px;
  color: #1f3a2e;
  background: #edf1ee;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.secure-label svg,
.back-link svg,
.secondary-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.access-card {
  position: relative;
  width: min(100%, 460px);
  margin: auto;
  overflow: hidden;
  border: 1px solid #e8e4dc;
  border-radius: 12px;
  padding: clamp(26px, 3vw, 38px);
  background: #fff;
  box-shadow: var(--login-shadow);
}
.access-card::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 3px;
  background: #8b6914;
}
.access-view,
.context-group { padding: 0; }
.access-view:not([hidden]) { animation: login-view-in 220ms var(--login-ease-out) both; }
@keyframes login-view-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.mobile-brand { display: none; margin-bottom: 30px; }
.mobile-brand .brand-mark { width: 46px; height: 46px; }
.mobile-brand .brand-name { color: #1f3a2e; font-size: 24px; }
.mobile-brand .brand-tagline { color: var(--login-muted); font-size: 9px; }

.access-view h2,
.forgot-card h2 {
  margin: 0;
  color: #1a1a1a;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -.02em;
}
.access-view h2 em {
  color: #8b6914;
  font-weight: 400;
}
.view-copy,
.forgot-card > p:not(.eyebrow) {
  margin: 10px 0 0;
  color: #5c5c5c;
  font-size: 14px;
  line-height: 1.6;
}

.access-form {
  display: grid;
  gap: 18px;
  margin-top: 26px;
}
.field-group { display: grid; gap: 7px; }
.field-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.field-group label {
  color: var(--login-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.text-button,
.password-toggle {
  border: 0;
  color: #8b6914;
  background: transparent;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.text-button {
  padding: 0;
  text-decoration: underline;
  text-decoration-color: rgba(139, 105, 20, .35);
  text-underline-offset: 3px;
}

.field-control {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 50px;
  border: 1.5px solid #e8e4dc;
  border-radius: 8px;
  background: #fff;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.field-control:focus-within {
  border-color: #1f3a2e;
  box-shadow: 0 0 0 3px rgba(31, 58, 46, .1);
}
.field-control:has(input[aria-invalid="true"]) {
  border-color: #7a1f1f;
  box-shadow: 0 0 0 3px rgba(122, 31, 31, .08);
}
.field-control > svg {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin-left: 14px;
  fill: none;
  stroke: var(--login-muted);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.field-control input {
  width: 100%;
  min-width: 0;
  height: 47px;
  border: 0;
  outline: 0;
  padding: 0 14px;
  color: #1a1a1a;
  background: transparent;
  font-size: 15px;
}
.field-control input::placeholder { color: var(--login-muted); opacity: .8; }
.field-control-password input { padding-right: 8px; }
.password-toggle {
  align-self: center;
  margin-right: 8px;
  border-radius: 6px;
  padding: 6px 10px;
  color: #5c5c5c;
  background: #f4f1ea;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  transition: color 150ms ease, background-color 150ms ease;
}

.form-message {
  padding: 11px 13px;
  border: 1px solid rgba(122, 31, 31, .18);
  border-radius: 8px;
  color: #7a1f1f;
  background: #f5e8e8;
  font-size: 13px;
  line-height: 1.5;
}
.form-message.is-success {
  border-color: rgba(45, 95, 63, .18);
  color: #2d5f3f;
  background: #e8efe9;
}

.primary-button,
.secondary-button,
.context-button {
  transition: transform 150ms var(--login-ease-out), border-color 150ms ease, background-color 150ms ease, color 150ms ease;
}
.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  border: 1px solid #1f3a2e;
  border-radius: 8px;
  padding: 0 22px;
  color: #faf8f4;
  background: #1f3a2e;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
}
.primary-button > svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.primary-button:disabled { cursor: wait; opacity: .72; }
.primary-button.is-loading > svg { display: none; }
.button-spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #faf8f4;
  border-radius: 50%;
  animation: login-spin .65s linear infinite;
}
.is-loading .button-spinner { display: block; }
@keyframes login-spin { to { transform: rotate(360deg); } }

.account-help {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid #e8e4dc;
}
.help-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  color: #1f3a2e;
  background: #edf1ee;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
}
.account-help p { margin: 0; color: #5c5c5c; font-size: 13px; line-height: 1.55; }
.account-help strong { color: #1a1a1a; font-weight: 600; }

.legal-copy {
  max-width: 500px;
  margin: 0 auto;
  color: var(--login-muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}
.legal-copy a {
  color: #5c5c5c;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.view-heading-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.step-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 10px;
  color: #6f5410;
  background: #f5efe0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
}
.context-groups { display: grid; gap: 22px; margin-top: 24px; }
.context-group { display: grid; gap: 10px; }
.context-group-title {
  margin: 0;
  color: var(--login-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.context-button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto 16px;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  border: 1px solid #e8e4dc;
  border-radius: 8px;
  padding: 14px 16px;
  color: #1a1a1a;
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.context-button:disabled { cursor: not-allowed; opacity: .5; }
.context-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid #d4ded7;
  border-radius: 8px;
  color: #1f3a2e;
  background: #edf1ee;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.context-copy { min-width: 0; }
.context-copy strong {
  display: block;
  overflow: hidden;
  color: #1a1a1a;
  font-size: 14.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.context-copy small {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--login-muted);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .04em;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.context-role {
  border-radius: 999px;
  padding: 3px 9px;
  color: #5c5c5c;
  background: #f4f1ea;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.context-arrow {
  width: 16px;
  height: 16px;
  color: var(--login-muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.context-button.is-loading .context-arrow { display: none; }
.context-button .button-spinner { border-color: rgba(31, 58, 46, .2); border-top-color: #1f3a2e; }

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: fit-content;
  min-height: 42px;
  margin-top: 22px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 18px;
  color: #6f5410;
  background: #f5efe0;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
}

.code-control input {
  padding-left: 16px;
  font-family: var(--mono);
  font-size: 26px;
  letter-spacing: .34em;
  text-align: center;
}
.mfa-setup-box {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 16px;
  align-items: center;
  margin-top: 22px;
  padding: 16px;
  border: 1px solid #e8e4dc;
  border-radius: 8px;
  background: #f4f1ea;
}
.mfa-setup-box img { width: 96px; height: 96px; border: 1px solid #d4cfc0; border-radius: 6px; background: #fff; }
.mfa-setup-box span { display: block; color: var(--login-muted); font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.mfa-setup-box code { display: block; margin-top: 6px; overflow-wrap: anywhere; color: #1f3a2e; font-family: var(--mono); font-size: 13px; line-height: 1.5; }

.forgot-dialog {
  width: min(420px, calc(100% - 40px));
  max-height: calc(100vh - 40px);
  margin: auto;
  border: 1px solid #e8e4dc;
  border-radius: 12px;
  padding: 0;
  color: #1a1a1a;
  background: #fff;
  box-shadow: 0 24px 64px rgba(10, 20, 24, .18);
}
.forgot-dialog::backdrop {
  background: rgba(26, 26, 26, .55);
  backdrop-filter: blur(2px);
}
.forgot-dialog[open] { animation: login-dialog-in 200ms var(--login-ease-out) both; }
@keyframes login-dialog-in {
  from { opacity: 0; transform: scale(.97) translateY(7px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.forgot-card { position: relative; padding: 30px; background: #fff; }
.forgot-card .field-group { margin-top: 20px; }
.forgot-card .primary-button { margin-top: 16px; }
.dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  color: var(--login-muted);
  background: transparent;
  cursor: pointer;
  font-size: 20px;
}
.dialog-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-bottom: 16px;
  border: 1px solid #d4ded7;
  border-radius: 8px;
  color: #1f3a2e;
  background: #edf1ee;
}
.dialog-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 3px solid rgba(139, 105, 20, .35); outline-offset: 3px; }

@media (hover: hover) and (pointer: fine) {
  .back-link:hover { color: #1f3a2e; }
  .primary-button:hover:not(:disabled) { background: #2a4d3d; }
  .secondary-button:hover:not(:disabled) { background: #ede4d0; }
  .context-button:hover:not(:disabled) { border-color: #1f3a2e; transform: translateY(-1px); }
  .text-button:hover { color: #6f5410; }
  .password-toggle:hover { color: #1f3a2e; background: #e8e4dc; }
  .dialog-close:hover { color: #1a1a1a; background: #f4f1ea; }
}

.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.context-button:active:not(:disabled),
.dialog-close:active { transform: scale(.975); }
.back-link:active,
.text-button:active,
.password-toggle:active { opacity: .7; }

@media (max-width: 940px) {
  .login-layout { display: block; }
  .brand-panel { display: none; }
  .access-panel { min-height: 100vh; padding: max(20px, env(safe-area-inset-top)) 24px max(20px, env(safe-area-inset-bottom)); }
  .mobile-brand { display: inline-flex; }
}

@media (max-width: 560px) {
  .access-panel { gap: 20px; padding-inline: 16px; }
  .access-panel-top { margin-bottom: 8px; }
  .secure-label { display: none; }
  .access-card { margin: 0 auto auto; padding: 26px 20px; }
  .mobile-brand { margin-bottom: 26px; }
  .mobile-brand .brand-mark { width: 42px; height: 42px; }
  .mobile-brand .brand-name { font-size: 22px; }
  .access-view h2, .forgot-card h2 { font-size: 28px; }
  .context-button { grid-template-columns: 38px minmax(0, 1fr) 16px; gap: 11px; padding: 13px; }
  .context-role { grid-column: 2; width: fit-content; }
  .context-button > :last-child { grid-column: 3; grid-row: 1 / 3; }
  .mfa-setup-box { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .forgot-card { padding: 30px 22px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  /* El spinner de carga es feedback esencial (§14): sigue girando, solo más lento. */
  .button-spinner {
    animation-duration: 1.4s !important;
    animation-iteration-count: infinite !important;
  }
}

/* ── ETAPA 2 — botones de login social ─────────────────────────────── */
/* `display: flex` de las reglas siguientes gana al `display: none` del UA que
   aplica el atributo `hidden`, dejando visible un proveedor apagado por flag
   (p. ej. Apple con APPLE_AUTH_ENABLED=false). Restaurar la semántica de hidden. */
.oauth-buttons[hidden],
.oauth-button[hidden] { display: none !important; }

.oauth-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

.oauth-button {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px 16px;
  border: 1px solid #d9d4c8; border-radius: 12px;
  background: #fff; color: #1a1a1a; font-weight: 600; font-size: 15px;
  cursor: pointer;
  transition: transform 150ms var(--login-ease-out), border-color 150ms ease, background-color 150ms ease;
}
@media (hover:hover) and (pointer:fine) { .oauth-button:hover:not(:disabled) { border-color: #1F3A2E; background: #fbfaf7; } }
.oauth-button:active:not(:disabled) { transform: translateY(1px); }
.oauth-button:disabled { cursor: wait; opacity: .6; }
.oauth-button[data-oauth-provider="apple"] { color: #000; }
.oauth-icon { display: inline-flex; }

.oauth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 4px; color: var(--login-muted); font-size: 13px;
}
.oauth-divider::before, .oauth-divider::after {
  content: ""; flex: 1; height: 1px; background: #e4dfd3;
}

@media (prefers-reduced-motion: reduce) {
  .oauth-button { transition-duration: .01ms !important; }
}
