/* Login Bsuite — temi dark (default) e light tramite html[data-theme] */

/* --- Tema scuro (blu notte / antracite) --- */
html[data-theme="dark"] {
  --login-bg: linear-gradient(165deg, #070b14 0%, #0f172a 38%, #111827 72%, #0c1220 100%);
  --login-surface: #141c2e;
  --login-surface-elevated: #1a2438;
  --login-text: #f1f5f9;
  --login-text-soft: #cbd5e1;
  --login-muted: #94a3b8;
  --login-border: rgba(148, 163, 184, 0.28);
  --login-border-strong: rgba(148, 163, 184, 0.42);
  --login-shadow: 0 24px 56px rgba(0, 0, 0, 0.45), 0 8px 24px rgba(0, 0, 0, 0.35);
  --login-focus-ring: rgba(96, 165, 250, 0.35);
  --login-input-bg: rgba(15, 23, 42, 0.65);
  --login-input-bg-hover: rgba(30, 41, 59, 0.75);
  --login-input-bg-focus: rgba(15, 23, 42, 0.9);
  --login-icon: #64748b;
  --login-label: #cbd5e1;
  --login-remember-text: #94a3b8;
  --login-amec-navy: #93c5fd;
  --login-accent: #3b82f6;
  --login-error-text: #fecaca;
  --login-error-bg: rgba(127, 29, 29, 0.45);
  --login-error-border: rgba(248, 113, 113, 0.45);
  --login-toggle-bg: rgba(148, 163, 184, 0.12);
  --login-toggle-border: rgba(148, 163, 184, 0.25);
  --login-toggle-hover: rgba(30, 41, 59, 0.92);
}

/* --- Tema chiaro --- */
html[data-theme="light"] {
  --login-bg: linear-gradient(165deg, #f8fafc 0%, #eef2f7 42%, #f1f5f9 100%);
  --login-surface: #ffffff;
  --login-surface-elevated: #ffffff;
  --login-text: #0f172a;
  --login-text-soft: #334155;
  --login-muted: #64748b;
  --login-border: #e2e8f0;
  --login-border-strong: #cbd5e1;
  --login-shadow: 0 22px 50px rgba(15, 23, 42, 0.12), 0 8px 20px rgba(15, 23, 42, 0.06);
  --login-focus-ring: rgba(37, 99, 235, 0.22);
  --login-input-bg: #fafbfc;
  --login-input-bg-hover: #ffffff;
  --login-input-bg-focus: #ffffff;
  --login-icon: #94a3b8;
  --login-label: #334155;
  --login-remember-text: #475569;
  --login-amec-navy: #1e3a5f;
  --login-accent: #2563eb;
  --login-error-text: #991b1b;
  --login-error-bg: rgba(254, 226, 226, 0.95);
  --login-error-border: rgba(248, 113, 113, 0.55);
  --login-toggle-bg: rgba(15, 23, 42, 0.06);
  --login-toggle-border: rgba(148, 163, 184, 0.35);
  --login-toggle-hover: rgba(255, 255, 255, 0.95);
}

body.login-body {
  margin: 0;
  min-height: 100vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--login-bg);
  background-attachment: fixed;
  color: var(--login-text);
  -webkit-font-smoothing: antialiased;
}

.login-page {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1.25rem, 4vw, 2.5rem);
  width: 100%;
  box-sizing: border-box;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--login-surface);
  border-radius: 16px;
  box-shadow: var(--login-shadow);
  border: 1px solid var(--login-border);
  padding: clamp(1.75rem, 4vw, 2.25rem) clamp(1.5rem, 4vw, 2rem) clamp(1.5rem, 3vw, 2rem);
  box-sizing: border-box;
}

html[data-theme="dark"] .login-card {
  background: linear-gradient(180deg, var(--login-surface-elevated) 0%, var(--login-surface) 100%);
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.login-logo-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: radial-gradient(circle at 30% 22%, #60a5fa 0, #2563eb 42%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  box-shadow: 0 12px 28px rgba(30, 58, 95, 0.35);
  flex-shrink: 0;
}

.login-logo-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  text-align: left;
}

.login-logo-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--login-amec-navy);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

html[data-theme="dark"] .login-logo-title {
  color: #e2e8f0;
}

