/* Import Modern Font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* CSS Variables - Design System */
:root {
  /* Colors - Neutral Pastel Sand Palette */
  --primary: hsl(40, 35%, 70%);
  /* Warm sand */
  --primary-light: hsl(40, 40%, 80%);
  --primary-dark: hsl(40, 30%, 60%);
  --secondary: hsl(35, 30%, 65%);
  /* Soft beige */
  --accent: hsl(45, 25%, 75%);
  /* Light sand accent */

  /* Background */
  --bg-gradient-start: hsl(40, 20%, 92%);
  --bg-gradient-end: hsl(35, 25%, 88%);

  /* Glass Effect */
  --glass-bg: rgba(255, 250, 240, 0.4);
  --glass-border: rgba(210, 190, 170, 0.3);
  --glass-shadow: rgba(150, 130, 110, 0.15);

  /* Text - Improved Visibility */
  --text-primary: hsl(30, 20%, 20%);
  /* Much darker for better contrast */
  --text-secondary: hsl(30, 15%, 35%);
  /* Darker secondary text */
  --text-muted: hsl(31, 12%, 50%);
  /* Darker muted text */


  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
  --spacing-xl: 3rem;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;

  /* Transitions */
  --transition-fast: 0.2s ease;
  --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  padding: var(--spacing-md);
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) rgba(210, 190, 170, 0.2);
}

/* Custom scrollbar styling */
body::-webkit-scrollbar {
  width: 12px;
}

body::-webkit-scrollbar-track {
  background: rgba(210, 190, 170, 0.2);
}

body::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 6px;
}

body::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
}

/* Animated Background Elements */
body::before,
body::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.3;
  animation: float 20s ease-in-out infinite;
  z-index: 0;
}

body::before {
  width: 500px;
  height: 500px;
  background: var(--primary);
  top: -250px;
  right: -250px;
  animation-delay: 0s;
}

body::after {
  width: 400px;
  height: 400px;
  background: var(--secondary);
  bottom: -200px;
  left: -200px;
  animation-delay: 5s;
}

@keyframes float {

  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }

  33% {
    transform: translate(50px, -50px) scale(1.1);
  }

  66% {
    transform: translate(-50px, 50px) scale(0.9);
  }
}

/* Container */
.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
}

/* Glass Card */
.portal-card {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  box-shadow: 0 20px 60px var(--glass-shadow), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.portal-header {
  text-align: center;
  margin-bottom: var(--spacing-xl);
  width: 100%;
}

/* Logo */
.logo {
  width: 12rem;
  height: 12rem;
  margin: 0 auto var(--spacing-md);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.5rem;
  padding: 3rem;
  box-sizing: border-box;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: pulse 3s ease-in-out infinite;
  overflow: hidden;
  /* Ensure content doesn't spill out */
}

.logo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  }

  50% {
    transform: scale(1.05);
    box-shadow: 0 15px 40px rgba(210, 180, 140, 0.4);
  }
}

.portal-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: var(--spacing-xs);
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transform: translateZ(0);
  will-change: transform;
  text-align: center;
  /* Enforce centering */
  width: 100%;
}

.portal-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 400;
  transform: translateZ(0);
  text-align: center;
  /* Enforce centering */
  width: 100%;
}

/* Form */
.portal-form {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

/* Form Group */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: var(--spacing-xs);
  transition: color var(--transition-fast);
  transform: translateZ(0);
}

.form-input {
  width: 100%;
  padding: var(--spacing-md);
  background: rgba(255, 250, 240, 0.5);
  border: 1px solid rgba(210, 190, 170, 0.3);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: all var(--transition-smooth);
  outline: none;
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-input:focus {
  background: rgba(255, 250, 240, 0.6);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(210, 180, 140, 0.25);
  transform: translateY(-2px);
}

.form-input:hover:not(:focus) {
  border-color: rgba(210, 190, 170, 0.5);
}

/* Select dropdown specific styling */
select.form-input {
  cursor: pointer;
}

/* Dropdown options - sand background with dark text for readability */
select.form-input option {
  background-color: hsl(40, 30%, 95%);
  color: hsl(30, 15%, 30%);
  padding: 8px;
}

/* Input with Icon */
.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: var(--spacing-md);
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  pointer-events: none;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}

.input-wrapper .form-input {
  padding-left: calc(var(--spacing-md) * 2.5);
}

.input-wrapper .form-input:focus~.input-icon {
  opacity: 1;
}

