/**
 * MonAvec - Styles d'authentification
 * Design mobile-first
 */

/* ============================================
   PRELOADER
   ============================================ */
.preloader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.4s, visibility 0.4s;
}
.preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.dots-loader {
  display: flex;
  gap: 8px;
}
.dots-loader span {
  width: 12px;
  height: 12px;
  background: #10b981;
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite both;
}
.dots-loader span:nth-child(1) { animation-delay: -0.32s; }
.dots-loader span:nth-child(2) { animation-delay: -0.16s; }
.dots-loader span:nth-child(3) { animation-delay: 0s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ============================================
   VARIABLES & RESET
   ============================================ */
:root {
  --auth-input-height: 50px;
  --auth-btn-height: 54px;
  --auth-radius: 12px;
  --auth-radius-lg: 20px;
  --auth-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  --auth-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.2);
  --auth-transition: all 0.3s ease;
}

* {
  box-sizing: border-box;
}

/* ============================================
   BASE - MOBILE FIRST
   ============================================ */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  display: flex;
  flex-direction: column;
  background: var(--theme-gradient);
  padding: 0;
  margin: 0;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ============================================
   HEADER - MOBILE
   ============================================ */
.auth-header {
  padding: 40px 24px 30px;
  text-align: center;
  flex-shrink: 0;
}

.auth-logo {
  width: 72px;
  height: 72px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border-radius: var(--auth-radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.auth-logo i {
  font-size: 2rem;
  color: #fff;
}

.auth-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
  margin: 0 0 6px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.auth-header p {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.85);
  margin: 0;
}

/* ============================================
   FORM CONTAINER - MOBILE
   ============================================ */
.auth-form-container {
  flex: 1;
  background: #fff;
  border-radius: var(--auth-radius-lg) var(--auth-radius-lg) 0 0;
  padding: 32px 24px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.1);
}

.auth-form {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
}

.input-wrapper i.input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
  color: #9ca3af;
  transition: var(--auth-transition);
  pointer-events: none;
}

.form-control {
  width: 100%;
  height: var(--auth-input-height);
  padding: 0 16px 0 48px;
  font-size: 1rem;
  border: 2px solid #e5e7eb;
  border-radius: var(--auth-radius);
  background: #f9fafb;
  color: #1f2937;
  transition: var(--auth-transition);
  -webkit-appearance: none;
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--theme-primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(var(--theme-primary-rgb), 0.1);
}

.form-control:focus + i.input-icon,
.input-wrapper:focus-within i.input-icon {
  color: var(--theme-primary);
}

.form-control::placeholder {
  color: #9ca3af;
}

/* Password toggle */
.password-toggle {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: #9ca3af;
  font-size: 1.25rem;
  transition: var(--auth-transition);
}

.password-toggle:hover {
  color: var(--theme-primary);
}

.form-control.has-toggle {
  padding-right: 48px;
}

/* ============================================
   CHECKBOX - REMEMBER ME
   ============================================ */
.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-check-input {
  width: 20px;
  height: 20px;
  border: 2px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  accent-color: var(--theme-primary);
}

.form-check-label {
  font-size: 0.9rem;
  color: #6b7280;
  cursor: pointer;
}

.forgot-link {
  font-size: 0.9rem;
  color: var(--theme-primary);
  text-decoration: none;
  font-weight: 600;
}

.forgot-link:hover {
  text-decoration: underline;
}

/* ============================================
   SUBMIT BUTTON
   ============================================ */
.btn-submit {
  width: 100%;
  height: var(--auth-btn-height);
  background: var(--theme-gradient);
  border: none;
  border-radius: var(--auth-radius);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: var(--auth-transition);
  margin-top: auto;
  box-shadow: 0 4px 15px rgba(var(--theme-primary-rgb), 0.3);
}

.btn-submit:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(var(--theme-primary-rgb), 0.4);
}

.btn-submit:active {
  transform: translateY(0);
}

.btn-submit:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn-submit i {
  font-size: 1.25rem;
}

