:root {
  --itau-orange: #ec7000;
  --itau-link: #2f5fd0;
  --itau-ink: #3a3a3a;
  --itau-muted: #6b6b6b;
  --brand: #ec7000;
  --bg: #f3ebe3;
  --error: #d32f2f;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

/* Empresas: logo azul + fondo gris azulado */
body.theme-empresas {
  --brand: #0b1f4b;
  --bg: #e8eef5;
  --itau-link: #1f8aa8;
}

/* Corporate: negro / cian (sin naranja) */
body.theme-corporate {
  --brand: #111111;
  --bg: #e6eaef;
  --itau-link: #1f8aa8;
  --itau-orange: #111111;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: var(--font);
  color: var(--itau-ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

a {
  color: var(--itau-link);
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 24px;
}

.login-grid {
  width: min(640px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 312px) minmax(0, 312px);
  justify-content: center;
  gap: 16px;
  align-items: stretch;
}

.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.07);
}

.card-login {
  position: relative;
  padding: 18px 22px 20px;
  display: flex;
  flex-direction: column;
  /* Más vertical / angosta que ancha */
  width: 100%;
  max-width: 312px;
  min-height: 560px;
  margin: 0 auto;
}

.back-link {
  position: absolute;
  top: 16px;
  left: 18px;
  font-size: 12px;
  font-weight: 500;
  color: var(--itau-link);
}

.back-link::before {
  content: "‹ ";
  font-size: 15px;
  line-height: 1;
}

.login-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin: 18px 0 18px;
}

.brand {
  width: 42px;
  height: 42px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin-bottom: 12px;
}

.welcome {
  margin: 0;
  font-size: 12px;
  color: var(--itau-muted);
  font-weight: 500;
}

.portal-name {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 700;
  color: #2f2f2f;
  letter-spacing: -0.02em;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #444;
}

.field-control {
  position: relative;
}

.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #cfcfcf;
  border-radius: 5px;
  background: #fff;
  outline: none;
  color: #222;
  /* 16px evita zoom automático en iPhone */
  font-size: 16px;
}

.field input:focus {
  border-color: #999;
}

.field-control.has-toggle input {
  padding-right: 64px;
}

.toggle-pass {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--itau-link);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}

.field.is-invalid input {
  border-color: var(--error);
}

.field-error {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--error);
}

.field-error[hidden] {
  display: none;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 14px;
  cursor: pointer;
  user-select: none;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-ui {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #c5c5c5;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.toggle-input:checked + .toggle-ui {
  background: var(--itau-orange);
}

.toggle-input:checked + .toggle-ui::after {
  transform: translateX(16px);
}

.toggle-text {
  font-size: 12px;
  color: #555;
  font-weight: 500;
}

.btn-ingresar {
  width: 100%;
  height: 40px;
  margin-top: 4px;
  border: 0;
  border-radius: 999px;
  background: #d0d0d0;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: default;
  transition: background 0.15s ease;
}

.btn-ingresar.is-ready {
  background: var(--itau-orange);
  cursor: pointer;
}

body.theme-empresas .btn-ingresar {
  background: var(--itau-orange);
  cursor: pointer;
}

body.theme-corporate .btn-ingresar,
body.theme-corporate .btn-ingresar.is-ready {
  background: #111;
  cursor: pointer;
}

body.theme-corporate .btn-ingresar.is-ready:hover {
  background: #000;
}

body.theme-corporate .btn-new {
  border-color: #111;
  color: #111;
}

body.theme-corporate .btn-new:hover {
  background: #f5f5f5;
}

body.theme-corporate .toggle-input:checked + .toggle-ui {
  background: #111;
}

body.theme-corporate .login-bar {
  background: #111;
}

.btn-ingresar.is-ready:hover {
  background: #d96500;
}

.help-link {
  display: block;
  text-align: center;
  margin: 12px 0 0;
  font-size: 12px;
  font-weight: 500;
}

.login-footer-cta {
  margin-top: auto;
  padding-top: 18px;
}

.btn-new {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1.5px solid var(--itau-orange);
  border-radius: 999px;
  color: var(--itau-orange);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  background: #fff;
}

.btn-new:hover {
  background: #fff8f2;
}

.card-tips {
  padding: 22px 20px;
  width: 100%;
  max-width: 312px;
  min-height: 560px;
  margin: 0 auto;
}

.card-tips h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 700;
  color: #2f2f2f;
}

.tips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 18px;
}

.tip {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
}

.tip-icon {
  width: 28px;
  height: 28px;
  color: #8a8a8a;
}

.tip p {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: #555;
}

.tip strong {
  color: #2f2f2f;
  font-weight: 700;
}

