/* ========================================
   NON STRUTTURATI - STILI DEDICATI
   Overlay e form per utenti non strutturati
   ======================================== */

/* Overlay NS - ALLARGATO */
#nsLoginOverlay .admin-overlay-content {
    max-width: 780px !important;
    width: 95% !important;
    padding: 1px 1px 0 1px !important;
    overflow: hidden;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   HEADER ELEGANTE STILE ISTITUZIONALE
   ======================================== */

#nsLoginOverlay .overlay-header {
    background: linear-gradient(135deg, #003d7a 0%, #0066cc 100%);
    color: white;
    padding: 30px 40px;
    text-align: center;
    position: relative;
    margin: 0;
    border-radius: 14px 14px 0 0;
    flex-shrink: 0;
}

#nsLoginOverlay .overlay-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at top right, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
    pointer-events: none;
}

#nsLoginOverlay .overlay-logo-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

#nsLoginOverlay .overlay-logo {
    height: 50px;
    width: auto;
    filter: brightness(0) invert(1) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

#nsLoginOverlay .overlay-title {
    font-size: 24px;
    font-weight: 700;
    color: white;
    margin: 0 0 8px;
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#nsLoginOverlay .overlay-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
    position: relative;
    z-index: 1;
    font-weight: 400;
}

/* L'overlay-step occupa lo spazio disponibile */
#nsLoginOverlay .overlay-step {
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Header fisso */
#nsLoginOverlay .overlay-step > .overlay-header {
    flex-shrink: 0;
}

/* Contenuto scrollabile */
#nsLoginOverlay .overlay-step-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 25px 40px 30px 40px;
}

/* Per gli step senza wrapper (login, otp) */
#nsLoginOverlay #nsLoginStep,
#nsLoginOverlay #nsOtpStep,
#nsLoginOverlay #nsPendingStep {
    overflow-y: auto;
}

#nsLoginOverlay .overlay-form-intro {
    padding: 25px 40px 0 40px;
}

#nsLoginOverlay #nsLoginStep > form,
#nsLoginOverlay #nsOtpStep > form,
#nsLoginOverlay #nsOtpStep > .overlay-otp-info {
    margin: 0 40px;
}

#nsLoginOverlay #nsLoginStep > form {
    padding-bottom: 30px;
}

#nsLoginOverlay #nsOtpStep > form {
    padding-bottom: 30px;
}

#nsLoginOverlay #nsOtpStep > .overlay-back-btn {
    margin: 0 40px 30px 40px;
}

#nsLoginOverlay #nsPendingStep > .overlay-pending-message {
    padding: 30px 40px;
}

/* Form intro text */
#nsLoginOverlay .overlay-form-intro {
    text-align: center;
}

#nsLoginOverlay .overlay-form-intro p {
    color: #64748b;
    font-size: 15px;
    margin: 0 0 20px 0;
}

/* Form intro text */
#nsLoginOverlay .overlay-form-intro {
    text-align: center;
    margin-bottom: 20px;
}

#nsLoginOverlay .overlay-form-intro p {
    color: #64748b;
    font-size: 15px;
    margin: 0;
}

/* Target badge nell'header (sopra il titolo) */
#nsLoginOverlay .overlay-target-badge {
    position: relative;
    z-index: 1;
    margin-bottom: 15px;
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.9) 0%, rgba(245, 158, 11, 0.9) 100%);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Close button sopra l'header */
#nsLoginOverlay .overlay-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: white;
    z-index: 10;
}

#nsLoginOverlay .overlay-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Target badge arancione */
.overlay-target-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: linear-gradient(135deg, var(--cnr-blue) 0%, var(--cnr-light-blue) 100%);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: white;
    margin-bottom: 12px;
}

.overlay-target-badge.ns-badge {
    background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
}

/* Submit button NS (arancione) */
.overlay-submit-btn-ns {
    background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%) !important;
    box-shadow: 0 4px 15px rgba(217, 119, 6, 0.3) !important;
}

.overlay-submit-btn-ns:hover:not(:disabled) {
    background: linear-gradient(135deg, #b45309 0%, #d97706 100%) !important;
    box-shadow: 0 6px 20px rgba(217, 119, 6, 0.4) !important;
}

/* ========================================
   FORM RICHIESTA ACCESSO - LAYOUT GRID
   ======================================== */

#nsRequestStep {
    width: 100%;
}

#nsRequestStep .overlay-header {
    text-align: center;
    margin-bottom: 20px;
}

/* Alert warning migliorato */
#nsRequestStep .overlay-alert-warning {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 18px 22px;
    margin-bottom: 25px;
    border-radius: 12px;
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1px solid #fcd34d;
    border-left: 4px solid #f59e0b;
}

#nsRequestStep .overlay-alert-warning svg {
    flex-shrink: 0;
    margin-top: 2px;
}

#nsRequestStep .overlay-alert-warning strong {
    display: block;
    color: #92400e;
    font-size: 15px;
    margin-bottom: 4px;
}

#nsRequestStep .overlay-alert-warning p {
    color: #a16207;
    font-size: 13px;
    line-height: 1.5;
    margin: 0;
}

/* Form Grid Layout */
#nsRequestForm {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px 28px;
}

/* Campi che occupano tutta la larghezza */
#nsRequestForm > .overlay-input-group:nth-child(3),  /* Email */
#nsRequestForm > .overlay-input-group:nth-child(7),  /* Profilo */
#nsRequestForm > .overlay-submit-btn,
#nsRequestForm > .overlay-back-btn {
    grid-column: 1 / -1;
}

