/* ──────────────────────────────────────────────────────────────────────
 *  France Carte Grise — Login moderne
 *  Design: glassmorphism + gradient FR (bleu/blanc/rouge subtil)
 *  Funciona standalone (não precisa Bootstrap; sem deps).
 *  Dark-mode aware via prefers-color-scheme.
 * ────────────────────────────────────────────────────────────────────── */

:root {
  --c-bg-1: #0b1d3a;
  --c-bg-2: #1e3a8a;
  --c-bg-3: #0e7490;
  --c-accent: #2563eb;
  --c-accent-hover: #1d4ed8;
  --c-accent-glow: rgba(37, 99, 235, 0.45);
  --c-fr-blue: #002654;
  --c-fr-red:  #ed2939;
  --c-text: #0f172a;
  --c-text-muted: #64748b;
  --c-text-on-glass: #1e293b;
  --c-card-bg: rgba(255, 255, 255, 0.78);
  --c-card-border: rgba(255, 255, 255, 0.85);
  --c-input-bg: rgba(255, 255, 255, 0.72);
  --c-input-border: rgba(15, 23, 42, 0.12);
  --c-input-focus: rgba(37, 99, 235, 0.55);
  --c-divider: rgba(15, 23, 42, 0.10);
  --c-success: #10b981;
  --c-error: #dc2626;
  --c-error-bg: rgba(220, 38, 38, 0.08);
  --shadow-card: 0 30px 80px -20px rgba(2, 6, 23, 0.55), 0 8px 30px -10px rgba(2, 6, 23, 0.35);
  --radius: 18px;
  --radius-input: 12px;
  --transition-fast: 150ms cubic-bezier(.2,.9,.2,1);
  --transition-slow: 350ms cubic-bezier(.2,.9,.2,1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-card-bg: rgba(15, 23, 42, 0.72);
    --c-card-border: rgba(255, 255, 255, 0.10);
    --c-input-bg: rgba(15, 23, 42, 0.65);
    --c-input-border: rgba(255, 255, 255, 0.10);
    --c-text: #f1f5f9;
    --c-text-muted: #94a3b8;
    --c-text-on-glass: #e2e8f0;
    --c-divider: rgba(255, 255, 255, 0.08);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  color: var(--c-text);
}

body.login-modern {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(37, 99, 235, 0.30), transparent 60%),
    radial-gradient(ellipse 70% 70% at 80% 100%, rgba(14, 116, 144, 0.30), transparent 60%),
    linear-gradient(135deg, var(--c-bg-1) 0%, var(--c-bg-2) 50%, var(--c-bg-3) 100%);
  background-attachment: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-x: hidden;
  position: relative;
}

/* ── Animated background orbs ────────────────────────────────────────── */
body.login-modern::before,
body.login-modern::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  opacity: 0.45;
  z-index: 0;
}
body.login-modern::before {
  width: 480px; height: 480px;
  top: -120px; left: -120px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.6), transparent 70%);
  animation: floatOrb 18s ease-in-out infinite;
}
body.login-modern::after {
  width: 600px; height: 600px;
  bottom: -200px; right: -200px;
  background: radial-gradient(circle, rgba(237, 41, 57, 0.45), transparent 70%);
  animation: floatOrb 22s ease-in-out infinite reverse;
}
@keyframes floatOrb {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(40px, -40px) scale(1.08); }
}

