/* ============================================================
   AUTH / LOGIN SCREEN
   Full-screen dark background, radial glow, glassmorphism card
   ============================================================ */

/* ── Login Overlay ────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
  padding: 20px 24px;
  overflow-y: auto;
  transition: opacity 0.5s var(--ease-out-expo), visibility 0.5s;
}

#login-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ── Background Glow ─────────────────────── */
.login-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.login-bg::before {
  content: '';
  position: absolute;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(209, 16, 57, 0.12) 0%, rgba(209, 16, 57, 0.04) 40%, transparent 70%);
  border-radius: 50%;
  animation: loginGlowPulse 4s ease-in-out infinite;
}

.login-bg::after {
  content: '';
  position: absolute;
  bottom: -10%;
  left: 50%;
  transform: translateX(-50%);
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(209, 16, 57, 0.06) 0%, transparent 60%);
  border-radius: 50%;
  animation: loginGlowPulse 5s ease-in-out 1s infinite;
}

@keyframes loginGlowPulse {
  0%, 100% { opacity: 0.6; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.08); }
}

/* ── Floating Particles (CSS only) ────────── */
.login-particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.login-particle {
  position: absolute;
  width: 2px;
  height: 2px;
  background: rgba(209, 16, 57, 0.4);
  border-radius: 50%;
  animation: particleFloat linear infinite;
}

.login-particle:nth-child(1) { left: 10%; animation-duration: 12s; animation-delay: 0s; }
.login-particle:nth-child(2) { left: 25%; animation-duration: 15s; animation-delay: 2s; width: 3px; height: 3px; background: rgba(255, 45, 85, 0.3); }
.login-particle:nth-child(3) { left: 40%; animation-duration: 10s; animation-delay: 4s; }
.login-particle:nth-child(4) { left: 55%; animation-duration: 14s; animation-delay: 1s; width: 1.5px; height: 1.5px; }
.login-particle:nth-child(5) { left: 70%; animation-duration: 11s; animation-delay: 3s; background: rgba(255, 45, 85, 0.25); }
.login-particle:nth-child(6) { left: 85%; animation-duration: 13s; animation-delay: 5s; width: 2.5px; height: 2.5px; }
.login-particle:nth-child(7) { left: 15%; animation-duration: 16s; animation-delay: 6s; width: 1px; height: 1px; background: rgba(255,255,255,0.15); }
.login-particle:nth-child(8) { left: 60%; animation-duration: 9s; animation-delay: 2.5s; background: rgba(255,255,255,0.1); }

@keyframes particleFloat {
  0% {
    transform: translateY(100vh) scale(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
    transform: translateY(90vh) scale(1);
  }
  90% {
    opacity: 0.6;
  }
  100% {
    transform: translateY(-10vh) scale(0.5);
    opacity: 0;
  }
}

/* ── ECG Heartbeat Line ──────────────────── */
.login-ecg-wrap {
  position: absolute;
  bottom: 15%;
  left: 0;
  right: 0;
  height: 60px;
  overflow: hidden;
  opacity: 0.06;
  pointer-events: none;
}

.login-ecg-line {
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: ecgDraw 3s linear infinite;
}

@keyframes ecgDraw {
  0% { stroke-dashoffset: 600; }
  100% { stroke-dashoffset: 0; }
}

/* ── Login Content ───────────────────────── */
.login-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: visible;
}

/* ── Logo Section ────────────────────────── */
.login-logo {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-md);
  overflow: visible;
  flex-shrink: 0;
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(209, 16, 57, 0.2)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 20px rgba(209, 16, 57, 0.4)); transform: scale(1.03); }
}

.login-brand {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--red-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.login-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: var(--space-xl);
}

