/* ============================================================
   LOGIN PAGE - FIX OVERFLOW & ENHANCED UI/UX
   ============================================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Prevent x-axis overflow on mobile - MUST be on html and body */
html {
  overflow-x: hidden;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #fff;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  padding: 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Animated background - FIX: use 100% and background-position to avoid overflow */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 255, 255, 0.04) 2px,
      rgba(255, 255, 255, 0.04) 4px
    );
  background-size: 40px 40px;
  animation: backgroundMove 25s linear infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes backgroundMove {
  0% { background-position: 0 0; }
  100% { background-position: 40px 40px; }
}

/* Login container - prevent overflow, match dashboard style */
.login-container {
  background: #fff;
  padding: 48px 40px;
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
  width: 100%;
  max-width: 420px;
  min-width: 0;
  text-align: center;
  position: relative;
  z-index: 1;
  animation: slideInUp 0.4s cubic-bezier(0, 0, 0.2, 1);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-container h2 {
  color: #1e293b;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 32px;
  letter-spacing: -0.02em;
}

.login-container h2::after {
  content: '';
  display: block;
  width: 48px;
  height: 3px;
  background: #2563eb;
  margin: 14px auto 0;
  border-radius: 2px;
}

.login-container form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  text-align: left;
}

.login-container .form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-container .form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #334155;
}

.login-container input {
  width: 100%;
  padding: 12px 16px;
  padding-right: 48px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: #1e293b;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-container input#email {
  padding-right: 16px;
}

.login-container input::placeholder {
  color: #94a3b8;
}

.login-container input:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.login-container .password-wrapper {
  position: relative;
  width: 100%;
}

.login-container .password-wrapper input {
  padding-right: 48px;
}

/* Password toggle */
.login-container .password-wrapper button[type="button"] {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: #64748b;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.login-container .password-wrapper button[type="button"]:hover {
  color: #1e293b;
  background: #f1f5f9;
}

/* Submit button */
.login-container button[type="submit"] {
  width: 100%;
  padding: 14px;
  border: none;
  background: #2563eb;
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 8px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  transition: background 0.2s, transform 0.15s;
}

.login-container button[type="submit"]:hover {
  background: #1d4ed8;
}

.login-container button[type="submit"]:active {
  transform: scale(0.99);
}

/* Error message */
#errorMsg {
  font-size: 0.875rem;
  margin-top: 16px;
  padding: 12px 14px;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: 8px;
  font-weight: 500;
  text-align: center;
  display: none;
}

#errorMsg:not(:empty) {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Loading state */
.login-container button[type="submit"].loading {
  pointer-events: none;
  opacity: 0.8;
}

.login-container button[type="submit"].loading span {
  visibility: hidden;
}

.login-container button[type="submit"].loading::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  margin: -10px 0 0 -10px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.login-container button[type="submit"] {
  position: relative;
}

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

/* Shake on error */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-6px); }
  20%, 40%, 60%, 80% { transform: translateX(6px); }
}

/* ========== Responsive - prevent x overflow ========== */
@media (max-width: 768px) {
  body {
    padding: 16px;
  }

  .login-container {
    max-width: min(420px, calc(100vw - 32px));
    padding: 40px 28px;
  }

  .login-container h2 {
    font-size: 1.35rem;
    margin-bottom: 28px;
  }

  .login-container input {
    padding: 12px 14px;
    font-size: 1rem;
  }

  .login-container .password-wrapper input {
    padding-right: 48px;
  }
}

@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  .login-container {
    max-width: min(100%, calc(100vw - 24px));
    padding: 32px 20px;
  }

  .login-container h2 {
    font-size: 1.25rem;
    margin-bottom: 24px;
  }

  .login-container input {
    padding: 12px 14px;
    font-size: 1rem;
  }

  .login-container button[type="submit"] {
    padding: 13px;
    font-size: 0.9375rem;
  }

  #errorMsg {
    font-size: 0.8125rem;
    padding: 10px 12px;
    margin-top: 14px;
  }
}

@media (max-width: 360px) {
  .login-container {
    padding: 24px 16px;
  }

  .login-container h2 {
    font-size: 1.125rem;
  }
}
