:root {
  /* Primary palette */
  --primary-500: #3b82f6; /* blue-500 */
  --primary-600: #2563eb; /* blue-600 */
  --primary-700: #1d4ed8; /* blue-700 */
  --secondary-500: #6366f1; /* indigo-500 */
  --secondary-600: #4f46e5; /* indigo-600 */

  /* Dark theme colors */
  --dark-bg: #0f172a; /* slate-900 */
  --dark-card: #1e293b; /* slate-800 */
  --dark-card-lighter: #334155; /* slate-700 */
  --dark-input: #1e293b;
  --dark-border: #334155;

  /* Text colors */
  --text-primary: #f8fafc; /* slate-50 */
  --text-secondary: #cbd5e1; /* slate-300 */
  --text-muted: #94a3b8; /* slate-400 */
  --white: #ffffff;

  /* Status */
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-400: #f87171;
  --green-500: #22c55e;

  /* Focus & Glow */
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --glow-blue: rgba(59, 130, 246, 0.4);
}

html, body { height: 100%; }

/* Ensure padding/border are included in width to avoid overflow */
*, *::before, *::after { box-sizing: border-box; }

/* Page background with dark gradient and animated mesh */
body.login-page {
  min-height: 100vh;
  margin: 0;
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text-primary);
  background: var(--dark-bg);
  background-image:
    radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.08) 0px, transparent 50%),
    radial-gradient(at 0% 100%, rgba(99, 102, 241, 0.08) 0px, transparent 50%);
}
body.login-page::before {
  content: "";
  position: absolute; inset: 0; pointer-events: none; opacity: .03;
  background-image:
    linear-gradient(var(--dark-card-lighter) 1px, transparent 1px),
    linear-gradient(90deg, var(--dark-card-lighter) 1px, transparent 1px);
  background-size: 50px 50px;
}

/* Decorative bubbles with glow effect */
.bg-bubble {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: .2;
}
.bg-bubble.b1 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--primary-500), transparent);
  top: -100px; left: -100px;
}
.bg-bubble.b2 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, var(--secondary-500), transparent);
  bottom: -80px; right: -80px;
}

/* Card with dark glassmorphism */
.login-card {
  width: 100%; max-width: 32rem; /* 512px */
  border-radius: 20px;
  background: rgba(30, 41, 59, 0.8); /* dark-card with transparency */
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(148, 163, 184, 0.1);
  box-shadow:
    0 0 0 1px rgba(59, 130, 246, 0.1),
    0 20px 25px -5px rgba(0, 0, 0, 0.4),
    0 10px 10px -5px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  z-index: 10;
}

.login-header {
  padding: 40px 32px;
  text-align: center;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.9), rgba(79, 70, 229, 0.9));
  position: relative;
  color: var(--white);
  width: 100%;
}
.login-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><defs><pattern id="grid" width="20" height="20" patternUnits="userSpaceOnUse"><path d="M 20 0 L 0 0 0 20" fill="none" stroke="rgba(255,255,255,0.05)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url("#grid#grid")"/></svg>');
  opacity: 0.5;
}

.brand-icon {
  width: 140px; height: 140px;
  border-radius: 28px;
  margin: 0 auto 24px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow:
    0 0 0 1px rgba(59, 130, 246, 0.2),
    0 10px 30px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  overflow: hidden;
  position: relative;
  z-index: 1;
}
.brand-icon img { max-width: 112px; max-height: 112px; object-fit: contain; }

.login-title {
  font-size: 30px;
  line-height: 1.2;
  font-weight: 700;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}
.login-subtitle {
  font-size: 14px;
  line-height: 1.5;
  opacity: .95;
  position: relative;
  z-index: 1;
}