/* ── Glass Form Card ─────────────────────── */
.login-card {
  width: 100%;
  background: rgba(19, 19, 26, 0.7);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 32px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 0 60px rgba(209, 16, 57, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.login-title {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: var(--space-lg);
  color: var(--text-primary);
}

/* ── Floating Label Inputs ───────────────── */
.login-field {
  position: relative;
  margin-bottom: 16px;
}

.login-field-input {
  width: 100%;
  padding: 20px 20px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: #fff;
  font-size: 16px;
  font-family: var(--font-body);
  outline: none;
  transition: all 0.25s ease;
  appearance: none;
}

.login-field-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.login-field-label {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.4);
  pointer-events: none;
  transition: all 0.25s var(--ease-out-expo);
  transform-origin: left center;
}

/* Float up on focus or when input has value */
.login-field-input:focus + .login-field-label,
.login-field-input:not(:placeholder-shown) + .login-field-label {
  top: 10px;
  transform: translateY(0) scale(0.75);
  color: var(--red-accent);
  font-weight: 500;
}

.login-field-input:focus {
  border-color: #D11039;
  box-shadow: 0 0 0 3px rgba(209, 16, 57, 0.15);
  background: rgba(255, 255, 255, 0.08);
}

.login-field-input.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* Password toggle */
.login-field-toggle {
  position: absolute;
  right: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease;
}

.login-field-toggle:hover {
  color: var(--text-secondary);
}

/* ── Error Message ───────────────────────── */
.login-error {
  display: none;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  border-radius: var(--radius-sm);
  background: var(--error-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  font-size: 0.85rem;
  color: var(--error);
}

.login-error.visible {
  display: flex;
}

.login-error svg {
  flex-shrink: 0;
}

/* ── Login Button ────────────────────────── */
.login-btn {
  width: 100%;
  padding: 16px var(--space-lg);
  background: linear-gradient(135deg, var(--red-primary), var(--red-accent));
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.03em;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.25s ease;
  box-shadow: 0 4px 20px rgba(209, 16, 57, 0.25);
}

.login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(209, 16, 57, 0.35);
}

.login-btn:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 12px rgba(209, 16, 57, 0.2);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Loading spinner state */
.login-btn .btn-text { transition: opacity 0.2s ease; }

.login-btn .btn-spinner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.login-btn .btn-spinner::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: loginSpin 0.6s linear infinite;
}

@keyframes loginSpin {
  to { transform: rotate(360deg); }
}

.login-btn.loading .btn-text { opacity: 0; }
.login-btn.loading .btn-spinner { opacity: 1; }

/* Ripple on button */
.login-btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: scale(0);
  animation: ripple 0.6s ease-out;
  pointer-events: none;
}

/* ── Forgot Password ─────────────────────── */
.login-forgot {
  display: block;
  text-align: center;
  margin-top: var(--space-lg);
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color 0.2s ease;
}

.login-forgot:hover {
  color: var(--red-accent);
}

/* ── Footer ──────────────────────────────── */
.login-footer {
  margin-top: var(--space-xl);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ── Error Shake Animation ───────────────── */
@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.login-card.shake {
  animation: loginShake 0.5s ease-in-out;
}

/* ── Remember Me Checkbox ────────────────── */
.login-remember {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  -webkit-user-select: none;
  user-select: none;
}

.login-remember input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.login-remember input[type="checkbox"]:checked {
  background: var(--red-primary);
  border-color: var(--red-primary);
}

.login-remember input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ── Auth-aware visibility ───────────────── */
body.authenticated #login-screen {
  display: none;
}

body:not(.authenticated) #app {
  display: none;
}

body:not(.authenticated) #splash-screen {
  display: none;
}

/* Hide admin/scanner nav for non-admins */
.nav-item[data-nav="admin"],
.nav-item[data-nav="scanner"] {
  display: none !important;
}

body.role-admin .nav-item[data-nav="admin"],
body.role-superadmin .nav-item[data-nav="admin"],
body.role-admin .nav-item[data-nav="scanner"],
body.role-superadmin .nav-item[data-nav="scanner"] {
  display: flex !important;
}