/* Input group styling */
#nsRequestForm .overlay-input-group {
    margin-bottom: 0;
}

#nsRequestForm .overlay-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 8px;
    letter-spacing: 0.2px;
}

#nsRequestForm .overlay-input {
    width: 100%;
    padding: 14px 18px;
    font-size: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

#nsRequestForm .overlay-input:hover {
    border-color: #cbd5e1;
}

#nsRequestForm .overlay-input:focus {
    outline: none;
    border-color: #f59e0b;
    background: white;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.1);
}

#nsRequestForm .overlay-input[readonly] {
    background: #f1f5f9;
    color: #64748b;
    cursor: not-allowed;
}

#nsRequestForm .overlay-input::placeholder {
    color: #94a3b8;
    font-size: 14px;
}

/* Field hint */
#nsRequestForm .overlay-field-hint {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: #64748b;
    font-style: italic;
    line-height: 1.4;
}

/* Submit button */
#nsRequestForm .overlay-submit-btn {
    margin-top: 10px;
    padding: 16px 28px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
}

/* Back button */
#nsRequestForm .overlay-back-btn {
    margin-top: 5px;
    padding: 12px;
    font-size: 14px;
    color: #64748b;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: color 0.2s ease;
}

#nsRequestForm .overlay-back-btn:hover {
    color: #f59e0b;
}

/* Error e Success alerts */
#nsRequestError,
#nsRequestSuccess {
    grid-column: 1 / -1;
    margin-bottom: 10px;
}

/* ========================================
   USER FOUND MESSAGE (OTP Step)
   ======================================== */

.overlay-user-found {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border: 1px solid #34d399;
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 18px;
    color: #065f46;
    font-size: 15px;
}

.overlay-user-found svg {
    color: #10b981;
    flex-shrink: 0;
}

.overlay-user-found strong {
    color: #047857;
}

/* ========================================
   PENDING REQUEST STEP
   ======================================== */

.overlay-pending-message {
    text-align: center;
    padding: 40px 30px;
}

.overlay-pending-icon {
    width: 90px;
    height: 90px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 3px solid #fcd34d;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 25px;
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.2);
}

.overlay-pending-icon svg {
    color: #d97706;
}

.overlay-pending-message h3 {
    color: #1e293b;
    font-size: 20px;
    font-weight: 700;
    margin: 0 0 15px;
}

.overlay-pending-message p {
    color: #64748b;
    font-size: 15px;
    line-height: 1.7;
    margin: 0 0 10px;
}

.overlay-pending-message p strong {
    color: #334155;
}

/* ========================================
   WARNING ALERT STYLE
   ======================================== */

.overlay-alert-warning {
    background: #fffbeb;
    border-left: 4px solid #f59e0b;
    color: #92400e;
}

.overlay-alert-warning svg {
    color: #f59e0b;
    flex-shrink: 0;
}

/* ========================================
   RESPONSIVE - Mobile
   ======================================== */

@media (max-width: 768px) {
    #nsLoginOverlay .admin-overlay-content {
        max-width: 95% !important;
        padding: 25px 20px !important;
    }

    #nsRequestForm {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    #nsRequestForm > .overlay-input-group:nth-child(3),
    #nsRequestForm > .overlay-input-group:nth-child(7),
    #nsRequestForm > .overlay-submit-btn,
    #nsRequestForm > .overlay-back-btn {
        grid-column: 1;
    }

    #nsLoginOverlay .overlay-title {
        font-size: 22px;
    }

    #nsRequestStep .overlay-alert-warning {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
}

/* ========================================
   TARGET WIDGET (Questionario Header)
   ======================================== */

.quest-target-widget {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 8px 18px;
    margin-bottom: 15px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: white;
}

.quest-target-widget svg {
    opacity: 0.9;
}

.quest-target-widget.target-non-strutturati {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.3) 0%, rgba(217, 119, 6, 0.2) 100%);
    border-color: rgba(245, 158, 11, 0.5);
}

/* ========================================
   AUTOCOMPLETE REFERENTE SCIENTIFICO
   ======================================== */

.referente-autocomplete-wrapper {
    position: relative;
    width: 100%;
}

.referente-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #e2e8f0;
    border-top: none;
    border-radius: 0 0 10px 10px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.referente-dropdown.active {
    display: block;
}

.referente-dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.referente-dropdown-item:last-child {
    border-bottom: none;
    border-radius: 0 0 8px 8px;
}

.referente-dropdown-item:hover,
.referente-dropdown-item.selected {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
}

.referente-dropdown-item-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #003d7a 0%, #0066cc 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.referente-dropdown-item-icon svg {
    color: white;
    width: 18px;
    height: 18px;
}

.referente-dropdown-item-info {
    flex: 1;
    min-width: 0;
}

.referente-dropdown-item-name {
    font-weight: 600;
    color: #1e293b;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.referente-dropdown-item-matricola {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
}

.referente-dropdown-empty {
    padding: 20px 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
}

.referente-dropdown-loading {
    padding: 16px;
    text-align: center;
    color: #64748b;
    font-size: 14px;
}

/* Input con dropdown aperto */
#nsReqReferente:focus + .referente-dropdown.active,
.referente-autocomplete-wrapper:focus-within .referente-dropdown.active {
    border-color: #f59e0b;
}

#nsReqReferente.has-selection {
    background: #f0fdf4;
    border-color: #22c55e;
}