.login-logo-tagline {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--login-muted);
  letter-spacing: 0.02em;
}

.login-title {
  margin: 0 0 1.35rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--login-text);
  letter-spacing: -0.01em;
  text-align: center;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.login-field label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--login-label);
  letter-spacing: 0.01em;
}

.login-input-shell {
  position: relative;
  display: flex;
  align-items: center;
}

/* Icone decorative nei campi: non intercettano i click (il toggle password resta sopra con z-index) */
.login-input-shell .login-input-icon,
.login-input-shell svg.login-input-icon {
  position: absolute;
  left: 0.85rem;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--login-icon);
  pointer-events: none;
  z-index: 1;
}

.login-input-shell input {
  width: 100%;
  min-height: 48px;
  padding: 0.65rem 0.85rem 0.65rem 2.75rem;
  font-size: 1rem;
  line-height: 1.35;
  color: var(--login-text);
  background: var(--login-input-bg);
  border: 1px solid var(--login-border);
  border-radius: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  box-sizing: border-box;
}

.login-input-shell input::placeholder {
  color: var(--login-muted);
}

.login-input-shell input:hover {
  border-color: var(--login-border-strong);
  background: var(--login-input-bg-hover);
}

.login-input-shell input:focus {
  outline: none;
  border-color: var(--login-accent);
  background: var(--login-input-bg-focus);
  box-shadow: 0 0 0 3px var(--login-focus-ring);
}

/* Autofill WebKit: evita sfondo bianco e testo illeggibile (tema dark / light) */
html[data-theme="dark"] .login-input-shell input:-webkit-autofill,
html[data-theme="dark"] .login-input-shell input:-webkit-autofill:hover,
html[data-theme="dark"] .login-input-shell input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--login-text) !important;
  caret-color: var(--login-text);
  -webkit-box-shadow: 0 0 0 1000px #1a1a1a inset !important;
  box-shadow: 0 0 0 1000px #1a1a1a inset, 0 0 0 3px var(--login-focus-ring) !important;
  transition: background-color 5000s ease-in-out 0s;
}

html[data-theme="light"] .login-input-shell input:-webkit-autofill,
html[data-theme="light"] .login-input-shell input:-webkit-autofill:hover,
html[data-theme="light"] .login-input-shell input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--login-text) !important;
  caret-color: var(--login-text);
  -webkit-box-shadow: 0 0 0 1000px #fafbfc inset !important;
  box-shadow: 0 0 0 1000px #fafbfc inset, 0 0 0 3px var(--login-focus-ring) !important;
  transition: background-color 5000s ease-in-out 0s;
}

.login-input-shell:focus-within .login-input-icon {
  color: var(--login-accent);
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.15rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--login-remember-text);
  user-select: none;
}

.login-remember input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--login-accent);
  cursor: pointer;
}

.login-form .primary-button {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.8rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  color: #f8fafc;
  background: linear-gradient(
    135deg,
    #1e3a5f 0%,
    #1d4ed8 55%,
    var(--login-accent) 100%
  );
  box-shadow: 0 10px 26px rgba(30, 58, 95, 0.32);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.login-form .primary-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  box-shadow: 0 14px 32px rgba(30, 58, 95, 0.38);
}

.login-form .primary-button:active {
  transform: translateY(0);
  filter: brightness(0.97);
}

/* Messaggi errore: leggibili in entrambi i temi */
.login-error {
  margin: 1rem 0 0;
  min-height: 1.25em;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--login-error-text);
  text-align: center;
  line-height: 1.45;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: var(--login-error-bg);
  border: 1px solid var(--login-error-border);
  box-sizing: border-box;
}

.login-error:empty {
  padding: 0;
  min-height: 0;
  border: none;
  background: transparent;
}

.login-page .build-badge {
  margin-top: 1.25rem;
  text-align: center;
  color: var(--login-muted);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
}

/* Theme switcher: basso a sinistra, discreto */
.login-theme-toggle {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  z-index: 50;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--login-toggle-border);
  background: var(--login-toggle-bg);
  color: var(--login-muted);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease,
    transform 0.15s ease, opacity 0.2s ease;
  opacity: 0.72;
}

