/**
 * ============================================
 * AUTH.CSS - Stili per autenticazione
 * ============================================
 * Login, registrazione, recupero password, reset password.
 * Sezioni: container, card, tab, form, role selector, alert, media query.
 * ============================================
 */

/* ============================================
   Container e background (full viewport)
   ============================================ */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-page-bg);
    padding: 2rem 1rem;
    position: relative;
    animation: fadeIn 0.6s ease-out;
    overflow-x: hidden;
    min-width: 280px;
}

/* Background decorativo con pattern sottile */
.auth-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 30%, rgba(255, 90, 95, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(0, 166, 153, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(252, 98, 45, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* Pattern texture sottile */
.auth-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.03) 2px,
            rgba(255, 255, 255, 0.03) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(255, 255, 255, 0.03) 2px,
            rgba(255, 255, 255, 0.03) 4px
        );
    pointer-events: none;
    z-index: 0;
}

/* Nota: fadeIn è definita in main.css */

/* ============================================
   Card e header (titolo, icona)
   ============================================ */
.auth-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-2xl);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 500px;
    overflow: hidden;
    position: relative;
    z-index: 1;
    border: 1px solid rgba(255, 255, 255, 0.8);
    animation: slideUp 0.6s ease-out;
    min-width: 280px;
}

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

.auth-header {
    background: var(--gradient-header);
    color: white;
    padding: var(--space-3xl);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.auth-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
    border-radius: 50%;
}

.auth-header::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -5%;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.08) 0%, transparent 70%);
    border-radius: 50%;
}

.auth-header__icon {
    margin-bottom: var(--space-md);
    position: relative;
    z-index: 1;
    display: inline-block;
    padding: var(--space-md);
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-full);
    backdrop-filter: blur(10px);
}

.auth-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: var(--space-sm);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1;
}

.auth-subtitle {
    opacity: 0.95;
    font-size: 1rem;
    position: relative;
    z-index: 1;
}

/* ============================================
   Tab Login / Registro (switch)
   ============================================ */
.auth-tabs {
    display: flex;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-light);
}

.auth-tab {
    flex: 1;
    padding: var(--space-lg) var(--space-md);
    text-align: center;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition-fast);
    position: relative;
    font-size: 0.9375rem;
}

.auth-tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.auth-tab.active {
    background: white;
    color: var(--primary-color);
}

.auth-tab.active::after {
    transform: scaleX(1);
}

.auth-tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.5);
    color: var(--text-primary);
}

/* ============================================
   Contenuto form (campi, label, pulsanti)
   ============================================ */
.auth-content {
    padding: var(--space-3xl);
    background: white;
}

.auth-form {
    display: none;
    animation: fadeInForm 0.4s ease-out;
}

.auth-form.active {
    display: block;
}

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

.form-group {
    margin-bottom: var(--space-xl);
}

/* Convenzione BEM: .form__input e .form__label sono alias di .form-input e .form-label in contesto auth */
.auth-card .form__label,
.form-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    font-size: 0.9375rem;
}

.auth-card .form__input,
.form-input {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    transition: var(--transition-fast);
    background: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
    cursor: text;
    caret-color: var(--text-primary);
    position: relative;
    z-index: 1;
    isolation: isolate;
}

.auth-card .form__input::placeholder,
.form-input::placeholder {
    color: var(--text-light);
}

.auth-card .form__input:focus,
.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(255, 90, 95, 0.1);
    background: white;
}

.auth-card .form__input:hover:not(:focus),
.form-input:hover:not(:focus) {
    border-color: var(--border-accent);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.auth-card .form__input:hover::placeholder,
.form-input:hover::placeholder {
    color: var(--text-light);
}

.form-button {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    margin-top: var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-weight: 600;
    font-size: 1rem;
    border-radius: var(--radius-lg);
    transition: var(--transition-fast);
}

.form-button svg {
    flex-shrink: 0;
}

.form-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 90, 95, 0.3);
}

/* ============================================
   Role Selector (Cliente / Provider)
   ============================================ */
.role-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    margin-top: var(--space-sm);
}

.role-option {
    display: block;
    cursor: pointer;
}