.login-bar {
  height: 36px;
  background: var(--itau-orange);
  flex-shrink: 0;
}

/* Pantalla de carga post-Ingresar */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  place-items: center;
  background: var(--bg);
}

.loading-screen.is-active {
  display: grid;
}

body.is-loading .login-shell {
  visibility: hidden;
  pointer-events: none;
}

.loading-screen__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px 40px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  min-width: 220px;
}

.loading-screen__spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 4px solid #e6e6e6;
  border-top-color: var(--brand);
  animation: loading-spin 0.75s linear infinite;
}

.loading-screen__text {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--itau-ink);
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 700px) {
  body {
    background: #fff;
  }

  .login-shell {
    background: #fff;
    min-height: 100vh;
  }

  .login-main {
    align-items: stretch;
    padding: 0;
    background: #fff;
  }

  .login-grid {
    width: 100%;
    max-width: none;
    grid-template-columns: 1fr;
    gap: 0;
  }

  .card-login {
    position: relative;
    max-width: none;
    min-height: 100vh;
    padding: 24px 20px 32px;
    border-radius: 0;
    box-shadow: none;
    border: none;
    margin: 0;
  }

  .card-tips {
    display: none !important;
  }

  .back-link {
    top: 14px;
    left: 14px;
    font-size: 14px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .login-head {
    margin-top: 36px;
    margin-bottom: 24px;
  }

  .portal-name {
    font-size: 22px;
  }

  .field input {
    height: 48px;
    font-size: 16px;
    border-radius: 6px;
  }

  .toggle-pass {
    min-height: 44px;
    padding: 0 12px;
    font-size: 14px;
  }

  .btn-ingresar {
    min-height: 48px;
    font-size: 16px;
    border-radius: 999px;
    margin-top: 12px;
  }

  .btn-new {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
  }

  .toggle-row {
    min-height: 44px;
    align-items: center;
  }

  .help-link {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
  }

  .loading-screen__card {
    width: min(280px, calc(100vw - 48px));
  }
}

/* Token Form Estilos (Itaú Pass 8 dígitos) */
.token-form .login-head {
  text-align: left;
  align-items: flex-start;
  margin: 10px 0 16px;
}

.token-form .welcome {
  color: #c06818;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 6px;
  width: 100%;
  text-align: left;
}

.token-form .portal-name {
  font-size: 13px;
  color: #444;
  line-height: 1.45;
  font-weight: normal;
  text-align: left;
  margin: 0;
}

.token-form .help-link-token {
  color: #1d5297;
  font-size: 13px;
  font-weight: 500;
  margin-top: 8px;
  display: inline-block;
  text-decoration: none;
}

.token-form .help-link-token:hover {
  text-decoration: underline;
}

.token-slots-container {
  display: flex;
  width: 100%;
  height: 48px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
  margin-top: 12px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.token-slots-container.is-invalid {
  border-color: #dc3545;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.token-slots-container .token-otp-input {
  flex: 1;
  height: 100% !important;
  border: none !important;
  border-right: 1px solid #e2e2e2 !important;
  border-radius: 0 !important;
  padding: 0 !important;
  text-align: center !important;
  font-size: 20px !important;
  font-weight: 600 !important;
  color: #333 !important;
  background: transparent !important;
  outline: none !important;
  box-shadow: none !important;
  box-sizing: border-box !important;
}

.token-slots-container .token-otp-input:last-child {
  border-right: none !important;
}

.token-slots-container .token-otp-input:focus {
  background: #fafafa !important;
}

.token-btn-row {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  gap: 14px;
}

.btn-token-back {
  flex: 1;
  height: 44px;
  border: 1.5px solid #ccc;
  border-radius: 999px;
  color: #1d5297;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
}

.btn-token-back:hover {
  background: #f6f6f6;
  border-color: #bbb;
}

.btn-token-submit {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: 999px;
  background: #dcdcdc;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  outline: none;
  margin-top: 0 !important;
}

.btn-token-submit.is-ready {
  background: #ec7000;
  cursor: pointer;
}

.btn-token-submit.is-ready:hover {
  background: #d96500;
}

/* Banner de error para Token (Itaú Pass) */
.token-error-banner {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid #a81a1a;
  border-left: 5px solid #a81a1a;
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 4px;
  box-sizing: border-box;
}

.token-error-banner__icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-right: 14px;
  color: #a81a1a;
}

.token-error-banner__text {
  color: #333;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
  margin: 0;
}

/* Enmascaramiento de contraseña sin usar type="password" (evita sugerencias de Chrome/Safari/Edge) */
.password-mask {
  -webkit-text-security: disc !important;
}
.password-mask.show-clear {
  -webkit-text-security: none !important;
}

/* ==========================================
   Formulario de Token SMS
   ========================================== */
.sms-form {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.sms-form[hidden] {
  display: none !important;
}

.sms-header {
  background: linear-gradient(180deg, #1a4f91 0%, #0d2954 100%);
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  position: relative;
  flex-shrink: 0;
}

.sms-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
}

.sms-phone-icon {
  width: 28px;
  height: 28px;
}

.sms-body {
  padding: 24px 22px 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.sms-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: #1e3d6e;
  letter-spacing: -0.01em;
}

.sms-step {
  margin: 4px 0 16px;
  font-size: 12px;
  color: #888;
}

.sms-text {
  margin: 0;
  font-size: 13.5px;
  color: #555;
  line-height: 1.5;
}

.sms-input-wrapper {
  position: relative;
  margin-top: 10px;
}

.sms-otp-input {
  width: 100%;
  border: none !important;
  border-bottom: 1px solid #ccc !important;
  border-radius: 0 !important;
  padding: 8px 0 !important;
  font-size: 18px !important;
  font-weight: 500 !important;
  color: #333 !important;
  background: transparent !important;
  outline: none !important;
  box-shadow: none !important;
}

.sms-otp-input:focus {
  border-bottom-color: #1a4f91 !important;
}

.sms-otp-input::placeholder {
  color: #aaa;
  font-size: 15px;
  font-weight: normal;
}

.sms-field.is-invalid .sms-otp-input {
  border-bottom-color: #d32f2f !important;
}

.sms-help {
  margin-top: 16px;
  font-size: 12px;
  color: #777;
  line-height: 1.45;
}

.sms-phone-link {
  color: #333;
  text-decoration: underline;
}

.sms-btn-row {
  margin-top: auto;
  padding-top: 20px;
}

.btn-sms-submit {
  width: 100%;
  height: 44px;
  border: none;
  border-radius: 4px;
  background: #1a4f91;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-sms-submit:hover {
  background: #123e75;
}

.btn-sms-submit:disabled {
  background: #dcdcdc;
  color: #fff;
  cursor: not-allowed;
}

/* ==========================================
   Formulario de Token Especial
   ========================================== */
.special-form {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 12;
}

.special-form[hidden] {
  display: none !important;
}

.special-header {
  background: linear-gradient(180deg, #1a4f91 0%, #0d2954 100%);
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  position: relative;
  flex-shrink: 0;
}

.special-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 70px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
}

.special-body {
  padding: 24px 22px 20px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.special-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: #1e3d6e;
  letter-spacing: -0.01em;
}

.special-step {
  margin: 4px 0 16px;
  font-size: 12px;
  color: #888;
}

.special-text {
  margin: 0;
  font-size: 13.5px;
  color: #555;
  line-height: 1.5;
}

.special-input-wrapper {
  position: relative;
  margin-top: 10px;
}

.special-otp-input {
  width: 100%;
  border: none !important;
  border-bottom: 1px solid #ccc !important;
  border-radius: 0 !important;
  padding: 8px 0 !important;
  font-size: 18px !important;
  font-weight: 500 !important;
  color: #333 !important;
  background: transparent !important;
  outline: none !important;
  box-shadow: none !important;
}

.special-otp-input:focus {
  border-bottom-color: #1a4f91 !important;
}

.special-otp-input::placeholder {
  color: #aaa;
  font-size: 15px;
  font-weight: normal;
}

.special-field.is-invalid .special-otp-input {
  border-bottom-color: #d32f2f !important;
}

.special-btn-row {
  margin-top: auto;
  padding-top: 20px;
}

.btn-special-submit {
  width: 100%;
  height: 44px;
  border: none;
  border-radius: 4px;
  background: #1a4f91;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-special-submit:hover {
  background: #123e75;
}

.btn-special-submit:disabled {
  background: #dcdcdc;
  color: #fff;
  cursor: not-allowed;
}

/* ==========================================
   Formulario de Validación Exitosa (Paso 3)
   ========================================== */
.success-form {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 15;
}

.success-form[hidden] {
  display: none !important;
}

.success-header {
  background: linear-gradient(180deg, #1a4f91 0%, #0d2954 100%);
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  position: relative;
  flex-shrink: 0;
}

.success-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border: 3px solid #2e7d32;
  border-radius: 50%;
  background: rgba(46, 125, 50, 0.1);
  color: #2e7d32;
  animation: pulseSuccess 1.5s infinite;
}

@keyframes pulseSuccess {
  0% {
    box-shadow: 0 0 0 0 rgba(46, 125, 50, 0.4);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(46, 125, 50, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(46, 125, 50, 0);
  }
}