.login-theme-toggle:hover {
  opacity: 1;
  background: var(--login-toggle-hover);
  border-color: var(--login-border-strong);
  color: var(--login-text-soft);
}

.login-theme-toggle:active {
  transform: scale(0.96);
}

.login-theme-toggle svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* In dark: mostra il sole (passa al chiaro). In light: mostra la luna (passa allo scuro). */
html[data-theme="dark"] .login-theme-icon--moon {
  display: none;
}
html[data-theme="dark"] .login-theme-icon--sun {
  display: block;
}
html[data-theme="light"] .login-theme-icon--moon {
  display: block;
}
html[data-theme="light"] .login-theme-icon--sun {
  display: none;
}

@media (max-width: 380px) {
  .login-brand {
    flex-direction: column;
    text-align: center;
  }

  .login-logo-text {
    align-items: center;
  }

  .login-theme-toggle {
    bottom: 0.75rem;
    left: 0.75rem;
  }
}

/* --- Campo password: stato bloccato, toggle occhio (nessuna animazione) --- */
.login-input-shell--password input,
.login-input-shell--password input#password {
  padding-right: 3rem;
  transition: none;
  animation: none;
}

.login-input-shell input:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.login-input-shell input:disabled:hover {
  border-color: var(--login-border);
  background: var(--login-input-bg);
}

.login-field--password-locked .login-password-toggle {
  opacity: 0.45;
  pointer-events: none;
}

.login-password-toggle,
#passwordToggle {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--login-icon);
  cursor: pointer;
  transition: none;
  animation: none;
}

/* Un solo occhio visibile: aperto = mostra password; chiuso = nascondi */
#passwordToggle .login-eye--open {
  display: block;
}
#passwordToggle .login-eye--closed {
  display: none;
}
#passwordToggle.is-password-visible .login-eye--open {
  display: none;
}
#passwordToggle.is-password-visible .login-eye--closed {
  display: block;
}

/* SVG dentro il pulsante occhio: i click vanno al button */
.login-password-toggle:hover:not(:disabled) {
  color: var(--login-accent);
  background: rgba(37, 99, 235, 0.08);
}

html[data-theme="dark"] .login-password-toggle:hover:not(:disabled) {
  background: rgba(96, 165, 250, 0.12);
}

.login-password-toggle:focus-visible {
  outline: 2px solid var(--login-accent);
  outline-offset: 2px;
}

.login-password-toggle svg,
#passwordToggle svg {
  pointer-events: none;
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  transition: none;
  animation: none;
}

.login-password-toggle.is-password-visible {
  color: var(--login-accent);
}

/* --- Splash post-login --- */
.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: clamp(1rem, 4vw, 2rem);
  box-sizing: border-box;
  background: var(--login-bg);
  background-attachment: fixed;
}

.splash-screen[hidden] {
  display: none !important;
}

.splash-screen__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1.25rem;
  max-width: min(92vw, 28rem);
}

/* Contesto utente / azienda sotto il logo Bsuite */
.splash-user-context {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
}

.splash-user-context[hidden] {
  display: none !important;
}

.splash-user-context__loading-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  order: -1;
}

.splash-user-context__loading-gif {
  width: 60px;
  height: 60px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

.splash-user-context__line {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--login-text-soft);
  line-height: 1.4;
}

.splash-user-context__line #splashUserName {
  font-weight: 700;
  color: var(--login-text);
}

.splash-user-context__company {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--login-muted);
  letter-spacing: 0.02em;
}

.splash-screen__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.splash-screen__brand--animate {
  animation: splash-logo-enter 0.55s ease-out forwards;
}

.splash-screen__brand--animate .splash-screen__logo-mark {
  animation: splash-logo-pulse 0.85s ease-in-out 0.52s infinite;
}

.splash-screen__logo-mark {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: radial-gradient(circle at 30% 22%, #60a5fa 0, #2563eb 42%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 2rem;
  letter-spacing: -0.02em;
  box-shadow: 0 18px 48px rgba(30, 58, 95, 0.45);
  flex-shrink: 0;
}

.splash-screen__logo-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  text-align: left;
}