/* ── Card ─────────────────────────────────────────────────────────── */
.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  padding: 40px 36px 32px;
  background: var(--c-card-bg);
  border: 1px solid var(--c-card-border);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  color: var(--c-text-on-glass);
  animation: cardIn 600ms cubic-bezier(.2,.9,.2,1);
  transition: box-shadow var(--transition-slow);
}
.login-card:focus-within {
  box-shadow: var(--shadow-card), 0 0 0 1px var(--c-input-focus);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(20px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Logo + branding ──────────────────────────────────────────────── */
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Container flexível — adapta-se ao logo PNG (ou SVG legacy). */
  max-width: 120px;
  max-height: 120px;
  margin-bottom: 18px;
  filter: drop-shadow(0 10px 28px rgba(0,0,0,0.35));
  animation: logoIn 700ms cubic-bezier(.2,.9,.2,1);
}
.login-logo img {
  width: 100px;
  height: 100px;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  -webkit-user-drag: none;
  user-drag: none;
}
.login-logo svg {
  width: 76px;
  height: 76px;
  display: block;
}
@keyframes logoIn {
  from { opacity: 0; transform: scale(.82) rotate(-6deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}
@media (prefers-reduced-motion: reduce) {
  .login-logo { animation: none; }
}
.login-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -.01em;
  color: var(--c-text-on-glass);
}
.login-subtitle {
  font-size: 14px;
  color: var(--c-text-muted);
  margin: 0;
}

/* ── Form fields ──────────────────────────────────────────────────── */
.login-field {
  margin-bottom: 14px;
}
.login-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-text-muted);
  margin-bottom: 6px;
}
.login-field input[type="text"],
.login-field input[type="email"],
.login-field input[type="password"] {
  width: 100%;
  padding: 13px 16px;
  font-size: 15px;
  font-family: inherit;
  background: var(--c-input-bg);
  border: 1px solid var(--c-input-border);
  border-radius: var(--radius-input);
  color: var(--c-text-on-glass);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
  outline: none;
}
.login-field input:focus {
  border-color: var(--c-input-focus);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18);
  background: var(--c-card-bg);
}
.login-field input:hover:not(:focus) {
  border-color: rgba(37, 99, 235, 0.30);
}
.login-field input:autofill,
.login-field input:-webkit-autofill {
  /* Prevent yellow autofill bg in dark mode */
  -webkit-box-shadow: 0 0 0 1000px var(--c-input-bg) inset;
  -webkit-text-fill-color: var(--c-text-on-glass);
}
.login-field input::placeholder {
  color: var(--c-text-muted);
  opacity: .6;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: 0;
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--c-accent) 0%, var(--c-accent-hover) 100%);
  color: #fff;
  box-shadow: 0 6px 24px -8px var(--c-accent-glow);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 30px -8px var(--c-accent-glow);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled {
  opacity: .55;
  cursor: not-allowed;
  filter: grayscale(.2);
}
.btn-passkey {
  background: linear-gradient(135deg, #0f766e 0%, #14b8a6 100%);
  color: #fff;
  box-shadow: 0 6px 24px -8px rgba(20, 184, 166, .45);
}
.btn-passkey:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 30px -8px rgba(20, 184, 166, .50);
}
.btn-ghost {
  background: transparent;
  color: var(--c-text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 10px;
}
.btn-ghost:hover { color: var(--c-text-on-glass); }

.btn .icon { font-size: 18px; line-height: 1; }
.btn .spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Subtle pulse animation on idle passkey button to draw attention */
.btn-passkey:not(:disabled):not(:hover) {
  animation: passkeyIdle 3.2s ease-in-out infinite;
}
@keyframes passkeyIdle {
  0%, 100% { box-shadow: 0 6px 24px -8px rgba(20, 184, 166, .45); }
  50%      { box-shadow: 0 6px 24px -4px rgba(20, 184, 166, .65), 0 0 0 4px rgba(20, 184, 166, .12); }
}
@media (prefers-reduced-motion: reduce) {
  .btn-passkey:not(:disabled):not(:hover) { animation: none; }
}

/* ── Divider "ou" ─────────────────────────────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--c-text-muted);
}
.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--c-divider);
}

/* ── Collapse "ou avec mot de passe" ──────────────────────────────── */
.divider-toggle {
  /* reset agressivo de defaults browser para <button> */
  background: transparent !important;
  background-color: transparent !important;
  background-image: none !important;
  border: 0;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  box-shadow: none;
  width: 100%;
  cursor: pointer;
  font-family: inherit;
  color: var(--c-text-muted);
  padding: 8px 0;
  margin: 20px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  transition: color var(--transition-fast);
}
.divider-toggle:focus-visible {
  outline: 2px solid var(--c-input-focus);
  outline-offset: 4px;
  border-radius: 6px;
}
.divider-toggle::before,
.divider-toggle::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--c-divider);
  transition: background var(--transition-fast);
}
.divider-toggle:hover { color: var(--c-text-on-glass); }
.divider-toggle:hover::before,
.divider-toggle:hover::after { background: var(--c-input-focus); }

.divider-toggle .caret {
  display: inline-block;
  width: 14px;
  text-align: center;
  font-weight: 800;
  font-size: 14px;
  transition: transform var(--transition-slow);
}
.divider-toggle[aria-expanded="true"] .caret {
  transform: rotate(90deg);
}

.collapse {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height var(--transition-slow), opacity var(--transition-slow);
}
.collapse.open {
  max-height: 320px;
  opacity: 1;
}

/* ── Status / error / footer ──────────────────────────────────────── */
.login-status {
  font-size: 13px;
  text-align: center;
  margin-top: 14px;
  min-height: 18px;
  color: var(--c-text-muted);
}
.login-status.error {
  color: var(--c-error);
  background: var(--c-error-bg);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(220, 38, 38, .15);
}
.login-status.info { color: var(--c-accent); }
.login-status.success { color: var(--c-success); }

.login-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 12px;
  color: var(--c-text-muted);
}
.login-footer a {
  color: var(--c-text-muted);
  text-decoration: none;
  border-bottom: 1px dashed var(--c-divider);
  padding-bottom: 1px;
}
.login-footer a:hover { color: var(--c-accent); border-bottom-color: var(--c-accent); }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .login-card { padding: 28px 22px; max-width: 100%; }
  .login-logo { max-width: 88px; max-height: 88px; }
  .login-logo img { width: 80px; height: 80px; }
  .login-logo svg { width: 60px; height: 60px; }
  .login-title { font-size: 19px; }
}

/* ── Reduced motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .login-card { animation: none; }
  body.login-modern::before,
  body.login-modern::after { animation: none; }
}

/* ── Tabs (login_step2) ───────────────────────────────────────────── */
.method-tabs {
  display: flex;
  gap: 6px;
  background: var(--c-input-bg);
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--c-input-border);
}
.method-tab {
  flex: 1;
  text-align: center;
  padding: 9px 8px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  text-decoration: none;
  color: var(--c-text-muted);
  transition: all var(--transition-fast);
}
.method-tab:hover { color: var(--c-text-on-glass); }
.method-tab.active {
  background: var(--c-card-bg);
  color: var(--c-accent);
  box-shadow: 0 2px 8px -2px rgba(0,0,0,.08);
}

/* ── Code grid (totp / recovery) ──────────────────────────────────── */
.totp-input {
  text-align: center;
  letter-spacing: .25em;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 22px !important;
  font-weight: 600;
}

/* ── Username chip ─────────────────────────────────────────────────── */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--c-input-bg);
  border: 1px solid var(--c-input-border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--c-text-on-glass);
  margin-bottom: 14px;
}
.user-chip .avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--c-fr-blue), var(--c-accent));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