/* Error States */
.form-input.error {
  border-color: hsl(0, 80%, 60%);
  animation: shake 0.3s ease;
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

.error-message {
  color: hsl(0, 80%, 65%);
  font-size: 0.8rem;
  margin-top: calc(var(--spacing-xs) * -0.5);
  margin-left: var(--spacing-xs);
  display: none;
}

.form-input.error+.error-message {
  display: block;
}

.submit-btn {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  font-size: 1rem;
  font-weight: 600;
  color: hsl(30, 15%, 30%);
  cursor: pointer;
  transition: all var(--transition-smooth);
  margin-top: var(--spacing-sm);
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(210, 180, 140, 0.3);
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
}

.submit-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.submit-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 15px 40px rgba(210, 180, 140, 0.5);
}

.submit-btn:hover::before {
  left: 100%;
}

.submit-btn:active {
  transform: translateY(0);
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Loading State */
.submit-btn.loading {
  pointer-events: none;
}

.submit-btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Success Message */
.success-message {
  background: rgba(180, 160, 120, 0.8);
  border: 3px solid rgba(160, 140, 100, 0.9);
  border-radius: var(--radius-lg);
  padding: 3rem 2rem;
  text-align: center;
  color: hsl(30, 15%, 30%);
  display: none;
  animation: slideUp 0.4s ease-out;
  font-size: 1.3rem;
  box-shadow: 0 15px 60px rgba(180, 160, 120, 0.5), 0 0 30px rgba(180, 160, 120, 0.3);
  max-width: 600px;
  margin: 0 auto;
  font-weight: 500;
}

.success-message.show {
  display: block;
}

/* Footer */
.portal-footer {
  text-align: center;
  margin-top: var(--spacing-lg);
  padding-top: var(--spacing-md);
  border-top: 1px solid rgba(210, 190, 170, 0.3);
}

.footer-text {
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
}

.footer-link {
  color: var(--primary-light);
  text-decoration: none;
  transition: color var(--transition-fast);
  font-weight: 600;
}

.footer-link:hover {
  color: var(--accent);
}

/* Responsive Design */
@media (max-width: 640px) {
  body {
    padding: var(--spacing-sm);
  }

  .portal-card {
    padding: var(--spacing-lg) var(--spacing-md);
  }

  .portal-title {
    font-size: 1.75rem;
  }

  .portal-subtitle {
    font-size: 0.875rem;
  }

  .logo {
    width: 100px;
    height: 100px;
    font-size: 2.8rem;
  }

  .form-input {
    padding: var(--spacing-md);
    font-size: 16px;
    /* Prevents zoom on iOS */
  }

  .submit-btn {
    padding: var(--spacing-md);
    font-size: 1rem;
    min-height: 48px;
    /* Make button more touch-friendly */
  }

  body::before,
  body::after {
    filter: blur(80px);
  }
}

/* Extra small devices */
@media (max-width: 360px) {
  .portal-card {
    padding: var(--spacing-md);
  }

  .portal-title {
    font-size: 1.5rem;
  }

  .logo {
    width: 60px;
    height: 60px;
    font-size: 1.75rem;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {

  .form-input,
  .submit-btn {
    min-height: 44px;
    /* Ensure touch targets are at least 44x44px */
  }

  .submit-btn:hover {
    transform: none;
    /* Disable hover effects on touch devices */
  }

  .submit-btn:active {
    transform: scale(0.98);
  }
}

/* Specific override for Index Page to provide darker text */
.container {
  --text-primary: hsl(30, 15%, 30%);
  --text-secondary: hsl(30, 12%, 45%);
  --text-muted: hsl(30, 10%, 60%);
  --primary-light: hsl(40, 35%, 55%);
  /* Darker sand for links */
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(210, 190, 170, 0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.show {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: hsl(40, 30%, 95%);
  background: linear-gradient(135deg, hsl(40, 25%, 93%), hsl(35, 30%, 90%));
  padding: 2rem;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  border: 1px solid rgba(210, 190, 170, 0.3);
  box-shadow: 0 20px 50px rgba(150, 130, 110, 0.3);
  position: relative;
  color: hsl(30, 15%, 30%);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
  transform: translateY(0);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: rgba(100, 80, 60, 0.6);
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: hsl(30, 15%, 30%);
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Tablet and below (768px) */
@media (max-width: 768px) {
  :root {
    --spacing-xs: 0.375rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 0.75rem;
    --spacing-lg: 1rem;
    --spacing-xl: 1.5rem;
  }

  body {
    padding: var(--spacing-md);
  }

  .container {
    padding: var(--spacing-sm);
    min-height: 100vh;
  }

  .portal-card {
    padding: var(--spacing-lg);
    margin: 0;
    max-width: 100%;
  }

  .portal-header {
    margin-bottom: var(--spacing-lg);
  }

  .logo {
    width: 4rem;
    height: 4rem;
    font-size: 2rem;
  }

  .portal-title {
    font-size: 1.75rem;
    margin: var(--spacing-md) 0;
  }

  .portal-subtitle {
    font-size: 0.95rem;
  }

  /* Form optimizations for mobile */
  .form-input,
  .form-select {
    font-size: 16px;
    /* Prevents zoom on iOS */
    padding: 0.875rem var(--spacing-md);
    min-height: 48px;
    /* Touch-friendly */
  }

  .form-label {
    font-size: 0.9rem;
  }

  .submit-btn {
    padding: 1rem;
    font-size: 1rem;
    min-height: 48px;
    /* Touch-friendly */
  }

  /* Footer */
  .footer {
    margin-top: var(--spacing-lg);
    padding: var(--spacing-md);
  }

  .footer-text {
    font-size: 0.8rem;
  }

  /* Terms Modal */
  .modal-content {
    width: 95%;
    max-width: 95%;
    padding: var(--spacing-lg);
    max-height: 85vh;
  }

  .modal-header h2 {
    font-size: 1.25rem;
  }

  .modal-close {
    font-size: 1.75rem;
  }

  /* Success message */
  .success-message {
    padding: var(--spacing-lg);
    font-size: 0.95rem;
  }

  .success-message h2 {
    font-size: 1.5rem;
  }
}

/* Mobile phones and small tablets (767px and below) */
@media (max-width: 767px) {
  :root {
    --spacing-xs: 0.2rem;
    --spacing-sm: 0.3rem;
    --spacing-md: 0.4rem;
    --spacing-lg: 0.6rem;
    --spacing-xl: 0.8rem;
  }

  html,
  body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    /* Prevent body scroll */
  }

  body {
    padding: 0;
    align-items: stretch;
    background-attachment: fixed;
    /* Prevent background scroll */
  }

  .container {
    padding: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
  }

  .portal-card {
    padding: 1.5rem;
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .portal-header {
    margin-bottom: 0.4rem;
  }

  .logo {
    width: 5rem;
    height: 5rem;
    font-size: 1.2rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    box-sizing: border-box;
    /* Ensure padding doesn't affect total width */
  }

  .portal-title {
    font-size: 1.15rem;
    margin-bottom: 0.2rem;
  }

  .portal-subtitle {
    font-size: 0.75rem;
  }

  .form-group {
    margin-bottom: 0.3rem;
  }

  .form-label {
    font-size: 0.75rem;
    margin-bottom: 0.15rem;
  }

  .form-input,
  .form-select {
    padding: 0.5rem 0.4rem;
    font-size: 14px;
  }

  .input-wrapper .form-input {
    padding-left: 1.5rem;
  }

  .input-icon {
    font-size: 1rem;
    left: 0.4rem;
  }

  .submit-btn {
    padding: 0.65rem;
    font-size: 0.875rem;
    margin-top: 0.4rem;
  }

  .portal-footer {
    margin-top: 0.6rem;
    padding-top: 0.4rem;
  }

  .footer-text {
    font-size: 0.7rem;
    line-height: 1.3;
  }

  /* Stack form elements more compactly */
  .portal-form {
    gap: 0.2rem;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 600px) and (orientation: landscape) {
  .container {
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .portal-card {
    padding: var(--spacing-md);
  }

  .logo {
    width: 3rem;
    height: 3rem;
    font-size: 1.5rem;
  }

  .portal-title {
    font-size: 1.25rem;
    margin: var(--spacing-sm) 0;
  }

  .portal-subtitle {
    font-size: 0.8rem;
  }

  .portal-header {
    margin-bottom: var(--spacing-md);
  }

  .form-group {
    margin-bottom: var(--spacing-sm);
  }

  .footer {
    margin-top: var(--spacing-md);
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {

  /* Larger touch targets */
  .form-input,
  .form-select,
  .submit-btn {
    min-height: 48px;
  }

  /* Remove hover effects on touch devices */
  .submit-btn:hover {
    transform: none;
  }

  /* Better tap feedback */
  .submit-btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  .footer-link:active {
    opacity: 0.7;
  }

  /* Prevent text selection on buttons */
  .submit-btn,
  .footer-link {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
}

/* High DPI displays (Retina) */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
  .portal-card {
    border-width: 0.5px;
  }

  .form-input,
  .form-select {
    border-width: 0.5px;
  }
}

/* Dark mode support for mobile */
@media (prefers-color-scheme: dark) {

  /* Keep the sand theme but adjust for dark mode if needed */
  :root {
    --text-primary: hsl(40, 40%, 85%);
    --text-secondary: hsl(40, 30%, 70%);
    --glass-bg: rgba(255, 250, 240, 0.12);
  }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .floating-bg {
    animation: none !important;
  }
}

/* Print styles */
@media print {
  body {
    background: white;
  }

  .portal-card {
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .submit-btn,
  .footer-link {
    display: none;
  }

  .floating-bg {
    display: none;
  }
}