/* Loading spinner */
.btn-submit .spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================
   ALERTS
   ============================================ */
.alert {
  padding: 14px 16px;
  border-radius: var(--auth-radius);
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.9rem;
}

.alert i {
  font-size: 1.25rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
}

.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #16a34a;
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #2563eb;
}

/* ============================================
   FOOTER LINKS
   ============================================ */
.auth-footer {
  margin-top: 24px;
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #e5e7eb;
}

.auth-footer p {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: #6b7280;
}

.auth-footer a {
  color: var(--theme-primary);
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  font-size: 0.9rem;
  color: #6b7280;
  text-decoration: none;
}

.back-link:hover {
  color: var(--theme-primary);
}

/* ============================================
   DESKTOP STYLES (≥ 768px)
   ============================================ */
@media (min-width: 768px) {
  .auth-page {
    align-items: center;
    justify-content: center;
    padding: 40px;
  }

  .auth-wrapper {
    display: flex;
    width: 100%;
    max-width: 900px;
    background: #fff;
    border-radius: var(--auth-radius-lg);
    box-shadow: var(--auth-shadow-lg);
    overflow: hidden;
  }

  /* Left panel - Illustration */
  .auth-panel-left {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 45%;
    padding: 40px;
    background: var(--theme-gradient);
    color: #fff;
    text-align: center;
  }

  .auth-panel-left .auth-logo {
    width: 90px;
    height: 90px;
    margin-bottom: 24px;
  }

  .auth-panel-left .auth-logo i {
    font-size: 2.5rem;
  }

  .auth-panel-left h1 {
    font-size: 2rem;
    margin-bottom: 12px;
  }

  .auth-panel-left p {
    font-size: 1rem;
    opacity: 0.9;
    max-width: 280px;
  }

  .auth-panel-left .illustration {
    margin-top: 30px;
    font-size: 6rem;
    opacity: 0.2;
  }

  /* Right panel - Form */
  .auth-panel-right {
    width: 55%;
    padding: 50px 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .auth-panel-right .form-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0 0 8px;
  }

  .auth-panel-right .form-subtitle {
    font-size: 0.95rem;
    color: #6b7280;
    margin: 0 0 30px;
  }

  /* Hide mobile header on desktop */
  .auth-header.mobile-only {
    display: none;
  }

  .auth-form-container.mobile-only {
    display: none;
  }

  /* Desktop form adjustments */
  .auth-panel-right .form-group {
    margin-bottom: 24px;
  }

  .auth-panel-right .btn-submit {
    margin-top: 10px;
  }

  .auth-panel-right .auth-footer {
    margin-top: 30px;
  }
}

/* ============================================
   LARGE DESKTOP (≥ 1024px)
   ============================================ */
@media (min-width: 1024px) {
  .auth-wrapper {
    max-width: 1000px;
  }

  .auth-panel-left {
    width: 50%;
    padding: 60px;
  }

  .auth-panel-right {
    width: 50%;
    padding: 60px 50px;
  }
}

/* ============================================
   MOBILE ONLY - Hide desktop elements
   ============================================ */
@media (max-width: 767px) {
  .auth-wrapper {
    display: contents;
  }

  .auth-panel-left {
    display: none;
  }

  .auth-panel-right {
    display: none;
  }

  .desktop-only {
    display: none !important;
  }
}

/* ============================================
   UTILITIES
   ============================================ */
.text-center {
  text-align: center;
}

.mt-auto {
  margin-top: auto;
}

/* Safe area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .auth-form-container {
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }
}

/* Keyboard open - adjust layout */
@media (max-height: 500px) and (max-width: 767px) {
  .auth-header {
    padding: 20px 24px 15px;
  }

  .auth-logo {
    width: 50px;
    height: 50px;
  }

  .auth-logo i {
    font-size: 1.5rem;
  }

  .auth-header h1 {
    font-size: 1.25rem;
  }

  .auth-header p {
    display: none;
  }

  .auth-form-container {
    padding: 20px 24px;
  }

  .form-group {
    margin-bottom: 14px;
  }
}