.role-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.role-option__content {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-lg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    transition: var(--transition-fast);
    text-align: left;
    height: 100%;
    min-height: 100px;
    box-sizing: border-box;
}

.role-option__content svg {
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: var(--transition-fast);
}

.role-option__content div {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.role-option__content strong {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.role-option__content span {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.role-option input[type="radio"]:checked + .role-option__content {
    border-color: var(--primary-color);
    background: var(--gradient-card-hover);
    box-shadow: 0 0 0 4px rgba(255, 90, 95, 0.1);
}

.role-option input[type="radio"]:checked + .role-option__content svg {
    color: var(--primary-color);
}

.role-option:hover .role-option__content {
    border-color: var(--border-accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.role-option input[type="radio"]:checked:hover + .role-option__content {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(255, 90, 95, 0.15), var(--shadow-md);
}

/* Campi aggiuntivi per ruolo Provider */
.provider-fields {
    animation: slideDown 0.3s ease-out;
    margin-top: var(--space-md);
}

.provider-fields.u-hidden {
    display: none !important;
    padding: var(--space-lg);
    background: rgba(255, 90, 95, 0.03);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 90, 95, 0.1);
}

.provider-fields .form-group {
    margin-bottom: var(--space-lg);
}

.provider-fields .form-group:last-child {
    margin-bottom: 0;
}

/* ============================================
   Link (recupero password, torna a login)
   ============================================ */
.auth-links {
    text-align: center;
    margin-top: 1.5rem;
}

.auth-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

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

.auth-link--inline {
    display: inline-block;
    margin-top: var(--space-sm);
    font-size: 0.875rem;
}

.auth-link-wrap {
    text-align: center;
    margin-top: var(--space-xl);
}

.auth-link-wrap .auth-link,
.auth-link-wrap .btn {
    display: inline-block;
}

/* ============================================
   Alert (errore, successo) e pulsante indietro
   ============================================ */
.alert {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-xl);
    font-weight: 500;
    font-size: 0.9375rem;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    animation: slideDown 0.3s ease-out;
}

.alert::before {
    content: '';
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.alert-error {
    background: linear-gradient(135deg, #fef2f2, #fee2e2);
    color: #dc2626;
    border: 2px solid #fecaca;
}

.alert-error::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23dc2626' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cline x1='12' y1='8' x2='12' y2='12'%3E%3C/line%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'%3E%3C/line%3E%3C/svg%3E");
}

.alert-success {
    background: linear-gradient(135deg, #f0fdf4, #d1fae5);
    color: #16a34a;
    border: 2px solid #bbf7d0;
}

.alert-success::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2316a34a' stroke-width='2'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
}

.back-home {
    position: absolute;
    top: var(--space-2xl);
    left: var(--space-2xl);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    transition: var(--transition-fast);
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.back-home:hover {
    background: white;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    color: var(--primary-color);
}

.back-home svg {
    transition: transform 0.3s ease;
}

.back-home:hover svg {
    transform: translateX(-4px);
}

/* ============================================
   MEDIA QUERIES - Mobile
   ============================================ */

@media (max-width: 991px) {
  /* Container principale */
  .auth-container {
    padding: var(--space-md) var(--space-sm);
    min-height: 100vh;
    align-items: flex-start;
    padding-top: var(--space-2xl);
  }

  /* Card auth */
  .auth-card {
    max-width: 100%;
    border-radius: var(--radius-xl);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    min-width: 280px;
  }

  /* Header auth */
  .auth-header {
    padding: var(--space-2xl) var(--space-lg);
  }

  .auth-header__icon {
    padding: var(--space-sm);
    margin-bottom: var(--space-sm);
  }

  .auth-header__icon svg {
    width: 40px;
    height: 40px;
  }

  .auth-title {
    font-size: 1.5rem;
    margin-bottom: var(--space-xs);
  }

  .auth-subtitle {
    font-size: 0.875rem;
  }

  /* Tabs */
  .auth-tabs {
    flex-wrap: nowrap;
  }

  .auth-tab {
    padding: var(--space-md) var(--space-sm);
    font-size: 0.875rem;
  }

  /* Content */
  .auth-content {
    padding: var(--space-xl) var(--space-lg);
  }

  /* Form groups */
  .form-group {
    margin-bottom: var(--space-lg);
  }

  .form-label {
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
  }

  .form-input {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9375rem;
    border-radius: var(--radius-md);
  }

  /* Form button */
  .form-button {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9375rem;
    margin-top: var(--space-md);
  }

  /* Role selector - stack verticale su mobile */
  .role-selector {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }

  .role-option__content {
    padding: var(--space-md);
    min-height: 80px;
    gap: var(--space-sm);
  }

  .role-option__content svg {
    width: 20px;
    height: 20px;
  }

  .role-option__content strong {
    font-size: 0.875rem;
  }

  .role-option__content span {
    font-size: 0.75rem;
  }

  /* Provider fields */
  .provider-fields {
    padding: var(--space-md);
    margin-top: var(--space-sm);
  }

  .provider-fields .form-group {
    margin-bottom: var(--space-md);
  }

  /* Back home button */
  .back-home {
    position: fixed;
    top: var(--space-md);
    left: var(--space-md);
    right: auto;
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.875rem;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }

  .back-home svg {
    width: 18px;
    height: 18px;
  }

  /* Alert */
  .alert {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    margin-bottom: var(--space-lg);
  }

  .alert::before {
    width: 18px;
    height: 18px;
  }
}

/* Mobile molto piccolo */
@media (max-width: 480px) {
  .auth-container {
    padding: var(--space-sm);
    padding-top: calc(var(--space-2xl) + 50px); /* Spazio per back-home button */
  }

  .auth-header {
    padding: var(--space-xl) var(--space-md);
  }

  .auth-title {
    font-size: 1.25rem;
  }

  .auth-subtitle {
    font-size: 0.8125rem;
  }

  .auth-content {
    padding: var(--space-lg) var(--space-md);
  }

  .form-input {
    font-size: 16px; /* Previene zoom su iOS */
  }

  .role-option__content {
    min-height: 70px;
    padding: var(--space-sm);
  }

  .back-home {
    top: var(--space-sm);
    left: var(--space-sm);
    font-size: 0.8125rem;
    padding: var(--space-xs) var(--space-xs);
  }

  .back-home span {
    display: none; /* Nascondi testo su schermi molto piccoli */
  }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
  @media screen and (max-width: 991px) {
    .auth-container {
      min-height: -webkit-fill-available;
    }

    .form-input {
      font-size: 16px; /* Previene zoom automatico su iOS */
    }
  }
}

/* ============================================
   DEV-AUTH - Accesso area sviluppo (public/auth/dev-auth.php)
   ============================================ */
.dev-auth-container {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 40px;
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.dev-auth-container form {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.dev-auth-header {
  text-align: center;
  margin-bottom: 30px;
}

.dev-auth-header h1 {
  color: #333;
  font-size: 24px;
  margin-bottom: 8px;
}

.dev-auth-header p {
  color: #666;
  font-size: 14px;
}

.dev-auth-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  color: #667eea;
  display: block;
}

.dev-auth-form-group {
  margin-bottom: 20px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.dev-auth-label {
  display: block;
  color: #333;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 14px;
}

.dev-auth-input {
  width: 100%;
  max-width: 100%;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
  background: #fff;
  color: #222;
  cursor: text;
  caret-color: #222;
  position: relative;
  z-index: 1;
  isolation: isolate;
  box-sizing: border-box;
  display: block;
}

.dev-auth-input::placeholder {
  color: #999;
}

.dev-auth-input:hover {
  border-color: #b0b0b0;
  background: #fff;
  color: #222;
}

.dev-auth-input:hover::placeholder {
  color: #999;
}

.dev-auth-input:focus {
  outline: none;
  border-color: #667eea;
  background: #fff;
  color: #222;
}

.dev-auth-btn {
  width: 100%;
  max-width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  display: block;
}

.dev-auth-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

.dev-auth-error {
  background: #fee;
  color: #c33;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
  border-left: 4px solid #c33;
}

body:has(.dev-auth-container) {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  margin: 0;
  box-sizing: border-box;
}

body:has(.dev-auth-container) *,
body:has(.dev-auth-container) *::before,
body:has(.dev-auth-container) *::after {
  box-sizing: border-box;
}

