/* ===== CSS Custom Properties ===== */
:root {
  /* Light theme colors - default */
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --border-color: #e0e0e0;
  --input-bg: #f9fafb;
  --input-border: #d1d5db;
  --button-primary: #4f46e5;
  --button-hover: #4338ca;
  --button-active: #3730a3;
  --accent-color: #6366f1;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
  --error-color: #dc2626;
  --success-color: #16a34a;
}

/* Dark theme via data attribute */
html[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --border-color: #334155;
  --input-bg: #1e293b;
  --input-border: #475569;
  --button-primary: #6366f1;
  --button-hover: #818cf8;
  --button-active: #a5b4fc;
  --accent-color: #818cf8;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --error-color: #ef4444;
  --success-color: #22c55e;
}

/* Light theme via data attribute */
html[data-theme="light"] {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --border-color: #e0e0e0;
  --input-bg: #f9fafb;
  --input-border: #d1d5db;
  --button-primary: #4f46e5;
  --button-hover: #4338ca;
  --button-active: #3730a3;
  --accent-color: #6366f1;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
  --error-color: #dc2626;
  --success-color: #16a34a;
}

/* System dark theme preference fallback */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --input-bg: #1e293b;
    --input-border: #475569;
    --button-primary: #6366f1;
    --button-hover: #818cf8;
    --button-active: #a5b4fc;
    --accent-color: #818cf8;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --error-color: #ef4444;
    --success-color: #22c55e;
  }
}

/* ===== Global Styles ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Login page specific styles */
body:has(.login-container) {
  align-items: center;
  justify-content: center;
}

/* ===== Login Container ===== */
.login-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

/* Background decoration */
.bg-decoration {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
}

.blob {
  position: absolute;
  background: linear-gradient(135deg, var(--accent-color), var(--button-primary));
  opacity: 0.15;
  border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
  animation: float 8s ease-in-out infinite;
}

.blob-1 {
  width: 300px;
  height: 300px;
  top: -10%;
  left: -5%;
  animation-delay: 0s;
}

.blob-2 {
  width: 200px;
  height: 200px;
  bottom: -5%;
  right: -5%;
  animation-delay: 2s;
}

@keyframes float {
  0%,
  100% {
    transform: translate(0px, 0px);
  }
  50% {
    transform: translate(30px, -30px);
  }
}

/* ===== Login Form ===== */
.login-form {
  background-color: var(--bg-secondary);
  border-radius: 30px;
  padding: 50px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
  animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Header ===== */
.form-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo {
  font-size: 48px;
  margin-bottom: 15px;
  animation: bounce 0.6s ease-out;
}

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.form-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.form-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ===== Form Groups ===== */
.form-group {
  margin-bottom: 24px;
  animation: fadeInUp 0.6s ease-out;
  animation-fill-mode: both;
}

.form-group:nth-child(1) {
  animation-delay: 0.2s;
}

.form-group:nth-child(2) {
  animation-delay: 0.3s;
}

.form-group:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.label-icon {
  font-size: 16px;
}

/* ===== Input Fields ===== */
.form-input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--input-border);
  border-radius: 16px;
  background-color: var(--input-bg);
  color: var(--text-primary);
  font-size: 14px;
  transition: all 0.3s ease;
  padding-left: 45px;
  position: relative;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  font-size: 18px;
  color: var(--text-secondary);
  pointer-events: none;
  transition: color 0.3s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--button-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  background-color: var(--bg-secondary);
}

.form-input:focus + .input-icon {
  color: var(--button-primary);
}

.form-input::placeholder {
  color: var(--text-secondary);
}

/* ===== Password Toggle ===== */
.password-toggle {
  position: absolute;
  right: 14px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 18px;
  transition: color 0.3s ease;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-toggle:hover {
  color: var(--button-primary);
}

/* ===== Checkbox ===== */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.checkbox-input {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--button-primary);
  border-radius: 6px;
  transition: all 0.3s ease;
}

.checkbox-input:checked {
  background-color: var(--button-primary);
}

.checkbox-label {
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  flex: 1;
}

/* ===== Button ===== */
.btn-login {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--button-primary), var(--accent-color));
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  animation: fadeInUp 0.6s ease-out 0.5s both;
}

.btn-login:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-login:active {
  transform: translateY(0);
}

.btn-login:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-login::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn-login:active::before {
  width: 300px;
  height: 300px;
}

.btn-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Error Message ===== */
.error-message {
  background-color: rgba(220, 38, 38, 0.1);
  border: 1px solid var(--error-color);
  color: var(--error-color);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* ===== Success Message ===== */
.success-message {
  background-color: rgba(34, 197, 94, 0.1);
  border: 1px solid var(--success-color);
  color: var(--success-color);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideDown 0.4s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Footer ===== */
.form-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-secondary);
}

.form-footer p {
  margin-bottom: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .login-form {
    padding: 30px;
  }

  .form-title {
    font-size: 24px;
  }

  .logo {
    font-size: 40px;
  }

  .blob-1 {
    width: 200px;
    height: 200px;
  }

  .blob-2 {
    width: 150px;
    height: 150px;
  }

  .form-input {
    padding: 12px 14px;
    padding-left: 40px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* ===== Theme Toggle Button ===== */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, var(--button-primary), var(--accent-color));
  border: 2px solid var(--border-color);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  color: white;
  font-weight: bold;
  overflow: hidden;
  position: relative;
}

.theme-toggle:hover {
  transform: scale(1.15) rotate(20deg);
  box-shadow: var(--shadow-lg);
}

.theme-toggle:active {
  transform: scale(0.95) rotate(20deg);
}

.theme-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s ease;
  position: absolute;
  width: 100%;
  height: 100%;
  font-size: 24px;
}

.icon-sun {
  animation: rotateIn 0.4s ease-out forwards;
}

.icon-moon {
  animation: rotateOut 0.4s ease-out forwards;
}

@keyframes rotateIn {
  from {
    opacity: 0;
    transform: rotate(-180deg) scale(0);
  }
  to {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
}

@keyframes rotateOut {
  from {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
  to {
    opacity: 0;
    transform: rotate(180deg) scale(0);
  }
}

/* Animation for theme icon swap */
.theme-toggle.switching .icon-sun {
  animation: rotateOut 0.4s ease-out forwards;
}

.theme-toggle.switching .icon-moon {
  animation: rotateIn 0.4s ease-out forwards;
}

/* Pulse animation */
@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.7);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(99, 102, 241, 0);
  }
}

.theme-toggle::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%);
  animation: pulse 2s ease-in-out infinite;
}