.splash-screen__title {
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  font-weight: 700;
  color: var(--login-amec-navy);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

html[data-theme="dark"] .splash-screen__title {
  color: #e2e8f0;
}

.splash-screen__tagline {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--login-muted);
  letter-spacing: 0.02em;
}

@keyframes splash-logo-enter {
  from {
    opacity: 0;
    transform: scale(0.88) translateY(14px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes splash-logo-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.04);
    opacity: 0.96;
  }
}

body.login-splash-active {
  overflow: hidden;
}

/* Honeypot + verifica umana leggera (STEP 11–12)
   Limite: solo client-side; non sostituisce rate limit / WAF / protezioni server.
   Stessa logica su /login e /partner/login. */
.login-hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.login-captcha {
  margin-bottom: 0.65rem;
}

.login-captcha label {
  display: block;
  font-size: 0.8rem;
  color: var(--login-label);
  margin-bottom: 0.35rem;
}

.login-captcha input {
  width: 100%;
  max-width: 8rem;
  box-sizing: border-box;
}

.login-step.hidden,
.login-step[hidden] {
  display: none !important;
}

.login-title--sub {
  font-size: 1.15rem;
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.login-twofa-lead {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--login-text-soft);
  line-height: 1.45;
}

.login-twofa-hint {
  margin: 0.5rem 0 0.75rem;
  font-size: 0.82rem;
  color: var(--login-muted);
}

.login-twofa-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.login-twofa-block.hidden {
  display: none;
}

.login-twofa-qr {
  max-width: 400px;
  width: 100%;
  margin: 0.5rem auto 1rem;
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  box-sizing: border-box;
}

.login-twofa-qr svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Setup 2FA: due riquadri distinti (account vs installazione app) */
.login-twofa-setup-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin: 0.35rem 0 0.75rem;
}

.login-twofa-panel {
  border-radius: 12px;
  padding: 0.9rem 1rem 1rem;
  border: 1px solid var(--login-border);
  background: var(--login-input-bg);
}

.login-twofa-panel--account {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.12);
}

html[data-theme="dark"] .login-twofa-panel--account {
  border-color: rgba(96, 165, 250, 0.42);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.1);
}

.login-twofa-panel--app {
  border-style: dashed;
  border-color: var(--login-border-strong);
  background: transparent;
}

.login-twofa-panel__badge {
  margin: 0 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--login-accent);
}

.login-twofa-panel__title {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--login-text);
  line-height: 1.3;
}

.login-twofa-panel__title--compact {
  font-size: 0.9rem;
}

.login-twofa-panel__lead {
  margin: 0 0 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--login-text-soft);
}

.login-twofa-panel__text {
  margin: 0 0 0.5rem !important;
}

.login-twofa-qr--account {
  margin-top: 0.35rem;
  margin-bottom: 0.5rem;
}

.login-twofa-qr--app-download {
  max-width: 148px;
  margin: 0.35rem auto 0.5rem;
  padding: 8px;
  border: 1px dashed var(--login-border-strong);
}

.login-twofa-qr--app-download img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 120px;
  margin: 0 auto;
}

.login-twofa-fallback-note {
  margin: 0 !important;
  font-size: 0.8rem !important;
  color: var(--login-muted) !important;
}

.login-twofa-store-links {
  margin: 0;
  font-size: 0.78rem;
  text-align: center;
  line-height: 1.5;
}

.login-twofa-store-links a {
  color: var(--login-accent);
  font-weight: 600;
  text-decoration: none;
}

.login-twofa-store-links a:hover {
  text-decoration: underline;
}

.login-twofa-store-links__sep {
  margin: 0 0.25rem;
  color: var(--login-muted);
  user-select: none;
}

.login-twofa-readonly {
  font-size: 0.8rem;
  font-family: ui-monospace, monospace;
}

.login-twofa-codes {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.78rem;
  line-height: 1.5;
  background: var(--login-input-bg);
  border: 1px solid var(--login-border);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

.login-twofa-trust {
  margin-top: 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
}

.login-twofa-back {
  margin-top: 1.25rem;
  width: 100%;
  padding: 0.5rem;
  border: none;
  background: transparent;
  color: var(--login-muted);
  cursor: pointer;
  font-size: 0.88rem;
}

.login-twofa-back:hover {
  color: var(--login-accent);
}