.login-body { padding: 40px 32px; width: 100%; }
.login-welcome {
  font-size: 24px;
  line-height: 1.3;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.login-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

/* Form */
.form-label {
  font-size: 14px;
  line-height: 1.4;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: block;
}

.form-text {
  color: var(--text-muted);
  font-size: 13px;
}

/* Vertical spacing between fields */
.login-body .form-group { margin-bottom: 20px; }

.input-group { position: relative; }
.input-group .input-group-text { display: none; }

.form-control {
  width: 100%;
  height: 48px;
  background: var(--dark-input);
  border: 1px solid var(--dark-border);
  color: var(--text-primary);
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.4;
  padding: 12px 16px;
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
.form-control::placeholder {
  color: var(--text-muted);
}
.form-control:focus {
  outline: none;
  border-color: var(--primary-500);
  background: rgba(30, 41, 59, 0.7);
  box-shadow: 0 0 0 3px var(--glow-blue), 0 0 20px rgba(59, 130, 246, 0.2);
}
.form-control:hover {
  border-color: rgba(148, 163, 184, 0.3);
}
.form-control[disabled] {
  background: rgba(30, 41, 59, 0.5);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Inputs with icons */
.input-with-icon { position: relative; }
.input-icon-left {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 18px;
  pointer-events: none;
}
.input-icon-right {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 18px;
}
.input-with-icon .form-control { padding-left: 48px; padding-right: 48px; }

/* Icon button reset for better look */
.btn-icon {
  background: transparent;
  border: 0;
  padding: 6px;
  border-radius: 8px;
  line-height: 1;
  transition: all 150ms ease;
}
.btn-icon:focus {
  outline: 2px solid var(--glow-blue);
  outline-offset: 2px;
}
.btn-icon:hover {
  color: var(--text-secondary);
  background: rgba(148, 163, 184, 0.1);
}

/* Error state */
.form-control.is-invalid {
  border-color: var(--red-500);
}
.form-control.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
}
.form-error {
  margin-top: 8px;
  font-size: 14px;
  color: var(--red-400);
  display: none;
}

/* Alert messages */
.alert {
  border-radius: 10px;
  border: 1px solid;
  margin-bottom: 20px;
}
.alert-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--red-400);
}
.alert-danger .close {
  color: var(--red-400);
  opacity: 0.8;
}
.alert-danger .close:hover {
  opacity: 1;
}

/* Remember + links */
.inline-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.custom-control-label {
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
}
.custom-control-input:checked ~ .custom-control-label::before {
  background-color: var(--primary-500);
  border-color: var(--primary-500);
}
.custom-control-input:focus ~ .custom-control-label::before {
  box-shadow: 0 0 0 3px var(--glow-blue);
}
.link {
  color: var(--blue-400);
  text-decoration: none;
  font-weight: 500;
  transition: color 150ms ease;
}
.link:hover {
  color: var(--primary-500);
}
.link:focus {
  outline: 2px solid var(--glow-blue);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Button */
.btn-login {
  width: 100%;
  height: 56px;
  border-radius: 12px;
  border: 0;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: .3px;
  color: var(--white);
  background: linear-gradient(135deg, var(--primary-600), var(--secondary-600));
  box-shadow:
    0 0 0 1px rgba(59, 130, 246, 0.3),
    0 10px 30px rgba(0, 0, 0, 0.5),
    0 0 30px rgba(59, 130, 246, 0.3);
  transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}
.btn-login::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s;
}
.btn-login:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, var(--primary-500), var(--secondary-500));
  box-shadow:
    0 0 0 1px rgba(59, 130, 246, 0.5),
    0 15px 40px rgba(0, 0, 0, 0.6),
    0 0 50px rgba(59, 130, 246, 0.5);
}
.btn-login:hover::before {
  transform: translateX(100%);
}
.btn-login:active {
  transform: translateY(0);
}
.btn-login:focus {
  outline: none;
  box-shadow:
    0 0 0 3px var(--glow-blue),
    0 10px 30px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(59, 130, 246, 0.4);
}
.btn-login[disabled] {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

/* Loading spinner */
.btn-spinner { width: 20px; height: 20px; border: 2px solid #fff; border-top-color: transparent; border-radius: 50%; display: inline-block; margin-right: 8px; vertical-align: middle; animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .btn-login { transition: none; transform: none !important; }
  .btn-login:hover { transform: none !important; }
  .btn-spinner { animation: none; }
  .link { transition: none; }
}

/* Footer */
.login-footer {
  padding: 16px 32px;
  text-align: center;
  background: rgba(15, 23, 42, 0.5);
  color: var(--text-muted);
  font-size: 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}
.login-footer .lock {
  color: var(--text-muted);
  margin-right: 6px;
  font-size: 14px;
}

/* Responsive tweaks */
@media (max-width: 768px) {
  .login-header, .login-body { padding: 32px; }
}
@media (max-width: 480px) {
  .login-header, .login-body { padding: 24px; }
  .brand-icon { width: 96px; height: 96px; border-radius: 20px; }
  .brand-icon img { max-width: 64px; max-height: 64px; }
  .login-title { font-size: 24px; }
  .login-welcome { font-size: 20px; }
}

/* Accessibility helpers */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
